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