/** * Given the specified surrogate class, return the list of POJO swaps. * * <p> * A transform is returned for each public 1-arg constructor found. * Returns an empty list if no public 1-arg constructors are found. * * @param c The surrogate class. * @return The list of POJO swaps that apply to this class. */ @SuppressWarnings({"unchecked", "rawtypes"}) public static List<SurrogateSwap<?,?>> findPojoSwaps(Class<?> c) { List<SurrogateSwap<?,?>> l = new LinkedList<>(); for (Constructor<?> cc : c.getConstructors()) { Class<?>[] pt = cc.getParameterTypes(); if (cc.getAnnotation(BeanIgnore.class) == null && hasNumArgs(cc, 1) && isPublic(cc) && pt[0] != c.getDeclaringClass()) { // Find the unswap method if there is one. Method unswapMethod = null; for (Method m : c.getMethods()) { if (pt[0].equals(m.getReturnType()) && isPublic(m)) unswapMethod = m; } l.add(new SurrogateSwap(pt[0], cc, unswapMethod)); } } return l; }
/** * Given the specified surrogate class, return the list of POJO swaps. * * <p> * A transform is returned for each public 1-arg constructor found. * Returns an empty list if no public 1-arg constructors are found. * * @param c The surrogate class. * @return The list of POJO swaps that apply to this class. */ @SuppressWarnings({"unchecked", "rawtypes"}) public static List<SurrogateSwap<?,?>> findPojoSwaps(Class<?> c) { List<SurrogateSwap<?,?>> l = new LinkedList<>(); for (Constructor<?> cc : c.getConstructors()) { Class<?>[] pt = cc.getParameterTypes(); if (cc.getAnnotation(BeanIgnore.class) == null && hasNumArgs(cc, 1) && isPublic(cc) && pt[0] != c.getDeclaringClass()) { // Find the unswap method if there is one. Method unswapMethod = null; for (Method m : c.getMethods()) { if (pt[0].equals(m.getReturnType()) && isPublic(m)) unswapMethod = m; } l.add(new SurrogateSwap(pt[0], cc, unswapMethod)); } } return l; }
/** * Given the specified surrogate class, return the list of POJO swaps. * * <p> * A transform is returned for each public 1-arg constructor found. * Returns an empty list if no public 1-arg constructors are found. * * @param c The surrogate class. * @return The list of POJO swaps that apply to this class. */ @SuppressWarnings({"unchecked", "rawtypes"}) public static List<SurrogateSwap<?,?>> findPojoSwaps(Class<?> c) { List<SurrogateSwap<?,?>> l = new LinkedList<>(); for (Constructor<?> cc : c.getConstructors()) { Class<?>[] pt = cc.getParameterTypes(); if (cc.getAnnotation(BeanIgnore.class) == null && hasNumArgs(cc, 1) && isPublic(cc) && pt[0] != c.getDeclaringClass()) { // Find the unswap method if there is one. Method unswapMethod = null; for (Method m : c.getMethods()) { if (pt[0].equals(m.getReturnType()) && isPublic(m)) unswapMethod = m; } l.add(new SurrogateSwap(pt[0], cc, unswapMethod)); } } return l; }
/** * Finds a public method with the specified parameters. * * @param c The class to look for the method. * @param name The method name. * @param returnType * The return type of the method. * Can be a super type of the actual return type. * For example, if the actual return type is <code>CharSequence</code>, then <code>Object</code> will match but * <code>String</code> will not. * @param argTypes * The argument types of the method. * Can be subtypes of the actual parameter types. * For example, if the parameter type is <code>CharSequence</code>, then <code>String</code> will match but * <code>Object</code> will not. * @return The matched method, or <jk>null</jk> if no match was found. */ public static Method findPublicMethod(Class<?> c, String name, Class<?> returnType, Class<?>...argTypes) { for (Method m : c.getMethods()) { if (isPublic(m) && hasName(m, name) && hasReturnTypeParent(m, returnType) && argsMatch(m.getParameterTypes(), argTypes)) return m; } return null; }
/** * Finds a public method with the specified parameters. * * @param c The class to look for the method. * @param name The method name. * @param returnType * The return type of the method. * Can be a super type of the actual return type. * For example, if the actual return type is <code>CharSequence</code>, then <code>Object</code> will match but * <code>String</code> will not. * @param argTypes * The argument types of the method. * Can be subtypes of the actual parameter types. * For example, if the parameter type is <code>CharSequence</code>, then <code>String</code> will match but * <code>Object</code> will not. * @return The matched method, or <jk>null</jk> if no match was found. */ public static Method findPublicMethod(Class<?> c, String name, Class<?> returnType, Class<?>...argTypes) { for (Method m : c.getMethods()) { if (isPublic(m) && hasName(m, name) && hasReturnTypeParent(m, returnType) && argsMatch(m.getParameterTypes(), argTypes)) return m; } return null; }
/** * Finds a public method with the specified parameters. * * @param c The class to look for the method. * @param name The method name. * @param returnType * The return type of the method. * Can be a super type of the actual return type. * For example, if the actual return type is <code>CharSequence</code>, then <code>Object</code> will match but * <code>String</code> will not. * @param argTypes * The argument types of the method. * Can be subtypes of the actual parameter types. * For example, if the parameter type is <code>CharSequence</code>, then <code>String</code> will match but * <code>Object</code> will not. * @return The matched method, or <jk>null</jk> if no match was found. */ public static Method findPublicMethod(Class<?> c, String name, Class<?> returnType, Class<?>...argTypes) { for (Method m : c.getMethods()) { if (isPublic(m) && hasName(m, name) && hasReturnTypeParent(m, returnType) && argsMatch(m.getParameterTypes(), argTypes)) return m; } return null; }
/** * Constructor. * * @param c The interface class annotated with a {@link RemoteResource @RemoteResource} annotation (optional). */ public RemoteResourceMeta(Class<?> c) { String path = ""; for (RemoteResource r : getAnnotationsParentFirst(RemoteResource.class, c)) if (! r.path().isEmpty()) path = trimSlashes(r.path()); Map<Method,RemoteMethodMeta> methods = new LinkedHashMap<>(); for (Method m : c.getMethods()) if (isPublic(m)) methods.put(m, new RemoteMethodMeta(path, m, false, "GET")); this.methods = unmodifiableMap(methods); this.path = path; }
/** * Constructor. * * @param c The interface class annotated with a {@link RemoteResource @RemoteResource} annotation (optional). */ public RemoteResourceMeta(Class<?> c) { String path = ""; for (RemoteResource r : getAnnotationsParentFirst(RemoteResource.class, c)) if (! r.path().isEmpty()) path = trimSlashes(r.path()); Map<Method,RemoteMethodMeta> methods = new LinkedHashMap<>(); for (Method m : c.getMethods()) if (isPublic(m)) methods.put(m, new RemoteMethodMeta(path, m, false, "GET")); this.methods = unmodifiableMap(methods); this.path = path; }
/** * Constructor. * * @param c The interface class annotated with a {@link RemoteResource @RemoteResource} annotation (optional). */ public RemoteResourceMeta(Class<?> c) { String path = ""; for (RemoteResource r : getAnnotationsParentFirst(RemoteResource.class, c)) if (! r.path().isEmpty()) path = trimSlashes(r.path()); Map<Method,RemoteMethodMeta> methods = new LinkedHashMap<>(); for (Method m : c.getMethods()) if (isPublic(m)) methods.put(m, new RemoteMethodMeta(path, m, false, "GET")); this.methods = unmodifiableMap(methods); this.path = path; }
/** * Constructor. * * @param c * The interface class annotated with a {@link RemoteInterface @RemoteInterface} annotation. * <br>Note that the annotations are optional. * @param uri * The absolute URL of the remote REST interface that implements this proxy interface. * <br>This is only used on the client side. */ public RemoteInterfaceMeta(Class<?> c, String uri) { this.c = c; String path = ""; List<RemoteInterface> rr = getAnnotationsParentFirst(RemoteInterface.class, c); for (RemoteInterface r : rr) if (! r.path().isEmpty()) path = trimSlashes(r.path()); Map<Method,RemoteInterfaceMethod> methods = new LinkedHashMap<>(); for (Method m : c.getMethods()) if (isPublic(m)) methods.put(m, new RemoteInterfaceMethod(uri, m)); Map<String,RemoteInterfaceMethod> methodsByPath = new LinkedHashMap<>(); for (RemoteInterfaceMethod rmm : methods.values()) methodsByPath.put(rmm.getPath(), rmm); this.methods = unmodifiableMap(methods); this.methodsByPath = unmodifiableMap(methodsByPath); this.path = path; }
/** * Constructor. * * @param c * The interface class annotated with a {@link RemoteInterface @RemoteInterface} annotation. * <br>Note that the annotations are optional. * @param uri * The absolute URL of the remote REST interface that implements this proxy interface. * <br>This is only used on the client side. */ public RemoteInterfaceMeta(Class<?> c, String uri) { this.c = c; String path = ""; List<RemoteInterface> rr = getAnnotationsParentFirst(RemoteInterface.class, c); for (RemoteInterface r : rr) if (! r.path().isEmpty()) path = trimSlashes(r.path()); Map<Method,RemoteInterfaceMethod> methods = new LinkedHashMap<>(); for (Method m : c.getMethods()) if (isPublic(m)) methods.put(m, new RemoteInterfaceMethod(uri, m)); Map<String,RemoteInterfaceMethod> methodsByPath = new LinkedHashMap<>(); for (RemoteInterfaceMethod rmm : methods.values()) methodsByPath.put(rmm.getPath(), rmm); this.methods = unmodifiableMap(methods); this.methodsByPath = unmodifiableMap(methodsByPath); this.path = path; }
/** * Constructor. * * @param c * The interface class annotated with a {@link RemoteInterface @RemoteInterface} annotation. * <br>Note that the annotations are optional. * @param uri * The absolute URL of the remote REST interface that implements this proxy interface. * <br>This is only used on the client side. */ public RemoteInterfaceMeta(Class<?> c, String uri) { this.c = c; String path = ""; List<RemoteInterface> rr = getAnnotationsParentFirst(RemoteInterface.class, c); for (RemoteInterface r : rr) if (! r.path().isEmpty()) path = trimSlashes(r.path()); Map<Method,RemoteInterfaceMethod> methods = new LinkedHashMap<>(); for (Method m : c.getMethods()) if (isPublic(m)) methods.put(m, new RemoteInterfaceMethod(uri, m)); Map<String,RemoteInterfaceMethod> methodsByPath = new LinkedHashMap<>(); for (RemoteInterfaceMethod rmm : methods.values()) methodsByPath.put(rmm.getPath(), rmm); this.methods = unmodifiableMap(methods); this.methodsByPath = unmodifiableMap(methodsByPath); this.path = path; }
/** * Creates a BuilderSwap from the specified builder class if it qualifies as one. * * @param builderClass The potential builder class. * @param cVis Minimum constructor visibility. * @param mVis Minimum method visibility. * @return A new swap instance, or <jk>null</jk> if class wasn't a builder class. */ @SuppressWarnings("rawtypes") public static BuilderSwap<?,?> findSwapFromBuilderClass(Class<?> builderClass, Visibility cVis, Visibility mVis) { if (! isPublic(builderClass)) return null; Class<?> pojoClass = resolveParameterType(Builder.class, 0, builderClass); Method createPojoMethod, createBuilderMethod; Constructor<?> pojoConstructor, builderConstructor; createPojoMethod = findCreatePojoMethod(builderClass); if (createPojoMethod != null) pojoClass = createPojoMethod.getReturnType(); if (pojoClass == null) return null; pojoConstructor = findConstructor(pojoClass, cVis, false, builderClass); if (pojoConstructor == null) return null; builderConstructor = findNoArgConstructor(builderClass, cVis); createBuilderMethod = findBuilderCreateMethod(pojoClass); if (builderConstructor == null && createBuilderMethod == null) return null; return new BuilderSwap(pojoClass, builderClass, pojoConstructor, builderConstructor, createBuilderMethod, createPojoMethod); }
/** * Creates a BuilderSwap from the specified builder class if it qualifies as one. * * @param builderClass The potential builder class. * @param cVis Minimum constructor visibility. * @param mVis Minimum method visibility. * @return A new swap instance, or <jk>null</jk> if class wasn't a builder class. */ @SuppressWarnings("rawtypes") public static BuilderSwap<?,?> findSwapFromBuilderClass(Class<?> builderClass, Visibility cVis, Visibility mVis) { if (! isPublic(builderClass)) return null; Class<?> pojoClass = resolveParameterType(Builder.class, 0, builderClass); Method createPojoMethod, createBuilderMethod; Constructor<?> pojoConstructor, builderConstructor; createPojoMethod = findCreatePojoMethod(builderClass); if (createPojoMethod != null) pojoClass = createPojoMethod.getReturnType(); if (pojoClass == null) return null; pojoConstructor = findConstructor(pojoClass, cVis, false, builderClass); if (pojoConstructor == null) return null; builderConstructor = findNoArgConstructor(builderClass, cVis); createBuilderMethod = findBuilderCreateMethod(pojoClass); if (builderConstructor == null && createBuilderMethod == null) return null; return new BuilderSwap(pojoClass, builderClass, pojoConstructor, builderConstructor, createBuilderMethod, createPojoMethod); }
/** * Creates a BuilderSwap from the specified builder class if it qualifies as one. * * @param builderClass The potential builder class. * @param cVis Minimum constructor visibility. * @param mVis Minimum method visibility. * @return A new swap instance, or <jk>null</jk> if class wasn't a builder class. */ @SuppressWarnings("rawtypes") public static BuilderSwap<?,?> findSwapFromBuilderClass(Class<?> builderClass, Visibility cVis, Visibility mVis) { if (! isPublic(builderClass)) return null; Class<?> pojoClass = resolveParameterType(Builder.class, 0, builderClass); Method createPojoMethod, createBuilderMethod; Constructor<?> pojoConstructor, builderConstructor; createPojoMethod = findCreatePojoMethod(builderClass); if (createPojoMethod != null) pojoClass = createPojoMethod.getReturnType(); if (pojoClass == null) return null; pojoConstructor = findConstructor(pojoClass, cVis, false, builderClass); if (pojoConstructor == null) return null; builderConstructor = findNoArgConstructor(builderClass, cVis); createBuilderMethod = findBuilderCreateMethod(pojoClass); if (builderConstructor == null && createBuilderMethod == null) return null; return new BuilderSwap(pojoClass, builderClass, pojoConstructor, builderConstructor, createBuilderMethod, createPojoMethod); }
this.cm = BeanContext.DEFAULT.getClassMeta(c); for (Method m : ClassUtils.getAllMethods(c, false)) { if (isPublic(m)) { assertNoAnnotations(m, Request.class, ResponseHeader.class, ResponseBody.class, ResponseStatus.class); String n = m.getName();
this.cm = BeanContext.DEFAULT.getClassMeta(c); for (Method m : ClassUtils.getAllMethods(c, false)) { if (isPublic(m)) { assertNoAnnotations(m, Request.class, ResponseHeader.class, ResponseBody.class, ResponseStatus.class); String n = m.getName();
Builder apply(Type t) { Class<?> c = ClassUtils.toClass(t); this.cm = BeanContext.DEFAULT.getClassMeta(c); for (Method m : ClassUtils.getAllMethods(c, false)) { if (isPublic(m)) { assertNoAnnotations(m, Response.class, Body.class, Header.class, Query.class, FormData.class, Path.class); if (hasAnnotation(ResponseHeader.class, m)) { assertNoArgs(m, ResponseHeader.class); assertReturnNotVoid(m, ResponseHeader.class); HttpPartSchema s = HttpPartSchema.create(getAnnotation(ResponseHeader.class, m), getPropertyName(m)); headerMethods.put(s.getName(), ResponseBeanPropertyMeta.create(RESPONSE_HEADER, s, m)); } else if (hasAnnotation(ResponseStatus.class, m)) { assertNoArgs(m, ResponseHeader.class); assertReturnType(m, ResponseHeader.class, int.class, Integer.class); statusMethod = ResponseBeanPropertyMeta.create(RESPONSE_STATUS, m); } else if (hasAnnotation(ResponseBody.class, m)) { Class<?>[] pt = m.getParameterTypes(); if (pt.length == 0) assertReturnNotVoid(m, ResponseHeader.class); else assertArgType(m, ResponseHeader.class, OutputStream.class, Writer.class); bodyMethod = ResponseBeanPropertyMeta.create(RESPONSE_BODY, m); } } } return this; }
Builder apply(Type t) { Class<?> c = ClassUtils.toClass(t); this.cm = BeanContext.DEFAULT.getClassMeta(c); for (Method m : ClassUtils.getAllMethods(c, false)) { if (isPublic(m)) { assertNoAnnotations(m, Response.class, Body.class, Header.class, Query.class, FormData.class, Path.class); if (hasAnnotation(ResponseHeader.class, m)) { assertNoArgs(m, ResponseHeader.class); assertReturnNotVoid(m, ResponseHeader.class); HttpPartSchema s = HttpPartSchema.create(getAnnotation(ResponseHeader.class, m), getPropertyName(m)); headerMethods.put(s.getName(), ResponseBeanPropertyMeta.create(RESPONSE_HEADER, s, m)); } else if (hasAnnotation(ResponseStatus.class, m)) { assertNoArgs(m, ResponseHeader.class); assertReturnType(m, ResponseHeader.class, int.class, Integer.class); statusMethod = ResponseBeanPropertyMeta.create(RESPONSE_STATUS, m); } else if (hasAnnotation(ResponseBody.class, m)) { Class<?>[] pt = m.getParameterTypes(); if (pt.length == 0) assertReturnNotVoid(m, ResponseHeader.class); else assertArgType(m, ResponseHeader.class, OutputStream.class, Writer.class); bodyMethod = ResponseBeanPropertyMeta.create(RESPONSE_BODY, m); } } } return this; }
Builder apply(Type t) { Class<?> c = ClassUtils.toClass(t); this.cm = BeanContext.DEFAULT.getClassMeta(c); for (Method m : ClassUtils.getAllMethods(c, false)) { if (isPublic(m)) { assertNoAnnotations(m, Response.class, Body.class, Header.class, Query.class, FormData.class, Path.class); if (hasAnnotation(ResponseHeader.class, m)) { assertNoArgs(m, ResponseHeader.class); assertReturnNotVoid(m, ResponseHeader.class); HttpPartSchema s = HttpPartSchema.create(getAnnotation(ResponseHeader.class, m), getPropertyName(m)); headerMethods.put(s.getName(), ResponseBeanPropertyMeta.create(RESPONSE_HEADER, s, m)); } else if (hasAnnotation(ResponseStatus.class, m)) { assertNoArgs(m, ResponseHeader.class); assertReturnType(m, ResponseHeader.class, int.class, Integer.class); statusMethod = ResponseBeanPropertyMeta.create(RESPONSE_STATUS, m); } else if (hasAnnotation(ResponseBody.class, m)) { Class<?>[] pt = m.getParameterTypes(); if (pt.length == 0) assertReturnNotVoid(m, ResponseHeader.class); else assertArgType(m, ResponseHeader.class, OutputStream.class, Writer.class); bodyMethod = ResponseBeanPropertyMeta.create(RESPONSE_BODY, m); } } } return this; }