Package org.apache.felix.ipojo.metadata

Examples of org.apache.felix.ipojo.metadata.Attribute


     * @param values the property value
     * @return the current instantiated sub-service
     */
    public InstantiatedService addProperty(String name, Map values) {
        Element elem = new Element("property", "");
        elem.addAttribute(new Attribute("name", name));
        elem.addAttribute(new Attribute("type", "map"));

        m_conf.add(elem);
        Set entries = values.entrySet();
        Iterator it = entries.iterator();
        while (it.hasNext()) {
            Map.Entry entry = (Entry) it.next();
            Element e = new Element("property", "");
            elem.addElement(e);

            String n = (String) entry.getKey();
            Object v = entry.getValue();
            if (v instanceof String) {
                e.addAttribute(new Attribute("name", n));
                e.addAttribute(new Attribute("value", v.toString()));
            } else {
                // TODO
                throw new UnsupportedOperationException(
                        "Complex properties are not supported yet");
            }
View Full Code Here


     * @param values the property value
     * @return the current instantiated sub-service
     */
    public InstantiatedService addProperty(String name, Dictionary values) {
        Element elem = new Element("property", "");
        elem.addAttribute(new Attribute("name", name));
        elem.addAttribute(new Attribute("type", "dictionary"));

        m_conf.add(elem);
        Enumeration e = values.keys();
        while (e.hasMoreElements()) {
            Element el = new Element("property", "");
            elem.addElement(el);

            String n = (String) e.nextElement();
            Object v = values.get(n);
            if (v instanceof String) {
                el.addAttribute(new Attribute("name", n));
                el.addAttribute(new Attribute("value", v.toString()));
            } else {
                // TODO
                throw new UnsupportedOperationException(
                        "Complex properties are not supported yet");
            }
View Full Code Here

    public Element getHandlerInfo() {
        Element services = super.getHandlerInfo();
        for (int i = 0; i < m_imports.size(); i++) {
            ServiceImporter imp = (ServiceImporter) m_imports.get(i);
            Element impo = new Element("Requires", "");
            impo.addAttribute(new Attribute("Specification", imp.getSpecification().getName()));
            if (imp.getFilter() != null) {
                impo.addAttribute(new Attribute("Filter", imp.getFilter()));
            }
            if (imp.getState() == DependencyModel.RESOLVED) {
                impo.addAttribute(new Attribute("State", "resolved"));
                for (int j = 0; j < imp.getProviders().size(); j++) {
                    Element prov = new Element("Provider", "");
                    prov.addAttribute(new Attribute("name", (String) imp.getProviders().get(j)));
                    impo.addElement(prov);
                }
            } else {
                impo.addAttribute(new Attribute("State", "unresolved"));
            }
            services.addElement(impo);
        }
       
        for (int i = 0; i < m_instances.size(); i++) {
            SvcInstance inst = (SvcInstance) m_instances.get(i);
            Element service = new Element("Service", "");
            service.addAttribute(new Attribute("Specification", inst.getServiceSpecification()));
            String state = "unresolved";
            if (inst.getState() == DependencyModel.RESOLVED) {
                state = "resolved";
            }
            service.addAttribute(new Attribute("State", state));
            Map map = inst.getMatchingFactories();
            Set keys = map.keySet();
            Iterator iterator = keys.iterator();
            while (iterator.hasNext()) {
                ServiceReference ref = (ServiceReference) iterator.next();
                Object object = map.get(ref);
                if (object != null) {
                    Element fact = new Element("Factory", "");
                    fact.addAttribute(new Attribute("Name", ((ComponentInstance) object).getFactory().getName()));
                    service.addElement(fact);
                }
            }
            services.addElement(service);
        }
View Full Code Here

            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;
View Full Code Here

        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);
        }
View Full Code Here

     * @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);
View Full Code Here

                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);
            }
View Full Code Here

public class TestBadFactories extends Common {

    private Element getElementFactoryWithNoClassName() {
        Element elem = new Element("component", "");
        elem.addAttribute(new Attribute("name", "noclassname"));
        return elem;
    }
View Full Code Here

        return elem;
    }

    private Element getElementHandlerFactoryWithNoClassName() {
        Element elem = new Element("handler", "");
        elem.addAttribute(new Attribute("name", "noclassname"));
        return elem;
    }
View Full Code Here

        return elem;
    }

    private Element getElementHandlerFactoryWithNoName() {
        Element elem = new Element("handler", "");
        elem.addAttribute(new Attribute("className", "noclassname"));
        return elem;
    }
View Full Code Here

TOP

Related Classes of org.apache.felix.ipojo.metadata.Attribute

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.