Package fr.imag.adele.apam

Examples of fr.imag.adele.apam.Component


    /*
     * target definition is a specification, an implementation or instance
     * by name
     */
    if (getTarget() instanceof ComponentReference<?>) {
      Component group = target;
      while (group != null) {
        if (group.getName().equals(getTarget().getName())) {
          return true;
        }
        group = group.getGroup();
      }
      return false;
    }

    // if (dep.getTarget() instanceof ResourceReference) {
View Full Code Here


       * of contextual dependencies and use the correct bundle context.
       *
       * Evaluate changes to relationDeclaration, relation,
       * CoreMetadataParser and computeEffectiverelation
       */
      Component declaringComponent = source;
      while (declaringComponent != null) {

        RelationDeclaration declaration = declaringComponent.getDeclaration().getRelation(relToResolve.getName());
        if (declaration != null && declaration.getMissingException() != null && declaration.getMissingException().equals(exceptionName)) {
          break;
        }

        declaringComponent = declaringComponent.getGroup();
      }

      if (declaringComponent == null && source instanceof Instance) {
        declaringComponent = ((Instance) source).getComposite().getCompType();
      }

      if (declaringComponent == null) {
        throw new ResolutionException();
      }

      /*
       * throw the specified exception
       */

      Class<?> exceptionClass = declaringComponent.getApformComponent().getBundle().loadClass(exceptionName);
      Exception exception = Exception.class.cast(exceptionClass.newInstance());

      FailedResolutionManager.<RuntimeException> doThrow(exception);

    } catch (ClassNotFoundException e) {
View Full Code Here

    return res.singletonResolved;
  }

  @Override
  public Component findComponentByName(Component client, String name) {
    Component ret = findImplByName(client, name);
    if (ret != null) {
      return ret;
    }
    ret = findSpecByName(client, name);
    if (ret != null) {
View Full Code Here

      /*
       * check if the source of the promoted relation matches the client (or one of its ancestor groups)
       */
      String source     = promotion.getContentRelation().getDeclaringComponent().getName();
      Component matching   = null;
      Component ancestor  = client;
     
      while (matching == null && ancestor != null) {
        if (ancestor.getName().equals(source)) {
          matching = ancestor;
        }
       
        ancestor = ancestor.getGroup();
      }
     
      /*
       * If we find a matching explicit promotion try to resolve using the matched composite relation
       */
 
View Full Code Here

    /*
     * This manager succeeded to find a solution If an unused or deployed
     * implementation. Can be into singleton or in toInstantiate if an
     * instance is required
     */
    Component source = relToResolve.getLinkSource();
    boolean deployed = !manager.getName().equals(CST.APAMMAN) && !manager.getName().equals(CST.UPDATEMAN) ;
    Component depl = (resolved.toInstantiate != null) ? resolved.toInstantiate : resolved.singletonResolved;

    deployedImpl(source, depl, deployed);

    /*
     * If an implementation is returned as "toInstantiate" it has to be instantiated
View Full Code Here

    boolean createManual = rel.getCreation() == CreationPolicy.MANUAL;
    if (createManual) {
      return null;
    }

    Component source = rel.getRelSource(source2);
    if (source == null) {
      logger.error("Component source not at the right level; found " + source2 + " expected " + rel.getSourceKind());
      return null;
    }
View Full Code Here

   *
   */
  @Override
  public Resolved<?> resolve(RelToResolve relToResolve) {

    Component source = relToResolve.getLinkSource();
   
    Set<Implementation> impls = null;
    String name = relToResolve.getTarget().getName();

    /*
     * For target by name, wait until the declaration has been processed
     */
    if (Apform2Apam.isReifying(name) )
      Apform2Apam.waitForComponent(name);

    /*
     * First analyze the component references
     */
    if (relToResolve.getTarget() instanceof SpecificationReference) {
      Specification spec = CST.componentBroker.getSpec(name);
      if (spec == null) {
        return null;
      }
      if (relToResolve.getTargetKind() == ComponentKind.SPECIFICATION) {
        return new Resolved<Specification>(spec);
      }
      impls = spec.getImpls();
    } else if (relToResolve.getTarget() instanceof ImplementationReference) {
      Implementation impl = CST.componentBroker.getImpl(name);
      if (impl == null) {
        return null;
      }
      if (relToResolve.getTargetKind() == ComponentKind.IMPLEMENTATION) {
        return new Resolved<Implementation>(impl);
      }
      impls = new HashSet<Implementation>();
      impls.add(impl);
    } else if (relToResolve.getTarget() instanceof InstanceReference) {
      Instance inst = CST.componentBroker.getInst(name);
      if (inst == null) {
        return null;
      }
      if (relToResolve.getTargetKind() == ComponentKind.INSTANCE) {
        return new Resolved<Instance>(inst);
      }
      logger.debug("if (relToResolve.getTarget() instanceof InstanceReference) ") ;
      return null;
    } else if (relToResolve.getTarget() instanceof ComponentReference<?>) {
      logger.error("Invalid target reference : " + relToResolve.getTarget());
      return null;
    }

    /*
     * We have computed all component references It is either already
     * resolved, or the implems are in impls. Now Resolve by resource.
     */
    else if (relToResolve.getTarget() instanceof ResourceReference) {
      if (relToResolve.getTargetKind() == ComponentKind.SPECIFICATION) {
        Set<Specification> specs = new HashSet<Specification>();
        for (Specification spec : CST.componentBroker.getSpecs()) {
          if (spec.getProvidedResources().contains(relToResolve.getTarget())) {
            specs.add(spec);
          }
        }
        return relToResolve.getResolved(specs, false);
      }

      /*
       * target Kind is implem or instance get all the implems that
       * implement the resource
       */
      impls = new HashSet<Implementation>();
      for (Implementation impl : CST.componentBroker.getImpls()) {
        if (impl.getProvidedResources().contains((relToResolve.getTarget()))) {
          impls.add(impl);
        }
      }
    }

    // TargetKind is implem or instance, but no implem found.
    if (impls == null || impls.isEmpty()) {
      return null;
    }

    // If TargetKind is implem, select the good one(s)
    if (relToResolve.getTargetKind() == ComponentKind.IMPLEMENTATION) {
      return relToResolve.getResolved(impls, false);
    }

    /*
     * We have in impls all the implementations satisfying the relation
     * target (type and name only). We are looking for instances. Take all
     * the instances of these implementations satisfying the relation
     * constraints and visibility.
     */

    /*
     *  Fast track : if looking for one instance and no preferences, return the first valid instance
     */
    boolean fast = (!relToResolve.isMultiple() && !relToResolve.hasPreferences());

    Set<Instance> insts = new HashSet<Instance>();
    for (Implementation impl : impls) {
      for (Instance inst : impl.getInsts()) {
        if (inst.isSharable() && source.canSee(inst) && inst.matchRelationConstraints(relToResolve)) {
          if (fast) {
            return new Resolved<Instance>(inst);
          }
          insts.add(inst);
        }
View Full Code Here

   
    Assert.assertTrue( String.format(message,
        "Although, there exist no instance of dependence required(specification 'electronic-device'), which means that it was not injected correctly."),
        resolutionResult.size() == 1);

    Component destination = resolutionResult.iterator().next().getDestination();
    Assert.assertTrue( String.format(message,
        "Although, the resolution of dependence required(specification 'electronic-device') doesn't satisfy the target kind"),
        destination instanceof Instance);

    Instance target = (Instance) destination;
View Full Code Here

     * Check if the candidate matches the target of the relation
     */
    boolean matchTarget = false;

    if (relDef.getTarget() instanceof ComponentReference<?>) {
      Component target = CST.componentBroker.getComponent(relDef.getTarget().getName());
      matchTarget = (target != null) && (target.isAncestorOf(candidate) || target.equals(candidate));
    }

    if (relDef.getTarget() instanceof ResourceReference) {
      matchTarget = candidate.getProvidedResources().contains(relDef.getTarget());
    }
View Full Code Here

   * a component disappeared in the platform; we have to delete it from the
   * ASM.
   */
  public void disappearedComponent(String componentName) {
   
    Component component = getComponent(componentName);
    if (component == null) {
      return;
    }
   
    disappearedComponent(component);
View Full Code Here

TOP

Related Classes of fr.imag.adele.apam.Component

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.