Search in sources :

Example 51 with Attribute

use of org.apache.felix.ipojo.metadata.Attribute in project felix by apache.

the class TestBadServiceDependencies method getBadField.

private Element getBadField() {
    Element elem = new Element("component", "");
    elem.addAttribute(new Attribute("classname", clazz));
    Element callback = new Element("requires", "");
    // missing field.
    callback.addAttribute(new Attribute("field", "BAD_FIELD"));
    elem.addElement(callback);
    elem.addElement(manipulation);
    return elem;
}
Also used : Attribute(org.apache.felix.ipojo.metadata.Attribute) Element(org.apache.felix.ipojo.metadata.Element)

Example 52 with Attribute

use of org.apache.felix.ipojo.metadata.Attribute in project felix by apache.

the class CompositeInstanceDescription method getInternalServices.

/**
 * Gets the list of internally published services.
 * @return the list of published services.
 */
public Element getInternalServices() {
    Element services = new Element("services", "");
    ServiceContext internal = ((CompositeManager) m_instance).getServiceContext();
    try {
        ServiceReference[] refs = internal.getServiceReferences((String) null, "(!(objectclass=" + Factory.class.getName() + "))");
        for (int i = 0; refs != null && i < refs.length; i++) {
            Element svc = new Element("service", "");
            String[] keys = refs[i].getPropertyKeys();
            for (int j = 0; j < keys.length; j++) {
                Object v = refs[i].getProperty(keys[j]);
                if (v instanceof String[]) {
                    List l = Arrays.asList((String[]) v);
                    svc.addAttribute(new Attribute(keys[j], l.toString()));
                } else {
                    svc.addAttribute(new Attribute(keys[j], v.toString()));
                }
            }
            services.addElement(svc);
        }
    } catch (InvalidSyntaxException e) {
    // Cannot happen
    }
    return services;
}
Also used : Attribute(org.apache.felix.ipojo.metadata.Attribute) ServiceContext(org.apache.felix.ipojo.ServiceContext) Element(org.apache.felix.ipojo.metadata.Element) Factory(org.apache.felix.ipojo.Factory) ServiceReference(org.osgi.framework.ServiceReference) List(java.util.List) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException)

Example 53 with Attribute

use of org.apache.felix.ipojo.metadata.Attribute in project felix by apache.

the class InstanceHandlerDescription method getHandlerInfo.

/**
 * Build handler description.
 * @return the handler description
 * @see org.apache.felix.ipojo.architecture.HandlerDescription#getHandlerInfo()
 */
public Element getHandlerInfo() {
    Element instances = super.getHandlerInfo();
    for (int i = 0; i < m_configurations.length; i++) {
        ManagedConfiguration inst = m_configurations[i];
        Element instance = new Element("Instance", "");
        if (inst.getInstance() == null) {
            instance.addAttribute(new Attribute("Factory", inst.getConfiguration().get("component").toString()));
            instance.addAttribute(new Attribute("State", "Not Available"));
        } else {
            instance.addAttribute(new Attribute("Factory", inst.getFactory()));
            instance.addAttribute(new Attribute("Name", inst.getInstance().getInstanceName()));
            String state = null;
            switch(inst.getInstance().getState()) {
                case ComponentInstance.DISPOSED:
                    state = "disposed";
                    break;
                case ComponentInstance.STOPPED:
                    state = "stopped";
                    break;
                case ComponentInstance.VALID:
                    state = "valid";
                    break;
                case ComponentInstance.INVALID:
                    state = "invalid";
                    break;
                default:
                    break;
            }
            instance.addAttribute(new Attribute("State", state));
        // The instance description is already contained inside parent instance description.
        // instance.addElement(inst.getInstance().getInstanceDescription().getDescription());
        }
        instances.addElement(instance);
    }
    return instances;
}
Also used : Attribute(org.apache.felix.ipojo.metadata.Attribute) Element(org.apache.felix.ipojo.metadata.Element) ManagedConfiguration(org.apache.felix.ipojo.composite.instance.InstanceHandler.ManagedConfiguration)

Example 54 with Attribute

use of org.apache.felix.ipojo.metadata.Attribute in project felix by apache.

the class CompositionMetadata method buildMetadata.

/**
 * Build service implementation metadata.
 * @param name : name of the future instance (used to avoid cycle)
 * @return Component Type metadata.
 */
protected Element buildMetadata(String name) {
    Element elem = new Element("component", "");
    Attribute className = new Attribute("classname", m_name);
    Attribute factory = new Attribute("public", "false");
    elem.addAttribute(className);
    elem.addAttribute(factory);
    // Add architecture for debug
    elem.addAttribute(new Attribute("architecture", "true"));
    // Provides
    Element provides = new Element("provides", "");
    provides.addAttribute(new Attribute("specification", m_specification.getName()));
    elem.addElement(provides);
    // Dependencies
    List fields = getFieldList();
    for (int i = 0; i < fields.size(); i++) {
        FieldMetadata field = (FieldMetadata) fields.get(i);
        if (field.isUseful() && field.getSpecification().isInterface()) {
            Element dep = new Element("requires", "");
            dep.addAttribute(new Attribute("field", field.getName()));
            dep.addAttribute(new Attribute("scope", "composite"));
            dep.addAttribute(new Attribute("proxy", "false"));
            if (field.getSpecification().isOptional()) {
                dep.addAttribute(new Attribute("optional", "true"));
            }
            dep.addAttribute(new Attribute("filter", "(!(instance.name=" + name + "))"));
            elem.addElement(dep);
        }
    }
    Element properties = new Element("properties", "");
    for (int i = 0; i < fields.size(); i++) {
        FieldMetadata field = (FieldMetadata) fields.get(i);
        if (field.isUseful() && !field.getSpecification().isInterface()) {
            Element prop = new Element("Property", "");
            prop.addAttribute(new Attribute("field", field.getName()));
            properties.addElement(prop);
        }
    }
    if (properties.getElements().length != 0) {
        elem.addElement(properties);
    }
    // Insert information to metadata
    elem.addElement(m_manipulation);
    return elem;
}
Also used : Attribute(org.apache.felix.ipojo.metadata.Attribute) Element(org.apache.felix.ipojo.metadata.Element) ArrayList(java.util.ArrayList) List(java.util.List)

Example 55 with Attribute

use of org.apache.felix.ipojo.metadata.Attribute in project felix by apache.

the class ProvidedServiceHandlerDescription method getHandlerInfo.

/**
 * Get the handler description.
 * @return the provided service handler description
 * @see org.apache.felix.ipojo.architecture.HandlerDescription#getHandlerInfo()
 */
public Element getHandlerInfo() {
    Element services = super.getHandlerInfo();
    for (int i = 0; i < m_services.size(); i++) {
        ProvidedService svc = (ProvidedService) m_services.get(i);
        Element service = new Element("service", "");
        String state = "unregistered";
        if (svc.isRegistered()) {
            state = "registered";
        }
        String spec = "[" + svc.getSpecification() + "]";
        service.addAttribute(new Attribute("Specification", spec));
        service.addAttribute(new Attribute("State", state));
        services.addElement(service);
    }
    for (int i = 0; i < m_exports.size(); i++) {
        ServiceExporter exp = (ServiceExporter) m_exports.get(i);
        Element expo = new Element("Exports", "");
        expo.addAttribute(new Attribute("Specification", exp.getSpecification().getName()));
        expo.addAttribute(new Attribute("Filter", exp.getFilter()));
        if (exp.getState() == DependencyModel.RESOLVED) {
            expo.addAttribute(new Attribute("State", "resolved"));
        } else {
            expo.addAttribute(new Attribute("State", "unresolved"));
        }
        services.addElement(expo);
    }
    return services;
}
Also used : Attribute(org.apache.felix.ipojo.metadata.Attribute) Element(org.apache.felix.ipojo.metadata.Element)

Aggregations

Attribute (org.apache.felix.ipojo.metadata.Attribute)125 Element (org.apache.felix.ipojo.metadata.Element)109 Test (org.junit.Test)9 PojoMetadata (org.apache.felix.ipojo.parser.PojoMetadata)6 Iterator (java.util.Iterator)4 Enumeration (java.util.Enumeration)3 Map (java.util.Map)3 Set (java.util.Set)3 ServiceReference (org.osgi.framework.ServiceReference)3 List (java.util.List)2 Entry (java.util.Map.Entry)2 PropertyDescription (org.apache.felix.ipojo.architecture.PropertyDescription)2 FieldMetadata (org.apache.felix.ipojo.parser.FieldMetadata)2 MethodMetadata (org.apache.felix.ipojo.parser.MethodMetadata)2 Type (org.objectweb.asm.Type)2 Member (java.lang.reflect.Member)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1