/**
  * Return true if @EmbeddedId is present in id
  *
  * @param clazz
  * @return
  */
 public static boolean hasEmbeddedId(Class clazz) {
   AccessibleObject accessibleObject = getIdAccessibleObject(clazz);
   if (accessibleObject != null && accessibleObject.isAnnotationPresent(EmbeddedId.class)) {
     return true;
   }
   return false;
 }
 /**
  * Return true is @GeneratedValue is present in id
  *
  * @param clazz
  * @return
  */
 public static boolean hasAutoGeneratedId(Class clazz) {
   AccessibleObject accessibleObject = getIdAccessibleObject(clazz);
   if (accessibleObject != null && accessibleObject.isAnnotationPresent(GeneratedValue.class)) {
     return true;
   }
   return false;
 }
 @Override
 public Match postMatch(Class targetClass, AccessibleObject target) {
   if (declaring.isAnnotationPresent(PreMatching.class)) return null;
   if (targetClass != null && target != null) {
     if (nameBound.size() > 0) {
       for (Class<? extends Annotation> annotation : nameBound) {
         if (targetClass.isAnnotationPresent(annotation)
             || target.isAnnotationPresent(annotation)) {
           return new Match(getInterceptor(), order);
         }
       }
       return null;
     } else {
       return new Match(getInterceptor(), order);
     }
   } else if (nameBound.size() == 0) {
     return new Match(getInterceptor(), order);
   } else {
     return null;
   }
 }
  void getMemberInfo(AccessibleObject[] accessers, MemberType type) {
    for (AccessibleObject a : accessers) {
      if (!a.isAnnotationPresent(JsApi.class) && !a.isAnnotationPresent(JsConstructor.class))
        continue;

      MemberInfo mInfo = new MemberInfo();
      String name = ((Member) a).getName();
      mInfo.javaName = name;
      mInfo.accesser = a;
      mInfo.isStatic = Modifier.isStatic(((Member) a).getModifiers());
      if (a.isAnnotationPresent(JsApi.class)) {
        JsApi mAnno = a.getAnnotation(JsApi.class);

        // Get eventList from properties.
        if (type == MemberType.JS_PROPERTY && mAnno.isEventList()) {
          if (!((Field) a).getType().equals(String[].class)) {
            Log.w(TAG, "Invalid type for Supported JS event list" + name);
            continue;
          }
          try {
            // Event List should be a class property with "static".
            eventList = (String[]) (((Field) a).get(null));
          } catch (IllegalArgumentException | IllegalAccessException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
          continue;
        }

        mInfo.type = type;
        mInfo.isWritable = mAnno.isWritable();
        mInfo.isEntryPoint = mAnno.isEntryPoint();
        mInfo.withPromise = mAnno.withPromise();
        mInfo.jsName = name;
        mInfo.wrapArgs = mAnno.wrapArgs();
        mInfo.wrapReturns = mAnno.wrapReturns();
      } else if (a.isAnnotationPresent(JsConstructor.class)) {
        if (type != MemberType.JS_METHOD) {
          Log.w(TAG, "Invalid @JsConstructor on non-function member:" + name);
          continue;
        }
        JsConstructor cAnno = a.getAnnotation(JsConstructor.class);
        mInfo.type = MemberType.JS_CONSTRUCTOR;
        mInfo.isEntryPoint = cAnno.isEntryPoint();
        mInfo.mainClass = cAnno.mainClass();
        // Currently Constructor with promise is not supported.
        mInfo.withPromise = false;
        // TODO: more detail checking for main class.
        // Is there a way to throw compile error if main class missing?
        if (mInfo.mainClass == null) continue;

        mInfo.jsName = mInfo.mainClass.getSimpleName();
        // Create relections for constructor main classes.
        bindingClasses.put(mInfo.mainClass.getName(), mInfo.jsName);
        constructorReflections.put(mInfo.jsName, new ReflectionHelper(mInfo.mainClass));
      }

      if (mInfo.isEntryPoint) {
        // Always get the first entry point setting.
        if (entryPoint != null) {
          Log.w(TAG, "Entry point already exist, try to set another:" + mInfo.jsName);
          continue;
        }
        // Flag isEntryPoint only meaningful for methods, constructors and BindingObjects.
        if (type == MemberType.JS_PROPERTY
            && !(isBindingClass(((Field) (mInfo.accesser)).getType()))) {
          Log.w(TAG, "Invalid entry point setting on property:" + name);
          continue;
        }
        // The first entry point will be used.
        entryPoint = mInfo;
      }
      if (members.containsKey(mInfo.jsName)) {
        Log.w(TAG, "Conflict namespace - " + mInfo.jsName);
        continue;
      }
      members.put(mInfo.jsName, mInfo);
    }
  }
    public T fromAnnotations() {
      Annotation[] annotations = parameter.getAnnotations();
      AccessibleObject injectTarget = parameter.getAccessibleObject();
      Class<?> type = parameter.getResourceClass().getClazz();

      parameter.encoded =
          findAnnotation(annotations, Encoded.class) != null
              || injectTarget.isAnnotationPresent(Encoded.class)
              || type.isAnnotationPresent(Encoded.class);
      DefaultValue defaultValue = findAnnotation(annotations, DefaultValue.class);
      if (defaultValue != null) parameter.defaultValue = defaultValue.value();

      QueryParam query;
      HeaderParam header;
      MatrixParam matrix;
      PathParam uriParam;
      CookieParam cookie;
      FormParam formParam;
      Form form;
      Suspend suspend;
      Suspended suspended;

      if ((query = findAnnotation(annotations, QueryParam.class)) != null) {
        parameter.paramType = Parameter.ParamType.QUERY_PARAM;
        parameter.paramName = query.value();
      } else if ((header = findAnnotation(annotations, HeaderParam.class)) != null) {
        parameter.paramType = Parameter.ParamType.HEADER_PARAM;
        parameter.paramName = header.value();
      } else if ((formParam = findAnnotation(annotations, FormParam.class)) != null) {
        parameter.paramType = Parameter.ParamType.FORM_PARAM;
        parameter.paramName = formParam.value();
      } else if ((cookie = findAnnotation(annotations, CookieParam.class)) != null) {
        parameter.paramType = Parameter.ParamType.COOKIE_PARAM;
        parameter.paramName = cookie.value();
      } else if ((uriParam = findAnnotation(annotations, PathParam.class)) != null) {
        parameter.paramType = Parameter.ParamType.PATH_PARAM;
        parameter.paramName = uriParam.value();
      } else if ((form = findAnnotation(annotations, Form.class)) != null) {
        parameter.paramType = Parameter.ParamType.FORM;
        parameter.paramName = form.prefix();
      } else if (findAnnotation(annotations, BeanParam.class) != null) {
        parameter.paramType = Parameter.ParamType.BEAN_PARAM;
      } else if ((matrix = findAnnotation(annotations, MatrixParam.class)) != null) {
        parameter.paramType = Parameter.ParamType.MATRIX_PARAM;
        parameter.paramName = matrix.value();
      } else if ((suspend = findAnnotation(annotations, Suspend.class)) != null) {
        parameter.paramType = Parameter.ParamType.SUSPEND;
        parameter.suspendTimeout = suspend.value();
      } else if (findAnnotation(annotations, Context.class) != null) {
        parameter.paramType = Parameter.ParamType.CONTEXT;
      } else if ((suspended = findAnnotation(annotations, Suspended.class)) != null) {
        parameter.paramType = Parameter.ParamType.SUSPENDED;
      } else if (javax.ws.rs.container.AsyncResponse.class.isAssignableFrom(type)) {
        parameter.paramType = Parameter.ParamType.SUSPENDED;
      } else if (findAnnotation(annotations, Body.class) != null) {
        parameter.paramType = Parameter.ParamType.MESSAGE_BODY;
      } else {
        parameter.paramType = Parameter.ParamType.UNKNOWN;
      }
      return (T) this;
    }
Example #6
0
 /**
  * Determine if the field or method is ignored because the <code>SirenPropertyIgnore</code>
  * annotation is present.
  *
  * @param obj
  * @return
  */
 public static boolean isIgnored(AccessibleObject obj) {
   return obj.isAnnotationPresent(Siren4JPropertyIgnore.class);
 }