Package fr.imag.adele.apam

Examples of fr.imag.adele.apam.Specification


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


      return null;
    }

    String specificationName = apfSpec.getDeclaration().getName();

    Specification specification = getSpec(specificationName);
    if (specification != null) {
      logger.error("Error adding specification: already exists " + specificationName);
      return specification;
    }
View Full Code Here

     * Reference the declared provided specification
     */
    if (declaration.getSpecification() != null) {

      String specificationName = declaration.getSpecification().getName();
      Specification specification = CST.componentBroker.getSpec(specificationName);

      assert specification != null;
      mySpec = specification;

    }
View Full Code Here

      }
      return;
  }

  String specificationName = args[0];
  Specification specification = CST.componentBroker
    .getSpec(specificationName);
  if (specification == null) {
      out.println("No such specification : " + specificationName);
      return;
  }
View Full Code Here

      }
      return;
  }

  String specificationName = args[0];
  Specification specification = CST.componentBroker
    .getSpec(specificationName);
  if (specification == null) {
      out.println("No such specification : " + specificationName);
      return;
  }
View Full Code Here

     * If a new specification is defined we need to try match existing services in the registry 
     */
    if (!(component instanceof Specification))
      return;
   
    Specification specification = (Specification) component;

    if (!isMatchable(specification))
      return;
   
    StringBuilder filter = new StringBuilder();
    filter.append("(").append("&");
    for (InterfaceReference providedInterface : specification.getDeclaration().getProvidedResources(InterfaceReference.class)) {
      filter.append("(").append(Constants.OBJECTCLASS).append("=").append(providedInterface.getName()).append(")");
    }
    filter.append(")");
   
    String filterText = filter.toString();
View Full Code Here

    /*
     * If a new specification is defined we need to try match existing factories in the registry 
     */
    if (component instanceof Specification) {

      Specification specification = (Specification) component;
      if (!isMatchable(specification))
        return;


      /*
 
View Full Code Here

     
    for (String providedResource : factory.getComponentDescription().getprovidedServiceSpecification()) {
      providedResources.add(new InterfaceReference(providedResource));
    }

    Specification best   = null;
    int bestScore    = 0;
   
    for (Specification specification : CST.componentBroker.getSpecs()) {
     
      int score = matchingScore(factory, specification);
View Full Code Here

  public void testFindImplByName () {
    System.out.println("=====MODIFIED====== start testFindImplByName");
    System.out.println("testing findImplByName in OBR");

    System.out.println("Empty spec");
    Specification spec = CST.apamResolver.findSpecByName(null,"dummySpec");
    assertTrue(spec != null);

    System.out.println("Abstract composite with empty spec");
    Implementation implem = CST.apamResolver.findImplByName(null,"AbstractCompositeType");
    assertTrue(implem != null);
View Full Code Here

    assertTrue (appliSetAttr_0 != null);
    //assertEquals ((CompositeImpl)appliSetAttr_0.getMainInst () != null);

    System.out.println(" Testing attributes on main implem declared: location = {living, kitchen, bedroom}");
    Implementation impl = appliSetAttr.getMainImpl(); //S1toS2Final
    Specification spec = impl.getSpec() ;
    Instance inst = null ;
    inst = impl.getInst() ; // any instance
    System.out.println("Tested instance : " + inst + ". TestedImpl : " + impl + " Tested spec : " + spec);


    //check attributes defined in the xml
    System.out.println("=========== start testing xml attributes");
    assertEquals (spec.getProperty("S1-Attr"), "coucou") ;
    assertNotEquals (spec.getProperty("s1-attr"), "coucou") ; //case sensitive for attr
    assertNotEquals (spec.getProperty("S1-Attr"), "Coucou") ; // case sensitive for value
    assertEquals (impl.getProperty("S1-Attr"), "coucou") ;
    assertEquals (inst.getProperty("S1-Attr"), "coucou") ;

    assertEquals (spec.getProperty("S1-Enum"), "s1-2") ;
    assertEquals (impl.getProperty("S1-Enum"), "s1-2") ;
    assertEquals (inst.getProperty("S1-Enum"), "s1-2") ;

    //default values S1toS2Final-Attr
    assertNotEquals (spec.getProperty("s1b"), "true") ;
    assertEquals (impl.getProperty("s1b"), "true") ;
    assertEquals (inst.getProperty("s1b"), "true") ;
    assertEquals (impl.getProperty("location"), "bedroom") ;
    assertEquals (inst.getProperty("S1toS2Final-Bool"), "true") ;
    assertNotEquals (impl.getProperty("S1toS2Final-Bool"), "true") ;

    assertTrue (impl.getProperty("S1toS2Final-Attr") == null) ;
    assertTrue (inst.getProperty("S1toS2Final-Attr") == null) ;

    assertEquals (impl.getProperty("testEnumere"), "v2") ;
    assertEquals (inst.getProperty("testEnumere"), "v2") ;

    //    assertTrue (inst.getProperty("S1toS2Final-Bool") == null) ;
    //    assertEquals (inst.getProperty("S1toS2Final-String"), "a String Value") ;
    //    assertTrue (inst.getProperty("badAttr") == null) ;
    System.out.println("=========== passed testing xml attributes");


    System.out.println("=========== start testing setting attributes");

    //    <property   name="autoString" value="aValue" type="string"/>
    //    <property   name="autoSet" value="Z-1, Z-2" type="{Z-0, Z-1, Z-2, Z-3}"/>

    //setting auto defined attributes
    assertEquals (impl.getProperty("autoString"), "aValue") ;
    assertEquals (inst.getProperty("autoString"), "aValue") ;
    assertEquals (impl.getProperty("autoSet"), "Z-1, Z-2") ;
    assertEquals (inst.getProperty("autoSet"), "Z-1, Z-2") ;

    impl.setProperty("autoString", "New-value") ;
    assertEquals (impl.getProperty("autoString"), "New-value") ;
    assertEquals (inst.getProperty("autoString"), "New-value") ;
    impl.setProperty("autoSet", "Z-3, Z-2") ;
    assertEquals (impl.getProperty("autoSet"), "Z-3, Z-2") ;
    assertEquals (inst.getProperty("autoSet"), "Z-3, Z-2") ;

    //is it allowed to set an attribute at the level of its definition ? If YES, it should be equal.
    impl.setProperty("S1toS2Final-String1", "falseVal") ;
    assertEquals(impl.getProperty("S1toS2Final-String1"), "falseVal");

    //Setting spec attributes.
    spec.setProperty("xxx", "value") ;
    assertTrue (spec.getProperty("xxx") == null) ;

    spec.setProperty("S1-Attr", "New-value") ;
    assertEquals (spec.getProperty("S1-Attr"), "New-value") ;
    assertEquals (impl.getProperty("S1-Attr"), "New-value") ;
    assertEquals (inst.getProperty("S1-Attr"), "New-value") ;

    spec.setProperty("S1-Enum", "New-value") ;
    assertEquals (spec.getProperty("S1-Enum"), "s1-2") ;
    spec.setProperty("S1-Enum", "s1-3") ;
    assertEquals (spec.getProperty("S1-Enum"), "s1-3") ;
    assertEquals (impl.getProperty("S1-Enum"), "s1-3") ;
    assertEquals (inst.getProperty("S1-Enum"), "s1-3") ;

    impl.setProperty("S1-Enum", "s1-1") ;
    assertEquals (spec.getProperty("S1-Enum"), "s1-3") ;
    assertEquals (impl.getProperty("S1-Enum"), "s1-3") ;
    assertEquals (inst.getProperty("S1-Enum"), "s1-3") ;

    impl.setProperty("location", "living"); // good
    assertEquals(impl.getProperty("location"), "living");
    assertEquals(inst.getProperty("location"), "living");

    impl.setProperty("location", "Living"); // error: Value is case sensitive
    assertEquals(impl.getProperty("location"), "living");

    impl.setProperty("location", "anywhere"); // error: false value
    assertEquals(impl.getProperty("location"), "living");

    impl.setProperty("testMain", "valeurTestMain"); // error: not defined
    assertTrue(impl.getProperty("testMain") == null);

    impl.setProperty("impl-name", "5"); // error: final attribute
    assertEquals(impl.getProperty("impl-name"), impl.getName());

    //boolean
    impl.setProperty("s1b", "5"); // error: bool attribute
    assertNotEquals(impl.getProperty("s1b"), "5");

    impl.setProperty("s1b", "true"); // Ok
    assertEquals(impl.getProperty("s1b"), "true");
    assertEquals(inst.getProperty("s1b"), "true");

    //integer
    impl.setProperty("s1i", "entier"); // error: int attribute
    assertTrue(impl.getProperty("s1i") == null);

    impl.setProperty("s1i", "5"); // Ok
    assertEquals(impl.getProperty("s1i"), "5");
    assertEquals(inst.getProperty("s1i"), "5");
    impl.setProperty("s1i", "5, 7, 55,985"); // Ok
    assertNotEquals(impl.getProperty("s1i"), "5, 7, 55,985");

    //    assertEquals(inst.getProperty("s1i"), "5, 7, 55,985");

    //    impl.setProperty("s1i", "5, zz, 55,985"); // wrong
    //    assertNotEquals(impl.getProperty("s1i"), "5, zz, 55,985");

    boolean ok  ;

    assertTrue ( inst.match("(s1i>=4)")) ;
    assertTrue (!inst.match("(s1i<=4)")) ;
    assertTrue (!inst.match("(s1i>=6)")) ;
    assertTrue ( inst.match("(s1i<=6)")) ;
    assertTrue (!inst.match("(s1i>=10)")) ;
    assertTrue ( inst.match("(s1i<=10)")) ;
    assertTrue ( inst.match("(s1i>=01)")) ;
    assertTrue (!inst.match("(s1i<=01)")) ;
    assertTrue ( inst.match("(s1i>=-61)")) ;
    assertTrue (!inst.match("(s1i<=-61)")) ;

    impl.setProperty("S1-Attr", "5"); // error: cannot redefine
    assertEquals(spec.getProperty("S1-Attr"), "New-value");

    //field and internal. Set by program when starting
    assertEquals(inst.getProperty("fieldAttr"), "initial set by program");
    String s = "to set the field attribute" ;
    ((TestAttr)inst.getServiceObject()).callS1 (s) ; //callS1 sets the attribute to s
View Full Code Here

TOP

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

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.