Search in sources :

Example 21 with InitParams

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

the class MX4JComponentAdapter method create.

/**
 * {@inheritDoc}
 */
public T create(CreationalContext<T> creationalContext) {
    // 
    T instance;
    Component component = null;
    ConfigurationManager manager;
    String componentKey;
    InitParams params = null;
    boolean debug = false;
    CreationalContextComponentAdapter<T> ctx = (CreationalContextComponentAdapter<T>) creationalContext;
    try {
        // Avoid to create duplicate instances if it is called at the same time by several threads
        if (instance_ != null)
            return instance_;
        else if (ctx.get() != null)
            return ctx.get();
        // Get the component
        Object key = getComponentKey();
        if (key instanceof String)
            componentKey = (String) key;
        else
            componentKey = ((Class<?>) key).getName();
        manager = exocontainer.getComponentInstanceOfType(ConfigurationManager.class);
        component = manager == null ? null : manager.getComponent(componentKey);
        if (component != null) {
            params = component.getInitParams();
            debug = component.getShowDeployInfo();
        }
        instance = createInstance(ctx, component, manager, componentKey, params, debug);
        if (instance instanceof Startable && exocontainer.canBeStopped()) {
            // Start the component if the container is already started
            ((Startable) instance).start();
        }
    } catch (Exception ex) {
        String msg = "Cannot instantiate component " + getComponentImplementation();
        if (component != null) {
            msg = "Cannot instantiate component key=" + component.getKey() + " type=" + component.getType() + " found at " + component.getDocumentURL();
        }
        throw new RuntimeException(msg, ex);
    }
    return instance;
}
Also used : InitParams(org.exoplatform.container.xml.InitParams) PrivilegedActionException(java.security.PrivilegedActionException) DefinitionException(org.exoplatform.container.context.DefinitionException) Startable(org.picocontainer.Startable) Component(org.exoplatform.container.xml.Component) ConfigurationManager(org.exoplatform.container.configuration.ConfigurationManager) CreationalContextComponentAdapter(org.exoplatform.container.ConcurrentContainer.CreationalContextComponentAdapter)

Example 22 with InitParams

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

the class TestPropertyManagerConfigurator method testFromXML.

public void testFromXML() throws Exception {
    reset();
    URL propertiesURL = TestPropertyManagerConfigurator.class.getResource("property-configurator.xml");
    assertNotNull(propertiesURL);
    System.setProperty(PropertyManager.PROPERTIES_URL, propertiesURL.toString());
    System.setProperty("property_2", "property_value_2");
    PropertiesParam propertiesParam = new PropertiesParam();
    InitParams params = new InitParams();
    params.put("properties", propertiesParam);
    new PropertyConfigurator(params, new ConfigurationManagerImpl(new HashSet<String>()));
    Map<String, String> additions = reset();
    assertEquals("property_value_1", additions.get("property_1"));
    assertEquals("property_value_2", additions.get("property_2"));
    assertEquals("${property_3}", additions.get("property_3"));
    assertEquals("property_value_1-property_value_2", additions.get("property_4"));
}
Also used : InitParams(org.exoplatform.container.xml.InitParams) PropertiesParam(org.exoplatform.container.xml.PropertiesParam) ConfigurationManagerImpl(org.exoplatform.container.configuration.ConfigurationManagerImpl) URL(java.net.URL) HashSet(java.util.HashSet)

Example 23 with InitParams

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

the class TestPropertyManagerConfigurator method testFromPropertiesByParam.

public void testFromPropertiesByParam() throws Exception {
    reset();
    URL propertiesURL = TestPropertyManagerConfigurator.class.getResource("property-configurator.properties");
    assertNotNull(propertiesURL);
    System.setProperty("property_2", "property_value_2");
    ValueParam propertiesPathParam = new ValueParam();
    propertiesPathParam.setName("properties.url");
    propertiesPathParam.setValue(propertiesURL.toString());
    InitParams params = new InitParams();
    params.put("properties.url", propertiesPathParam);
    new PropertyConfigurator(params, new ConfigurationManagerImpl(new HashSet<String>()));
    Map<String, String> additions = reset();
    assertEquals("property_value_1", additions.get("property_1"));
    assertEquals("property_value_2", additions.get("property_2"));
    assertEquals("${property_3}", additions.get("property_3"));
    assertEquals("property_value_1-property_value_2", additions.get("property_4"));
}
Also used : InitParams(org.exoplatform.container.xml.InitParams) ValueParam(org.exoplatform.container.xml.ValueParam) ConfigurationManagerImpl(org.exoplatform.container.configuration.ConfigurationManagerImpl) URL(java.net.URL) HashSet(java.util.HashSet)

Example 24 with InitParams

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

the class TestExoCacheFactoryImpl method testArguments.

public void testArguments() throws Exception {
    try {
        new ExoCacheFactoryImpl(pc.getContext(), null);
        fail("An IllegalArgumentException should occur");
    } catch (IllegalArgumentException e) {
    // OK
    }
    try {
        new ExoCacheFactoryImpl(pc.getContext(), new InitParams());
        fail("An IllegalArgumentException should occur");
    } catch (IllegalArgumentException e) {
    // OK
    }
    InitParams params;
    try {
        params = new InitParams();
        ValueParam vp = new ValueParam();
        vp.setName(ExoCacheFactoryImpl.MEMCACHED_LOCATIONS);
        params.addParam(vp);
        new ExoCacheFactoryImpl(pc.getContext(), params);
        fail("An IllegalArgumentException should occur");
    } catch (IllegalArgumentException e) {
    // OK
    }
    try {
        params = new InitParams();
        ValueParam vp = new ValueParam();
        vp.setName(ExoCacheFactoryImpl.MEMCACHED_LOCATIONS);
        vp.setValue("");
        params.addParam(vp);
        new ExoCacheFactoryImpl(pc.getContext(), params);
        fail("An IllegalArgumentException should occur");
    } catch (IllegalArgumentException e) {
    // OK
    }
    try {
        params = new InitParams();
        ValueParam vp = new ValueParam();
        vp.setName(ExoCacheFactoryImpl.MEMCACHED_LOCATIONS);
        vp.setValue("localhost:11211");
        params.addParam(vp);
        new ExoCacheFactoryImpl(pc.getContext(), params);
    } catch (Exception e) {
        fail("No exception was expected");
    }
    try {
        params = new InitParams();
        ValueParam vp = new ValueParam();
        vp.setName(ExoCacheFactoryImpl.MEMCACHED_LOCATIONS);
        vp.setValue("localhost:11211");
        params.addParam(vp);
        ObjectParameter op = new ObjectParameter();
        op.setName(ExoCacheFactoryImpl.CONNECTION_FACTORY_CREATOR);
        op.setObject(new Object());
        params.addParam(op);
        new ExoCacheFactoryImpl(pc.getContext(), params);
        fail("An IllegalArgumentException should occur");
    } catch (IllegalArgumentException e) {
    // OK
    }
    try {
        params = new InitParams();
        ValueParam vp = new ValueParam();
        vp.setName(ExoCacheFactoryImpl.MEMCACHED_LOCATIONS);
        vp.setValue("localhost:11211");
        params.addParam(vp);
        ObjectParameter op = new ObjectParameter();
        op.setName(ExoCacheFactoryImpl.CONNECTION_FACTORY_CREATOR);
        op.setObject(new BinaryConnectionFactoryCreator());
        params.addParam(op);
        new ExoCacheFactoryImpl(pc.getContext(), params);
    } catch (Exception e) {
        fail("No exception was expected");
    }
    try {
        params = new InitParams();
        ValueParam vp = new ValueParam();
        vp.setName(ExoCacheFactoryImpl.MEMCACHED_LOCATIONS);
        vp.setValue("localhost:11211");
        params.addParam(vp);
        ObjectParameter op = new ObjectParameter();
        op.setName(ExoCacheFactoryImpl.CONNECTION_FACTORY_CREATOR);
        op.setObject(new BinaryConnectionFactoryCreator());
        params.addParam(op);
        ValueParam vp2 = new ValueParam();
        vp2.setName(ExoCacheFactoryImpl.DEFAULT_EXPIRATION_TIMEOUT);
        vp2.setValue("foo");
        params.addParam(vp2);
        new ExoCacheFactoryImpl(pc.getContext(), params);
        fail("An exception was expected");
    } catch (Exception e) {
    // OK
    }
    try {
        params = new InitParams();
        ValueParam vp = new ValueParam();
        vp.setName(ExoCacheFactoryImpl.MEMCACHED_LOCATIONS);
        vp.setValue("localhost:11211");
        params.addParam(vp);
        ObjectParameter op = new ObjectParameter();
        op.setName(ExoCacheFactoryImpl.CONNECTION_FACTORY_CREATOR);
        op.setObject(new BinaryConnectionFactoryCreator());
        params.addParam(op);
        ValueParam vp2 = new ValueParam();
        vp2.setName(ExoCacheFactoryImpl.DEFAULT_EXPIRATION_TIMEOUT);
        vp2.setValue("1000");
        params.addParam(vp2);
        new ExoCacheFactoryImpl(pc.getContext(), params);
    } catch (Exception e) {
        fail("No exception was expected");
    }
}
Also used : InitParams(org.exoplatform.container.xml.InitParams) ObjectParameter(org.exoplatform.container.xml.ObjectParameter) ValueParam(org.exoplatform.container.xml.ValueParam)

Example 25 with InitParams

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

the class TestInitParamProfile method testFooBarProfiles.

public void testFooBarProfiles() throws Exception {
    Configuration config = getConfiguration("init-param-configuration.xml", "foo", "bar");
    Component component = config.getComponent("Component");
    InitParams initParams = component.getInitParams();
    ValueParam valueParam = initParams.getValueParam("param");
    assertEquals("bar", valueParam.getValue());
}
Also used : InitParams(org.exoplatform.container.xml.InitParams) Configuration(org.exoplatform.container.xml.Configuration) Component(org.exoplatform.container.xml.Component) ValueParam(org.exoplatform.container.xml.ValueParam)

Aggregations

InitParams (org.exoplatform.container.xml.InitParams)26 ValueParam (org.exoplatform.container.xml.ValueParam)16 RPCServiceImpl (org.exoplatform.services.rpc.jgv3.RPCServiceImpl)7 HashSet (java.util.HashSet)5 ConfigurationManagerImpl (org.exoplatform.container.configuration.ConfigurationManagerImpl)5 Component (org.exoplatform.container.xml.Component)5 PropertiesParam (org.exoplatform.container.xml.PropertiesParam)5 RemoteCommand (org.exoplatform.services.rpc.RemoteCommand)5 URL (java.net.URL)4 ArrayList (java.util.ArrayList)4 ObjectParameter (org.exoplatform.container.xml.ObjectParameter)4 RPCException (org.exoplatform.services.rpc.RPCException)4 ConfigurationManager (org.exoplatform.container.configuration.ConfigurationManager)3 Configuration (org.exoplatform.container.xml.Configuration)3 Serializable (java.io.Serializable)2 DataSource (javax.sql.DataSource)2 RootContainer (org.exoplatform.container.RootContainer)2 DataSourceProvider (org.exoplatform.services.jdbc.DataSourceProvider)2 MemberHasLeftException (org.exoplatform.services.rpc.impl.AbstractRPCService.MemberHasLeftException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1