Package fr.imag.adele.apam.declarations.references

Examples of fr.imag.adele.apam.declarations.references.ResolvableReference


        /*
         * ignore non matching candidates
         */

        ResolvableReference target = trigger.getTarget();

        if (trigger.getTarget() instanceof SpecificationReference && !candidate.getSpec().getDeclaration().getReference().equals(target)) {
          continue;
        }

View Full Code Here


   */
  private RelationDeclaration parseRelation(Element element, ComponentDeclaration component, boolean isContextual) {
    /*
     * Get the reference to the target of the relation if specified
     */
    ResolvableReference targetDef = parseResolvableReference(component.getName(), element, false);

    /*
     * All dependencies have an optional identifier and multiplicity
     * specification, as well as an optional source kind and target kind
     */
    String id = parseString(component.getName(), element, ATT_NAME, false);
    boolean isOverride = isContextual && element.getName().equals(OVERRIDE);

    boolean isMultiple = parseBoolean(component.getName(), element, ATT_MULTIPLE, false, false);

    String sourceName = parseString(component.getName(), element, ATT_SOURCE, isContextual && !isOverride);

    ComponentKind sourceKind = parseKind(component.getName(), element, ATT_SOURCE_KIND, isContextual && !isOverride, null);
    ComponentKind targetKind = parseKind(component.getName(), element, ATT_TARGET_KIND, false, null);

    /*
     * For atomic components, dependency declarations may optionally have a number of nested instrumentation declarations.
     *
     * These are parsed first, as a number of attributes of the relation that are not explicitly declared can be inferred
     * from the instrumentation metadata.
     */

    List<RequirerInstrumentation> instrumentations = new ArrayList<RequirerInstrumentation>();
    if (component instanceof AtomicImplementationDeclaration) {

      AtomicImplementationDeclaration atomic = (AtomicImplementationDeclaration) component;

      /*
       * Optionally, as a shortcut, a single injection may be specified
       * directly as an attribute of the relation
       */
      RequirerInstrumentation directInstrumentation = parseRelationInstrumentation(element, atomic, false);
      if (directInstrumentation != null) {
        instrumentations.add(directInstrumentation);
      }

      for (Element instrumentation : optional(element.getElements())) {

        /*
         * ignore elements that are not from APAM
         */
        if (!isApamDefinition(instrumentation)) {
          continue;
        }

        /*
         * Accept only resource references
         */
        String resourceKind = instrumentation.getName();
        if (!(INTERFACE.equals(resourceKind) || MESSAGE.equals(resourceKind)
            || PACKAGE.equals(resourceKind))) {
          continue;
        }

        instrumentations.add(parseRelationInstrumentation(instrumentation, atomic, true));

      }

    }


    /*
     * If no ID was explicitly specified, but a single instrumentation was declared the the name of the field or
     * method becomes the ID of the relation.
     */
    if (id == null && instrumentations.size() == 1) {
      id = instrumentations.get(0).getName();
    }

    /*
     * If no target was explicitly specified, sometimes we can infer it from the instrumentation metadata.
     */
    if (!instrumentations.isEmpty() && (targetDef == null || targetKind == null)) {

      ComponentKind inferredKind = null;
      ResolvableReference inferredTarget = null;

      for (RequirerInstrumentation instrumentation : instrumentations) {

        String javaType = instrumentation.getRequiredResource().getJavaType();
        ComponentKind candidateKind = null;
        ResolvableReference candidateTarget = null;

        if (ComponentKind.COMPONENT.isAssignableTo(javaType)) {
          candidateKind = null;
          candidateTarget = null;
        } else if (ComponentKind.SPECIFICATION.isAssignableTo(javaType)) {
View Full Code Here

  /**
   * encodes the target of a relation
   */
  private String target(RelationDeclaration relation) {

    ResolvableReference target  = relation.getTarget();
      String encodedTarget     = null;

      if (target instanceof InterfaceReference) {
        encodedTarget = "{"+ComponentParser.INTERFACE+"}"+target.getName();
      }
      else if (target instanceof MessageReference) {
        encodedTarget = "{"+ComponentParser.MESSAGE+"}"+target.getName();
      }
      else if (target instanceof PackageReference) {
        encodedTarget = "{"+ComponentParser.PACKAGE+"}"+target.getName();
      }
      else if (target instanceof UnknownReference && target.as(InterfaceReference.class) != null) {
        encodedTarget = "{"+ComponentParser.INTERFACE+"}";
      }
      else if (target instanceof UnknownReference && target.as(MessageReference.class) != null) {
        encodedTarget ="{"+ComponentParser.MESSAGE+"}";
      }
      else if (target instanceof ComponentReference) {
        encodedTarget = target.getName();
      }
      else {
        error("unknown kind of target for relation "+relation);
      }

View Full Code Here

    /*
     * 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;
          }
         
          source          = sourceAtDifferentLevel;
          target          = source.getReference();
          hasMultipleNavigation  = hasMultipleNavigation || relationName.equals(CST.REL_IMPLS) || relationName.equals(CST.REL_INSTS);
        }
      }
      else {

        /*
         * For normal relations, we get the relation declaration and follow the specified target
         */
        RelationDeclaration relation = source.getRelation(relationName);
       
        if (relation == null) {
          error("Invalid substitute expression "+value+ " , relation "+quoted(relationName)+" not defined in component "+source.getName());
          return null;
        }
       
        target          = relation.getTarget();
        hasMultipleNavigation  = hasMultipleNavigation || relation.isMultiple();
       
        /*
         * If the target is a component, we can move the source one step further
         */
        if (relation.getTarget().as(ComponentReference.class) != null) {
          source = getComponent(relation.getTarget().as(ComponentReference.class),true);
          if (source == null) {
            error("Invalid substitute expression "+value+ " , relation "+quoted(relationName)+" has unknown target "+relation.getTarget().getName());
            return null;
          }
         
        }
       
      }
     
      /*
       * When we get to an interface target, we cannot validate any further
       */
      if (target.as(ResourceReference.class) != null)
        break navigation;
     
    }

   
    /*
     * Get the type of the referenced property
     */
    Type propertyType = null;

    if (! Attribute.isFinalAttribute(expression.attr)) {
     

      /*
       * If the last target cannot be determined at build time, simply give up
       */
      if (target.as(ComponentReference.class) == null) {
        warning("Substitute expression "+value+ ", cannot be completely validated at build-time");
        return Type.NONE;
      }
     
      /*
       * The last computed source of the navigation is used to look for the final property
       */
      PropertyDefinition property = source.getPropertyDefinition(expression.attr);
      if (property == null) {
        error("Invalid substitute expression "+value+ ", invalid property "+quoted(expression.attr)+" for component "+target.getName());
        return null;
      }

      /*
       * Infer the type of the expression from the type of the property, and the multiplicity of the navigation
View Full Code Here

  // Get the ResolvableReference name
  String rr_name = rr_json.get(JSON_RESOLVABLE_REF_NAME).asText();

  String providerURL = json.get(JSON_PROVIDER_URL).asText();

  ResolvableReference rr = null;
  // Create the ResolvableReference according to its type.
  switch (rr_type) {
  case instance:
      rr = new InstanceReference(rr_name);
      break;
View Full Code Here

TOP

Related Classes of fr.imag.adele.apam.declarations.references.ResolvableReference

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.