Search in sources :

Example 21 with RootContainer

use of org.exoplatform.container.RootContainer in project kernel by exoplatform.

the class Deserializer method resolveVariables.

/**
 * Resolve the variables of type ${my.var} for the current context which is composed
 * of the system properties, the portal container settings and the given settings
 * @param input the input value
 * @param props a set of parameters to add for the variable resolution
 * @return the resolve value
 */
public static String resolveVariables(String input, Map<String, Object> props) {
    final int NORMAL = 0;
    final int SEEN_DOLLAR = 1;
    final int IN_BRACKET = 2;
    if (input == null)
        return input;
    char[] chars = input.toCharArray();
    StringBuilder buffer = new StringBuilder();
    boolean properties = false;
    int state = NORMAL;
    int start = 0;
    boolean precedingBackslash = false;
    for (int i = 0; i < chars.length; ++i) {
        char c = chars[i];
        if (c == '$' && state != IN_BRACKET)
            state = SEEN_DOLLAR;
        else if (c == '{' && state == SEEN_DOLLAR && !precedingBackslash) {
            buffer.append(input.substring(start, i - 1));
            state = IN_BRACKET;
            start = i - 1;
        } else if (state == SEEN_DOLLAR)
            state = NORMAL;
        else if (c == '}' && state == IN_BRACKET && !precedingBackslash) {
            if (start + 2 == i) {
                buffer.append("${}");
            } else {
                String value = null;
                String key = input.substring(start + 2, i);
                String defaultValue = null;
                int index = key.indexOf(':');
                if (index > -1) {
                    defaultValue = key.substring(index + 1);
                    if (defaultValue != null && !defaultValue.isEmpty()) {
                        defaultValue = defaultValue.replace("\\{", "{").replace("\\}", "}");
                    }
                    key = key.substring(0, index);
                }
                if (key.equals(Deserializer.EXO_CONTAINER_PROP_NAME)) {
                    // The requested key is the name of current container
                    ExoContainer container = ExoContainerContext.getCurrentContainerIfPresent();
                    if (container instanceof PortalContainer) {
                        // The current container is a portal container
                        RootContainer rootContainer = (RootContainer) ExoContainerContext.getTopContainer();
                        value = rootContainer.isPortalContainerConfigAware() ? "_" + container.getContext().getName() : "";
                    }
                } else if (key.startsWith(Deserializer.PORTAL_CONTAINER_VARIABLE_PREFIX)) {
                    // We try to get a value tied to the current portal container.
                    ExoContainer container = ExoContainerContext.getCurrentContainerIfPresent();
                    if (container instanceof PortalContainer) {
                        // The current container is a portal container
                        Object oValue = ((PortalContainer) container).getSetting(key.substring(Deserializer.PORTAL_CONTAINER_VARIABLE_PREFIX.length()));
                        value = oValue == null ? null : oValue.toString();
                    }
                } else {
                    if (props != null) {
                        // Some parameters have been given thus we need to check inside first
                        Object oValue = props.get(key);
                        value = oValue == null ? null : oValue.toString();
                    }
                    if (value == null) {
                        // No value could be found so far, thus we try to get it from the
                        // system properties
                        value = PrivilegedSystemHelper.getProperty(key);
                    }
                }
                if (value == null && defaultValue != null) {
                    value = defaultValue;
                }
                if (value != null) {
                    properties = true;
                    buffer.append(value);
                }
            }
            start = i + 1;
            state = NORMAL;
        }
        if (c == '\\') {
            precedingBackslash = !precedingBackslash;
        } else {
            precedingBackslash = false;
        }
    }
    if (properties == false)
        return input;
    if (start != chars.length)
        buffer.append(input.substring(start, chars.length));
    return buffer.toString();
}
Also used : ExoContainer(org.exoplatform.container.ExoContainer) RootContainer(org.exoplatform.container.RootContainer) PortalContainer(org.exoplatform.container.PortalContainer)

Example 22 with RootContainer

use of org.exoplatform.container.RootContainer in project kernel by exoplatform.

the class TestComponentPlugin method testComponentPluginOverloading.

public void testComponentPluginOverloading() {
    RootContainer rootContainer = createRootContainer("test-component-plugin-configuration.xml");
    A a = (A) rootContainer.getComponentInstanceOfType(A.class);
    assertNotNull(a);
    assertEquals(1, a.countRegisterCP);
    assertEquals(1, a.countRegisterACP);
    assertEquals(2, a.countRegisterCP1);
}
Also used : RootContainer(org.exoplatform.container.RootContainer)

Example 23 with RootContainer

use of org.exoplatform.container.RootContainer in project kernel by exoplatform.

the class TestSpringContainer method testIntegrationClass.

public void testIntegrationClass() {
    URL rootURL = getClass().getResource("test-exo-container.xml");
    URL portalURL = getClass().getResource("test-exo-container2.xml");
    assertNotNull(rootURL);
    assertNotNull(portalURL);
    // 
    new ContainerBuilder().withRoot(rootURL).withPortal(portalURL).profiledBy("class").build();
    RootContainer root = RootContainer.getInstance();
    testIntegration(root);
}
Also used : ContainerBuilder(org.exoplatform.container.ContainerBuilder) RootContainer(org.exoplatform.container.RootContainer) URL(java.net.URL)

Example 24 with RootContainer

use of org.exoplatform.container.RootContainer in project kernel by exoplatform.

the class TestSpringContainer method testIntegrationFile.

public void testIntegrationFile() {
    URL rootURL = getClass().getResource("test-exo-container.xml");
    URL portalURL = getClass().getResource("test-exo-container2.xml");
    assertNotNull(rootURL);
    assertNotNull(portalURL);
    // 
    new ContainerBuilder().withRoot(rootURL).withPortal(portalURL).profiledBy("file").build();
    RootContainer root = RootContainer.getInstance();
    testIntegration(root);
}
Also used : ContainerBuilder(org.exoplatform.container.ContainerBuilder) RootContainer(org.exoplatform.container.RootContainer) URL(java.net.URL)

Example 25 with RootContainer

use of org.exoplatform.container.RootContainer in project kernel by exoplatform.

the class TestXSD_1_1 method testInitParams.

public void testInitParams() throws Exception {
    URL url = getClass().getResource("../../../../xsd_1_1/test-validation.xml");
    assertNotNull(url);
    RootContainer container = new ContainerBuilder().withRoot(url).build();
    container.getComponentInstanceOfType(TestValidation.class);
}
Also used : ContainerBuilder(org.exoplatform.container.ContainerBuilder) RootContainer(org.exoplatform.container.RootContainer) URL(java.net.URL)

Aggregations

RootContainer (org.exoplatform.container.RootContainer)38 URL (java.net.URL)14 ContainerBuilder (org.exoplatform.container.ContainerBuilder)14 PortalContainer (org.exoplatform.container.PortalContainer)9 MBeanServer (javax.management.MBeanServer)8 ExoContainer (org.exoplatform.container.ExoContainer)4 ObjectName (javax.management.ObjectName)3 ObjectInstance (javax.management.ObjectInstance)2 ManagedManagementAware (org.exoplatform.container.jmx.support.ManagedManagementAware)2 ManagedWithObjectNameTemplate (org.exoplatform.container.jmx.support.ManagedWithObjectNameTemplate)2 ComponentAdapter (org.exoplatform.container.spi.ComponentAdapter)2 InitParams (org.exoplatform.container.xml.InitParams)2 ObjectParameter (org.exoplatform.container.xml.ObjectParameter)2 Set (java.util.Set)1 ComponentPlugin (org.exoplatform.container.component.ComponentPlugin)1 ComponentRequestLifecycle (org.exoplatform.container.component.ComponentRequestLifecycle)1 ExoContainerFinder (org.exoplatform.container.jmx.support.ExoContainerFinder)1 ManagedByManager (org.exoplatform.container.jmx.support.ManagedByManager)1 ManagedComponentRequestLifeCycle (org.exoplatform.container.jmx.support.ManagedComponentRequestLifeCycle)1 ManagedDependent (org.exoplatform.container.jmx.support.ManagedDependent)1