Added: tomcat/sandbox/storeconfig7/src/main/java/org/apache/catalina/storeconfig/StoreLoader.java URL: http://svn.apache.org/viewvc/tomcat/sandbox/storeconfig7/src/main/java/org/apache/catalina/storeconfig/StoreLoader.java?rev=1401867&view=auto ============================================================================== --- tomcat/sandbox/storeconfig7/src/main/java/org/apache/catalina/storeconfig/StoreLoader.java (added) +++ tomcat/sandbox/storeconfig7/src/main/java/org/apache/catalina/storeconfig/StoreLoader.java Wed Oct 24 20:38:57 2012 @@ -0,0 +1,288 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.catalina.storeconfig; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; + +import org.apache.juli.logging.Log; +import org.apache.juli.logging.LogFactory; +import org.apache.tomcat.util.digester.Digester; +import org.xml.sax.SAXException; + +/** + * + * @author Peter Rossbach + * + * <b>XML Format </b> + * + * <pre> + * + * <Registry name="" encoding="UTF8" > + * <Description tag="Server" standard="true" default="true"/> + * tagClass="org.apache.catalina.core.StandardServer" + * storeFactory="org.apache.catalina.storeconfig.StandardServerSF"> + * <TransientAttributes> + * <Attribute></Attribute> + * </TransientAttributes> + * <TransientChilds> + * <Child></Child> + * </TransientChilds> + * </Description> + * ... + * </Tegistry> + * + * </pre> + * + * + * Convention: + * <ul> + * <li>Factories at subpackage <i>org.apache.catalina.core.storeconfig.xxxSF + * </i>.</li> + * <li>Element name are the unique Class name</li> + * <li>SF for StoreFactory</li> + * <li>standard implementation is false</li> + * </ul> + * other things: + * <ul> + * <li>Registry XML format is a very good option</li> + * <li>Store format is not fix</li> + * <li>We hope with the parent declaration we can build recursive child store + * operation //dream</li> + * <li>Problem is to access child data from array,collections or normal detail + * object</li> + * <li>Default definitions for Listener, Valve Resource? - Based on interface + * type!</li> + * </ul> + */ +public class StoreLoader { + private static Log log = LogFactory.getLog(StoreLoader.class); + + /** + * The <code>Digester</code> instance used to parse registry descriptors. + */ + protected static Digester digester = createDigester(); + + private StoreRegistry registry; + + private URL registryResource ; + + /** + * @return Returns the registry. + */ + public StoreRegistry getRegistry() { + return registry; + } + + /** + * @param registry + * The registry to set. + */ + public void setRegistry(StoreRegistry registry) { + this.registry = registry; + } + + /** + * Create and configure the Digester we will be using for setup store + * registry. + */ + protected static Digester createDigester() { + long t1 = System.currentTimeMillis(); + // Initialize the digester + Digester digester = new Digester(); + digester.setValidating(false); + digester.setClassLoader(StoreRegistry.class.getClassLoader()); + + // Configure the actions we will be using + digester.addObjectCreate("Registry", + "org.apache.catalina.storeconfig.StoreRegistry", "className"); + digester.addSetProperties("Registry"); + digester + .addObjectCreate("Registry/Description", + "org.apache.catalina.storeconfig.StoreDescription", + "className"); + digester.addSetProperties("Registry/Description"); + digester.addRule("Registry/Description", new StoreFactoryRule( + "org.apache.catalina.storeconfig.StoreFactoryBase", + "storeFactoryClass", + "org.apache.catalina.storeconfig.StoreAppender", + "storeAppenderClass")); + digester.addSetNext("Registry/Description", "registerDescription", + "org.apache.catalina.storeconfig.StoreDescription"); + digester.addCallMethod("Registry/Description/TransientAttribute", + "addTransientAttribute", 0); + digester.addCallMethod("Registry/Description/TransientChild", + "addTransientChild", 0); + + long t2 = System.currentTimeMillis(); + if (log.isDebugEnabled()) + log.debug("Digester for server-registry.xml created " + (t2 - t1)); + return (digester); + + } + + /** + * + * @param aFile + * @return The server file + */ + protected File serverFile(String aFile) { + + if (aFile == null || (aFile != null && aFile.length() < 1)) + aFile = "server-registry.xml"; + File file = new File(aFile); + if (!file.isAbsolute()) + file = new File(System.getProperty("catalina.base") + "/conf", + aFile); + try { + file = file.getCanonicalFile(); + } catch (IOException e) { + log.error(e); + } + return (file); + } + + /** + * Load Description from external source + * + * @param aURL + */ + public void load(String aURL) { + synchronized (digester) { + File aRegistryFile = serverFile(aURL); + try { + registry = (StoreRegistry) digester.parse(aRegistryFile); + registryResource = aRegistryFile.toURL(); + } catch (IOException e) { + log.error(e); + } catch (SAXException e) { + log.error(e); + } + } + + } + + /** + * Load from defaults + * <ul> + * <li>System Property URL catalina.storeregistry</li> + * <li>File $catalina.base/conf/server-registry.xml</li> + * <li>class resource org/apache/catalina/storeconfig/server-registry.xml + * </li> + * </ul> + */ + public void load() { + + InputStream is = null; + Throwable error = null; + registryResource = null ; + try { + String configUrl = getConfigUrl(); + if (configUrl != null) { + is = (new URL(configUrl)).openStream(); + if (log.isInfoEnabled()) + log + .info("Find registry server-registry.xml from system property at url " + + configUrl); + ; + registryResource = new URL(configUrl); + } + } catch (Throwable t) { + // Ignore + } + if (is == null) { + try { + File home = new File(getCatalinaBase()); + File conf = new File(home, "conf"); + File reg = new File(conf, "server-registry.xml"); + is = new FileInputStream(reg); + if (log.isInfoEnabled()) + log.info("Find registry server-registry.xml at file " + + reg.getCanonicalPath()); + ; + registryResource = reg.toURL() ; + } catch (Throwable t) { + // Ignore + } + } + if (is == null) { + try { + is = StoreLoader.class + .getResourceAsStream("/org/apache/catalina/storeconfig/server-registry.xml"); + if (log.isInfoEnabled()) + log + .info("Find registry server-registry.xml at classpath resource"); + registryResource = StoreLoader.class + .getResource("/org/apache/catalina/storeconfig/server-registry.xml"); + + } catch (Throwable t) { + // Ignore + } + } + if (is != null) { + try { + synchronized (digester) { + registry = (StoreRegistry) digester.parse(is); + } + } catch (Throwable t) { + error = t; + } finally { + try { + is.close(); + } catch (IOException e) { + } + } + } + if ((is == null) || (error != null)) { + log.error(error); + } + } + + /** + * Get the value of the catalina.home environment variable. + */ + private static String getCatalinaHome() { + return System.getProperty("catalina.home", System + .getProperty("user.dir")); + } + + /** + * Get the value of the catalina.base environment variable. + */ + private static String getCatalinaBase() { + return System.getProperty("catalina.base", getCatalinaHome()); + } + + /** + * Get the value of the configuration URL. + */ + private static String getConfigUrl() { + return System.getProperty("catalina.storeconfig"); + } + + + + /** + * @return Returns the registryResource. + */ + public URL getRegistryResource() { + return registryResource; + } +}
Added: tomcat/sandbox/storeconfig7/src/main/java/org/apache/catalina/storeconfig/StoreRegistry.java URL: http://svn.apache.org/viewvc/tomcat/sandbox/storeconfig7/src/main/java/org/apache/catalina/storeconfig/StoreRegistry.java?rev=1401867&view=auto ============================================================================== --- tomcat/sandbox/storeconfig7/src/main/java/org/apache/catalina/storeconfig/StoreRegistry.java (added) +++ tomcat/sandbox/storeconfig7/src/main/java/org/apache/catalina/storeconfig/StoreRegistry.java Wed Oct 24 20:38:57 2012 @@ -0,0 +1,210 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.catalina.storeconfig; + +import java.util.HashMap; +import java.util.Map; + +import javax.naming.directory.DirContext; + +import org.apache.catalina.LifecycleListener; +import org.apache.catalina.Manager; +import org.apache.catalina.Realm; +import org.apache.catalina.Valve; +import org.apache.catalina.ha.CatalinaCluster; +import org.apache.catalina.ha.ClusterDeployer; +import org.apache.catalina.ha.ClusterListener; +import org.apache.catalina.tribes.Channel; +import org.apache.catalina.tribes.ChannelInterceptor; +import org.apache.catalina.tribes.ChannelListener; +import org.apache.catalina.tribes.ChannelReceiver; +import org.apache.catalina.tribes.ChannelSender; +import org.apache.catalina.tribes.Member; +import org.apache.catalina.tribes.MembershipService; +import org.apache.catalina.tribes.MessageListener; +import org.apache.catalina.tribes.transport.DataSender; +import org.apache.juli.logging.Log; +import org.apache.juli.logging.LogFactory; + +/** + * Central StoreRegistry for all server.xml elements + * + * @author Peter Rossbach + * + */ +public class StoreRegistry { + private static Log log = LogFactory.getLog(StoreRegistry.class); + + private Map descriptors = new HashMap(); + + private String encoding = "UTF-8"; + + private String name; + + private String version; + + // Access Information + private static Class interfaces[] = { CatalinaCluster.class, + ChannelSender.class, ChannelReceiver.class, Channel.class, + MembershipService.class, ClusterDeployer.class, Realm.class, + Manager.class, DirContext.class, LifecycleListener.class, + Valve.class, ClusterListener.class, MessageListener.class, + DataSender.class, ChannelInterceptor.class, Member.class }; + + /** + * @return Returns the name. + */ + public String getName() { + return name; + } + + /** + * @param name + * The name to set. + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return Returns the version. + */ + public String getVersion() { + return version; + } + + /** + * @param version + * The version to set. + */ + public void setVersion(String version) { + this.version = version; + } + + /** + * Find a description for id. Handle interface search when no direct match + * found. + * + * @param id + * @return The description + */ + public StoreDescription findDescription(String id) { + if (log.isDebugEnabled()) + log.debug("search descriptor " + id); + StoreDescription desc = (StoreDescription) descriptors.get(id); + if (desc == null) { + Class aClass = null; + try { + aClass = Class.forName(id, true, this.getClass() + .getClassLoader()); + } catch (ClassNotFoundException e) { + log.error("ClassName:" + id, e); + } + if (aClass != null) { + desc = (StoreDescription) descriptors.get(aClass.getName()); + for (int i = 0; desc == null && i < interfaces.length; i++) { + if (interfaces[i].isAssignableFrom(aClass)) { + desc = (StoreDescription) descriptors.get(interfaces[i] + .getName()); + } + } + } + } + if (log.isDebugEnabled()) + if (desc != null) + log.debug("find descriptor " + id + "#" + desc.getTag() + "#" + + desc.getStoreFactoryClass()); + else + log.debug(("Can't find descriptor for key " + id)); + return desc; + } + + /** + * Find Description by class + * + * @param aClass + * @return The description + */ + public StoreDescription findDescription(Class aClass) { + return findDescription(aClass.getName()); + } + + /** + * Find factory from classname + * + * @param aClassName + * @return The factory + */ + public IStoreFactory findStoreFactory(String aClassName) { + StoreDescription desc = findDescription(aClassName); + if (desc != null) + return desc.getStoreFactory(); + else + return null; + + } + + /** + * find factory from class + * + * @param aClass + * @return The factory + */ + public IStoreFactory findStoreFactory(Class aClass) { + return findStoreFactory(aClass.getName()); + } + + /** + * Register a new description + * + * @param desc + */ + public void registerDescription(StoreDescription desc) { + String key = desc.getId(); + if (key == null || "".equals(key)) + key = desc.getTagClass(); + descriptors.put(key, desc); + if (log.isDebugEnabled()) + log.debug("register store descriptor " + key + "#" + desc.getTag() + + "#" + desc.getTagClass()); + } + + public StoreDescription unregisterDescription(StoreDescription desc) { + String key = desc.getId(); + if (key == null || "".equals(key)) + key = desc.getTagClass(); + return (StoreDescription) descriptors.remove(key); + } + + // Attributes + + /** + * @return The encoding + */ + public String getEncoding() { + return encoding; + } + + /** + * @param string + */ + public void setEncoding(String string) { + encoding = string; + } + +} Added: tomcat/sandbox/storeconfig7/src/main/java/org/apache/catalina/storeconfig/WatchedResourceSF.java URL: http://svn.apache.org/viewvc/tomcat/sandbox/storeconfig7/src/main/java/org/apache/catalina/storeconfig/WatchedResourceSF.java?rev=1401867&view=auto ============================================================================== --- tomcat/sandbox/storeconfig7/src/main/java/org/apache/catalina/storeconfig/WatchedResourceSF.java (added) +++ tomcat/sandbox/storeconfig7/src/main/java/org/apache/catalina/storeconfig/WatchedResourceSF.java Wed Oct 24 20:38:57 2012 @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.catalina.storeconfig; + +import java.io.PrintWriter; + +import org.apache.catalina.core.StandardContext; +import org.apache.juli.logging.Log; +import org.apache.juli.logging.LogFactory; + +/** + * @author Peter Rossbach + * + */ +public class WatchedResourceSF extends StoreFactoryBase { + private static Log log = LogFactory.getLog(WatchedResourceSF.class); + + /* + * Store nested Element Value Arrays WatchedResource + * + * @see org.apache.catalina.config.IStoreFactory#store(java.io.PrintWriter, + * int, java.lang.Object) + */ + public void store(PrintWriter aWriter, int indent, Object aElement) + throws Exception { + if (aElement instanceof StandardContext) { + StoreDescription elementDesc = getRegistry().findDescription( + aElement.getClass().getName() + ".[WatchedResource]"); + String[] resources = ((StandardContext) aElement) + .findWatchedResources(); + if (elementDesc != null) { + if (log.isDebugEnabled()) + log.debug("store " + elementDesc.getTag() + "( " + aElement + + " )"); + getStoreAppender().printTagArray(aWriter, "WatchedResource", + indent, resources); + } + } else + log.warn("Descriptor for element" + aElement.getClass() + + ".[WatchedResource] not configured!"); + } +} \ No newline at end of file Added: tomcat/sandbox/storeconfig7/src/main/java/org/apache/catalina/storeconfig/WrapperLifecycleSF.java URL: http://svn.apache.org/viewvc/tomcat/sandbox/storeconfig7/src/main/java/org/apache/catalina/storeconfig/WrapperLifecycleSF.java?rev=1401867&view=auto ============================================================================== --- tomcat/sandbox/storeconfig7/src/main/java/org/apache/catalina/storeconfig/WrapperLifecycleSF.java (added) +++ tomcat/sandbox/storeconfig7/src/main/java/org/apache/catalina/storeconfig/WrapperLifecycleSF.java Wed Oct 24 20:38:57 2012 @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.catalina.storeconfig; + +import java.io.PrintWriter; + +import org.apache.catalina.core.StandardContext; +import org.apache.juli.logging.Log; +import org.apache.juli.logging.LogFactory; + +/** + * @author Peter Rossbach + * + */ +public class WrapperLifecycleSF extends StoreFactoryBase { + private static Log log = LogFactory.getLog(WrapperLifecycleSF.class); + + /* + * Store nested Element Value Arrays + * + * @see org.apache.catalina.config.IStoreFactory#store(java.io.PrintWriter, + * int, java.lang.Object) + */ + public void store(PrintWriter aWriter, int indent, Object aElement) + throws Exception { + if (aElement instanceof StandardContext) { + StoreDescription elementDesc = getRegistry().findDescription( + aElement.getClass().getName() + ".[WrapperLifecycle]"); + String[] listeners = ((StandardContext) aElement) + .findWrapperLifecycles(); + if (elementDesc != null) { + if (log.isDebugEnabled()) + log.debug("store " + elementDesc.getTag() + "( " + aElement + + " )"); + getStoreAppender().printTagArray(aWriter, "WrapperLifecycle", + indent, listeners); + } + } else + log.warn("Descriptor for element" + aElement.getClass() + + ".[WrapperLifecycle] not configured!"); + } +} \ No newline at end of file Added: tomcat/sandbox/storeconfig7/src/main/java/org/apache/catalina/storeconfig/WrapperListenerSF.java URL: http://svn.apache.org/viewvc/tomcat/sandbox/storeconfig7/src/main/java/org/apache/catalina/storeconfig/WrapperListenerSF.java?rev=1401867&view=auto ============================================================================== --- tomcat/sandbox/storeconfig7/src/main/java/org/apache/catalina/storeconfig/WrapperListenerSF.java (added) +++ tomcat/sandbox/storeconfig7/src/main/java/org/apache/catalina/storeconfig/WrapperListenerSF.java Wed Oct 24 20:38:57 2012 @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.catalina.storeconfig; + +import java.io.PrintWriter; + +import org.apache.catalina.core.StandardContext; +import org.apache.juli.logging.Log; +import org.apache.juli.logging.LogFactory; + +/** + * @author Peter Rossbach (p...@apache.org) + * + */ +public class WrapperListenerSF extends StoreFactoryBase { + private static Log log = LogFactory.getLog(WrapperListenerSF.class); + + /* + * Store nested Element Value Arrays + * + * @see org.apache.catalina.config.IStoreFactory#store(java.io.PrintWriter, + * int, java.lang.Object) + */ + public void store(PrintWriter aWriter, int indent, Object aElement) + throws Exception { + if (aElement instanceof StandardContext) { + StoreDescription elementDesc = getRegistry().findDescription( + aElement.getClass().getName() + ".[WrapperListener]"); + String[] listeners = ((StandardContext) aElement) + .findWrapperListeners(); + if (elementDesc != null) { + if (log.isDebugEnabled()) + log.debug("store " + elementDesc.getTag() + "( " + aElement + + " )"); + getStoreAppender().printTagArray(aWriter, "WrapperListener", + indent, listeners); + } + } else + log.warn("Descriptor for element" + aElement.getClass() + + ".[WrapperListener] not configured!"); + } +} \ No newline at end of file Added: tomcat/sandbox/storeconfig7/src/main/resources/org/apache/catalina/storeconfig/LocalStrings.properties URL: http://svn.apache.org/viewvc/tomcat/sandbox/storeconfig7/src/main/resources/org/apache/catalina/storeconfig/LocalStrings.properties?rev=1401867&view=auto ============================================================================== --- tomcat/sandbox/storeconfig7/src/main/resources/org/apache/catalina/storeconfig/LocalStrings.properties (added) +++ tomcat/sandbox/storeconfig7/src/main/resources/org/apache/catalina/storeconfig/LocalStrings.properties Wed Oct 24 20:38:57 2012 @@ -0,0 +1,17 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +factory.storeTag=store tag {0} ( Object: {1} ) +factory.storeNoDescriptor=Descriptor for element class {0} not configured! Added: tomcat/sandbox/storeconfig7/src/main/resources/org/apache/catalina/storeconfig/mbeans-descriptors.xml URL: http://svn.apache.org/viewvc/tomcat/sandbox/storeconfig7/src/main/resources/org/apache/catalina/storeconfig/mbeans-descriptors.xml?rev=1401867&view=auto ============================================================================== Binary file - no diff available. Propchange: tomcat/sandbox/storeconfig7/src/main/resources/org/apache/catalina/storeconfig/mbeans-descriptors.xml ------------------------------------------------------------------------------ svn:mime-type = application/xml Added: tomcat/sandbox/storeconfig7/src/main/resources/org/apache/catalina/storeconfig/server-registry.xml URL: http://svn.apache.org/viewvc/tomcat/sandbox/storeconfig7/src/main/resources/org/apache/catalina/storeconfig/server-registry.xml?rev=1401867&view=auto ============================================================================== Binary file - no diff available. Propchange: tomcat/sandbox/storeconfig7/src/main/resources/org/apache/catalina/storeconfig/server-registry.xml ------------------------------------------------------------------------------ svn:mime-type = application/xml --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org