Package aQute.lib.xmldtoparser
Class DomDTOParser
- java.lang.Object
-
- aQute.lib.xmldtoparser.DomDTOParser
-
public class DomDTOParser extends java.lang.Object
Parse an XML file based on a DTO as schema
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static javax.xml.parsers.DocumentBuilderFactory
dbf
-
Constructor Summary
Constructors Constructor Description DomDTOParser()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static java.lang.reflect.Field
findField(java.lang.Class<? extends java.lang.Object> class1, java.lang.String name)
private static <T> void
get(T instance, org.w3c.dom.Node node)
private static <T> T
getField(java.lang.reflect.Field f, java.lang.Object targetObject)
private static java.lang.String
getName(java.lang.reflect.Field field)
private static boolean
isCollection(java.lang.Class<?> class1)
private static boolean
isSimple(java.lang.Class<?> class1)
private static boolean
isStatic(java.lang.reflect.Member m)
static <T> T
parse(java.lang.Class<T> type, java.io.File doc)
parse the given XML file based on the type as the schema.static <T> T
parse(java.lang.Class<T> type, java.io.InputStream doc)
parse the given XML file based on the type as the schema.private static <T> T
parse(java.lang.Class<T> type, org.w3c.dom.Node node)
private static void
setField(java.lang.reflect.Field f, java.lang.Object targetObject, java.lang.Object value)
private static java.lang.String
toSimpleName(java.lang.String nodeName)
-
-
-
Method Detail
-
parse
public static <T> T parse(java.lang.Class<T> type, java.io.File doc) throws java.lang.Exception
parse the given XML file based on the type as the schema. Attributes and elements are mapped to fields in an object of this type. If the field is a collection or a DTO type, the parse will be recursive.- Parameters:
type
- the type acting as schemedoc
- the file- Returns:
- a DTO of type
- Throws:
java.lang.Exception
-
parse
public static <T> T parse(java.lang.Class<T> type, java.io.InputStream doc) throws java.lang.Exception
parse the given XML file based on the type as the schema. Attributes and elements are mapped to fields in an object of this type. If the field is a collection or a DTO type, the parse will be recursive.- Parameters:
type
- the type acting as schemedoc
- the file- Returns:
- a DTO of type
- Throws:
java.lang.Exception
-
parse
private static <T> T parse(java.lang.Class<T> type, org.w3c.dom.Node node) throws java.lang.Exception
- Throws:
java.lang.Exception
-
get
private static <T> void get(T instance, org.w3c.dom.Node node) throws java.lang.Exception
- Throws:
java.lang.Exception
-
getName
private static java.lang.String getName(java.lang.reflect.Field field)
-
toSimpleName
private static java.lang.String toSimpleName(java.lang.String nodeName)
-
isSimple
private static boolean isSimple(java.lang.Class<?> class1)
-
isCollection
private static boolean isCollection(java.lang.Class<?> class1)
-
findField
private static java.lang.reflect.Field findField(java.lang.Class<? extends java.lang.Object> class1, java.lang.String name) throws java.lang.Exception
- Throws:
java.lang.Exception
-
setField
private static void setField(java.lang.reflect.Field f, java.lang.Object targetObject, java.lang.Object value) throws java.lang.Exception
- Throws:
java.lang.Exception
-
getField
private static <T> T getField(java.lang.reflect.Field f, java.lang.Object targetObject) throws java.lang.Exception
- Throws:
java.lang.Exception
-
isStatic
private static boolean isStatic(java.lang.reflect.Member m)
-
-