Package org.simpleframework.xml.core
Class MethodScanner
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<E>
-
- java.util.ArrayList<Contact>
-
- org.simpleframework.xml.core.ContactList
-
- org.simpleframework.xml.core.MethodScanner
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,java.lang.Iterable<Contact>,java.util.Collection<Contact>,java.util.List<Contact>,java.util.RandomAccess
class MethodScanner extends ContactList
TheMethodScannerobject is used to scan an object for matching get and set methods for an XML annotation. This will scan for annotated methods starting with the most specialized class up the class hierarchy. Thus, annotated methods can be overridden in a type specialization.The annotated methods must be either a getter or setter method following the Java Beans naming conventions. This convention is such that a method must begin with "get", "set", or "is". A pair of set and get methods for an annotation must make use of the same type. For instance if the return type for the get method was
Stringthen the set method must have a single argument parameter that takes aStringtype.For a method to be considered there must be both the get and set methods. If either method is missing then the scanner fails with an exception. Also, if an annotation marks a method which does not follow Java Bean naming conventions an exception is thrown.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classMethodScanner.PartMapThePartMapis used to contain method parts using the Java Bean method name for the part.
-
Field Summary
Fields Modifier and Type Field Description private DetaildetailThis contains the details for the class that is being scanned.private MethodPartFactoryfactoryThis is a factory used for creating property method parts.private MethodScanner.PartMapreadThis is used to collect all the get methods from the object.private SupportsupportThis object contains various support functions for the class.private MethodScanner.PartMapwriteThis is used to collect all the set methods from the object.
-
Constructor Summary
Constructors Constructor Description MethodScanner(Detail detail, Support support)Constructor for theMethodScannerobject.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidbuild()This method is used to pair the get methods with a matching set method.private voidbuild(MethodPart read)This method is used to create a read only contact.private voidbuild(MethodPart read, java.lang.String name)This method is used to pair the get methods with a matching set method.private voidbuild(MethodPart read, MethodPart write)This method is used to pair the get methods with a matching set method.private voidextend(java.lang.Class base, DefaultType access)This method is used to extend the provided class.private voidextract(Detail detail)This is used to scan the declared methods within the specified class.private voidextract(Detail detail, DefaultType access)This is used to scan all the methods of the class in order to determine if it should have a default annotation.private voidinsert(MethodPart method, MethodScanner.PartMap map)This is used to insert a contact to this contact list.private booleanisText(MethodPart method)This is used to determine if theTextannotation has been declared on the method.private voidprocess(java.lang.reflect.Method method, java.lang.annotation.Annotation[] list)This is used to classify the specified method into either a get or set method.private voidprocess(java.lang.reflect.Method method, java.lang.annotation.Annotation label, java.lang.annotation.Annotation[] list)This is used to classify the specified method into either a get or set method.private voidprocess(MethodContact contact)This is used to process a method from a super class.private voidprocess(MethodPart method, MethodScanner.PartMap map)This is used to determine whether the specified method can be inserted into the givenPartMap.private voidremove(java.lang.reflect.Method method, java.lang.annotation.Annotation label, java.lang.annotation.Annotation[] list)This method is used to remove a particular method from the list of contacts.private voidremove(MethodPart part, MethodScanner.PartMap map)This is used to remove the method part from the specified map.private voidscan(java.lang.reflect.Method method, java.lang.annotation.Annotation label, java.lang.annotation.Annotation[] list)This reflectively checks the annotation to determine the type of annotation it represents.private voidscan(Detail detail)This method is used to scan the class hierarchy for each class in order to extract methods that contain XML annotations.private voidvalidate()This is used to validate the object once all the get methods have been matched with a set method.private voidvalidate(MethodPart write, java.lang.String name)This is used to validate the object once all the get methods have been matched with a set method.-
Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, equals, forEach, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeIf, removeRange, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray, trimToSize
-
-
-
-
Field Detail
-
factory
private final MethodPartFactory factory
This is a factory used for creating property method parts.
-
support
private final Support support
This object contains various support functions for the class.
-
write
private final MethodScanner.PartMap write
This is used to collect all the set methods from the object.
-
read
private final MethodScanner.PartMap read
This is used to collect all the get methods from the object.
-
detail
private final Detail detail
This contains the details for the class that is being scanned.
-
-
Constructor Detail
-
MethodScanner
public MethodScanner(Detail detail, Support support) throws java.lang.Exception
Constructor for theMethodScannerobject. This is used to create an object that will scan the specified class such that all bean property methods can be paired under the XML annotation specified within the class.- Parameters:
detail- this contains the details for the class scannedsupport- this contains various support functions- Throws:
java.lang.Exception
-
-
Method Detail
-
scan
private void scan(Detail detail) throws java.lang.Exception
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.- Parameters:
detail- this contains the details for the class scanned- Throws:
java.lang.Exception
-
extend
private void extend(java.lang.Class base, DefaultType access) throws java.lang.ExceptionThis 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.- Parameters:
base- the class to inherit scanned fields fromaccess- this is the access type used for the super type- Throws:
java.lang.Exception
-
extract
private void extract(Detail detail) throws java.lang.Exception
This is used to scan the declared methods within the specified class. Each method will be checked to determine if it contains an XML element and can be used as aContactfor an entity within the object.- Parameters:
detail- this is one of the super classes for the object- Throws:
java.lang.Exception
-
extract
private void extract(Detail detail, DefaultType access) throws java.lang.Exception
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.- Parameters:
detail- this is the detail to have its methods scannedaccess- this is the default access type for the class- Throws:
java.lang.Exception
-
scan
private void scan(java.lang.reflect.Method method, java.lang.annotation.Annotation label, java.lang.annotation.Annotation[] list) throws java.lang.ExceptionThis reflectively checks the annotation to determine the type of annotation it represents. If it represents an XML schema annotation it is used to create aContactwhich can be used to represent the method within the source object.- Parameters:
method- the method that the annotation comes fromlabel- the annotation used to model the XML schemalist- this is the list of annotations on the method- Throws:
java.lang.Exception
-
process
private void process(java.lang.reflect.Method method, java.lang.annotation.Annotation label, java.lang.annotation.Annotation[] list) throws java.lang.ExceptionThis is used to classify the specified method into either a get or set method. If the method is neither then an exception is thrown to indicate that the XML annotations can only be used with methods following the Java Bean naming conventions. Once the method is classified is is added to either the read or write map so that it can be paired after scanning is complete.- Parameters:
method- this is the method that is to be classifiedlabel- this is the annotation applied to the methodlist- this is the list of annotations on the method- Throws:
java.lang.Exception
-
process
private void process(java.lang.reflect.Method method, java.lang.annotation.Annotation[] list) throws java.lang.ExceptionThis is used to classify the specified method into either a get or set method. If the method is neither then an exception is thrown to indicate that the XML annotations can only be used with methods following the Java Bean naming conventions. Once the method is classified is is added to either the read or write map so that it can be paired after scanning is complete.- Parameters:
method- this is the method that is to be classifiedlist- this is the list of annotations on the method- Throws:
java.lang.Exception
-
process
private void process(MethodPart method, MethodScanner.PartMap map)
This is used to determine whether the specified method can be inserted into the givenPartMap. This ensures that only the most specialized method is considered, which enables annotated methods to be overridden in subclasses.- Parameters:
method- this is the method part that is to be insertedmap- this is the part map used to contain the method
-
process
private void process(MethodContact contact)
This is used to process a method from a super class. Processing the inherited method involves extracting out the individual parts of the method an initializing the internal state of this scanner. If method is overridden it overwrites the parts.- Parameters:
contact- this is a method inherited from a super class
-
insert
private void insert(MethodPart method, MethodScanner.PartMap map)
This is used to insert a contact to this contact list. Here if aTextannotation is declared on a method that already has an annotation then the other annotation is given the priority, this is to so text can be processes separately.- Parameters:
method- this is the part that is to be insertedmap- this is the map that the part is to be inserted in
-
isText
private boolean isText(MethodPart method)
This is used to determine if theTextannotation has been declared on the method. If this annotation is used then this will return true, otherwise this returns false.- Parameters:
contact- the contact to check for the text annotation- Returns:
- true if the text annotation was declared on the method
-
remove
private void remove(java.lang.reflect.Method method, java.lang.annotation.Annotation label, java.lang.annotation.Annotation[] list) throws java.lang.ExceptionThis method is used to remove a particular method from the list of contacts. If theTransientannotation is used by any method then this method must be removed from the schema. In particular it is important to remove methods if there are defaults applied to the class.- Parameters:
method- this is the method that is to be removedlabel- this is the label associated with the methodlist- this is the list of annotations on the method- Throws:
java.lang.Exception
-
remove
private void remove(MethodPart part, MethodScanner.PartMap map) throws java.lang.Exception
This is used to remove the method part from the specified map. Removal is performed using the name of the method part. If it has been scanned and added to the map then it will be removed and will not form part of the class schema.- Parameters:
part- this is the part to be removed from the mapmap- this is the map to removed the method part from- Throws:
java.lang.Exception
-
build
private void build() throws java.lang.ExceptionThis method is used to pair the get methods with a matching set method. This pairs methods using the Java Bean method name, the names must match exactly, meaning that the case and value of the strings must be identical. Also in order for this to succeed the types for the methods and the annotation must also match.- Throws:
java.lang.Exception
-
build
private void build(MethodPart read, java.lang.String name) throws java.lang.Exception
This method is used to pair the get methods with a matching set method. This pairs methods using the Java Bean method name, the names must match exactly, meaning that the case and value of the strings must be identical. Also in order for this to succeed the types for the methods and the annotation must also match.- Parameters:
read- this is a get method that has been extractedname- this is the Java Bean methods name to be matched- Throws:
java.lang.Exception
-
build
private void build(MethodPart read) throws java.lang.Exception
This method is used to create a read only contact. A read only contact object is used when there is constructor injection used by the class schema. So, read only methods can be used in a fully serializable and deserializable object.- Parameters:
read- this is the part to add as a read only contact- Throws:
java.lang.Exception
-
build
private void build(MethodPart read, MethodPart write) throws java.lang.Exception
This method is used to pair the get methods with a matching set method. This pairs methods using the Java Bean method name, the names must match exactly, meaning that the case and value of the strings must be identical. Also in order for this to succeed the types for the methods and the annotation must also match.- Parameters:
read- this is a get method that has been extractedwrite- this is the write method to compare details with- Throws:
java.lang.Exception
-
validate
private void validate() throws java.lang.ExceptionThis is used to validate the object once all the get methods have been matched with a set method. This ensures that there is not a set method within the object that does not have a match, therefore violating the contract of a property.- Throws:
java.lang.Exception
-
validate
private void validate(MethodPart write, java.lang.String name) throws java.lang.Exception
This is used to validate the object once all the get methods have been matched with a set method. This ensures that there is not a set method within the object that does not have a match, therefore violating the contract of a property.- Parameters:
write- this is a get method that has been extractedname- this is the Java Bean methods name to be matched- Throws:
java.lang.Exception
-
-