Examples of PojoMetadata


Examples of org.apache.felix.ipojo.parser.PojoMetadata

     * @param dictionary the instance configuration.
     * @throws ConfigurationException if the dependency is not configured correctly
     * @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.metadata.Element, java.util.Dictionary)
     */
    public void configure(Element meta, Dictionary dictionary) throws ConfigurationException {
        PojoMetadata manipulation = getFactory().getPojoMetadata();
        Element[] deps = meta.getElements("requires", NAMESPACE);

        // Also check with temporal is no requires.
        if (deps == null || deps.length == 0) {
          deps = meta.getElements("temporal", NAMESPACE);
        }

        for (int i = 0; i < deps.length; i++) {
            if (!deps[i].containsAttribute("field") || m_dependencies.contains(deps[i].getAttribute("field"))) {
                error("One temporal dependency must be attached to a field or the field is already used");
                return;
            }
            String field = deps[i].getAttribute("field");

            FieldMetadata fieldmeta = manipulation.getField(field);
            if (fieldmeta == null) {
                error("The field " + field + " does not exist in the class " + getInstanceManager().getClassName());
                return;
            }

            String fil = deps[i].getAttribute("filter");
            Filter filter = null;
            if (fil != null) {
                try {
                    filter = getInstanceManager().getContext().createFilter(fil);
                } catch (InvalidSyntaxException e) {
                    error("Cannot create the field from " + fil + ": " + e.getMessage());
                    return;
                }
            }

            boolean agg = false;
            boolean collection = false;
            String spec = fieldmeta.getFieldType();
            if (spec.endsWith("[]")) {
                agg = true;
                spec = spec.substring(0, spec.length() - 2);
            } else if (Collection.class.getName().equals(spec)) {
                agg = true;
                collection = true;
                // Collection detected. Check for the specification attribute
                spec = deps[i].getAttribute("specification");
                if (spec == null) {
                    error("A dependency injected inside a Collection must contain the 'specification' attribute");
                }
            }

            String prox = deps[i].getAttribute("proxy");
            //boolean proxy = prox != null && prox.equals("true");
            // Use proxy by default except for array:
            boolean proxy = prox == null  || prox.equals("true");

            if (prox == null  && proxy) { // Proxy set because of the default.
                if (agg  && ! collection) { // Aggregate and array
                    proxy = false;
                }
            }

            if (proxy && agg) {
                if (! collection) {
                    error("Proxied aggregate temporal dependencies cannot be an array. Only collections are supported");
                }
            }

            long timeout = DEFAULT_TIMEOUT;
            if (deps[i].containsAttribute("timeout")) {
                String to = deps[i].getAttribute("timeout");
                if (to.equalsIgnoreCase("infinite"|| to.equalsIgnoreCase("-1")) {
                    timeout = Long.MAX_VALUE; // Infinite wait time ...
                } else {
                    timeout = new Long(deps[i].getAttribute("timeout")).longValue();
                }
            }

            int policy = NO_POLICY;
            String di = null;
            String onTimeout = deps[i].getAttribute("onTimeout");
            if (onTimeout != null) {
                if (onTimeout.equalsIgnoreCase("nullable")) {
                    policy = NULLABLE;
                } else if (onTimeout.equalsIgnoreCase("empty-array"|| onTimeout.equalsIgnoreCase("empty")) {
                    policy = EMPTY;
                    if (! agg) {
                        // The empty array policy can only be used on aggregate dependencies
                        error("Cannot use the empty array policy for " + field + " : non aggregate dependency.");
                    }
                } else if (onTimeout.equalsIgnoreCase("null")) {
                    policy = NULL;
                } else if (onTimeout.length() > 0) {
                    di = onTimeout;
                    policy = DEFAULT_IMPLEMENTATION;
                }
            }

            Class specification = DependencyModel.loadSpecification(spec, getInstanceManager().getContext());
            TemporalDependency dep = new TemporalDependency(specification, agg, collection, proxy, filter, getInstanceManager().getContext(), timeout, policy, di, this);
            m_dependencies.add(dep);

            if (! proxy) { // Register method interceptor only if are not a proxy
                MethodMetadata[] methods = manipulation.getMethods();
                for (int k = 0; k < methods.length; k++) {
                    getInstanceManager().register(methods[k], dep);
                }
            }

View Full Code Here

Examples of org.apache.felix.ipojo.parser.PojoMetadata

    public void check(Element element) throws ConfigurationException {
        m_classname = element.getAttribute("classname");
        if (m_classname == null) {
            throw new ConfigurationException("A component needs a class name : " + element);
        }
        m_manipulation = new PojoMetadata(m_componentMetadata);
    }
View Full Code Here

Examples of org.apache.felix.ipojo.parser.PojoMetadata

            }

            String value = configurables[i].getAttribute("value");

            // Detect the type of the property
            PojoMetadata manipulation = getFactory().getPojoMetadata();
            String type = null;
            if (methodName != null) {
                MethodMetadata[] method = manipulation.getMethods(methodName);
                if (method.length == 0) {
                    type = configurables[i].getAttribute("type");
                    if (type == null) {
                        throw new ConfigurationException("Malformed property : The type of the property cannot be discovered, add a 'type' attribute");
                    }
                } else {
                    if (method[0].getMethodArguments().length != 1) {
                        throw new ConfigurationException("Malformed property :  The method " + methodName + " does not have one argument");
                    }
                    type = method[0].getMethodArguments()[0];
                    configurables[i].addAttribute(new Attribute("type", type)); // Add the type to avoid configure checking
                }
            } else if (fieldName != null) {
                FieldMetadata field = manipulation.getField(fieldName);
                if (field == null) {
                    throw new ConfigurationException("Malformed property : The field " + fieldName + " does not exist in the implementation class");
                }
                type = field.getFieldType();
                configurables[i].addAttribute(new Attribute("type", type)); // Add the type to avoid configure checking
            } else if (paramIndex != null) {
                int index = Integer.parseInt(paramIndex);
                type = configurables[i].getAttribute("type");
                MethodMetadata[] cts = manipulation.getConstructors();
                // If we don't have a type, try to get the first constructor and get the type of the parameter
                // we the index 'index'.
                if (type == null && cts.length > 0 && cts[0].getMethodArguments().length > index) {
                    type = cts[0].getMethodArguments()[index];
                } else if (type == null) { // Applied only if type was not determined.
View Full Code Here

Examples of org.apache.felix.ipojo.parser.PojoMetadata

        metadata.addAttribute(new Attribute("classname", classname));
        metadata.addElement(new Element("provides", ""));
        metadata.addElement(manipulation);
        manipulation.addAttribute(new Attribute("classname", classname));

        Mockito.when(factory.getPojoMetadata()).thenReturn(new PojoMetadata(metadata));
        Mockito.when(factory.getClassName()).thenReturn(classname);

        handler.initializeComponentFactory(desc, metadata);

        //Expected behavior: the implementation classname
View Full Code Here

Examples of org.apache.felix.ipojo.parser.PojoMetadata

        provides.addAttribute(new Attribute("specifications", "java.beans.SimpleBeanInfo"));
        metadata.addElement(provides);
        metadata.addElement(manipulation);
        manipulation.addAttribute(new Attribute("classname", classname));
        manipulation.addAttribute(new Attribute("super", "java.beans.SimpleBeanInfo"));
        Mockito.when(factory.getPojoMetadata()).thenReturn(new PojoMetadata(metadata));
        Mockito.when(factory.getClassName()).thenReturn(classname);

        handler.initializeComponentFactory(desc, metadata);

        System.out.println(metadata);
View Full Code Here

Examples of org.apache.felix.ipojo.parser.PojoMetadata

        provides.addAttribute(new Attribute("specifications", classname));
        metadata.addElement(provides);
        metadata.addElement(manipulation);
        manipulation.addAttribute(new Attribute("classname", classname));
        manipulation.addAttribute(new Attribute("super", "java.beans.SimpleBeanInfo"));
        Mockito.when(factory.getPojoMetadata()).thenReturn(new PojoMetadata(metadata));
        Mockito.when(factory.getClassName()).thenReturn(classname);

        handler.initializeComponentFactory(desc, metadata);

        System.out.println(metadata);
View Full Code Here

Examples of org.apache.felix.ipojo.parser.PojoMetadata

        metadata.addElement(provides);
        metadata.addElement(manipulation);
        manipulation.addAttribute(new Attribute("classname", classname));
        manipulation.addAttribute(new Attribute("super", "java.beans.MethodDescriptor"));

        Mockito.when(factory.getPojoMetadata()).thenReturn(new PojoMetadata(metadata));
        Mockito.when(factory.getClassName()).thenReturn(classname);

        handler.initializeComponentFactory(desc, metadata);

        System.out.println(metadata);
View Full Code Here

Examples of org.apache.felix.ipojo.parser.PojoMetadata

        m_callbacks = new LifecycleCallback[0];

        String imm = metadata.getAttribute("immediate");
        m_immediate = imm != null && imm.equalsIgnoreCase("true");
       
        PojoMetadata meta = getFactory().getPojoMetadata();

        Element[] hooksMetadata = metadata.getElements("callback");
        for (int i = 0; hooksMetadata != null && i < hooksMetadata.length; i++) {
            String method = hooksMetadata[i].getAttribute("method");
            if (method == null) {
                throw new ConfigurationException("Lifecycle callback : A callback needs to contain a method attribute");
            }
           
            MethodMetadata met = meta.getMethod(method, new String[0]);
           
            int transition = -1;
            String trans = hooksMetadata[i].getAttribute("transition");
            if (trans == null) {
                throw new ConfigurationException("Lifecycle callback : the transition attribute is missing");
View Full Code Here

Examples of org.apache.felix.ipojo.parser.PojoMetadata

        field = controller[0].getAttribute("field");
        if (field == null) {
            throw new ConfigurationException("Lifecycle controller : the controller element needs to contain a field attribute");
        }

        PojoMetadata method = getFactory().getPojoMetadata();
        FieldMetadata fieldMetadata = method.getField(field);
        if (fieldMetadata == null) {
            throw new ConfigurationException("Lifecycle controller : The field " + field + " does not exist in the implementation class");
        }

        if (!fieldMetadata.getFieldType().equalsIgnoreCase("boolean")) {
View Full Code Here

Examples of org.apache.felix.ipojo.parser.PojoMetadata

     * @see org.apache.felix.ipojo.Handler#initializeComponentFactory(org.apache.felix.ipojo.architecture.ComponentTypeDescription, org.apache.felix.ipojo.metadata.Element)
     */
    public void initializeComponentFactory(ComponentTypeDescription desc, Element metadata) throws ConfigurationException {
        // Change ComponentInfo
        Element[] provides = metadata.getElements("provides");
        PojoMetadata manipulation = getFactory().getPojoMetadata();

        for (Element provide : provides) {
            // First : create the serviceSpecification list
            String[] serviceSpecification = manipulation.getInterfaces();
            String parent = manipulation.getSuperClass();
            Set<String> interfaces = new HashSet<String>();
            Set<String> parentClasses = new HashSet<String>();
            try {
                computeInterfacesAndSuperClasses(serviceSpecification, parent, desc.getBundleContext().getBundle(), interfaces, parentClasses);
                getLogger().log(Logger.INFO, "Collected interfaces from " + metadata.getAttribute("classname") + " : " + interfaces);
                getLogger().log(Logger.INFO, "Collected super classes from " + metadata.getAttribute("classname") + " : " + parentClasses);
            } catch (ClassNotFoundException e) {
                throw new ConfigurationException("An interface or parent class cannot be loaded", e);
            }

            String serviceSpecificationStr = provide.getAttribute("specifications");
            if (serviceSpecificationStr == null) {
                serviceSpecificationStr = provide.getAttribute("interface");
                if (serviceSpecificationStr != null) {
                    warn("The 'interface' attribute is deprecated, use the 'specifications' attribute instead of 'interface'");
                }
            }

            if (serviceSpecificationStr != null) {
                List<String> itfs = ParseUtils.parseArraysAsList(serviceSpecificationStr);
                for (String itf : itfs)
                    if (!interfaces.contains(itf)
                            && !parentClasses.contains(itf)
                            && !desc.getFactory().getClassName().equals(itf)) {
                        desc.getFactory().getLogger().log(Logger.ERROR, "The specification " + itf + " is not implemented by " + metadata.getAttribute("classname"));
                    }
                interfaces.clear();
                interfaces.addAll(itfs);
            }

            if (interfaces.isEmpty()) {
                warn("No service interface found in the class hierarchy, use the implementation class");
                interfaces.add(desc.getFactory().getClassName());
            }

            StringBuffer specs = null;
            Set<String> set = new HashSet<String>(interfaces);
            set.remove(Pojo.class.getName()); // Remove POJO.
            for (String spec : set) {
                desc.addProvidedServiceSpecification(spec);
                if (specs == null) {
                    specs = new StringBuffer("{");
                    specs.append(spec);
                } else {
                    specs.append(',');
                    specs.append(spec);
                }
            }

            specs.append('}');
            provide.addAttribute(new Attribute("specifications", specs.toString())); // Add interface attribute to avoid checking in the configure method

            Element[] props = provide.getElements("property");
            for (int j = 0; props != null && j < props.length; j++) {
                String name = props[j].getAttribute("name");
                String value = props[j].getAttribute("value");
                String type = props[j].getAttribute("type");
                String field = props[j].getAttribute("field");


                // Get property name :
                if (field != null && name == null) {
                    name = field;
                }

                // Check type if not already set
                if (type == null) {
                    if (field == null) {
                        throw new ConfigurationException("The property " + name + " has neither type nor field.");
                    }
                    FieldMetadata fieldMeta = manipulation.getField(field);
                    if (fieldMeta == null) {
                        throw new ConfigurationException("A declared property was not found in the implementation class : " + field);
                    }
                    type = fieldMeta.getFieldType();
                    props[j].addAttribute(new Attribute("type", type));
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.