Search in sources :

Example 16 with ConfigurationException

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);
    }
}
Also used : FieldMetadata(org.apache.felix.ipojo.parser.FieldMetadata) Element(org.apache.felix.ipojo.metadata.Element) ArrayList(java.util.ArrayList) Callback(org.apache.felix.ipojo.util.Callback) ConfigurationException(org.apache.felix.ipojo.ConfigurationException) MethodMetadata(org.apache.felix.ipojo.parser.MethodMetadata)

Example 17 with ConfigurationException

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);
        }
    }
}
Also used : ConfigurationException(org.apache.felix.ipojo.ConfigurationException) Element(org.apache.felix.ipojo.metadata.Element) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException)

Example 18 with ConfigurationException

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");
    }
}
Also used : ConfigurationException(org.apache.felix.ipojo.ConfigurationException) Element(org.apache.felix.ipojo.metadata.Element) Test(org.junit.Test) BaseTest(org.ow2.chameleon.testing.helpers.BaseTest)

Example 19 with ConfigurationException

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;
    }
}
Also used : ConfigurationException(org.apache.felix.ipojo.ConfigurationException) Element(org.apache.felix.ipojo.metadata.Element)

Example 20 with ConfigurationException

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);
    }
}
Also used : ConfigurationException(org.apache.felix.ipojo.ConfigurationException) Element(org.apache.felix.ipojo.metadata.Element) ComponentFactory(org.apache.felix.ipojo.ComponentFactory)

Aggregations

ConfigurationException (org.apache.felix.ipojo.ConfigurationException)34 Element (org.apache.felix.ipojo.metadata.Element)22 FieldMetadata (org.apache.felix.ipojo.parser.FieldMetadata)9 MethodMetadata (org.apache.felix.ipojo.parser.MethodMetadata)6 PojoMetadata (org.apache.felix.ipojo.parser.PojoMetadata)6 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)6 Properties (java.util.Properties)5 Filter (org.osgi.framework.Filter)5 MissingHandlerException (org.apache.felix.ipojo.MissingHandlerException)4 UnacceptableConfiguration (org.apache.felix.ipojo.UnacceptableConfiguration)4 BundleContext (org.osgi.framework.BundleContext)4 ArrayList (java.util.ArrayList)3 Comparator (java.util.Comparator)3 Dictionary (java.util.Dictionary)3 Enumeration (java.util.Enumeration)3 PropertyDescription (org.apache.felix.ipojo.architecture.PropertyDescription)3 ParseException (org.apache.felix.ipojo.parser.ParseException)3 Callback (org.apache.felix.ipojo.util.Callback)3 ComponentFactory (org.apache.felix.ipojo.ComponentFactory)2 Factory (org.apache.felix.ipojo.Factory)2