-
Notifications
You must be signed in to change notification settings - Fork 41
Xml Hander
As it may be compact, the configuration in XML file format, there is always the possibility of error-prone writing it, to eliminate these risks and speed up its completion, the framework exposes the class XmlHandler
, with whom you can create or modify the configuration file.
IMPORTANT! XmlHandler handles the configuration but not the conversions
The empty constructor defines a jmapper.xml file positioned at the application root:new XmlHandler()
.
If exists an xml file that you want to handle, pass it to the constructor, as follows:new XmlHandler("jmapper.xml")
.
Each method invoked on its instance will modify the file.
IMPORTANT! In this case, you do not need to declare the full path but only the file name, JMapper finds it recursively.
XmlHandler
has a number of utility methods.
Most of its methods use two javaBean: Attribute
and Global
:
class Attribute { class Global {
String name; String value;
String value; String[] attributes;
String[] attributes; Class<?>[] classes;
Class<?>[] classes; String[] excluded;
// getters and setters... // getters and setters...
} }
The Attribute class reflects the parameters of the @JMap annotation plus a string: name, the name of the current attribute.
The Global class reflects the parameters of the @JGlobalMap.
addAttributes lets you to add one or more attributes in a class that is present in the xml configuration file.
String[] attributes = {"field2Class1","field2Class2","field2Class3"};
Class<?>[] classes = {Class1.class,Class2.class,Class3.class};
Attribute attribute = new Attribute("field2", attributes, classes);
xmlHandler.addAttributes(MyClass.class, attribute);
deleteAttributes eliminates attributes related to an existing class specifying their names.
xmlHandler.deleteAttributes(MyClass.class, "field2");
addGlobal permits to add a global mapping in a class that is present in the xml configuration file.
String[] excluded = {"field1Class1","field1Class2","field1Class3"};
Class<?>[] globalClasses = {Class1.class,Class2.class,Class3.class};
Global global = new Global("globalMapping", globalClasses, excluded);
xmlHandler.addGlobal(MyClass.class, global);
deleteGlobal eliminates the global mapping related to an existing class specifying class name.
xmlHandler.deleteGlobal(MyClass.class);
overrideGlobal allows you to override an existing global mapping specifying the class name.
String[] excluded = {"field1Class1","field1Class2","field1Class3"};
Class<?>[] globalClasses = {Class1.class,Class2.class,Class3.class};
Global global = new Global("globalMapping", globalClasses, excluded);
xmlHandler.overrideGlobal(MyClass.class, global);
addClass allows you to add, into the file configuration, the class passed in input.
There are many signatures of this method:
String[] attributes = {"field2Class1","field2Class2","field2Class3"};
Class<?>[] classes = {Class1.class,Class2.class,Class3.class};
Attribute attribute = new Attribute("field2", attributes, classes);
String[] excluded = {"field1Class1","field1Class2","field1Class3"};
Class<?>[] globalClasses = {Class1.class,Class2.class,Class3.class};
Global global = new Global("globalMapping", globalClasses, excluded);
xmlHandler.addClass(MyClass.class, attribute);
// or xmlHandler.addClass(MyClass.class, global);
// or xmlHandler.addClass(MyClass.class, global, attribute);
Deletes a class present in the Xml file.
xmlHandler.deleteClass(MyClass.class);
Override the class replacing the actual configuration with a new one given as input.
String[] attributes = {"field2Class1","field2Class2","field2Class3"};
Class<?>[] classes = {Class1.class,Class2.class,Class3.class};
Attribute attribute = new Attribute("field2", attributes, classes);
String[] excluded = {"field1Class1","field1Class2","field1Class3"};
Class<?>[] globalClasses = {Class1.class,Class2.class,Class3.class};
Global global = new Global("globalMapping", globalClasses, excluded);
xmlHandler.overrideClass(MyClass.class, attribute);
// or xmlHandler.overrideClass(MyClass.class, global);
// or xmlHandler.overrideClass(MyClass.class, global, attribute);
addAnnotatedClass allows you to add in the xml configuration file to one or more classes annotated passed as input to the method, not specifying any class the same will be done for all classes configured with annotation xmlHandler.addAnnotatedClass()
.
xmlHandler.addAnnotatedClass(AnnotatedClass.class);
Same logic as the previous method with the difference that the function will be effective even for the innerClass present.
deleteAnnotatedClasses eliminates from xml file all the annotated classes.
xmlHandler.deleteAnnotatedClasses();
overrideAnnotatedClass allows you to update the xml configuration starting from the annotation of the classes passed as input, not specifying any parameters the same will be done for all annotated classes xmlHandler.overrideAnnotatedClass()
.
xmlHandler.overrideAnnotatedClass(AnnotatedClass.class);
Same logic as the previous method with the difference that the function will be effective even for the inner classes present.
This method allows to annotate a class starting from its xml configuration.
Not defining any class will be executed the same for all the classes present in the xml configuration file xmlHandler.fromXmlToAnnotation()
.
xmlHandler.fromXmlToAnnotation(MyClass.class);
This method eliminates the annotations from classes, without parameters will do the same for all annotated classes ```xmlHandler.cleanAnnotatedClass()```. ```java xmlHandler.cleanAnnotatedClass(AnnotatedClass.class); ``` Same logic as the previous method with the difference that the function will be effective even for the innerClass present.
© 2016 Alessandro Vurro
- Home
- How to map
- Relations
- Conversions
- creation/enrichment
- XML
- Annotation
- API
- Configurations
- Utilities
- Examples
- Articles
- More information
- Performance tests
- Release Notes