public class SSRFUtility extends Object
These methods help to assemble, validate, serialize and un-serialize object representations to and from XML.
Constructor and Description |
---|
SSRFUtility() |
Modifier and Type | Method and Description |
---|---|
static Set<String> |
evaluate(Object instance)
Evaluate a SSRF Object instance; record and report any configuration
errors.
|
static Set<Field> |
findDeclaredAndInheritedFields(Class<?> clazz)
Get all declared and inherited fields from a class type.
|
protected static Set<Method> |
findDeclaredAndInheritedMethods(Class<?> clazz)
Get all declared and inherited methods from a class type.
|
protected static Method |
findGetMethod(Class<?> clazz,
Field field)
Helper method to inspect the indicated Class to find the first declared or
inherited GET setter method for the indicated field type.
|
protected static Method |
findSetMethod(Class<?> clazz,
Field field)
Helper method to inspect the indicated Class to find the first declared or
inherited SET setter method for the indicated field type.
|
protected static Method |
findWithCollectionMethod(Class<?> clazz,
Field field)
Helper method to inspect the indicated Class to find the declared or
inherited WITH setter method for the indicated field type that accepts a
SET.
|
protected static Method |
findWithEnumMethod(Class<?> clazz,
Field field)
Helper method to inspect the indicated Class to find the declared or
inherited WITH setter method for the indicated field type that accepts a
SET.
|
protected static Method |
findWithMethod(Class<?> clazz,
Field field)
Helper method to inspect the indicated Class to find the first declared or
inherited WITH setter method for the indicated field type.
|
protected static boolean |
isRequired(Field field)
Inspect a class field and determine if it is required.
|
protected static boolean |
isTransient(Field field)
Inspect a class field and determine if it is TRANSIENT - e.g.
|
static <T> String |
marshal(T clazz)
Marshal an entity class into a XML String representation.
|
static BigInteger |
nextIndex()
Get the next guaranteed unique index compatible with SSRF "idx" fields.
|
static SSRF |
postLoad(SSRF ssrf)
Process a SSRF instance object after reading from XML.
|
static void |
prepare(Object sourceInstance,
Object rootInstance)
Process a SSRF instance object for export (recursive, internal).
|
static SSRF |
prepare(SSRF ssrf)
Process a SSRF instance object for export.
|
static void |
setProperties(SSRFProperties properties,
Object instance)
Assign a SSRF Properties configuration to a SSRF object instance.
|
static <T> T |
unmarshal(String xml,
Class<T> clazz)
Parse an XML file into a container class.
|
static void |
validate(Object instance)
Validate a SSRF object instance.
|
static void |
validate(Object instance,
ListCCL cls)
Validate a SSRF object instance.
|
public static BigInteger nextIndex()
All values increment from a randomly selected start value unique to each SSRFUtility instantiation.
This method is required by the following 9 classes which set an index in
their constructors:
Comment
, ConfigFreq
, Curve
, Ellipse
, ExtReferenceRef
, Footnote
, Point
, Polygon
, Remarks
,
AtomicInteger
, wrapped inside a BigInteger
instance.public static void validate(Object instance) throws Exception
This method keeps track of the instance parent instance, plus the field within that parent instance where the current object instance is set. These are tracked to help produce a set of legible error messages.
Developer note: For more information about Java reflection see The Reflection API and Java Reflection Tutorial.
instance
- the object instance to validateException
- if the SSRF instance fails to validatepublic static void validate(Object instance, ListCCL cls) throws Exception
This method keeps track of the instance parent instance, plus the field within that parent instance where the current object instance is set. These are tracked to help produce a set of legible error messages.
Developer note: For more information about Java reflection see The Reflection API and Java Reflection Tutorial.
instance
- the object instance to validatecls
- The parent (maximum) classification. If set all subordinate
classifications in the class tree must be less than or
equal to this value.Exception
- if the SSRF instance fails to validatepublic static Set<String> evaluate(Object instance)
This method recursively validates the provided object instance and all of its components. The validation procedure ensures that all required fields are set and that all configured fields contain valid data according to the SSRF data formatting rules.
If the SSRF object instance does not validate OK then each specific validation error condition is recorded and returned.
It is expected that this method will only be called on the top-level SSRF class. However it will just as easily validate any SSRF data type.
instance
- the object instance to validatepublic static Set<Field> findDeclaredAndInheritedFields(Class<?> clazz)
Reflection does not expose inherited fields. This method implements a recursive search (up to but not including the base Object) of the Class inheritance tree and returns all declared fields.
clazz
- the class type to inspectHashSet
instance of Fieldsprotected static Set<Method> findDeclaredAndInheritedMethods(Class<?> clazz)
Reflection does not expose inherited fields. This method implements a recursive search (up to but not including the base Object) of the Class inheritance tree and returns all declared methods.
clazz
- the class type to inspectHashSet
instance of Methodsprotected static boolean isRequired(Field field)
This method looks for and inspects XmlAttribute
, XmlElement
and XmlElementRef
field annotation types marked as REQUIRED; also,
XmlValue
.
field
- the field to inspectprotected static boolean isTransient(Field field)
This method looks for a XmlTransient
field annotation.
field
- the field to inspectpublic static SSRF prepare(SSRF ssrf)
This method examines the class tree and copies all required data objects into their proper location and prepares the SSRF destination instance for export.
ssrf
- A SSRF working copypublic static void prepare(Object sourceInstance, Object rootInstance)
This method examines the class tree and copies all required data objects into their proper location and prepares the SSRF destination instance for export.
sourceInstance
- the current object instance to inspectrootInstance
- the root SSRF/SMADEF object instance into which the
source instance components are copiedpublic static SSRF postLoad(SSRF ssrf)
This method examines the class tree and copies all required data objects into their proper location and preparing the SSRF software class hierarchy for working.
ssrf
- a SSRF
instancepublic static void setProperties(SSRFProperties properties, Object instance)
This assigns default values declared in a SSRF configuration profile to a SSRF configuration.
properties
- a SSRF properties configurationinstance
- a SSRF object instance. The field type is a generic
object as this method calls itself recursively.protected static Method findWithMethod(Class<?> clazz, Field field)
This method supports
setProperties(SSRFProperties, java.lang.Object)
.
clazz
- the class type to inspectfield
- the field to look forprotected static Method findWithCollectionMethod(Class<?> clazz, Field field)
This method supports
setProperties(SSRFProperties, java.lang.Object)
.
clazz
- the class type to inspectfield
- the field to look forprotected static Method findWithEnumMethod(Class<?> clazz, Field field)
This method supports
setProperties(SSRFProperties, java.lang.Object)
.
clazz
- the class type to inspectfield
- the field to look forprotected static Method findSetMethod(Class<?> clazz, Field field)
clazz
- the class type to inspectfield
- the field to look forprotected static Method findGetMethod(Class<?> clazz, Field field)
clazz
- the class type to inspectfield
- the field to look forpublic static <T> String marshal(T clazz) throws JAXBException
The output of this method is typically either written to a file or sent via a SOAP communication link.
T
- the entity class typeclazz
- the entity class to be writtenJAXBException
- if the entity class cannot be marshaled (serialized)public static <T> T unmarshal(String xml, Class<T> clazz) throws JAXBException
T
- the class type to be returnedxml
- the XML source contentclazz
- the parsed and populated class type; this is the same as the
class type that is returnedJAXBException
- if the XML source file does not match the input class
typeCopyright © 2016 OpenSSRF.org. All rights reserved.