private boolean parsePath(Class<?> cls) { Path path = cls.getAnnotation(Path.class); if (path != null) { getMetadata().addPath(path.value()); logger.trace("parseClass() returning true for class direct"); return true; path = superclass.getAnnotation(Path.class); if (path != null) { getMetadata().addPath(path.value()); logger.trace("parseClass() returning true for superclass {}", superclass); return true; path = interfaceClass.getAnnotation(Path.class); if (path != null) { getMetadata().addPath(path.value()); logger.trace("parseClass() returning true for interface {}", interfaceClass); return true;
private boolean parseWorkspace(Class<?> cls) { Workspace workspace = cls.getAnnotation(Workspace.class); if (workspace != null) { getMetadata().setWorkspaceName(workspace.workspaceTitle()); getMetadata().setCollectionTitle(workspace.collectionTitle()); return true; } return false; }
private void parseClass() { Class<?> cls = getMetadata().getResourceClass(); parseClass(cls); }
private boolean parseClassConsumes(Class<?> cls) { String[] consumes = getConsumes(cls); // if (consumes.length == 0) { // getMetadata().addConsumes(MediaType.WILDCARD_TYPE); // return false; // } for (String mediaType : consumes) { getMetadata().addConsumes(MediaType.valueOf(mediaType)); } return true; }
public static ClassMetadata collectMetadata(Class<?> clazz) { logger.trace("collectMetadata({}) entry", clazz); ResourceMetadataCollector collector = new ResourceMetadataCollector(clazz); collector.parseClass(); collector.parseFields(); collector.parseConstructors(); collector.parseMethods(); ClassMetadata md = collector.getMetadata(); logger.trace("collectMetadata() exit returning {}", md); return md; }
private boolean parseClassProduces(Class<?> cls) { String[] consumes = getProduces(cls); // if (consumes.length == 0) { // getMetadata().addProduces(MediaType.WILDCARD_TYPE); // return false; // } for (String mediaType : consumes) { getMetadata().addProduces(MediaType.valueOf(mediaType)); } return true; }
private void parseMethods() { logger.trace("entry"); F1: for (Method method : getMetadata().getResourceClass().getMethods()) { Class<?> declaringClass = method.getDeclaringClass(); if (declaringClass == Object.class) { logger.trace("Was subresource method"); getMetadata().getSubResourceMethods().add(methodMetadata); } else { logger.trace("Was subresource locator"); getMetadata().getSubResourceLocators().add(methodMetadata); getMetadata().getResourceMethods().add(methodMetadata);
private void parseMethodParameters(Method method, MethodMetadata methodMetadata) { logger.trace("parseMethodParameters({}, {}), entry", method, methodMetadata); Annotation[][] parameterAnnotations = method.getParameterAnnotations(); Type[] paramTypes = getParamTypesFilterByXmlElementAnnotation(method); boolean entityParamExists = false; for (int pos = 0, limit = paramTypes.length; pos < limit; pos++) { Injectable fp = InjectableFactory.getInstance().create(paramTypes[pos], parameterAnnotations[pos], method, getMetadata().isEncoded() || methodMetadata .isEncoded(), methodMetadata.getDefaultValue()); if (fp.getParamType() == Injectable.ParamType.ENTITY) { if (entityParamExists) { // we are allowed to have only one entity parameter String methodName = method.getDeclaringClass().getName() + "." + method.getName(); //$NON-NLS-1$ throw new IllegalStateException(Messages .getMessage("resourceMethodMoreThanOneEntityParam", methodName)); //$NON-NLS-1$ } entityParamExists = true; } methodMetadata.getFormalParameters().add(fp); logger.trace("Adding formal parameter {}", fp); } logger.trace("parseMethodParameters(), exit"); }
private void mergeFormalParameterMetadata(MethodMetadata metadata, Method method) { logger.trace("mergeFormalParameterMetadata({})", new Object[] {metadata, method}); Type[] parameterTypes = method.getGenericParameterTypes(); List<Injectable> currentParameters = new ArrayList<Injectable>(metadata.getFormalParameters()); metadata.getFormalParameters().clear(); int i = 0; for (Injectable injectable : currentParameters) { Injectable fp = InjectableFactory.getInstance().create(parameterTypes[i], injectable.getAnnotations(), method, getMetadata().isEncoded() || metadata .isEncoded(), metadata.getDefaultValue()); metadata.getFormalParameters().add(fp); ++i; } logger.trace("mergeFormalParameterMetadata exit"); }
private boolean parseClass(Class<?> cls) { logger.trace("parseClass({})", cls); boolean workspacePresent = parseWorkspace(cls); boolean pathPresent = parsePath(cls); boolean consumesPresent = parseClassConsumes(cls); boolean producesPresent = parseClassProduces(cls); Parent parent = cls.getAnnotation(Parent.class); if (parent != null) { getMetadata().getParents().add(parent.value()); } parseEncoded(cls); // if the class contained any annotations, we can to stop if (workspacePresent || pathPresent || consumesPresent || producesPresent) { return true; } // no annotations return false; }
@Override protected final Injectable parseAccessibleObject(AccessibleObject field, Type fieldType) { Injectable injectable = InjectableFactory.getInstance().create(fieldType, field.getAnnotations(), (Member)field, getMetadata().isEncoded(), null); if (injectable.getParamType() == Injectable.ParamType.ENTITY) { // EntityParam should be ignored for fields (see JSR-311 3.2) return null; } return injectable; }
MethodMetadata metadata = new MethodMetadata(getMetadata()); metadata.setReflectionMethod(method);