Exemplo n.º 1
0
  private void checkInterfaces(Composant comp, CompDesc element)
      throws InstantiationException, IllegalAccessException, ArchitectureException,
          NoSuchInterfaceException, ClassNotFoundException {

    Logger.getAnonymousLogger()
        .log(Level.INFO, "Checking interfaces for component {0}...", element.name());

    for (String pName : element.ports) {
      Field f = (Field) comp.getInterfaceForName(pName, Boolean.TRUE);
      if (f == null) {
        f = (Field) comp.getInterfaceForName(pName, Boolean.FALSE);
        if (f == null) {
          throw new NoSuchInterfaceException("Cannot find port " + pName);
        }
      }
    }

    for (String sName : element.services) {
      Method m = (Method) comp.getInterfaceForName(sName, Boolean.TRUE);
      if (m == null) {
        m = (Method) comp.getInterfaceForName(sName, Boolean.FALSE);
        if (m == null) {
          throw new NoSuchInterfaceException("Cannot find service " + element.name() + "." + sName);
        }
      }
    }
  }
Exemplo n.º 2
0
  private Composant getComposant(Configuration conf, String cName) throws ArchitectureException {

    for (Composant cmp : conf.getComposants()) {
      if (cmp.getClass().getAnnotation(Component.class).value().equals(cName)) {
        return cmp;
      }
    }
    throw new ArchitectureException("No component found for name " + cName);
  }
Exemplo n.º 3
0
  private Composant instanciate(CompDesc element)
      throws ClassNotFoundException, ArchitectureException, NoSuchMethodException,
          IllegalArgumentException, InvocationTargetException, NoSuchComponentException,
          NoSuchInterfaceException, WrongTypeException {
    Logger.getAnonymousLogger().log(Level.INFO, ">>> Instanciate : {0}", element.name());

    String name = element.name();
    Set<String> classes = annotdb.getAnnotationIndex().get(Component.class.getName());

    for (String clName : classes) {
      Class compC = loader.loadClass(clName);
      if (Composant.class.isAssignableFrom(compC)) {
        try {
          Composant compTest = (Composant) compC.newInstance();
          String value = compTest.getClass().getAnnotation(Component.class).value();
          if (name.equals(value)) {
            checkInterfaces(compTest, element); // DONE
            // On a trouvé la classe qui va bien ! il faut l'ajouter au système, et passer à la
            // suite.
            if (element instanceof ConfDesc) {
              if (compTest instanceof Configuration) {
                for (CompDesc cm : ((ConfDesc) element).children) {
                  Logger.getAnonymousLogger()
                      .log(
                          Level.INFO,
                          "Adding component {0} to configuration {1}...",
                          new Object[] {cm.name(), element.name()});
                  ((Configuration) compTest).addComposant(instanciate(cm));
                }
                addConnectors((Configuration) compTest, (ConfDesc) element); // DONE
                addBindings((Configuration) compTest, (ConfDesc) element); // DONE
              } else {
                throw new ArchitectureException(
                    "The "
                        + element.name()
                        + " node is configuration and refers to a simplecomposant.");
              }
            } else if (compTest instanceof Configuration) {
              throw new ArchitectureException(
                  "The "
                      + element.name()
                      + " node is simplecomposant and refers to a configuration.");
            }
            return compTest;
          }
        } catch (InstantiationException ex) {
          Logger.getLogger(SystemManager.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
          Logger.getLogger(SystemManager.class.getName()).log(Level.SEVERE, null, ex);
        }
      } else {
        throw new ArchitectureException(
            "Only Composant class should be annotated with Component annotation.");
      }
    }
    throw new ArchitectureException("No component found with name " + name);
  }
Exemplo n.º 4
0
 private Method getEntryPoint(Configuration conf, String cRef, String iRef)
     throws ArchitectureException {
   Composant cmp = getComposant(conf, cRef);
   Method ep = cmp.getEntryPoint();
   if (ep == null || !Validator.checkEntryPoint(ep)) {
     throw new ArchitectureException(
         "The composant " + cRef + " should have entry point " + iRef + ".");
   } else {
     return ep;
   }
 }
Exemplo n.º 5
0
  /**
   * Vérifie qu'une interface est bien présente dans les interfaces d'un composant.
   *
   * @param name nom de l'interface dans le xml et l'annotation
   * @param intNames noms des classes annotées
   * @param comp composant censé contenir l'interface
   * @return
   * @throws ClassNotFoundException
   * @throws InstantiationException
   * @throws IllegalAccessException
   */
  private boolean isOneOf(String name, Set<String> intNames, Composant comp)
      throws ClassNotFoundException, InstantiationException, IllegalAccessException {
    for (String intName : intNames) {
      Class intC = loader.loadClass(intName);
      if (AccessibleObject.class.isAssignableFrom(intC) && Member.class.isAssignableFrom(intC)) {
        AccessibleObject member = (AccessibleObject) intC.newInstance();

        // Faut check qu'il est bien de la bonne classe
        if (((Member) member).getDeclaringClass().equals(comp.getClass())) {
          // Faut check que l'annotation a bien pName comme value.
          RequiredInterface annotation = member.getAnnotation(RequiredInterface.class);
          if (annotation == null) {
            ProvidedInterface annotation1 = member.getAnnotation(ProvidedInterface.class);
            if (annotation1.value().equals(name)) {
              return true;
            }
          } else {
            if (annotation.value().equals(name)) {
              return true;
            }
          }
        }
      }
    }
    return false;
  }
Exemplo n.º 6
0
  private AccessibleObject getInterface(
      Configuration conf, String cName, String iName, Boolean from) throws ArchitectureException {

    Composant cmp = getComposant(conf, cName);
    AccessibleObject ao = cmp.getInterfaceForName(iName, from);
    if (ao == null) {
      throw new ArchitectureException("No field or method for interface " + cName + "." + iName);
    }
    if (from) {
      if (ao instanceof Field) {
        if (Validator.checkProvided((Field) ao)) {
          return ao;
        } else {
          throw new ArchitectureException(
              "The Field " + ((Field) ao).getName() + " should be public.");
        }
      } else {
        if (Validator.checkProvided((Method) ao)) {
          return ao;
        } else {
          throw new ArchitectureException(
              "The Method " + ((Method) ao).getName() + " should be public.");
        }
      }
    } else {
      if (ao instanceof Field) {
        if (Validator.checkRequired((Field) ao)) {
          return ao;
        } else {
          throw new ArchitectureException(
              "The Field " + ((Field) ao).getName() + " should be public.");
        }
      } else {
        if (Validator.checkRequired((Method) ao)) {
          return ao;
        } else {
          throw new ArchitectureException(
              "The Method " + ((Method) ao).getName() + " should be public.");
        }
      }
    }
  }