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