Package fr.imag.adele.apam.declarations

Examples of fr.imag.adele.apam.declarations.ComponentDeclaration


    StringBuilder contents = new StringBuilder("    contains components: ");
   
    Decoder<Element> parser = new MetadataParser();
   
    for (Element element : metadata.getElements()) {
      ComponentDeclaration declaration = parser.decode(element,reporter);
     
      if (declaration == null)
        continue;
   
      components.add(declaration);
      index.put(versioned(declaration));
     
      contents.append(declaration.getName()).append(" ");
    }

    info(contents.toString());
  }
View Full Code Here


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

  @Override
  public ComponentDeclaration decode(Element metadata, Reporter errorHandler) {
   
    this.errorHandler   = errorHandler;

    ComponentDeclaration component = null;
   
    /*
     * Ignore not APAM elements
     */
    if (!isApamDefinition(metadata)) {
View Full Code Here

     */
  private ComponentDeclaration result() {
        this.properties   = null;
        this.reporter  = null;
       
        ComponentDeclaration result = component;
        this.component    = null;
       
        return result;
  }
View Full Code Here

       *
       * NOTE notice that we create and modify an effective cloned declaration, we must be careful
       * not to modify the original declaration in the project repository
       *
       */
      ComponentDeclaration group     = context.getComponent(component.getGroupVersioned());
      ComponentDeclaration effective  = component.getEffectiveDeclaration(group);
     
     
      /*
       * Name property is not inherited directly, but renamed at each level
       */
      ComponentDeclaration level = component;
      while (level != null) {


        if (level instanceof SpecificationDeclaration) {
          effective.getProperties().put(CST.SPECNAME, level.getName());
        }

        if (level instanceof ImplementationDeclaration) {
          effective.getProperties().put(CST.IMPLNAME, level.getName());
        }

        if (level instanceof InstanceDeclaration) {
          effective.getProperties().put(CST.INSTNAME, level.getName());
        }
       
        level = context.getComponent(level.getGroupVersioned());
      }
     
      /*
       * For unvalued properties we add default values, this allows filter to be evaluated even if no value
       * is explicitly specified
View Full Code Here

    /*
     * Get the source of the relations' navigation
     */
    String sourceName            = expression.sourceName;
    ComponentReference<?> sourceReference  = sourceName.equals("this") ? getComponent().getReference() : new ComponentReference<ComponentDeclaration>(sourceName);
    ComponentDeclaration source        = getComponent(sourceReference, true);

    if (source == null) {
      error("Invalid substitute expression "+value+ ", component not found "+sourceReference.getName());
      return null;
    }
   
    /*
     * iteratively get the target and the multiplicity of the relations' navigation
     */
   
    boolean hasMultipleNavigation  = false;
    ResolvableReference target    = source.getReference();

    navigation:
    for (String relationName : expression.depIds != null ? expression.depIds : Collections.<String> emptyList()) {


      /*
       * Otherwise try to best approximate the target of the relation with the build-time information
       */
      if (CST.isFinalRelation(relationName)) {
       
        if (relationName.equals(CST.REL_COMPOSITE) || relationName.equals(CST.REL_COMPOTYPE) || relationName.equals(CST.REL_CONTAINS)) {
          /*
           * For relations that navigate the nested hierarchy of composites, we cannot know the actual types
           * at build-time, as this hierarchy is completely build at runtime. We simply stop navigation
           */
          target = new UnknownReference(new ResourceReference("<RUNTIME>"));
        }       
        else {
          /*
           * For relations that navigate the abstraction levels, we can navigate to more abstract levels, and
           * for more concrete levels we continue validating in the same context
           */
          ComponentKind targetLevel = source.getKind();

          if (relationName.equals(CST.REL_SPEC)) {
            targetLevel = ComponentKind.SPECIFICATION;
          }
          else if (relationName.equals(CST.REL_IMPL) || relationName.equals(CST.REL_IMPLS)) {
            targetLevel = ComponentKind.IMPLEMENTATION;
          }
          else if (relationName.equals(CST.REL_INST) || relationName.equals(CST.REL_INSTS)) {
            targetLevel = ComponentKind.INSTANCE;
          }
         
          ComponentDeclaration sourceAtDifferentLevel =  changeAbstractionLevel(source,targetLevel);
          if (sourceAtDifferentLevel == null) {
            error("Invalid substitute expression "+value+ " , relation "+quoted(relationName)+" not defined for component "+source.getName());
            return null;
          }
         
View Full Code Here

   * validating substitution expression, as the mentioned relations and attributes must be defined in
   * the abstract component.
   */
  private ComponentDeclaration changeAbstractionLevel(ComponentDeclaration component, ComponentKind level) {
   
    ComponentDeclaration result = component;
    while (level.isMoreAbstractThan(result.getKind())) {
     
      /*
       * try to go up the abstraction levels
       */
      ComponentDeclaration parent = getComponent(result.getGroupVersioned(),true);
     
      /*
       * There is no ancestor defined, we have to stop
       */
      if (parent == null) {
View Full Code Here

    /*
     *  A function is only valid for instrumented concrete components
     */
   
    ComponentDeclaration context   = getComponent();
    String method           = value.substring(1).trim();
   
    if (!(context instanceof AtomicImplementationDeclaration)) {
      error("Invalid substitute value, function substitution is only valid for atomic components "+method);
      return null;
View Full Code Here

   
    /*
     *  Load the parent group, this may fail if the group or one of its ancestors is not
     *  in the repository
     */
    ComponentDeclaration group = getComponent(component.getGroupVersioned(),true);
    if (effective && component.getGroup() != null && group == null)
      return null;
     
    /*
     *  Compute the effective declaration.
View Full Code Here

   *
   * TODO This method should be directly available in class {@link ComponentDeclaration}, this requires to migrate
   * part of the validation and repository API directly to the declarations package.
   */
  public boolean isAncestor(ComponentDeclaration component, ComponentReference<?> candidate, boolean orEquals) {
    ComponentDeclaration ancestor = orEquals ? component : getComponent(component.getGroupVersioned());
    while (ancestor != null) {
     
      if (ancestor.getReference().equals(candidate))
        return true;
     
      ancestor = getComponent(ancestor.getGroupVersioned());
    }
   
    return false;
  }
View Full Code Here

TOP

Related Classes of fr.imag.adele.apam.declarations.ComponentDeclaration

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.