Search in sources :

Example 21 with Configuration

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

the class TestRemoveConfigProfile method testNoProfile.

public void testNoProfile() throws Exception {
    Configuration config = getConfiguration("remove-configuration.xml");
    assertEquals(1, config.getRemoveConfiguration().size());
}
Also used : Configuration(org.exoplatform.container.xml.Configuration)

Example 22 with Configuration

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

the class TestRemoveConfigProfile method testFooBarProfiles.

public void testFooBarProfiles() throws Exception {
    Configuration config = getConfiguration("remove-configuration.xml", "foo", "bar");
    assertEquals(3, config.getRemoveConfiguration().size());
}
Also used : Configuration(org.exoplatform.container.xml.Configuration)

Example 23 with Configuration

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

the class TestConfigurationXML method testTrimValue.

@SuppressWarnings("unchecked")
public void testTrimValue() throws Exception {
    InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("test-trim-value.xml");
    assertNotNull(is);
    try {
        IBindingFactory bfact = BindingDirectory.getFactory(XMLObject.class);
        IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
        Configuration conf = (Configuration) uctx.unmarshalDocument(is, null);
        assertNotNull(conf);
        Iterator it = conf.getContainerLifecyclePluginIterator();
        assertNotNull(it);
        assertTrue(it.hasNext());
        ContainerLifecyclePlugin conlp = (ContainerLifecyclePlugin) it.next();
        assertEquals("container-lifecycle-plugin-type", conlp.getType());
        assertNotNull(conlp.getInitParams());
        assertEquals("container-lifecycle-plugin-value-param-value", (conlp.getInitParams().getValueParam("container-lifecycle-plugin-value-param-name")).getValue());
        it = conf.getComponentLifecyclePluginIterator();
        assertNotNull(it);
        assertTrue(it.hasNext());
        ComponentLifecyclePlugin comlp = (ComponentLifecyclePlugin) it.next();
        assertEquals("component-lifecycle-plugin", comlp.getType());
        ManageableComponents mc = comlp.getManageableComponents();
        assertNotNull(mc);
        assertEquals("manageable-components-component-type", mc.getComponentsType().get(0));
        ValuesParam valuesParam = comlp.getInitParams().getValuesParam("component-lifecycle-plugin-values-param-name");
        assertNotNull(valuesParam);
        assertNotNull(valuesParam.getValues());
        assertTrue(valuesParam.getValues().contains("component-lifecycle-plugin-values-param-value1"));
        assertTrue(valuesParam.getValues().contains("component-lifecycle-plugin-values-param-value2"));
        Component c = conf.getComponent("component-key1");
        assertNotNull(c);
        assertEquals("component-type1", c.getType());
        PropertiesParam propertiesParam = c.getInitParams().getPropertiesParam("component-key1-properties-param-name");
        assertNotNull(propertiesParam);
        assertEquals("component-key1-properties-param-prop-value", propertiesParam.getProperty("component-key1-properties-param-prop-name"));
        c = conf.getComponent("component-type2");
        assertNotNull(c);
        ObjectParameter objectParameter = c.getInitParams().getObjectParam("component-key2-object-param-name");
        assertNotNull(objectParameter);
        MyObject o = (MyObject) objectParameter.getObject();
        assertNotNull(o);
        assertEquals("string-value", o.field1);
        assertEquals(1, o.field2);
        assertEquals(1l, o.field3);
        assertEquals(1d, o.field4);
        assertEquals(true, o.field5);
        assertNotNull(o.field6);
        assertEquals("entry-value", o.field6.get("entry-name"));
        assertNotNull(o.field7);
        assertTrue(o.field7.contains("string-value"));
        assertNotNull(o.field8);
        assertEquals(1, o.field8[0]);
        List list = c.getComponentPlugins();
        assertNotNull(list);
        assertFalse(list.isEmpty());
        ComponentPlugin cp = (ComponentPlugin) list.get(0);
        assertEquals("component-plugins-name", cp.getName());
        assertEquals("set-method-name", cp.getSetMethod());
        assertEquals("component-plugins-type", cp.getType());
        assertEquals(1, cp.getPriority());
        it = conf.getExternalComponentPluginsIterator();
        assertNotNull(it);
        assertTrue(it.hasNext());
        ExternalComponentPlugins ecps = (ExternalComponentPlugins) it.next();
        assertEquals("target-component-name", ecps.getTargetComponent());
        list = ecps.getComponentPlugins();
        assertNotNull(list);
        assertFalse(list.isEmpty());
        cp = (ComponentPlugin) list.get(0);
        assertEquals("component-plugins-name", cp.getName());
        assertEquals("set-method-name", cp.getSetMethod());
        assertEquals("component-plugins-type", cp.getType());
        assertEquals(1, cp.getPriority());
        list = conf.getImports();
        assertNotNull(list);
        assertFalse(list.isEmpty());
        assertEquals("import-value", list.get(0));
        list = conf.getRemoveConfiguration();
        assertNotNull(list);
        assertFalse(list.isEmpty());
        assertEquals("remove-configuration-value", list.get(0));
    } finally {
        try {
            is.close();
        } catch (Exception e) {
        // ignore me
        }
    }
}
Also used : ComponentPlugin(org.exoplatform.container.xml.ComponentPlugin) Configuration(org.exoplatform.container.xml.Configuration) IBindingFactory(org.jibx.runtime.IBindingFactory) InputStream(java.io.InputStream) PropertiesParam(org.exoplatform.container.xml.PropertiesParam) ContainerLifecyclePlugin(org.exoplatform.container.xml.ContainerLifecyclePlugin) IUnmarshallingContext(org.jibx.runtime.IUnmarshallingContext) ComponentLifecyclePlugin(org.exoplatform.container.xml.ComponentLifecyclePlugin) ValuesParam(org.exoplatform.container.xml.ValuesParam) ExternalComponentPlugins(org.exoplatform.container.xml.ExternalComponentPlugins) ObjectParameter(org.exoplatform.container.xml.ObjectParameter) Iterator(java.util.Iterator) List(java.util.List) ManageableComponents(org.exoplatform.container.xml.ManageableComponents) Component(org.exoplatform.container.xml.Component)

Example 24 with Configuration

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

the class ExoContainer method getExternalComponentPluginsUnused.

/**
 * Gives all the {@link ExternalComponentPlugins} that have not been used, <code>null</code>
 * if there are all used.
 */
protected Collection<ExternalComponentPlugins> getExternalComponentPluginsUnused() {
    Configuration configuration = getConfiguration();
    if (configuration == null)
        return null;
    Collection<ExternalComponentPlugins> result = null;
    for (Iterator<ExternalComponentPlugins> it = configuration.getExternalComponentPluginsIterator(); it.hasNext(); ) {
        ExternalComponentPlugins plugins = it.next();
        boolean toAdd = false;
        String target = plugins.getTargetComponent();
        if (target == null)
            toAdd = true;
        else if (configuration.getComponent(target) == null) {
            try {
                Class<?> c = ClassLoading.loadClass(target, ExoContainer.class);
                if (c.isAnnotation()) {
                // We assume that the target is a qualifier so we cannot know if it is normal
                // or not as it could be auto-registered and we don't know the bind type
                } else if (getComponentAdapterOfType(c) == null) {
                    // There is no ComponentAdapter corresponding to this
                    // particular class even the auto-registration could
                    // not allow to find a candidate so we can consider it
                    // as unused
                    toAdd = true;
                }
            } catch (ClassNotFoundException e) {
                if (LOG.isTraceEnabled())
                    LOG.trace("The class {} could not be found", target);
            // We assume that the target is meant to be used with
            // the annotation Named so we cannot know if it is normal
            // or not as it could be auto-registered and we don't know
            // the bind type
            }
        }
        if (toAdd) {
            if (result == null) {
                result = new ArrayList<ExternalComponentPlugins>();
            }
            result.add(plugins);
        }
    }
    return result;
}
Also used : Configuration(org.exoplatform.container.xml.Configuration) ExternalComponentPlugins(org.exoplatform.container.xml.ExternalComponentPlugins)

Example 25 with Configuration

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

the class RootContainer method loadConfigurationManager.

/**
 * @param rootContainer
 * @return
 * @throws Exception
 */
private static ConfigurationManager loadConfigurationManager(RootContainer rootContainer, boolean logEnabled) throws Exception {
    final ConfigurationManagerImpl service = new ConfigurationManagerImpl(rootContainer.profiles, logEnabled);
    service.addConfiguration(ContainerUtil.getConfigurationURL("conf/configuration.xml"));
    if (System.getProperty("maven.exoplatform.dir") != null) {
        service.addConfiguration(ContainerUtil.getConfigurationURL("conf/test-configuration.xml"));
    }
    J2EEServerInfo serverEnv = rootContainer.getServerEnvironment();
    service.addConfiguration(Archive.getConfigurationURL(serverEnv.getApplicationDeployDirectories(), serverEnv.getApplicationDeployArchives(), "META-INF/exo-conf/configuration.xml"));
    String confDir = serverEnv.getExoConfigurationDirectory();
    String overrideConf = confDir + "/configuration.xml";
    File file = new File(overrideConf);
    if (PrivilegedFileHelper.exists(file)) {
        service.addConfiguration("file:" + overrideConf);
    }
    service.processRemoveConfiguration();
    if (PropertyManager.isDevelopping()) {
        Configuration conf = service.getConfiguration();
        if (conf != null) {
            conf.keepCurrentState();
        }
    }
    return service;
}
Also used : Configuration(org.exoplatform.container.xml.Configuration) J2EEServerInfo(org.exoplatform.container.monitor.jvm.J2EEServerInfo) ConfigurationManagerImpl(org.exoplatform.container.configuration.ConfigurationManagerImpl) MockConfigurationManagerImpl(org.exoplatform.test.MockConfigurationManagerImpl) File(java.io.File)

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