Package org.milyn.scribe

Examples of org.milyn.scribe.IllegalAnnotationUsageException


   */
  private void analyzeFlushMethod(final AnnotatedMethod aMethod) {
    Method method = aMethod.getMethod();

    if(flushMethod != null) {
      throw new IllegalAnnotationUsageException("At least two methods are annotated with the '"+ Flush.class.getName() +"'. Only one method per class is allowed to be the flush method.");
    }
    if(method.getParameterTypes().length > 0) {
      throw new IllegalAnnotationUsageException("The Flush annotated method '"+ method +"' of the DAO class '"+ daoClass.getName() +"' has parameters, which isn't allowed.");
    }

    flushMethod = new FlushMethod(method);
  }
View Full Code Here


    }

    assertUniqueName(updateMethods, Update.class, name);

    if(annotation.isDefault() && defaultUpdateMethod != null) {
      throw new IllegalAnnotationUsageException("At least two methods are annotated with the '"+ Update.class.getName() +"' having the isDefault on true. Only one method per class is allowed to be the default update method.");
    }
    if(method.getParameterTypes().length == 0) {
      throw new IllegalAnnotationUsageException("The Update annotated method '"+ method +"' of the DAO class '"+ daoClass.getName() +"' doesn't have any parameters.");
    }
    if(method.getParameterTypes().length > 1) {
      throw new IllegalAnnotationUsageException("The Update annotated method '"+ method +"' of the DAO class '"+ daoClass.getName() +"' has more then 1 parameter, which isn't allowed.");
    }


    boolean returnsEntity  = !method.isAnnotationPresent(ReturnsNoEntity.class);
View Full Code Here

    }

    assertUniqueName(insertMethods, Insert.class, name);

    if(annotation.isDefault() && defaultInsertMethod != null) {
      throw new IllegalAnnotationUsageException("At least two methods are annotated with the '"+ Insert.class.getName() +"'annotation having the isDefault on true. Only one method per class is allowed to be the default insert method.");
    }
    if(method.getParameterTypes().length == 0) {
      throw new IllegalAnnotationUsageException("The Insert annotated method '"+ method +"' of the DAO class '"+ daoClass.getName() +"'  doesn't have any parameters.");
    }
    if(method.getParameterTypes().length > 1) {
      throw new IllegalAnnotationUsageException("The Insert annotated method '"+ method +"' of the DAO class '"+ daoClass.getName() +"' has more then 1 parameter, which isn't allowed.");
    }

    boolean returnsEntity  = !method.isAnnotationPresent(ReturnsNoEntity.class);

    EntityMethod insertMethod = new EntityMethod(method, returnsEntity);
View Full Code Here

    }

    assertUniqueName(deleteMethods, Delete.class, name);

    if(annotation.isDefault() && defaultDeleteMethod != null) {
      throw new IllegalAnnotationUsageException("At least two methods are annotated with the '"+ Delete.class.getName() +"' annotation having the isDefault on true. Only one method per class is allowed to be the default delete method.");
    }
    if(method.getParameterTypes().length == 0) {
      throw new IllegalAnnotationUsageException("The Delete annotated method '"+ method +"' of the DAO class '"+ daoClass.getName() +"' doesn't have a parameter, which it needs.");
    }
    if(method.getParameterTypes().length > 1) {
      throw new IllegalAnnotationUsageException("The Delete annotated method '"+ method +"'  the DAO class '"+ daoClass.getName() +"' has more then 1 parameter, which isn't allowed.");
    }


    boolean returnsEntity  = !method.isAnnotationPresent(ReturnsNoEntity.class);
View Full Code Here

    Method method = aMethod.getMethod();

    Class<?>[] parameters = method.getParameterTypes();

    if(method.getParameterTypes().length != 2) {
      throw new IllegalAnnotationUsageException("The FindByQuery annotated method '"+ method +"' of the DAO class '"+ daoClass.getName() +"' " +
          "doesn't have exactly two parameters.");
    }

    if(!Collection.class.isAssignableFrom(method.getReturnType())) {
      throw new IllegalAnnotationUsageException("The FindByQuery annotated method '"+ method +"' of the DAO class '"+ daoClass.getName() +"' " +
        "doesn't return an instance of Collection.");

    }

    int queryIndex = indexOffFirstAssignableClass(String.class, parameters);
    if(queryIndex == -1) {
      throw new IllegalAnnotationUsageException("The FindByQuery annotated method '"+ method +"' of the DAO class '"+ daoClass.getName() +"' " +
        "doesn't have a String parameter. This parameter is needed to receive the query string.");
    }

    int parameterIndex = (queryIndex == 0) ? 1 : 0;

    if(containsAssignableClass(List.class, parameters) || containsAssignableClass(Object[].class, parameters)) {

      if(lookupWithPositionalQueryMethod != null) {
        throw new IllegalAnnotationUsageException("A second method annotated with the '"+ LookupByQuery.class.getName() +"' annotation is found for a Positional query. " +
            "Only one method, with a List or Object array parameter, per class is allowed to be annotated with this annotation.");
      }

      lookupWithPositionalQueryMethod = new LookupWithPositionalQueryMethod(method, queryIndex, parameterIndex);

    } else if(containsAssignableClass(Map.class, parameters)){

      if(lookupWithNamedQueryMethod != null) {
        throw new IllegalAnnotationUsageException("A second method annotated with the '"+ LookupByQuery.class.getName() +"' annotation is found for a Positional query. " +
            "Only one method, with a Map parameter, per class is allowed to be annotated with this annotation.");
      }

      lookupWithNamedQueryMethod = new LookupWithNamedQueryMethod(method, queryIndex, parameterIndex);

    } else {
      throw new IllegalAnnotationUsageException("The FindByQuery annotated method '"+ method +"' of the DAO class '"+ daoClass.getName() +"' " +
        "doesn't have a List, Object array or Map parameter. This parameter is needed to receive the query parameters.");
    }


  }
View Full Code Here

    }

    assertUniqueName(lookupWithNamedParameters, Lookup.class, name);

    if(void.class.equals(method.getReturnType())){
      throw new IllegalAnnotationUsageException("The FindBy annotated method '"+ method +"' of the DAO class '"+ daoClass.getName() +"' " +
          "returns void, which isn't allowed. The method must return something.");
    }

    lookupWithNamedParameters.put(name, new LookupMethod(method));
  }
View Full Code Here

  /**
   * @param name
   */
  private void assertUniqueName(Map<String, ?> methods, Class<? extends Annotation> annotation, String name) {
    if(methods.containsKey(name)) {
      throw new IllegalAnnotationUsageException("A second method annotated with the '"+ annotation.getName() +"' annotation and the name '"+ name +"' is found." +
          "If you have defined a name on the annotation then please define a different one. If you haven't defined a name then please define one that is unique.");
    }
  }
View Full Code Here

TOP

Related Classes of org.milyn.scribe.IllegalAnnotationUsageException

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.