Package org.apache.felix.ipojo.metadata

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


      this.propertyHandler = propertyHandler;
    }

    @Override
    public Element getHandlerInfo() {
      Element root = super.getHandlerInfo();

      if (propertyHandler.getInstanceManager() instanceof ApamInstanceManager) {
        ApamInstanceManager instance = (ApamInstanceManager) propertyHandler.getInstanceManager();
        for (PropertyDefinition definition : instance.getFactory().getDeclaration().getPropertyDefinitions()) {

          /*
           * Ignore non injected properties
           */
          if (definition.getField() == null && definition.getCallback() == null)
            continue;

          String name = definition.getName();
          String field = definition.getField();
          String method = definition.getCallback();
          String value = instance.getApamComponent() != null ? instance.getApamComponent().getProperty(name) : null;

          Element property = new Element("property", ApamComponentFactory.APAM_NAMESPACE);
         
          property.addAttribute(new Attribute("name",  ApamComponentFactory.APAM_NAMESPACE,  name));
          property.addAttribute(new Attribute("field", ApamComponentFactory.APAM_NAMESPACE, field != null ? field : ""));
          property.addAttribute(new Attribute("method",ApamComponentFactory.APAM_NAMESPACE, method != null ? method : ""));
          property.addAttribute(new Attribute("value", ApamComponentFactory.APAM_NAMESPACE, value != null ? value : ""));

          root.addElement(property);
        }
      }
      return root;
View Full Code Here


         * Gets the component type description.
         */
        @Override
        public Element getDescription() {

            Element description = super.getDescription();

            if (getFactory().declaration != null) {

                ComponentDeclaration declaration = getFactory().declaration;

                Element componentDescription = new Element(COMPONENT_DECLARATION_PROPERTY, APAM_NAMESPACE);
                componentDescription.addAttribute(new Attribute("name",declaration.getName()));
                componentDescription.addAttribute(new Attribute("type",declaration.getClass().getSimpleName()));

                if (declaration instanceof ImplementationDeclaration) {
                    ImplementationDeclaration implementation = (ImplementationDeclaration) declaration;
                    if (implementation.getSpecification() != null ) {
                        componentDescription.addAttribute(new Attribute("specification",implementation.getSpecification().getName()));
                    }
                }

                if (declaration instanceof CompositeDeclaration) {
                    CompositeDeclaration composite = (CompositeDeclaration) declaration;
                    if (composite.getSpecification() != null && composite.getMainComponent() != null) {
                        componentDescription.addAttribute(new Attribute("main",composite.getMainComponent().getName()));
                    }
                }

                if (declaration instanceof InstanceDeclaration) {
                    InstanceDeclaration instance = (InstanceDeclaration) declaration;
                    if (instance.getImplementation() != null ) {
                        componentDescription.addAttribute(new Attribute("implementation",instance.getImplementation().getName()));
                    }
                }

                Element providesDescription = new Element("provides", APAM_NAMESPACE);;
                for (ResourceReference resource : declaration.getProvidedResources()) {
                    Element provideDescription = new Element("provides", APAM_NAMESPACE);
                    provideDescription.addAttribute(new Attribute("resource", resource.toString()));
                    providesDescription.addElement(provideDescription);
                }
                componentDescription.addElement(providesDescription);

                Element relationsDescription = new Element("dependencies", APAM_NAMESPACE);;
                for (RelationDeclaration relationDeclaration : declaration.getRelations()) {
                    Element relationDescription = new Element("relation", APAM_NAMESPACE);
                    relationDescription.addAttribute(new Attribute("id", relationDeclaration.getIdentifier()));
                    relationDescription.addAttribute(new Attribute("resource", relationDeclaration.getTarget().toString()));
                    relationDescription.addAttribute(new Attribute("multiple", Boolean.toString(relationDeclaration.isMultiple())));


                    Element injectionsDescription = new Element("instrumentations", APAM_NAMESPACE);
                    for (RequirerInstrumentation injectionDeclaration : relationDeclaration.getInstrumentations()) {
                        Element injectionDescription = new Element("instrumentation", APAM_NAMESPACE);
                        injectionDescription.addAttribute(new Attribute("name", injectionDeclaration.getName()));
                        injectionDescription.addAttribute(new Attribute("resource", injectionDeclaration.getRequiredResource().toString()));
                        injectionDescription.addAttribute(new Attribute("multiple", Boolean.toString(injectionDeclaration.acceptMultipleProviders())));
                        injectionsDescription.addElement(injectionDescription);
                    }
                    relationDescription.addElement(injectionsDescription);

                    Element constraintsDescription = new Element("constraints", APAM_NAMESPACE);
                    for (String constraint : relationDeclaration.getImplementationConstraints()) {
                        Element constraintDescription = new Element("implementation", APAM_NAMESPACE);
                        constraintDescription.addAttribute(new Attribute("filter", constraint));
                        constraintsDescription.addElement(constraintDescription);
                    }
                    for (String constraint : relationDeclaration.getInstanceConstraints()) {
                        Element constraintDescription = new Element("instance", APAM_NAMESPACE);
                        constraintDescription.addAttribute(new Attribute("filter", constraint));
                        constraintsDescription.addElement(constraintDescription);
                    }
                    relationDescription.addElement(constraintsDescription);

                    Element preferencesDescription = new Element("preferences", APAM_NAMESPACE);
                    int priority=0;
                    for ( String preference : relationDeclaration.getImplementationPreferences()) {
                        Element preferenceDescription = new Element("implementation", APAM_NAMESPACE);
                        preferenceDescription.addAttribute(new Attribute("filter", preference));
                        preferenceDescription.addAttribute(new Attribute("priority", Integer.toString(priority++)));
                        preferencesDescription.addElement(preferenceDescription);
                    }

                    priority=0;
                    for (String preference : relationDeclaration.getInstancePreferences()) {
                        Element preferenceDescription = new Element("instance", APAM_NAMESPACE);
                        preferenceDescription.addAttribute(new Attribute("filter", preference));
                        preferenceDescription.addAttribute(new Attribute("priority", Integer.toString(priority++)));
                        preferencesDescription.addElement(preferenceDescription);
                    }
                    relationDescription.addElement(preferencesDescription);

                    relationsDescription.addElement(relationDescription);
                }
                componentDescription.addElement(relationsDescription);

                Element definitionsDescription = new Element("definitions", APAM_NAMESPACE);;
                for (PropertyDefinition propertyDeclaration : declaration.getPropertyDefinitions()) {
                    Element definitionDescription = new Element("property", APAM_NAMESPACE);
                    definitionDescription.addAttribute(new Attribute("name", propertyDeclaration.getName()));
                    definitionDescription.addAttribute(new Attribute("type", propertyDeclaration.getType()));
                    if (propertyDeclaration.hasDefaultValue())
                        definitionDescription.addAttribute(new Attribute("value", propertyDeclaration.getDefaultValue().toString()));
                    definitionsDescription.addElement(definitionDescription);
                }
                componentDescription.addElement(definitionsDescription);

                Element propertiesDescription = new Element("properties", APAM_NAMESPACE);;
                for (Entry<String,String> propertyEntry : declaration.getProperties().entrySet()) {
                    Element propertyDescription = new Element("property", APAM_NAMESPACE);
                    propertyDescription.addAttribute(new Attribute("name", propertyEntry.getKey()));
                    if (propertyEntry.getValue() != null)
                        propertyDescription.addAttribute(new Attribute("value", propertyEntry.getValue().toString()));
                    propertiesDescription.addElement(propertyDescription);
                }
                componentDescription.addElement(propertiesDescription);

                description.addElement(componentDescription);
View Full Code Here

     * Get an XML representation of the state of this relation
     */
    @Override
    public Element getDescription() {

    Element relationDescription = new Element("injection",  ApamComponentFactory.APAM_NAMESPACE);
    relationDescription.addAttribute(new Attribute("relation", relation.getIdentifier()));
    relationDescription.addAttribute(new Attribute("target", relation.getTarget().toString()));
    relationDescription.addAttribute(new Attribute("name", injection.getName()));
    relationDescription.addAttribute(new Attribute("type", injection.getRequiredResource().toString()));
    relationDescription.addAttribute(new Attribute("isAggregate", Boolean.toString(injection.acceptMultipleProviders())));
 
    /*
     * show the current state of resolution. To avoid unnecessary
     * synchronization overhead make a copy of the current target services
     * and do not use directly the field that can be concurrently modified
     */
    Set<Component> resolutions = new HashSet<Component>();
    synchronized (this) {
        resolutions.addAll(targetServices);
    }
 
    relationDescription.addAttribute(new Attribute("resolved", Boolean.toString(!resolutions.isEmpty())));
    for (Component target : resolutions) {
        Element bindingDescription = new Element("binding",ApamComponentFactory.APAM_NAMESPACE);
        bindingDescription.addAttribute(new Attribute("target", target.getName()));
        relationDescription.addElement(bindingDescription);
    }
 
    return relationDescription;

View Full Code Here

   * Get an XML representation of the state of this relation
   */
    @Override
  public Element getDescription() {

        Element consumerDescription = new Element("injection", ApamComponentFactory.APAM_NAMESPACE);
    consumerDescription.addAttribute(new Attribute("relation", relation.getIdentifier()));
        consumerDescription.addAttribute(new Attribute("target", relation.getTarget().toString()));
        consumerDescription.addAttribute(new Attribute("method", injection.getName()));
        consumerDescription.addAttribute(new Attribute("type", injection.getRequiredResource().toString()));
        consumerDescription.addAttribute(new Attribute("isAggregate",   Boolean.toString(injection.acceptMultipleProviders())));

        /*
         * show the current state of resolution. To avoid unnecessary synchronization overhead make a copy of the
         * current target services and do not use directly the field that can be concurrently modified
         */
        List<Wire> resolutions = new ArrayList<Wire>();
        synchronized (this) {
            resolutions.addAll(wires.values());
        }

           
        consumerDescription.addAttribute(new Attribute("resolved",Boolean.toString(!resolutions.isEmpty())));
        consumerDescription.addAttribute(new Attribute("consumer.id",consumerId));
        consumerDescription.addAttribute(new Attribute("flavors",Arrays.toString(messageFlavors)));
        consumerDescription.addAttribute(new Attribute("buffered",Integer.toString(buffer.size())));

        for (Wire wire : resolutions) {
           
            Element wireInfo = new Element("wire",ApamComponentFactory.APAM_NAMESPACE);
            wireInfo.addAttribute(new Attribute("producer.id",(String)wire.getProperties().get(WireConstants.WIREADMIN_PRODUCER_PID)));
            wireInfo.addAttribute(new Attribute("flavors",Arrays.toString(wire.getFlavors())));
            consumerDescription.addElement(wireInfo);
        }
       

       
View Full Code Here

  private void parseCompositeContent(Element element, CompositeDeclaration declaration) {

    /*
     * Look for content management specification
     */
    Element contents[] = optional(element.getElements(CONTENT, APAM));

    if (contents.length > 1) {
      errorHandler.report(Severity.ERROR, "A single content management is allowed in a composite declaration" + element);
    }

    if (contents.length == 0) {
      return;
    }

    Element content = contents[0];

    parseState(content, declaration);
    parseVisibility(content, declaration);
    parsePromotions(content, declaration);
    parseOwns(content, declaration);
View Full Code Here

    /*
     * look for optional trigger declarations
     */

    Element triggers[] = optional(element.getElements(TRIGGER, APAM));
    Element trigger = triggers.length > 0 ? triggers[0] : null;

    if (triggers.length > 1) {
      errorHandler.report(Severity.ERROR, "A single trigger declaration is allowed in an instance declaration" + element);
    }

    /*
     * Parse triggering conditions
     */
    Set<ConstrainedReference> triggerDeclarations = new HashSet<ConstrainedReference>();
    for (Element triggerCondition : optional(trigger != null ? trigger.getElements() : null)) {

      /*
       * ignore elements that are not from APAM
       */
      if (!isApamDefinition(triggerCondition)) {
View Full Code Here

   */
  private void parseState(Element element, CompositeDeclaration composite) {
    /*
     * Look for content management specification
     */
    Element states[] = optional(element.getElements(STATE, APAM));

    if (states.length > 1) {
      errorHandler.report(Severity.ERROR, "A single state declaration is allowed in a composite declaration" + element);
    }

    if (states.length == 0) {
      return;
    }

    Element state = states[0];

    composite.setStateProperty(parsePropertyReference(composite.getName(), state, true));
  }
View Full Code Here

      super(MessageProviderHandler.this);
    }
   
    @Override
    public Element getHandlerInfo() {
      Element info = super.getHandlerInfo();
      info.addAttribute(new Attribute("producer.id",producerId));
      info.addAttribute(new Attribute("session.id",sessionId));
      info.addAttribute(new Attribute("flavors",Arrays.toString(messageFlavors)));
      info.addAttribute(new Attribute("isRegistered",Boolean.toString(isRegisteredProducer)));
 
          /*
           * show the current state of resolution. To avoid unnecessary synchronization overhead make a copy of the
           * current target services and do not use directly the field that can be concurrently modified
           */
          List<Wire> resolutions = new ArrayList<Wire>();
          synchronized (this) {
              resolutions.addAll(wires.values());
          }

      for (Wire wire : resolutions) {
        Element wireInfo = new Element("wire",ApamComponentFactory.APAM_NAMESPACE);
        wireInfo.addAttribute(new Attribute("consumer.id",(String)wire.getProperties().get(WireConstants.WIREADMIN_CONSUMER_PID)));
        wireInfo.addAttribute(new Attribute("flavors",Arrays.toString(wire.getFlavors())));
        info.addElement(wireInfo);
      }
      return info;
    }
View Full Code Here

    checkExistingProperty(element, addedProperties,
        componentPropertyDefinitions);

    // Finally we can add definitions
    for (PropertyDefinition def : mapAddedDefinitions.values()) {
      Element toAdd = new Element(ComponentParser.DEFINITION,
          ComponentParser.APAM);

      toAdd.addAttribute(new Attribute(ComponentParser.ATT_NAME, def
          .getName()));
     
      if(def.getType()!= null) {
      toAdd.addAttribute(new Attribute(ComponentParser.ATT_TYPE, def
          .getType()));
      }
     
      if(def.hasDefaultValue()) {
      toAdd.addAttribute(new Attribute(ComponentParser.ATT_DEFAULT,
          def.getDefaultValue()));
      }
     
      if(def.getField()!=null) {
      toAdd.addAttribute(new Attribute(ComponentParser.ATT_FIELD, def
          .getField()));
      }
     
      if(def.getCallback()!=null) {
        toAdd.addAttribute(new Attribute(ComponentParser.ATT_METHOD, def
          .getCallback()));
      }
     
      if (def.getInjected() != null) {
        toAdd.addAttribute(new Attribute(
            ComponentParser.ATT_INJECTED, def.getInjected()
                .toString()));
      }

      element.addElement(toAdd);
    }

    // And add the properties
    for (String name : addedProperties.keySet()) {
      Element prop = new Element(ComponentParser.PROPERTY,
          ComponentParser.APAM);
      prop.addAttribute(new Attribute(ComponentParser.ATT_NAME, name));
      prop.addAttribute(new Attribute(ComponentParser.ATT_VALUE,
          addedProperties.get(name)));

      element.addElement(prop);
    }
View Full Code Here

      String componentHeader = manifest.getMainAttributes().getValue("iPOJO-Components");
      if (componentHeader == null) {
        return;
      }

      Element metadata = ManifestMetadataParser.parseHeaderMetadata(componentHeader);
      store.setManifest(bundle.getManifest());

     
      ComponentDeclaration template = getVersionedComponentTemplate(artifact);
      EnrichElementsHelper.addPropertiesToChildrenApAMComponents(metadata, template.getPropertyDefinitions(), template.getProperties());

      DefaultManifestBuilder builder = new DefaultManifestBuilder();
      builder.setMetadataRenderer(new MetadataRenderer());
     
      builder.addMetada(Arrays.asList(metadata.getElements()));
     
      store.setManifestBuilder(builder);

    } catch (Exception e) {
      getLog().error(e.getMessage(), e);
View Full Code Here

TOP

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

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.