View Javadoc

1   /*
2    * joey-gen and its relative products are published under the terms
3    * of the Apache Software License.
4    * 
5    * Created on 2004/08/10 17:00:26
6    */
7   package org.asyrinx.joey.gen.model;
8   
9   import java.util.Collections;
10  import java.util.HashMap;
11  import java.util.Map;
12  
13  import org.apache.commons.logging.Log;
14  import org.apache.commons.logging.LogFactory;
15  
16  /***
17   * @author akima
18   */
19  public abstract class Element implements Cloneable {
20  
21      /***
22       *  
23       */
24      public Element() {
25          this(null, null);
26      }
27  
28      /***
29       * @param parent
30       */
31      public Element(Element parent) {
32          this(parent, null);
33      }
34  
35      /***
36       * @param name
37       */
38      public Element(String name) {
39          this(null, name);
40      }
41  
42      /***
43       * @param parent
44       * @param name
45       */
46      public Element(Element parent, String name) {
47          this(parent, name, null);
48      }
49  
50      /***
51       * @param parent
52       * @param name
53       */
54      public Element(Element parent, String name, String label) {
55          super();
56          this.name = name;
57          this.label = label;
58          this.setParentElement(parent);
59      }
60  
61      protected final Log log = LogFactory.getLog(this.getClass());
62  
63      /*
64       * (non-Javadoc)
65       * 
66       * @see java.lang.Object#clone()
67       */
68      public Object clone() throws CloneNotSupportedException {
69          return super.clone();
70      }
71  
72      public String getFullName() {
73          return (getParentElement() == null) ? getName() : getParentElement().getFullName() + "." + getName();
74      }
75  
76      private Element parent = null;
77  
78      /***
79       * @return Returns the parent.
80       */
81      public Element getParentElement() {
82          return parent;
83      }
84  
85      /***
86       * @param parent
87       *            The parent to set.
88       */
89      protected void setParentElement(Element parent) {
90          if (this.parent == parent)
91              return;
92          this.parent = (parent == null) ? null : (parent.isEntity()) ? parent : parent.getParentElement();
93          if (this.parent != null)
94              this.parent.add(this);
95      }
96  
97      public boolean isEntity() {
98          return true;
99      }
100 
101     public void add(Element element) {
102         if (element instanceof ElementSet) {
103             //final ElementSet elementSet = (ElementSet)element;
104         } else {
105             throw new UnsupportedOperationException("element must not be ." + element.getClass().getName() + " @"
106                     + this.getClass().getName());
107         }
108     }
109 
110     private String name = null;
111 
112     private String label = null;
113 
114     private String description = null;
115 
116     private Map options = new HashMap();
117 
118     /***
119      * @return Returns the label.
120      */
121     public String getLabel() {
122         return label;
123     }
124 
125     /***
126      * @param label
127      *            The label to set.
128      */
129     public void setLabel(String label) {
130         this.label = label;
131     }
132 
133     /***
134      * @return Returns the name.
135      */
136     public String getName() {
137         return name;
138     }
139 
140     /***
141      * @param name
142      *            The name to set.
143      */
144     public void setName(String name) {
145         this.name = name;
146     }
147 
148     /***
149      * @return Returns the description.
150      */
151     public String getDescription() {
152         return description;
153     }
154 
155     /***
156      * @param description
157      *            The description to set.
158      */
159     public void setDescription(String description) {
160         this.description = description;
161     }
162 
163     /***
164      * @return Returns the options.
165      */
166     public Map getOptions() {
167         return options;
168     }
169 
170     /***
171      * @param options
172      *            The options to set.
173      */
174     public void setOptions(Map options) {
175         this.options = (options != null) ? options : Collections.EMPTY_MAP;
176     }
177 
178     public Object getOption(String key) {
179         final Object option = getOptions().get(key);
180         return (option != null) ? option : (getParentElement() == null) ? null : getParentElement().getOption(key);
181     }
182 
183     private Element original = null;
184 
185     /***
186      * @return Returns the original.
187      */
188     public Element getOriginal() {
189         return original;
190     }
191 
192     /***
193      * @param original
194      *            The original to set.
195      */
196     public void setOriginal(Element original) {
197         this.original = original;
198     }
199 }