Search in sources :

Example 1 with Configuration

use of org.exoplatform.container.xml.Configuration in project kernel by exoplatform.

the class PortalContainer method getConfigurationXML.

/**
 * @return returns the configuration of the container in XML format
 */
@Managed
@ManagedDescription("The configuration of the container in XML format.")
public String getConfigurationXML() {
    Configuration conf = getConfiguration();
    if (conf == null) {
        LOG.warn("The configuration of the PortalContainer could not be found");
        return null;
    }
    Configuration result = Configuration.merge(((ExoContainer) parent).getConfiguration(), conf);
    if (result == null) {
        LOG.warn("The configurations could not be merged");
        return null;
    }
    return result.toXML();
}
Also used : Configuration(org.exoplatform.container.xml.Configuration) ManagedDescription(org.exoplatform.management.annotations.ManagedDescription) Managed(org.exoplatform.management.annotations.Managed)

Example 2 with Configuration

use of org.exoplatform.container.xml.Configuration in project kernel by exoplatform.

the class RootContainer method dynamicReload.

private void dynamicReload() {
    final ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
    final Properties currentSystemProperties = System.getProperties();
    boolean hasChanged = false;
    Configuration newConfig = null;
    try {
        Thread.currentThread().setContextClassLoader(loadingCL);
        hasChanged = true;
        System.setProperties(loadingSystemProperties);
        ConfigurationManager cm = loadConfigurationManager(this, false);
        if (cm != null) {
            newConfig = cm.getConfiguration();
        }
    } catch (Exception e) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Could not load the new configuration of the root container", e);
        }
    } finally {
        if (hasChanged) {
            Thread.currentThread().setContextClassLoader(currentClassLoader);
            System.setProperties(currentSystemProperties);
        }
    }
    if (newConfig == null) {
        // We have no way to know if the configuration of the root container has changed so
        // we reload everything
        LOG.info("The new configuration of the root container could not be loaded," + " thus everything will be reloaded");
        reload();
        return;
    }
    Configuration currentConfig = getConfiguration();
    if (currentConfig == null) {
        // We have no way to know if the configuration of the root container has changed so
        // we reload everything
        LOG.info("The current configuration of the root container could not be loaded," + " thus everything will be reloaded");
        reload();
        return;
    }
    if (newConfig.getCurrentSize() != currentConfig.getCurrentSize() || newConfig.getCurrentHash() != currentConfig.getCurrentHash()) {
        // The root container has changed so we reload everything
        LOG.info("The configuration of the root container has changed," + " thus everything will be reloaded");
        reload();
        return;
    }
    LOG.info("The configuration of the root container did not change," + " thus only affected portal containers will be reloaded");
    for (String pc : portalContainer2Reload) {
        // At least one dependency has changed so we reload all the affected portal containers
        reload(pc);
    }
    onStartupComplete();
}
Also used : Configuration(org.exoplatform.container.xml.Configuration) Properties(java.util.Properties) ConfigurationManager(org.exoplatform.container.configuration.ConfigurationManager) ContainerException(org.exoplatform.container.spi.ContainerException) PrivilegedActionException(java.security.PrivilegedActionException)

Example 3 with Configuration

use of org.exoplatform.container.xml.Configuration in project kernel by exoplatform.

the class ConfigurationManagerImpl method addConfiguration.

private void addConfiguration(ServletContext context, URL url) {
    if (url == null)
        return;
    if (logEnabled && LOG_DEBUG)
        LOG.info("Add configuration " + url);
    try {
        contextPath = (new File(url.toString())).getParent() + "/";
        contextPath = contextPath.replaceAll("\\\\", "/");
    } catch (Exception e) {
        contextPath = null;
    }
    // Just to prevent some nasty bug to happen
    if (currentURL.get() != null) {
        throw new IllegalStateException("Would not expect that");
    } else {
        currentURL.set(url);
    }
    // 
    try {
        ConfigurationUnmarshaller unmarshaller = new ConfigurationUnmarshaller(profiles);
        Configuration conf = unmarshaller.unmarshall(url);
        if (configurations_ == null)
            configurations_ = conf;
        else
            configurations_.mergeConfiguration(conf);
        importConf(unmarshaller, conf);
    } catch (Exception ex) {
        LOG.error("Cannot process the configuration " + currentURL.get(), ex);
    } finally {
        currentURL.set(null);
    }
}
Also used : Configuration(org.exoplatform.container.xml.Configuration) File(java.io.File) IOException(java.io.IOException)

Example 4 with Configuration

use of org.exoplatform.container.xml.Configuration in project kernel by exoplatform.

the class ConfigurationUnmarshaller method unmarshall.

public Configuration unmarshall(final URL url) throws Exception {
    if (PropertyManager.isDevelopping()) {
        boolean valid = isValid(url);
        if (!valid) {
            LOG.info("The configuration file " + url + " was not found valid according to its XSD");
        }
    }
    // 
    DocumentBuilderFactory factory = null;
    try {
        // With Java 6, it's safer to precise the builder factory class name as it may result:
        // java.lang.AbstractMethodError: org.apache.xerces.dom.DeferredDocumentImpl.getXmlStandalone()Z
        // at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.setDocumentInfo(Unknown Source)
        Method dbfniMethod = DocumentBuilderFactory.class.getMethod("newInstance", String.class, ClassLoader.class);
        factory = (DocumentBuilderFactory) dbfniMethod.invoke(null, "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl", Thread.currentThread().getContextClassLoader());
    } catch (InvocationTargetException e) {
        Throwable cause = e.getCause();
        if (cause instanceof FactoryConfigurationError) {
            // do nothing and let try to instantiate later
            LOG.debug("Was not able to find document builder factory class in Java > 5, will use default", cause);
        } else {
            // Rethrow
            throw e;
        }
    } catch (NoSuchMethodException e) {
        if (LOG.isTraceEnabled()) {
            LOG.trace("An exception occurred: " + e.getMessage());
        }
    }
    // 
    if (factory == null) {
        factory = DocumentBuilderFactory.newInstance();
    }
    // 
    factory.setNamespaceAware(true);
    final DocumentBuilderFactory builderFactory = factory;
    try {
        return SecurityHelper.doPrivilegedExceptionAction(new PrivilegedExceptionAction<Configuration>() {

            public Configuration run() throws Exception {
                DocumentBuilder builder = builderFactory.newDocumentBuilder();
                Document doc = builder.parse(url.openStream());
                // Filter DOM
                ProfileDOMFilter filter = new ProfileDOMFilter(profiles);
                filter.process(doc.getDocumentElement());
                // SAX event stream -> String
                StringWriter buffer = new StringWriter();
                SAXTransformerFactory tf = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
                TransformerHandler hd = tf.newTransformerHandler();
                StreamResult result = new StreamResult(buffer);
                hd.setResult(result);
                Transformer serializer = tf.newTransformer();
                serializer.setOutputProperty(OutputKeys.ENCODING, "UTF8");
                serializer.setOutputProperty(OutputKeys.INDENT, "yes");
                // Transform -> SAX event stream
                SAXResult saxResult = new SAXResult(new NoKernelNamespaceSAXFilter(hd));
                // DOM -> Transform
                serializer.transform(new DOMSource(doc), saxResult);
                // Reuse the parsed document
                String document = buffer.toString();
                // Debug
                if (LOG.isTraceEnabled())
                    LOG.trace("About to parse configuration file " + document);
                // 
                IBindingFactory bfact = BindingDirectory.getFactory(Configuration.class);
                IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
                return (Configuration) uctx.unmarshalDocument(new StringReader(document), null);
            }
        });
    } catch (PrivilegedActionException pae) {
        Throwable cause = pae.getCause();
        if (cause instanceof JiBXException) {
            throw (JiBXException) cause;
        } else if (cause instanceof ParserConfigurationException) {
            throw (ParserConfigurationException) cause;
        } else if (cause instanceof IOException) {
            throw (IOException) cause;
        } else if (cause instanceof SAXException) {
            throw (SAXException) cause;
        } else if (cause instanceof IllegalArgumentException) {
            throw (IllegalArgumentException) cause;
        } else if (cause instanceof TransformerException) {
            throw (TransformerException) cause;
        } else if (cause instanceof TransformerConfigurationException) {
            throw (TransformerConfigurationException) cause;
        } else if (cause instanceof TransformerFactoryConfigurationError) {
            throw (TransformerFactoryConfigurationError) cause;
        } else if (cause instanceof RuntimeException) {
            throw (RuntimeException) cause;
        } else {
            throw new RuntimeException(cause);
        }
    }
}
Also used : TransformerHandler(javax.xml.transform.sax.TransformerHandler) DOMSource(javax.xml.transform.dom.DOMSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Transformer(javax.xml.transform.Transformer) Configuration(org.exoplatform.container.xml.Configuration) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IBindingFactory(org.jibx.runtime.IBindingFactory) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) TransformerFactoryConfigurationError(javax.xml.transform.TransformerFactoryConfigurationError) FactoryConfigurationError(javax.xml.parsers.FactoryConfigurationError) TransformerException(javax.xml.transform.TransformerException) TransformerFactoryConfigurationError(javax.xml.transform.TransformerFactoryConfigurationError) StreamResult(javax.xml.transform.stream.StreamResult) PrivilegedActionException(java.security.PrivilegedActionException) SAXTransformerFactory(javax.xml.transform.sax.SAXTransformerFactory) JiBXException(org.jibx.runtime.JiBXException) Method(java.lang.reflect.Method) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) TransformerException(javax.xml.transform.TransformerException) JiBXException(org.jibx.runtime.JiBXException) PrivilegedActionException(java.security.PrivilegedActionException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SAXParseException(org.xml.sax.SAXParseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) IUnmarshallingContext(org.jibx.runtime.IUnmarshallingContext) SAXResult(javax.xml.transform.sax.SAXResult) DocumentBuilder(javax.xml.parsers.DocumentBuilder)

Example 5 with Configuration

use of org.exoplatform.container.xml.Configuration in project kernel by exoplatform.

the class TestCollectionValue method getConfiguredCollection.

private XMLCollection getConfiguredCollection(String... profiles) throws Exception {
    Configuration config = getConfiguration("collection-configuration.xml", profiles);
    Component a = config.getComponent(InitParamsHolder.class.getName());
    ObjectParameter op = a.getInitParams().getObjectParam("test.configuration");
    XMLObject o = op.getXMLObject();
    XMLField xf = o.getField("role");
    return xf.getCollection();
}
Also used : XMLField(org.exoplatform.xml.object.XMLField) Configuration(org.exoplatform.container.xml.Configuration) ObjectParameter(org.exoplatform.container.xml.ObjectParameter) XMLObject(org.exoplatform.xml.object.XMLObject) Component(org.exoplatform.container.xml.Component)

Aggregations

Configuration (org.exoplatform.container.xml.Configuration)37 Component (org.exoplatform.container.xml.Component)9 ExternalComponentPlugins (org.exoplatform.container.xml.ExternalComponentPlugins)5 ObjectParameter (org.exoplatform.container.xml.ObjectParameter)4 InitParams (org.exoplatform.container.xml.InitParams)3 ValueParam (org.exoplatform.container.xml.ValueParam)3 IBindingFactory (org.jibx.runtime.IBindingFactory)3 IUnmarshallingContext (org.jibx.runtime.IUnmarshallingContext)3 File (java.io.File)2 IOException (java.io.IOException)2 URL (java.net.URL)2 PrivilegedActionException (java.security.PrivilegedActionException)2 InputStream (java.io.InputStream)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Properties (java.util.Properties)1