Author: remm Date: Thu Jun 26 13:03:04 2014 New Revision: 1605774 URL: http://svn.apache.org/r1605774 Log: Add back dead code.
Modified: tomcat/trunk/java/org/apache/catalina/storeconfig/StoreConfig.java Modified: tomcat/trunk/java/org/apache/catalina/storeconfig/StoreConfig.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/storeconfig/StoreConfig.java?rev=1605774&r1=1605773&r2=1605774&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/storeconfig/StoreConfig.java (original) +++ tomcat/trunk/java/org/apache/catalina/storeconfig/StoreConfig.java Thu Jun 26 13:03:04 2014 @@ -19,10 +19,16 @@ package org.apache.catalina.storeconfig; import java.io.PrintWriter; import java.net.URL; +import javax.management.MBeanServer; +import javax.management.MalformedObjectNameException; +import javax.management.ObjectName; + import org.apache.catalina.Context; import org.apache.catalina.Host; import org.apache.catalina.Server; import org.apache.catalina.Service; +import org.apache.catalina.core.StandardContext; +import org.apache.catalina.mbeans.MBeanUtils; import org.apache.juli.logging.Log; import org.apache.juli.logging.LogFactory; import org.apache.tomcat.util.res.StringManager; @@ -100,6 +106,121 @@ public class StoreConfig implements ISto } /** + * Store Server from Object Name (Catalina:type=Server) + * + * @param aServerName + * Server ObjectName + * @param backup + * @param externalAllowed + * s * + * @throws MalformedObjectNameException + */ + public synchronized void storeServer(String aServerName, boolean backup, + boolean externalAllowed) throws MalformedObjectNameException { + if (aServerName == null || aServerName.length() == 0) { + if (log.isErrorEnabled()) + log.error("Please, call with a correct server ObjectName!"); + return; + } + MBeanServer mserver = MBeanUtils.createServer(); + ObjectName objectName = new ObjectName(aServerName); + if (mserver.isRegistered(objectName)) { + try { + Server aServer = (Server) mserver.getAttribute(objectName, + "managedResource"); + StoreDescription desc = null; + desc = getRegistry().findDescription(StandardContext.class); + if (desc != null) { + boolean oldSeparate = desc.isStoreSeparate(); + boolean oldBackup = desc.isBackup(); + boolean oldExternalAllowed = desc.isExternalAllowed(); + try { + desc.setStoreSeparate(true); + desc.setBackup(backup); + desc.setExternalAllowed(externalAllowed); + store(aServer); + } finally { + desc.setStoreSeparate(oldSeparate); + desc.setBackup(oldBackup); + desc.setExternalAllowed(oldExternalAllowed); + } + } else { + store(aServer); + } + } catch (Exception e) { + if (log.isInfoEnabled()) + log.info("Object " + aServerName + + " is no a Server instance or store exception", e); + } + } else if (log.isInfoEnabled()) + log.info("Server " + aServerName + " not found!"); + } + + /** + * Store a Context from ObjectName + * + * @param aContextName + * MBean ObjectName + * @param backup + * @param externalAllowed + * @throws MalformedObjectNameException + */ + public synchronized void storeContext(String aContextName, boolean backup, + boolean externalAllowed) throws MalformedObjectNameException { + if (aContextName == null || aContextName.length() == 0) { + if (log.isErrorEnabled()) + log.error("Please, call with a correct context ObjectName!"); + return; + } + MBeanServer mserver = MBeanUtils.createServer(); + ObjectName objectName = new ObjectName(aContextName); + if (mserver.isRegistered(objectName)) { + try { + Context aContext = (Context) mserver.getAttribute(objectName, + "managedResource"); + URL configFile = aContext.getConfigFile(); + if (configFile != null) { + try { + StoreDescription desc = null; + desc = getRegistry().findDescription( + aContext.getClass()); + if (desc != null) { + boolean oldSeparate = desc.isStoreSeparate(); + boolean oldBackup = desc.isBackup(); + boolean oldExternalAllowed = desc + .isExternalAllowed(); + try { + desc.setStoreSeparate(true); + desc.setBackup(backup); + desc.setExternalAllowed(externalAllowed); + desc.getStoreFactory() + .store(null, -2, aContext); + } finally { + desc.setStoreSeparate(oldSeparate); + desc.setBackup(oldBackup); + desc.setBackup(oldExternalAllowed); + } + } + } catch (Exception e) { + log.error(e); + } + } else + log.error("Missing configFile at Context " + + aContext.getPath() + " to store!"); + } catch (Exception e) { + if (log.isInfoEnabled()) + log + .info( + "Object " + + aContextName + + " is no a context instance or store exception", + e); + } + } else if (log.isInfoEnabled()) + log.info("Context " + aContextName + " not found!"); + } + + /** * Write the configuration information for this entire <code>Server</code> * out to the server.xml configuration file. * --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org