Exemple #1
0
 protected DeleteHandler<Object> createDeleteHandler() {
   // look for @Consumed to allow custom callback when the Entity has been consumed
   final Class<?> entityType = getEndpoint().getEntityType();
   if (entityType != null) {
     List<Method> methods = ObjectHelper.findMethodsWithAnnotation(entityType, Consumed.class);
     if (methods.size() > 1) {
       throw new IllegalArgumentException(
           "Only one method can be annotated with the @Consumed annotation but found: " + methods);
     } else if (methods.size() == 1) {
       final Method method = methods.get(0);
       final boolean useExchangeParameter = checkParameters(method);
       return new DeleteHandler<Object>() {
         public void deleteObject(
             EntityManager entityManager, Object entityBean, Exchange exchange) {
           if (entityType.isInstance(entityBean)) {
             if (useExchangeParameter) {
               ObjectHelper.invokeMethod(method, entityBean, exchange);
             } else {
               ObjectHelper.invokeMethod(method, entityBean);
             }
           }
         }
       };
     }
   }
   if (getEndpoint().isConsumeDelete()) {
     return new DeleteHandler<Object>() {
       public void deleteObject(
           EntityManager entityManager, Object entityBean, Exchange exchange) {
         entityManager.remove(entityBean);
       }
     };
   } else {
     return new DeleteHandler<Object>() {
       public void deleteObject(
           EntityManager entityManager, Object entityBean, Exchange exchange) {
         // do nothing
       }
     };
   }
 }
Exemple #2
0
  protected DeleteHandler<Object> createPreDeleteHandler() {
    // Look for @PreConsumed to allow custom callback before the Entity has been consumed
    final Class<?> entityType = getEndpoint().getEntityType();
    if (entityType != null) {
      // Inspect the method(s) annotated with @PreConsumed
      List<Method> methods = ObjectHelper.findMethodsWithAnnotation(entityType, PreConsumed.class);
      if (methods.size() > 1) {
        throw new IllegalStateException(
            "Only one method can be annotated with the @PreConsumed annotation but found: "
                + methods);
      } else if (methods.size() == 1) {
        // Inspect the parameters of the @PreConsumed method
        final Method method = methods.get(0);
        final boolean useExchangeParameter = checkParameters(method);
        return new DeleteHandler<Object>() {
          @Override
          public void deleteObject(
              EntityManager entityManager, Object entityBean, Exchange exchange) {
            // The entityBean could be an Object array
            if (entityType.isInstance(entityBean)) {
              if (useExchangeParameter) {
                ObjectHelper.invokeMethod(method, entityBean, exchange);
              } else {
                ObjectHelper.invokeMethod(method, entityBean);
              }
            }
          }
        };
      }
    }

    // else do nothing
    return new DeleteHandler<Object>() {
      @Override
      public void deleteObject(EntityManager entityManager, Object entityBean, Exchange exchange) {
        // Do nothing
      }
    };
  }