Package fr.imag.adele.apam.declarations.instrumentation

Examples of fr.imag.adele.apam.declarations.instrumentation.InstrumentedClass


     
  }
 
  protected void validateInstrumentation() {
   
    InstrumentedClass instrumentedClass = getComponent().getImplementationClass();
   
    /*
     * Verify the callback method has a single parameter of a type compatible with the type of property
     */
    if (getType() != null && getProperty().getCallback() != null) {

      String method = getProperty().getCallback().trim();

      try {
        boolean hasParameter = instrumentedClass.getMethodParameterNumber(method,true) > 0;
        if (hasParameter) {
          String parameter = instrumentedClass.getMethodParameterType(method,true);
          if (!getType().isAssignableTo(parameter) && !parameter.equals(String.class.getCanonicalName())) {
            error("Property " + quoted(getProperty().getName()) + ", the specified method "+quoted(method)+" must have a parameter of type "+getType());
          }
        }
      }
      catch (NoSuchMethodException undefined) {
        error("Property " + quoted(getProperty().getName()) + ", the specified single-parameter method "+quoted(method)+" is not defined in class "+instrumentedClass.getName());
      }
    }

    /*
     * Verify the field has a type compatible with the type of property
     */
    if (getType() != null  && getProperty().getField() != null) {
     
      String field = getProperty().getField().trim();

      try {
        String fieldType = instrumentedClass.getDeclaredFieldType(field);
        if (!getType().isAssignableTo(fieldType)) {
          error("Property " + quoted(getProperty().getName()) + ", the specified field "+quoted(field)+" must have type "+getType());
        }
      }
      catch (NoSuchFieldException undefined) {
        error("Property " + quoted(getProperty().getName()) + ", the specified field "+quoted(field)+" is not defined in class "+instrumentedClass.getName());
      }
     
    }
   
  }
View Full Code Here


    } catch (ClassNotFoundException e) {
      errorHandler.report(Severity.ERROR, "Apam component " + name + ": " + "the component class " + className + " can not be loaded");
    } catch (Exception ignoredException) {
    }

    InstrumentedClass instrumentedClass = new InstrumentedClassMetadata(className, pojoMetadata, instrumentedCode);

    /*
     * load specification
     */
    SpecificationReference specification            = parseSpecificationReference(name, element, ATT_SPECIFICATION, false);
View Full Code Here

              SpecificationReference specification            = reference(CST.PROVIDE_SPECIFICATION, ComponentKind.SPECIFICATION);
              String range                         = property(CST.REQUIRE_VERSION);
              VersionedReference<SpecificationDeclaration> specificationVersion  = specification != null ? VersionedReference.range(specification,range) : null;
             
              InstrumentedClass instrumentedClass =  new UnloadedClassMetadata(property(CST.PROVIDE_CLASSNAME));
                component = new AtomicImplementationDeclaration(componentName, specificationVersion, instrumentedClass);
            }
        break;
      case INSTANCE:
              ImplementationReference<ImplementationDeclaration> implementation   = reference(CST.IMPLNAME,ComponentKind.IMPLEMENTATION);
View Full Code Here

    }
   
    /*
     *  Validate the specified method is valid
     */
    InstrumentedClass instrumentedClass = ((AtomicImplementationDeclaration) context).getImplementationClass();

    try {
      /*
       * Verify the method has a single parameter of type Instance
       */
      String parameterType  = instrumentedClass.getMethodParameterType(method,true);
     
      if (parameterType == null) {
        error("Invalid substitute value, method "+method+" with a single parameter is not defined in class "+instrumentedClass.getName());
        return null;
      }
     
      if (!ComponentKind.INSTANCE.isAssignableTo(parameterType)) {
        error("Invalid substitute value, method "+method+" with a single Instance parameter is not defined in class "+instrumentedClass.getName());
        return null;
      }

      /*
       * Verify the method return type is one of the supported property primitive types
       */
      String  returnType = instrumentedClass.getMethodReturnType(method, null,true);
      if (returnType == null) {
        error("Invalid substitute value, method "+method+"does not return a value");
        return null;
      }
     
      for (Type primitive : PrimitiveType.values()) {
        if (primitive.isAssignableFrom(returnType))
          return primitive;
      }
     
      /*
       * As a last resort, we also consider collections of strings
       *
       *  TODO modify CodeReflection to perform this validation and get the type of the collection if possible
       *  to be able to accept collections of primitive types
       */
      if ( returnType.equals(Collection.class.getCanonicalName()) || returnType.equals(Set.class.getCanonicalName())) {
        return new CollectionType(PrimitiveType.STRING,true);
      }
     
      error("Invalid substitute value, method "+method+"does not return a value of a valid type "+returnType);
      return null;
     
    } catch (NoSuchMethodException exc) {
      error("Invalid substitute value, method "+method+" with a single parameter is not defined in class "+instrumentedClass.getName());
      return null;
    }
   
  }
View Full Code Here

TOP

Related Classes of fr.imag.adele.apam.declarations.instrumentation.InstrumentedClass

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.