View Javadoc

1   package org.lsst.ccs.bus;
2   
3   import java.io.Serializable;
4   
5   /**
6    * Status with additional information.
7    * <P/>
8    * This class can used instead of subclassing Status: if the receiver does not have
9    * the needed classes in its classPath the code won't crash .
10   * @author bamade
11   */
12  // Date: 15/04/13
13  
14  public class DataStatus_Deprecated extends Status {
15  
16  
17      private static final long serialVersionUID = 5352206331036348142L;
18      protected Object value ;
19  
20      /**
21       * for use by subclasses only
22       */
23      protected DataStatus_Deprecated() {
24  
25      }
26  
27      /**
28       * any Object including null values.
29       * @param serializable
30       */
31      public DataStatus_Deprecated(Serializable serializable){
32          this.value = new ObjectNType(serializable) ;
33      }
34  
35      /**
36       * to be mostly used when primitive org.lsst.gruth.types are to be used. (the real type such as Integer.TYPE is kept)
37       * @param clazz
38       * @param serializable
39       */
40      public DataStatus_Deprecated(Class clazz, Serializable serializable){
41          this.value = new ObjectNType(clazz, serializable) ;
42      }
43  
44      public DataStatus_Deprecated(int intValue) {
45          this.value = new ObjectNType(intValue) ;
46      }
47      public DataStatus_Deprecated(double doubleValue) {
48          this.value = new ObjectNType(doubleValue) ;
49      }
50      public DataStatus_Deprecated(float floatValue) {
51          this.value = new ObjectNType(floatValue) ;
52      }
53      public DataStatus_Deprecated(char charValue) {
54          this.value = new ObjectNType(charValue) ;
55      }
56  
57      /**
58       * is the content of a "Well known type" as defined in  <TT>ObjectNType</TT>.
59       * Developers of subclasses should override this method.
60       * @return
61       */
62      public boolean isOfWellKnownType() {
63          if(value instanceof ObjectNType) {
64              return ((ObjectNType)value).isOfWellKnownType();
65          }
66          // assert false ;
67          return false ;
68      }
69  
70      /**
71       * is the content to be considered of a primitive type?
72       * Developers of subclasses should override this method.
73       * @return
74       */
75      public boolean isOfPrimitiveType() {
76          if(value instanceof ObjectNType) {
77              return ((ObjectNType)value).isOfPrimitiveType();
78          }
79          // assert false ;
80          return false ;
81      }
82  
83      /**
84       * what is the class of the contained data?
85       * Developers of subclasses should override this method.
86       * <P/>
87       * Beware: having the corresponding class in the ClassPath does not guarantee that the object will
88       * be deserialized properly (depends on class version)
89       * @return
90       */
91      public String getDataClassName() {
92          if(value instanceof ObjectNType) {
93              return ((ObjectNType)value).getClassName();
94          }
95          if(value == null) return null ;
96          return value.getClass().getCanonicalName() ;
97      }
98  
99      /**
100      * gets the data content but throws an Excepton if the object cannot be deserialized
101      * @return
102      * @throws ClassNotFoundException
103      */
104     public Object getData() throws ClassNotFoundException {
105         if(value instanceof ObjectNType) {
106             return ((ObjectNType)value).getData() ;
107         }
108         return value ;
109     }
110 
111     protected String contentString() {
112         return String.valueOf(value) ;
113     }
114     public String toString() {
115         return super.toString() + " = "+ contentString() ;
116     }
117 
118 
119 }