1
2
3
4 package org.xanot.structure;
5
6 /***
7 * Create instance rule. This rule define what class should be instantiated when
8 * it encounters an xml element start.
9 *
10 * @author Ferdinand Neman (newm4n _at_ gmail.com)
11 */
12 public class CreateInstanceRule extends XanotRule {
13 private Class baseClass = null;
14
15 private boolean root = false;
16
17 private boolean repeatable = false;
18
19 /***
20 * Creates a new CreateInstanceRule object.
21 *
22 * @param path
23 * Path name, should be equals to the xml open tag name.
24 * @param baseClass
25 * The class to instantiate
26 */
27 public CreateInstanceRule(String path, Class baseClass) {
28 super(path);
29 setBaseClass(baseClass);
30 }
31
32 /***
33 * Get the class to instantiate
34 *
35 * @return Returns the baseClass.
36 */
37 public Class getBaseClass() {
38 return baseClass;
39 }
40
41 /***
42 * Set the class to instantiate
43 *
44 * @param baseClass
45 * The baseClass to set.
46 */
47 public void setBaseClass(Class baseClass) {
48 this.baseClass = baseClass;
49 }
50
51 /***
52 * Create an object instance based on the base class
53 *
54 * @return Instance
55 * @throws InstantiationException
56 * Thrown when instantiating class.
57 * @throws IllegalAccessException
58 * Thrown when the class is not legally accessed.
59 */
60 public Object createInstance() throws InstantiationException,
61 IllegalAccessException {
62 return baseClass.newInstance();
63 }
64
65 /***
66 * Check wether the base class is the root class.
67 *
68 * @return Returns the root.
69 */
70 public boolean isRoot() {
71 return root;
72 }
73
74 /***
75 * Determine wether the base class is the root class.
76 *
77 * @param root
78 * The root to set.
79 */
80 public void setRoot(boolean root) {
81 this.root = root;
82 }
83
84 /***
85 * Check wether the base class can be nested inside the same or child of
86 * this class
87 *
88 * @return Returns the repeatable.
89 */
90 public boolean isRepeatable() {
91 return repeatable;
92 }
93
94 /***
95 * Determine wether the base class can be nested inside the same or child of
96 * this class
97 *
98 * @param repeatable
99 * The repeatable to set.
100 */
101 public void setRepeatable(boolean repeatable) {
102 this.repeatable = repeatable;
103 }
104
105 /***
106 * Get string representation of this object.
107 *
108 * @return String representation.
109 */
110 public String toString() {
111 return "CreateInstanceRule : [path:" + getPath() + "],[baseClass:"
112 + baseClass.getName() + "],[root:" + root + "],[repeatable:"
113 + repeatable + "]";
114 }
115 }