Examples of PojoMetadata


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

     * @param metadata the component metadata
     * @param dict the instance configuration
     */
    public void configure(Element metadata, Dictionary dict) {

        PojoMetadata manipulation = getPojoMetadata();

        m_instanceManager = getInstanceManager();

        m_jmxConfigFieldMap = new JmxConfigFieldMap();

        // Build the hashmap
        Element[] mbeans = metadata.getElements(JMX_CONFIG_ELT, m_namespace);
        if (mbeans == null || mbeans.length == 0) {
            mbeans = metadata.getElements(JMX_CONFIG_ALT_ELT, m_namespace);
        }

        if (mbeans.length != 1) {
            error("A component must have exactly one " + JMX_CONFIG_ELT + " or " + JMX_CONFIG_ALT_ELT + " element.");
            error("The JMX handler configuration is ignored.");
            return;
        }

        Element mbean = mbeans[0];

        // retrieve kind of MBeanServer to use
        m_usesMOSGi = Boolean.parseBoolean(mbean.getAttribute(JMX_USES_MOSGI_ELT));

        // retrieve object name
        m_completeObjNameElt = mbean.getAttribute(JMX_OBJ_NAME_ELT);
        m_domainElt = mbean.getAttribute(JMX_OBJ_NAME_DOMAIN_ELT);
        m_objNameWODomainElt = mbean.getAttribute(JMX_OBJ_NAME_WO_DOMAIN_ELT);

        // test if Pojo is interested in registration callbacks
        m_registerCallbacks = manipulation
            .isInterfaceImplemented(MBeanRegistration.class.getName());
        if (m_registerCallbacks) {
            // don't need to check that methods exist, the pojo implements
            // MBeanRegistration interface
            String[] preRegisterParams = { MBeanServer.class.getName(),
                    ObjectName.class.getName() };
            m_preRegisterMeth = manipulation.getMethod(PRE_REGISTER_METH_NAME,
                preRegisterParams);

            String[] postRegisterParams = { Boolean.class.getName() };
            m_postRegisterMeth = manipulation.getMethod(
                POST_REGISTER_METH_NAME, postRegisterParams);

            m_preDeregisterMeth = manipulation.getMethod(
                PRE_DEREGISTER_METH_NAME, new String[0]);

            m_postDeregisterMeth = manipulation.getMethod(
                POST_DEREGISTER_METH_NAME, new String[0]);
        }

        // set property
        Element[] attributes = mbean.getElements(JMX_PROPERTY_ELT, m_namespace);
        Element[] attributesAlt = mbean.getElements(JMX_PROPERTY_ELT_ALT, m_namespace);
        List<Element> listOfAttributes = new ArrayList<Element>();
        if (attributes != null) {
          listOfAttributes.addAll(Arrays.asList(attributes));
        }
        if (attributesAlt != null) {
          listOfAttributes.addAll(Arrays.asList(attributesAlt));
        }

        Element[] attributesOld = mbeans[0].getElements(JMX_PROPERTY_ELT);
        if (attributesOld != null) {
            warn("The JMX property element should use the '" + m_namespace + "' namespace.");
            listOfAttributes.addAll(Arrays.asList(attributesOld));
        }

        for (Element attribute : listOfAttributes) {
            boolean notif = false;
            String rights;
            String name;
            String field = attribute.getAttribute(JMX_FIELD_ELT);

            if (attribute.containsAttribute(JMX_NAME_ELT)) {
                name = attribute.getAttribute(JMX_NAME_ELT);
            } else {
                name = field;
            }
            if (attribute.containsAttribute(JMX_RIGHTS_ELT)) {
                rights = attribute.getAttribute(JMX_RIGHTS_ELT);
            } else {
                rights = "r";
            }

            PropertyField property = new PropertyField(name, field, rights,
                getTypeFromAttributeField(field, manipulation));

            if (attribute.containsAttribute(JMX_NOTIFICATION_ELT)) {
                notif = Boolean.parseBoolean(attribute
                    .getAttribute(JMX_NOTIFICATION_ELT));
            }

            property.setNotifiable(notif);

            if (notif) {
                // add the new notifiable property in structure
                NotificationField notification = new NotificationField(
                    name, this.getClass().getName() + "." + field, null);
                m_jmxConfigFieldMap.addNotificationFromName(name,
                    notification);
            }
            m_jmxConfigFieldMap.addPropertyFromName(name, property);
            getInstanceManager().register(manipulation.getField(field),
                this);
            info("property exposed:" + name + " " + field + ":"
                    + getTypeFromAttributeField(field, manipulation) + " "
                    + rights + ", Notif=" + notif);
        }
View Full Code Here

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

                String name = subscriberMetadata.getName();
                info(LOG_PREFIX + "Checking subscriber " + name);

                // Determine the event callback prototype
                PojoMetadata pojoMetadata = getPojoMetadata();
                String callbackType;
                if (subscriberMetadata.getDataKey() == null) {
                    callbackType = Event.class.getName();
                } else {
                    callbackType = subscriberMetadata.getDataType().getName();
                }

                // Check the event callback method is present
                MethodMetadata methodMetadata = pojoMetadata.getMethod(
                        subscriberMetadata.getCallback(),
                        new String[] { callbackType });
                String callbackSignature = subscriberMetadata.getCallback()
                        + "(" + callbackType + ")";
                if (methodMetadata == null) {
View Full Code Here

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

                for (int j = 0; j < subscriberTopics.length; j++) {
                    topics.add(subscriberTopics[j]);
                }

                // Determine the event callback prototype
                PojoMetadata pojoMetadata = getPojoMetadata();
                String callbackType;
                if (subscriberMetadata.getDataKey() == null) {
                    callbackType = Event.class.getName();
                } else {
                    callbackType = subscriberMetadata.getDataType().getName();
                }

                // Create the specified callback and register it
                MethodMetadata methodMetadata = pojoMetadata.getMethod(
                        subscriberMetadata.getCallback(),
                        new String[] { callbackType });
                Callback callback = new Callback(methodMetadata, m_manager);
                m_callbacksByName.put(name, callback);
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

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

  /**
   * The iPOJO metadata associated with the callback method to be invoked
   */
  public MethodMetadata getMethodMetadata() {
   
    PojoMetadata metadata   = instance.getFactory().getPojoMetadata();
    String[] arguments    = requiresArgument ? new String[] {m_methodObj.getParameterTypes()[0].getCanonicalName()}: new String[0];
   
    return metadata.getMethod(m_methodObj.getName(),arguments);
  }
View Full Code Here

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

     * load implementation class and Pojo instrumentation metadata
     */

    String className = parseString(name, element, ATT_CLASSNAME, true);

    PojoMetadata pojoMetadata = null;
    Class<?> instrumentedCode = null;
    try {
      pojoMetadata = new PojoMetadata(element);
      instrumentedCode = ((className != Decoder.UNDEFINED) && (introspector != null)) ? introspector.getInstrumentedClass(className) : null;
    } catch (ClassNotFoundException e) {
      errorHandler.report(Severity.ERROR, "Apam component " + name + ": " + "the component class " + className + " can not be loaded");
    } catch (Exception ignoredException) {
    }

    InstrumentedClass instrumentedClass = new InstrumentedClassMetadata(className, pojoMetadata, instrumentedCode);

    /*
     * load specification
     */
    SpecificationReference specification            = parseSpecificationReference(name, element, ATT_SPECIFICATION, false);
        String  versionRange                    = parseString(name, element, ATT_REQUIRE_VERSION, false);
        VersionedReference<SpecificationDeclaration> specificationVersion  = specification != null ? VersionedReference.range(specification,versionRange) : null;
       
        AtomicImplementationDeclaration declaration = new AtomicImplementationDeclaration(name, specificationVersion, instrumentedClass);
       
    parseComponent(element, declaration);

    /*
     * Parse message producer method interception
     */
    String messageMethods = parseString(name, element, ATT_PUSH, false);
    for (String messageMethod : list(messageMethods,true)) {

      /*
       * Parse optionally specified method signature
       */
      String methodName = messageMethod.trim();
      String methodSignature = null;

      if (methodName.indexOf("(") != -1 && methodName.endsWith(")")) {
        methodSignature = methodName.substring(methodName.indexOf("(") + 1, methodName.length() - 1);
        methodName = methodName.substring(0, methodName.indexOf("("));
      }

      ProviderInstrumentation instrumentation = new ProviderInstrumentation.MessageProviderMethodInterception(declaration, methodName, methodSignature);

      if (!instrumentation.isValidInstrumentation()) {
        errorHandler.report(Severity.ERROR, name + " : the specified method \"" + instrumentation.getName() + "\" in \"" + ATT_PUSH + "\" is invalid or not found");
      }

      declaration.getProviderInstrumentation().add(instrumentation);
    }

    /*
     * Verify that at least one method is intercepted for each declared produced message.
     */
    for (MessageReference message : declaration.getProvidedResources(MessageReference.class)) {

      boolean declared = declaration.getProviderInstrumentation().size() > 0;
      boolean injected = false;
      boolean defined = false;

      for (ProviderInstrumentation providerInstrumentation : declaration.getProviderInstrumentation()) {

        ResourceReference instrumentedResource = providerInstrumentation.getProvidedResource();

        if (instrumentedResource instanceof UnknownReference) {
          continue;
        }

        defined = true;

        if (!instrumentedResource.equals(message)) {
          continue;
        }

        injected = true;
        break;
      }

      /*
       * If we could determine the method types and there was no injection then signal error
       *
       * NOTE Notice that some errors will not be detected at build time since all the reflection information
       * is not available, and validation must be delayed until run time
       */
      if (!declared || (defined && !injected)) {
        errorHandler.report(Severity.ERROR, "Apam component " + name + ": " + " message of type " + message.getJavaType() + " is not produced by any push method");
      }

    }

    /*
     * if not explicitly provided, get all the implemented interfaces.
     */
    if (declaration.getProvidedResources(InterfaceReference.class).isEmpty() && (pojoMetadata != null)) {
      for (String implementedInterface : pojoMetadata.getInterfaces()) {
        declaration.getProvidedResources().add(new InterfaceReference(implementedInterface));
      }
    }

    /*
 
View Full Code Here

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

        return;
     
      /*
       * Register instrumentation for message push at the provider side
       */
      PojoMetadata manipulation           = getFactory().getPojoMetadata();
      AtomicImplementationDeclaration primitive  = (AtomicImplementationDeclaration) declaration;
      for (ProviderInstrumentation providerInstrumentation : primitive.getProviderInstrumentation()) {
       
          MessageReference messageReference = providerInstrumentation.getProvidedResource().as(MessageReference.class);
        if (messageReference == null)
          continue;

        if (! (providerInstrumentation instanceof ProviderInstrumentation.MessageProviderMethodInterception))
          continue;

        ProviderInstrumentation.MessageProviderMethodInterception interception =
            (ProviderInstrumentation.MessageProviderMethodInterception) providerInstrumentation;
         
      /*
       * Search for the specified method to intercept, we always look for a perfect match of the
       * specified signature, and do not allow ambiguous method names
       */
     
      MethodMetadata candidate = null;
      for (MethodMetadata method :  manipulation.getMethods(interception.getMethodName())) {
       
        if (interception.getMethodSignature() == null) {
          candidate = method;
          break;
        }
View Full Code Here

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);
        }

        // Get instance filters.
        Dictionary filtersConfiguration = getRequiresFilters(dictionary.get("temporal.filters"));
        if (filtersConfiguration == null || filtersConfiguration.isEmpty()) {
            // Fall back on the Requires handler configuration, if any
            filtersConfiguration = getRequiresFilters(dictionary.get("requires.filters"));
        }
        // Get from filters if any.
        Dictionary fromConfiguration = getRequiresFilters(dictionary.get("temporal.from"));
        if (fromConfiguration == null || fromConfiguration.isEmpty()) {
            // Fall back on the Requires handler configuration, if any
            fromConfiguration = getRequiresFilters(dictionary.get("requires.from"));
        }


        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");

            String id = field;
            if (deps[i].containsAttribute("id")) {
                id = deps[i].getAttribute("id");
            }

            FieldMetadata fieldmeta = manipulation.getField(field);
            if (fieldmeta == null) {
                error("The field " + field + " does not exist in the class " + getInstanceManager().getClassName());
                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");
                }
            }

            // Determine the filter
            String fil = deps[i].getAttribute("filter");
            // Override the filter if filter configuration if available in the instance configuration
            if (filtersConfiguration != null && id != null && filtersConfiguration.get(id) != null) {
                fil = (String) filtersConfiguration.get(id);
            }

            // Check the from attribute
            String from = deps[i].getAttribute("from");
            if (fromConfiguration != null && id != null && fromConfiguration.get(id) != null) {
                from = (String) fromConfiguration.get(id);
            }

            if (from != null) {
                String fromFilter = "(|(instance.name=" + from + ")(service.pid=" + from + "))";
                if (agg) {
                    warn("The 'from' attribute is incompatible with aggregate requirements: only one provider will " +
                            "match : " + fromFilter);
                }
                if (fil != null) {
                    fil = "(&" + fromFilter + fil + ")"; // Append the two filters
                } else {
                    fil = fromFilter;
                }
            }

            Filter filter = null;
            if (fil != null) {
                try {
                    filter = getInstanceManager().getContext().createFilter(fil);
                } catch (InvalidSyntaxException e) {
                    throw new ConfigurationException("A requirement filter is invalid : " + filter, e);
                }
            }

            String prox = deps[i].getAttribute("proxy");
            // 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 = DependencyMetadataHelper.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

        // Register fields
        // By convention, properties file entry are field name, so look for each property to get field list.

        //First get Pojo Metadata metadata :
        PojoMetadata pojoMeta = getPojoMetadata();
        Enumeration e = m_properties.keys();
        while (e.hasMoreElements()) {
            String field = (String) e.nextElement();
            FieldMetadata fm = pojoMeta.getField(field);

            if (fm == null) { // The field does not exist
                throw new ConfigurationException("The field " + field + " is declared in the properties file but does not exist in the pojo");
            }
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
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.