use of org.apache.felix.ipojo.ConfigurationException in project felix by apache.
the class TransactionHandler method configure.
public void configure(Element arg0, Dictionary arg1) throws ConfigurationException {
Element[] elements = arg0.getElements(NAME, NAMESPACE);
if (elements.length > 1) {
throw new ConfigurationException("The handler " + NAMESPACE + ":" + NAME + " cannot be declared several times");
}
String field = elements[0].getAttribute(FIELD_ATTRIBUTE);
if (field != null) {
FieldMetadata meta = getPojoMetadata().getField(field);
if (meta == null) {
throw new ConfigurationException("The transaction field does not exist in the pojo class : " + field);
}
if (!meta.getFieldType().equals(Transaction.class.getName())) {
throw new ConfigurationException("The transaction field type must be " + Transaction.class.getName());
}
// Register the interceptor
getInstanceManager().register(meta, this);
}
String oncommit = elements[0].getAttribute(ONCOMMIT_ATTRIBUTE);
if (oncommit != null) {
m_onCommit = new Callback(oncommit, new String[] { Transaction.class.getName() }, false, getInstanceManager());
}
String onrollback = elements[0].getAttribute(ONROLLBACK_ATTRIBUTE);
if (onrollback != null) {
m_onRollback = new Callback(onrollback, new String[] { Transaction.class.getName() }, false, getInstanceManager());
}
Element[] sub = elements[0].getElements(TRANSACTIONAL_ELEMENT);
if (sub == null || sub.length == 0) {
throw new ConfigurationException("The handler " + NAMESPACE + ":" + NAME + " must have " + TRANSACTIONAL_ELEMENT + " subelement");
}
for (int i = 0; i < sub.length; i++) {
String method = sub[i].getAttribute(METHOD_ATTRIBUTE);
String to = sub[i].getAttribute(TIMEOUT_ATTRIBUTE);
String propa = sub[i].getAttribute(PROPAGATION_ATTRIBUTE);
String nrbf = sub[i].getAttribute(NOROLLBACKFOR_ATTRIBUTE);
String eorb = sub[i].getAttribute(EXCEPTIONONROLLBACK_ATTRIBUTE);
if (method == null) {
throw new ConfigurationException("A transactional element must specified the method attribute");
}
MethodMetadata meta = this.getPojoMetadata().getMethod(method);
if (meta == null) {
throw new ConfigurationException("A transactional method is not in the pojo class : " + method);
}
int timeout = 0;
if (to != null) {
timeout = new Integer(to).intValue();
}
int propagation = DEFAULT_PROPAGATION;
if (propa != null) {
propagation = parsePropagation(propa);
}
List<String> exceptions = new ArrayList<String>();
if (nrbf != null) {
exceptions = (List<String>) ParseUtils.parseArraysAsList(nrbf);
}
boolean exceptionOnRollback = false;
if (eorb != null) {
exceptionOnRollback = new Boolean(eorb).booleanValue();
}
TransactionalMethod tm = new TransactionalMethod(method, propagation, timeout, exceptions, exceptionOnRollback, this);
m_methods.add(tm);
this.getInstanceManager().register(meta, tm);
}
}
use of org.apache.felix.ipojo.ConfigurationException in project felix by apache.
the class WhiteBoardPatternHandler method configure.
/**
* Configure method. Parses the metadata to analyze white-board-pattern elements.
* @param elem the component type description
* @param dict the instance description
* @throws ConfigurationException if the description is not valid.
* @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.metadata.Element, java.util.Dictionary)
*/
public void configure(Element elem, Dictionary dict) throws ConfigurationException {
// There is two way to configure the handler :
// - the wbp elements
// - the whiteboards elements
Element[] elems = elem.getElements("wbp", NAMESPACE);
if (elems == null || elems.length == 0) {
// Alternative way
Element[] whiteboards = elem.getElements("whiteboards", NAMESPACE);
if (whiteboards == null) {
throw new ConfigurationException("Cannot configure the whiteboard pattern handler - no suitable configuration found");
} else {
elems = whiteboards[0].getElements("wbp", NAMESPACE);
}
}
// Last check.
if (elems == null) {
throw new ConfigurationException("Cannot configure the whiteboard pattern handler - no suitable configuration found");
}
for (int i = 0; i < elems.length; i++) {
String filter = elems[i].getAttribute("filter");
String onArrival = elems[i].getAttribute("onArrival");
String onDeparture = elems[i].getAttribute("onDeparture");
String onModification = elems[i].getAttribute("onModification");
if (filter == null) {
throw new ConfigurationException("The white board pattern element requires a filter attribute");
}
if (onArrival == null || onDeparture == null) {
throw new ConfigurationException("The white board pattern element requires the onArrival and onDeparture attributes");
}
try {
WhiteBoardManager wbm = new WhiteBoardManager(this, getInstanceManager().getContext().createFilter(filter), onArrival, onDeparture, onModification);
m_managers.add(wbm);
} catch (InvalidSyntaxException e) {
throw new ConfigurationException("The filter " + filter + " is invalid : " + e);
}
}
}
use of org.apache.felix.ipojo.ConfigurationException in project felix by apache.
the class TestManipulationMetadataAPI method testGetMetadata.
@Test
public void testGetMetadata() {
String header = (String) getTestBundle().getHeaders().get("iPOJO-Components");
Element elem = null;
try {
elem = ManifestMetadataParser.parseHeaderMetadata(header);
} catch (ParseException e) {
fail("Parse Exception when parsing iPOJO-Component");
}
assertNotNull("Check elem not null", elem);
Element manip = getMetadataForComponent(elem, "ManipulationMetadata-FooProviderType-1");
assertNotNull("Check manipulation metadata not null for " + "Manipulation-FooProviderType-1", manip);
PojoMetadata mm;
try {
mm = new PojoMetadata(manip);
assertNotNull("Check mm not null", mm);
} catch (ConfigurationException e) {
fail("The creation of pojo metadata has failed");
}
}
use of org.apache.felix.ipojo.ConfigurationException in project felix by apache.
the class TestManipulationMetadataAPI method getManipulationMetadataForComponent.
private PojoMetadata getManipulationMetadataForComponent(String comp_name) {
String header = (String) getTestBundle().getHeaders().get("iPOJO-Components");
Element elem = null;
try {
elem = ManifestMetadataParser.parseHeaderMetadata(header);
} catch (ParseException e) {
fail("Parse Exception when parsing iPOJO-Component");
}
assertNotNull("Check elem not null", elem);
Element manip = getMetadataForComponent(elem, comp_name);
assertNotNull("Check manipulation metadata not null for " + comp_name, manip);
try {
return new PojoMetadata(manip);
} catch (ConfigurationException e) {
fail("The creation of pojo metadata for " + comp_name + " has failed");
return null;
}
}
use of org.apache.felix.ipojo.ConfigurationException in project felix by apache.
the class PrimitiveComponentType method createFactory.
/**
* Creates the component factory.
*/
private void createFactory() {
ensureValidity();
byte[] clazz = manipulate();
Element meta = generateComponentMetadata();
meta.addElement(m_manipulation);
try {
if (m_alreadyManipulated) {
// Already manipulated
m_factory = new ComponentFactory(m_context, meta);
} else {
m_factory = new ComponentFactory(m_context, clazz, meta);
m_factory.setUseFactoryClassloader(true);
}
m_factory.start();
} catch (ConfigurationException e) {
throw new IllegalStateException("An exception occurs during factory initialization", e);
}
}
Aggregations