Search in sources :

Example 11 with InitParams

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

the class TestInitParamProfile method testNoProfile.

public void testNoProfile() throws Exception {
    Configuration config = getConfiguration("init-param-configuration.xml");
    Component component = config.getComponent("Component");
    InitParams initParams = component.getInitParams();
    ValueParam valueParam = initParams.getValueParam("param");
    assertEquals("empty", 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)

Example 12 with InitParams

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

the class MX4JComponentAdapterMT method getCreateTask.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
protected ComponentTask<T> getCreateTask() {
    Component component = null;
    String componentKey;
    InitParams params = null;
    boolean debug = false;
    // Get the component
    Object key = getComponentKey();
    if (key instanceof String)
        componentKey = (String) key;
    else
        componentKey = ((Class<?>) key).getName();
    try {
        ConfigurationManager manager = (ConfigurationManager) exocontainer.getComponentInstanceOfType(ConfigurationManager.class);
        component = manager == null ? null : manager.getComponent(componentKey);
        if (component != null) {
            params = component.getInitParams();
            debug = component.getShowDeployInfo();
        }
        if (debug)
            LOG.debug("==> get constructor of the component : " + getComponentImplementation());
        List<Dependency> lDependencies = new ArrayList<Dependency>();
        Constructor<?> constructor = container.getConstructor(getComponentImplementation(), lDependencies);
        setCreateDependencies(lDependencies);
        if (debug)
            LOG.debug("==> create component : " + getComponentImplementation());
        return (ComponentTask<T>) container.createComponentTask(constructor, params, lDependencies, this);
    } catch (Exception e) {
        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, e);
    }
}
Also used : InitParams(org.exoplatform.container.xml.InitParams) ArrayList(java.util.ArrayList) Dependency(org.exoplatform.container.Dependency) CyclicDependencyException(org.exoplatform.container.CyclicDependencyException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ComponentTask(org.exoplatform.container.ComponentTask) Component(org.exoplatform.container.xml.Component) ConfigurationManager(org.exoplatform.container.configuration.ConfigurationManager)

Example 13 with InitParams

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

the class TestConfigurationXML method assertPropertyParam.

private void assertPropertyParam(String expectedValue, Component component, String paramName, String propertyName) {
    InitParams initParams = component.getInitParams();
    assertNotNull(initParams);
    PropertiesParam propertiesParam = initParams.getPropertiesParam(paramName);
    assertNotNull(paramName);
    assertEquals(expectedValue, propertiesParam.getProperty(propertyName));
}
Also used : InitParams(org.exoplatform.container.xml.InitParams) PropertiesParam(org.exoplatform.container.xml.PropertiesParam)

Example 14 with InitParams

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

the class TestDataSourceProviderImpl method testIsManaged.

public void testIsManaged() throws Exception {
    DataSourceProvider dsp = new DataSourceProviderImpl(null);
    assertFalse(dsp.isManaged(DS_NAME));
    InitParams params = new InitParams();
    dsp = new DataSourceProviderImpl(params);
    assertFalse(dsp.isManaged(DS_NAME));
    ValueParam paramConf = new ValueParam();
    paramConf.setName(DataSourceProviderImpl.PARAM_ALWAYS_MANAGED);
    paramConf.setValue("true");
    params.addParameter(paramConf);
    dsp = new DataSourceProviderImpl(params);
    assertTrue(dsp.isManaged(DS_NAME));
    paramConf.setValue("false");
    dsp = new DataSourceProviderImpl(params);
    assertFalse(dsp.isManaged(DS_NAME));
    ValuesParam paramsConf = new ValuesParam();
    paramsConf.setName(DataSourceProviderImpl.PARAM_MANAGED_DS);
    ArrayList<String> values = new ArrayList<String>();
    values.add(DS_NAME);
    values.add(" ds-foo1, ds-foo2 ");
    values.add("ds-foo3");
    paramsConf.setValues(values);
    params.addParameter(paramsConf);
    dsp = new DataSourceProviderImpl(params);
    assertTrue(dsp.isManaged(DS_NAME));
    assertTrue(dsp.isManaged("ds-foo1"));
    assertTrue(dsp.isManaged("ds-foo2"));
    assertTrue(dsp.isManaged("ds-foo3"));
}
Also used : InitParams(org.exoplatform.container.xml.InitParams) ValuesParam(org.exoplatform.container.xml.ValuesParam) DataSourceProvider(org.exoplatform.services.jdbc.DataSourceProvider) ArrayList(java.util.ArrayList) ValueParam(org.exoplatform.container.xml.ValueParam)

Example 15 with InitParams

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

the class TestDataSourceProviderImpl method testGetDataSource.

public void testGetDataSource() throws Exception {
    DataSourceProvider dsp = new DataSourceProviderImpl(null);
    DataSource ds = dsp.getDataSource(DS_NAME);
    assertNotNull(ds);
    Connection con = ds.getConnection();
    con.commit();
    assertTrue(mds.con.committed);
    con = ds.getConnection(null, null);
    con.commit();
    assertTrue(mds.con.committed);
    MyTransactionService mts = new MyTransactionService();
    mts.tm.setStatus(Status.STATUS_ACTIVE);
    dsp = new DataSourceProviderImpl(null, mts);
    ds = dsp.getDataSource(DS_NAME);
    assertNotNull(ds);
    con = ds.getConnection();
    con.commit();
    assertTrue(mds.con.committed);
    con = ds.getConnection(null, null);
    con.commit();
    assertTrue(mds.con.committed);
    mts.tm.setStatus(Status.STATUS_NO_TRANSACTION);
    con = ds.getConnection();
    con.commit();
    assertTrue(mds.con.committed);
    con = ds.getConnection(null, null);
    con.commit();
    assertTrue(mds.con.committed);
    InitParams params = new InitParams();
    ValueParam paramConf = new ValueParam();
    paramConf.setName(DataSourceProviderImpl.PARAM_ALWAYS_MANAGED);
    paramConf.setValue("true");
    params.addParameter(paramConf);
    dsp = new DataSourceProviderImpl(params, mts);
    ds = dsp.getDataSource(DS_NAME);
    assertNotNull(ds);
    mts.tm.setStatus(Status.STATUS_ACTIVE);
    con = ds.getConnection();
    con.commit();
    assertFalse(mds.con.committed);
    con = ds.getConnection(null, null);
    con.commit();
    assertFalse(mds.con.committed);
    mts.tm.setStatus(Status.STATUS_NO_TRANSACTION);
    con = ds.getConnection();
    con.commit();
    assertTrue(mds.con.committed);
    con = ds.getConnection(null, null);
    con.commit();
    assertTrue(mds.con.committed);
    paramConf = new ValueParam();
    paramConf.setName(DataSourceProviderImpl.PARAM_CHECK_TX);
    paramConf.setValue("false");
    params.addParameter(paramConf);
    dsp = new DataSourceProviderImpl(params, mts);
    ds = dsp.getDataSource(DS_NAME);
    assertNotNull(ds);
    mts.tm.setStatus(Status.STATUS_ACTIVE);
    con = ds.getConnection();
    con.commit();
    assertFalse(mds.con.committed);
    con = ds.getConnection(null, null);
    con.commit();
    assertFalse(mds.con.committed);
    mts.tm.setStatus(Status.STATUS_NO_TRANSACTION);
    con = ds.getConnection();
    con.commit();
    assertFalse(mds.con.committed);
    con = ds.getConnection(null, null);
    con.commit();
    assertFalse(mds.con.committed);
}
Also used : InitParams(org.exoplatform.container.xml.InitParams) DataSourceProvider(org.exoplatform.services.jdbc.DataSourceProvider) Connection(java.sql.Connection) ValueParam(org.exoplatform.container.xml.ValueParam) DataSource(javax.sql.DataSource)

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