/** * This is used to scan all the fields of the class in order to * determine if it should have a default annotation. If the field * should have a default XML annotation then it is added to the * list of contacts to be used to form the class schema. * * @param detail this is the detail to have its fields scanned * @param access this is the default access type for the class */ private void extract(Detail detail, DefaultType access) throws Exception { List<FieldDetail> fields = detail.getFields(); if(access == FIELD) { for(FieldDetail entry : fields) { Annotation[] list = entry.getAnnotations(); Field field = entry.getField(); Class real = field.getType(); if(!isStatic(field) && !isTransient(field)) { process(field, real, list); } } } }
/** * This is used to scan all the methods of the class in order to * determine if it should have a default annotation. If the method * should have a default XML annotation then it is added to the * list of contacts to be used to form the class schema. * * @param detail this is the detail to have its methods scanned * @param access this is the default access type for the class */ private void extract(Detail detail, DefaultType access) throws Exception { List<MethodDetail> methods = detail.getMethods(); if(access == PROPERTY) { for(MethodDetail entry : methods) { Annotation[] list = entry.getAnnotations(); Method method = entry.getMethod(); Class value = factory.getType(method); if(value != null) { process(method, list); } } } }
/** * Constructor for the <code>DetailScanner</code> object. This is * used to create a detail object from a type. All of the methods * fields and annotations are extracted so that they can be used * many times over without the need to process them again. * * @param type this is the type to scan for various details * @param override this is the override used for this detail */ public DetailScanner(Class type, DefaultType override) { this.methods = new LinkedList<MethodDetail>(); this.fields = new LinkedList<FieldDetail>(); this.labels = type.getDeclaredAnnotations(); this.override = override; this.strict = true; this.type = type; this.scan(type); }
/** * This method is used to scan the class hierarchy for each class * in order to extract fields that contain XML annotations. If * the field is annotated it is converted to a contact so that * it can be used during serialization and deserialization. * * @param detail this contains the details for the class scanned */ private void scan(Detail detail) throws Exception { DefaultType override = detail.getOverride(); DefaultType access = detail.getAccess(); Class base = detail.getSuper(); if(base != null) { extend(base, override); } extract(detail, access); extract(detail); build(); }
/** * This method is used to scan the class hierarchy for each class * in order to extract methods that contain XML annotations. If * a method is annotated it is converted to a contact so that * it can be used during serialization and deserialization. * * @param detail this contains the details for the class scanned */ private void scan(Detail detail) throws Exception { DefaultType override = detail.getOverride(); DefaultType access = detail.getAccess(); Class base = detail.getSuper(); if(base != null) { extend(base, override); } extract(detail, access); extract(detail); build(); validate(); }
/** * This is used to acquire the contacts for the annotated fields * within the specified class. The field contacts are added to * either the attributes or elements map depending on annotation. * * @param detail this contains the details for the class scanned */ private void field(Detail detail) throws Exception { Class type = detail.getType(); DefaultType access = detail.getOverride(); ContactList list = support.getFields(type, access); for(Contact contact : list) { Annotation label = contact.getAnnotation(); if(label != null) { builder.process(contact, label); } } }
/** * This is used to acquire the contacts for the annotated fields * within the specified class. The field contacts are added to * either the attributes or elements map depending on annotation. * * @param detail this contains the details for the class scanned */ private void method(Detail detail) throws Exception { Class type = detail.getType(); DefaultType access = detail.getOverride(); ContactList list = support.getMethods(type, access); for(Contact contact : list) { Annotation label = contact.getAnnotation(); if(label != null) { builder.process(contact, label); } } }
/** * Scan the fields and methods such that the given class is scanned * first then all super classes up to the root <code>Object</code>. * All fields and methods from the most specialized classes override * fields and methods from higher up the inheritance hierarchy. This * means that annotated details can be overridden. * * @param detail contains the methods and fields to be examined */ private void scan(Detail detail) throws Exception { DefaultType access = detail.getOverride(); Class type = detail.getType(); while(type != null) { Detail value = support.getDetail(type, access); namespace(value); method(value); definition(value); type = value.getSuper(); } commit(detail); }
public void testScanner() throws Exception { DetailScanner scanner = new DetailScanner(DetailExample.class); assertEquals(scanner.getNamespace(), null); assertEquals(scanner.getNamespaceList().value().length, 2); assertEquals(scanner.getNamespaceList().value()[0].reference(), "http://x.com/"); assertEquals(scanner.getNamespaceList().value()[0].prefix(), "x"); assertEquals(scanner.getNamespaceList().value()[1].reference(), "http://y.com/"); assertEquals(scanner.getNamespaceList().value()[1].prefix(), "y"); assertEquals(scanner.getNamespaceList().value().length, 2); assertEquals(scanner.getRoot().name(), "detail"); assertEquals(scanner.getAccess(), DefaultType.FIELD); assertEquals(scanner.getMethods().size(), 3); assertEquals(scanner.getFields().size(), 1); assertEquals(scanner.getFields().get(0).getName(), "value"); assertTrue(Arrays.asList(scanner.getMethods().get(0).getName(), scanner.getMethods().get(1).getName(), scanner.getMethods().get(2).getName()).containsAll(Arrays.asList("validate", "getValue", "setValue"))); for(MethodDetail detail : scanner.getMethods()) { if(detail.getName().equals("validate")) { assertEquals(detail.getAnnotations().length, 1); assertEquals(detail.getAnnotations()[0].annotationType(), Validate.class); } } assertTrue(scanner.getMethods() == scanner.getMethods()); assertTrue(scanner.getNamespaceList() == scanner.getNamespaceList()); assertTrue(scanner.getRoot() == scanner.getRoot()); assertTrue(scanner.getAccess() == scanner.getAccess()); }
public Detail getDetail(Class type, DefaultType access) { if(access != null) { return defaults.getDetail(type); } return details.getDetail(type); }
/** * This returns the <code>Default</code> annotation access type * that has been specified by this. If no default annotation has * been declared on the type then this will return null. * * @return this returns the default access type for this type */ public DefaultType getAccess() { if(override != null) { return override; } return access; }
/** * This method is used to extend the provided class. Extending a * class in this way basically means that the fields that have * been scanned in the specific class will be added to this. Doing * this improves the performance of classes within a hierarchy. * * @param base the class to inherit scanned fields from * @param access this is the access type used for the super type */ private void extend(Class base, DefaultType access) throws Exception { ContactList list = support.getFields(base, access); if(list != null) { addAll(list); } }
/** * This method is used to extend the provided class. Extending a * class in this way basically means that the fields that have * been scanned in the specific class will be added to this. Doing * this improves the performance of classes within a hierarchy. * * @param base the class to inherit scanned fields from * @param access this is the access type used for the super type */ private void extend(Class base, DefaultType access) throws Exception { ContactList list = support.getMethods(base, access); for(Contact contact : list) { process((MethodContact)contact); } }
/** * Constructor for the <code>DetailExtractor</code> object. This * is used to extract various details for a class, such as the * method and field details as well as the annotations used on * the class. The primary purpose for this is to create cachable * values that reduce the amount of reflection required. * * @param support this contains various support functions * @param override this is the override used for details created */ public DetailExtractor(Support support, DefaultType override) { this.methods = new ConcurrentCache<ContactList>(); this.fields = new ConcurrentCache<ContactList>(); this.details = new ConcurrentCache<Detail>(); this.override = override; this.support = support; }
/** * This is used to acquire a list of <code>Contact</code> objects * that represent the annotated fields in a type. The entire * class hierarchy is scanned for annotated fields. Caching of * the contact list is done to increase performance. * * @param type this is the type to scan for annotated fields * @param access this is the access type to use for the fields * * @return this returns a list of the annotated fields */ public ContactList getFields(Class type, DefaultType access) throws Exception { if(access != null) { return defaults.getFields(type); } return details.getFields(type); }
/** * This is used to acquire a list of <code>Contact</code> objects * that represent the annotated methods in a type. The entire * class hierarchy is scanned for annotated methods. Caching of * the contact list is done to increase performance. * * @param type this is the type to scan for annotated methods * @param access this is the access type used for the methods * * @return this returns a list of the annotated methods */ public ContactList getMethods(Class type, DefaultType access) throws Exception { if(access != null) { return defaults.getMethods(type); } return details.getMethods(type); }
/** * Constructor for the <code>DefaultDetail</code> object. This is * used to create a description of a class and also provide a * default access override type. This is used when we want to scan * a class with no annotations and extract default details. * * @param detail this is the detail that is delegated to * @param access this is the access type override used */ public DefaultDetail(Detail detail, DefaultType access) { this.detail = detail; this.access = access; }
/** * This returns the <code>Default</code> annotation access type * that has been specified by this. If no default annotation has * been declared on the type then this will return null. * * @return this returns the default access type for this type */ public DefaultType getAccess() { return detail.getAccess(); }
/** * This returns the <code>Default</code> annotation access type * that has been specified by this. If no default annotation has * been declared on the type then this will return null. * * @return this returns the default access type for this type */ public DefaultType getOverride() { return access; }
/** * This returns the <code>DefaultType</code> override used for this * detail. An override is used only when the class contains no * annotations and does not have a <code>Transform</code> of any * type associated with it. It allows serialization of external * objects without the need to annotate the types. * * @return this returns the access type override for this type */ public DefaultType getOverride() { return override; }
/** * This returns the <code>Default</code> annotation access type * that has been specified by this. If no default annotation has * been declared on the type then this will return null. * * @return this returns the default access type for this type */ DefaultType getAccess();
/** * This returns the <code>DefaultType</code> override used for this * detail. An override is used only when the class contains no * annotations and does not have a <code>Transform</code> of any * type associated with it. It allows serialization of external * objects without the need to annotate the types. * * @return this returns the access type override for this type */ DefaultType getOverride();