View Javadoc

1   package org.lsst.ccs.config;
2   
3   import org.hibernate.annotations.Immutable;
4   
5   import javax.persistence.Embeddable;
6   import javax.persistence.Embedded;
7   import javax.persistence.EmbeddedId;
8   import java.io.Serializable;
9   
10  /**
11   * this is an explicit duplication of description of parameter as it is in the subsystem configuration.
12   * all members are implicitly final! (no public mutator).
13   */
14  @Embeddable
15  @Immutable
16  public class ParameterBase implements Serializable, PathObject {
17      private static final long serialVersionUID = -1173880414018123185L;
18      // TODO: key to object
19      @Embedded
20      //@EmbeddedId : does not work!!
21      ParameterPath /*@NotNull*/ path ;
22      /**
23       * type of parameter: class Name.
24       * should have a valueOf(String) method
25       */
26      String /*@NotNull*/ typeName ;
27      /**
28       * default value as String
29       * TODO: define a possible NULL value!
30       */
31      String /*@Nullable*/ defaultValue ;
32  
33      //////////////////////////// CONSTRUCTORS
34  
35      ParameterBase() {}
36  
37      public ParameterBase(String componentName, String codeName, String parameterName, String typeName, String defaultValue) {
38          this( new ParameterPath(componentName,codeName,parameterName), typeName, defaultValue) ;
39      }
40  
41      public ParameterBase(ParameterPath path, String typeName, String defaultValue) {
42          //TODO: check for null!
43          this.path = path;
44          this.typeName = typeName;
45          this.defaultValue = defaultValue;
46      }
47  //////////////////////// ACCESSORS/MUTATORS
48  
49      public String getComponentName() {
50          return path.componentName;
51      }
52  
53       void setComponentName(String componentName) {
54          this.path.componentName = componentName;
55      }
56  
57      public String getCodeName() {
58          return path.codeName;
59      }
60  
61       void setCodeName(String codeName) {
62          this.path.codeName = codeName;
63      }
64  
65      public String getParameterName() {
66          return path.parameterName;
67      }
68  
69       void setParameterName(String parameterName) {
70          this.path.parameterName = parameterName;
71      }
72  
73      public String getTypeName() {
74          return typeName;
75      }
76  
77       void setTypeName(String typeName) {
78          this.typeName = typeName;
79      }
80  
81      public String getDefaultValue() {
82          return defaultValue;
83      }
84  
85       void setDefaultValue(String defaultValue) {
86          this.defaultValue = defaultValue;
87      }
88  
89      //hack: do not know why it's working here and not on member!
90      @EmbeddedId
91      public ParameterPath getPath() {
92          return path;
93      }
94  
95       void setPath(ParameterPath path) {
96          this.path = path;
97      }
98  //////////////////// IDENT METHODS
99      //TODO use PathObject
100 
101     /**
102      * special equals: works with all PathObjects
103      * @param o
104      * @return
105      */
106     @Override
107     public boolean equals(Object o) {
108         if (this == o) return true;
109         if (!(o instanceof PathObject)) return false;
110 
111         PathObject that = (PathObject) o ;
112         if(! this.getPath().equals(that.getPath())) return false ;
113 
114         return true;
115     }
116 
117     @Override
118     public int hashCode() {
119         return path.hashCode() ;
120     }
121 
122     @Override
123     public String toString() {
124         return "{" +
125                 "path=" + path.toString() +
126                 '}';
127     }
128     
129 }