protected List<ServerConfiguration> findAnnotationServerConfigurations(Module apiModule, List<Index> parentIndexes) throws ModuleLoadException, IOException, NoSuchFieldException, IllegalAccessException { List<Index> indexes = new ArrayList<>(); resolveBuildTimeIndex(apiModule, indexes); //resolveRuntimeIndex(module, indexes); indexes.addAll(parentIndexes); CompositeIndex compositeIndex = CompositeIndex.create(indexes.toArray(new Index[indexes.size()])); List<ServerConfiguration> impls = new ArrayList<>(); DotName configAnno = DotName.createSimple(Configuration.class.getName()); Set<ClassInfo> infos = compositeIndex.getAllKnownImplementors(DotName.createSimple(Fraction.class.getName())); for (ClassInfo info : infos) { for (AnnotationInstance anno : info.classAnnotations()) { if (anno.name().equals(configAnno)) { try { ServerConfiguration config = fromAnnotation(apiModule, anno); impls.add(config); } catch (ClassNotFoundException e) { e.printStackTrace(); } } } } return impls; }
public static AddressTemplate of(Class<?> entity) { Index index = IndexFactory.createIndex(entity); ClassInfo clazz = index.getClassByName(DotName.createSimple(entity.getCanonicalName())); AddressTemplate addr = null; for (AnnotationInstance annotation : clazz.classAnnotations()) { if (annotation.name().equals(IndexFactory.ADDRESS_META)) { Address meta = entity.getAnnotation(Address.class); addr = AddressTemplate.of(meta.value()); } else if (annotation.name().equals(IndexFactory.ADDRESSES_META)) { Addresses meta = entity.getAnnotation(Addresses.class); StringBuffer sb = new StringBuffer("\n"); for (String s : meta.value()) { sb.append(s).append("\n"); } throw new RuntimeException("Ambiguous resource reference on class "+entity +": "+ sb.toString()); } } if(null==addr) throw new RuntimeException("Missing resource reference on class "+entity); return addr; } }
public static AddressTemplate of(Class<?> entity) { Index index = IndexFactory.createIndex(entity); ClassInfo clazz = index.getClassByName(DotName.createSimple(entity.getCanonicalName())); AddressTemplate addr = null; for (AnnotationInstance annotation : clazz.classAnnotations()) { if (annotation.name().equals(IndexFactory.ADDRESS_META)) { Address meta = entity.getAnnotation(Address.class); addr = AddressTemplate.of(meta.value()); } else if (annotation.name().equals(IndexFactory.ADDRESSES_META)) { Addresses meta = entity.getAnnotation(Addresses.class); StringBuffer sb = new StringBuffer("\n"); for (String s : meta.value()) { sb.append(s).append("\n"); } throw new RuntimeException("Ambiguous resource reference on class "+entity +": "+ sb.toString()); } } if(null==addr) throw new RuntimeException("Missing resource reference on class "+entity); return addr; } }
private static PathAddress getPathElements(Object resource, PathAddress pathAddress, Class<?> entityClass, ClassInfo clazz) { for (AnnotationInstance annotation : clazz.classAnnotations()) { if (annotation.name().equals(IndexFactory.RESOURCE_TYPE)) { String resourceType = annotation.value().asString(); String name = null; try { Method keyMethod = entityClass.getMethod("getKey"); name = (String) keyMethod.invoke(resource); } catch (NoSuchMethodException e) { // Caught if the entity does not have a getKey method // e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } pathAddress = pathAddress.append(resourceType, name); return pathAddress; } } if (clazz.superName() != null) { // go up the object hierarchy looking for the annotation, // just in case our API objects are subclassed Index index = IndexFactory.createIndex(resource.getClass().getSuperclass()); ClassInfo superClazz = index.getClassByName(clazz.superName()); return getPathElements(resource, pathAddress, entityClass, superClazz); } return null; }
private static PathAddress getPathElements(Object resource, PathAddress pathAddress, Class<?> entityClass, ClassInfo clazz) { for (AnnotationInstance annotation : clazz.classAnnotations()) { if (annotation.name().equals(IndexFactory.RESOURCE_TYPE)) { String resourceType = annotation.value().asString(); String name = null; try { Method keyMethod = entityClass.getMethod("getKey"); name = (String) keyMethod.invoke(resource); } catch (NoSuchMethodException e) { // Caught if the entity does not have a getKey method // e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } pathAddress = pathAddress.append(resourceType, name); return pathAddress; } } if (clazz.superName() != null) { // go up the object hierarchy looking for the annotation, // just in case our API objects are subclassed Index index = IndexFactory.createIndex(resource.getClass().getSuperclass()); ClassInfo superClazz = index.getClassByName(clazz.superName()); return getPathElements(resource, pathAddress, entityClass, superClazz); } return null; }
for (AnnotationInstance classAnnotation : classInfo.classAnnotations()) { if (classAnnotation.name().equals(PATH)) { String methodPathValue = classAnnotation.value().asString();
for (AnnotationInstance classAnnotation : classInfo.classAnnotations()) { if (classAnnotation.name().equals(PATH)) { String methodPathValue = classAnnotation.value().asString();