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();
}
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();
}
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);
}
}
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);
}
}
}
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();
}
Aggregations