Package org.simpleframework.xml.core
Class FieldScanner
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<E>
-
- java.util.ArrayList<Contact>
-
- org.simpleframework.xml.core.ContactList
-
- org.simpleframework.xml.core.FieldScanner
-
- 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 FieldScanner extends ContactList
TheFieldScanner
object is used to scan an class for fields marked with an XML annotation. All fields that contain an XML annotation are added asContact
objects to the list of contacts for the class. This scans the object by checking the class hierarchy, this allows a subclass to override a super class annotated field, although this should be used rarely.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
FieldScanner.FieldKey
TheFieldKey
object is used to create a key that can store a contact using a field without using the methods ofhashCode
andequals
on the field directly, as these can perform poorly on certain platforms.
-
Field Summary
Fields Modifier and Type Field Description private ContactMap
done
This is used to determine which fields have been scanned.private AnnotationFactory
factory
This is used to create the synthetic annotations for fields.private Support
support
This object contains various support functions for the class.
-
Constructor Summary
Constructors Constructor Description FieldScanner(Detail detail, Support support)
Constructor for theFieldScanner
object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
build()
This is used to build a list of valid contacts for this scanner.private void
extend(java.lang.Class base, DefaultType access)
This method is used to extend the provided class.private void
extract(Detail detail)
This is used to scan the declared fields within the specified class.private void
extract(Detail detail, DefaultType access)
This is used to scan all the fields of the class in order to determine if it should have a default annotation.private void
insert(java.lang.Object key, Contact contact)
This is used to insert a contact to this contact list.private boolean
isStatic(java.lang.reflect.Field field)
This is used to determine if a field is static.private boolean
isText(Contact contact)
This is used to determine if theText
annotation has been declared on the field.private boolean
isTransient(java.lang.reflect.Field field)
This is used to determine if a field is transient.private void
process(java.lang.reflect.Field field, java.lang.annotation.Annotation label, java.lang.annotation.Annotation[] list)
This method is used to process the field an annotation given.private void
process(java.lang.reflect.Field field, java.lang.Class type, java.lang.annotation.Annotation[] list)
This method is used to process the field an annotation given.private void
remove(java.lang.reflect.Field field, java.lang.annotation.Annotation label)
This is used to remove a field from the map of processed fields.private void
scan(java.lang.reflect.Field field, java.lang.annotation.Annotation label, java.lang.annotation.Annotation[] list)
This reflectively checks the annotation to determine the type of annotation it represents.private void
scan(Detail detail)
This method is used to scan the class hierarchy for each class in order to extract fields that contain XML annotations.-
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 AnnotationFactory factory
This is used to create the synthetic annotations for fields.
-
done
private final ContactMap done
This is used to determine which fields have been scanned.
-
support
private final Support support
This object contains various support functions for the class.
-
-
Constructor Detail
-
FieldScanner
public FieldScanner(Detail detail, Support support) throws java.lang.Exception
Constructor for theFieldScanner
object. This is used to perform a scan on the specified class in order to find all fields that are labeled with an XML annotation.- 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 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.- 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.Exception
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.- 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)
This is used to scan the declared fields within the specified class. Each method will be check to determine if it contains an XML element and can be used as aContact
for an entity within the object.- Parameters:
detail
- this is one of the super classes for the object
-
extract
private void extract(Detail detail, DefaultType access) throws java.lang.Exception
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.- Parameters:
detail
- this is the detail to have its fields scannedaccess
- this is the default access type for the class- Throws:
java.lang.Exception
-
scan
private void scan(java.lang.reflect.Field field, java.lang.annotation.Annotation label, java.lang.annotation.Annotation[] list)
This reflectively checks the annotation to determine the type of annotation it represents. If it represents an XML schema annotation it is used to create aContact
which can be used to represent the field within the source object.- Parameters:
field
- the field that the annotation comes fromlabel
- the annotation used to model the XML schemalist
- this is the list of annotations on the field
-
process
private void process(java.lang.reflect.Field field, java.lang.Class type, java.lang.annotation.Annotation[] list) throws java.lang.Exception
This method is used to process the field an annotation given. This will check to determine if the field is accessible, if it is not accessible then it is made accessible so that private member fields can be used during the serialization process.- Parameters:
field
- this is the field to be added as a contacttype
- this is the type to acquire the annotationlist
- this is the list of annotations on the field- Throws:
java.lang.Exception
-
process
private void process(java.lang.reflect.Field field, java.lang.annotation.Annotation label, java.lang.annotation.Annotation[] list)
This method is used to process the field an annotation given. This will check to determine if the field is accessible, if it is not accessible then it is made accessible so that private member fields can be used during the serialization process.- Parameters:
field
- this is the field to be added as a contactlabel
- this is the XML annotation used by the fieldlist
- this is the list of annotations on the field
-
insert
private void insert(java.lang.Object key, Contact contact)
This is used to insert a contact to this contact list. Here if aText
annotation is declared on a field that already has an annotation then the other annotation is given the priority, this is to so text can be processes separately.- Parameters:
key
- this is the key that uniquely identifies the fieldcontact
- this is the contact that is to be inserted
-
isText
private boolean isText(Contact contact)
This is used to determine if theText
annotation has been declared on the field. 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 field
-
remove
private void remove(java.lang.reflect.Field field, java.lang.annotation.Annotation label)
This is used to remove a field from the map of processed fields. A field is removed with theTransient
annotation is used to indicate that it should not be processed by the scanner. This is required when default types are used.- Parameters:
field
- this is the field to be removed from the maplabel
- this is the label associated with the field
-
build
private void build()
This is used to build a list of valid contacts for this scanner. Valid contacts are fields that are either defaulted or those that have an explicit XML annotation. Any field that has been marked as transient will not be considered as valid.
-
isStatic
private boolean isStatic(java.lang.reflect.Field field)
This is used to determine if a field is static. If a field is static it should not be considered as a default field. This ensures the default annotation does not pick up static finals.- Parameters:
field
- this is the field to determine if it is static- Returns:
- true if the field is static, false otherwise
-
isTransient
private boolean isTransient(java.lang.reflect.Field field)
This is used to determine if a field is transient. For default fields that are processed no transient field should be considered. This ensures that the serialization of the object behaves in the same manner as with Java Object Serialization.- Parameters:
field
- this is the field to check for transience- Returns:
- this returns true if the field is a transient one
-
-