View Javadoc

1   package org.lsst.ccs.bus;
2   
3   import java.util.HashMap;
4   import java.util.List;
5   import java.util.Map;
6   
7   
8   /**
9    * A special status publishing a name/value pair on the status bus
10   * <P/>
11   * Though it extends <TT>DataStatus_Deprecated</TT> the main purpose is slightly different.
12   * 
13   * @author aubourg
14   * 
15   */
16  
17  public class TrendingStatus extends DataStatus_Deprecated {
18  
19      private static final long serialVersionUID = 6585487433733821541L;
20  
21  
22  
23  	public TrendingStatus() {
24  	}
25  
26      //TODO: newer version will create an ObjectandType or DataValuelNotification
27      @Deprecated
28  	public TrendingStatus(Object value) {
29  		super();
30  		this.value = value;
31  	}
32  
33      public TrendingStatus(DataValueNotification value) {
34          super() ;
35          this.value = value ;
36      }
37  
38      public TrendingStatus(List<? extends ValueNotification> list) {
39          super() ;
40          this.value = list ;
41          //System.out.println("calling TrendingStatus");
42      }
43  
44      public String dummy() {
45          return "dummy" ;
46      }
47  
48  
49      /**
50       *  gets the content
51       * @return
52       */
53      @Deprecated
54  	public Object getValue() {
55          try {
56              return getData();
57          } catch (ClassNotFoundException e) {
58              return value ;
59          }
60      }
61  
62      @Override
63      public Object getData() throws ClassNotFoundException {
64          //System.out.println("calling getData");
65          if(value instanceof ObjectNType) {
66              return ((ObjectNType) value).getData();
67          }
68          /* BUG
69          if(value instanceof DataValueNotification) {
70              return ((DataValueNotification)value).getRealData() ;
71          }
72          //TODO: reassess what to do
73      if(value instanceof List) {
74      if(((List)value).get(0) instanceof DataValueNotification) {
75          List<DataValueNotification> listValues = (List<DataValueNotification>) value ;
76          ArrayList<Object> res = new ArrayList<Object>(listValues.size()) ;
77          for(DataValueNotification notification : listValues) {
78              res.add(notification.getRealData()) ;
79          }
80          return res ;
81              }
82              if(((List)value).get(0) instanceof ValueNotification) {
83                  /*
84                  List<ValueNotification> listValues = (List<ValueNotification>) value ;
85                  ArrayList<Object> res = new ArrayList<Object>(listValues.size()) ;
86                  for(ValueNotification notification : listValues) {
87                      res.add(notification.getData()) ;
88                  }
89                  return res ;
90              }
91          }
92                  */
93          return value ;
94      }
95  
96      /**
97       * Map of Trending key/values: the values are itself of type
98       * <TT>ObjectNType</TT> so you can get the real type to be used.
99       * if the content is a list of <TT>DataValueNotification</TT> all trending info
100      * is added to the same Map.
101      * @returna may be null if content is not based on <TT>DataValueNotification</TT>
102      */
103     public Map<String, ObjectNType> getTrendingMap() {
104         if(value instanceof DataValueNotification) {
105             return ((DataValueNotification)value).getTrendingMap() ;
106         } else if (value instanceof List) {
107             // we only accept DataValue Notification as members of the list
108             HashMap<String,ObjectNType> mapres = new HashMap<String, ObjectNType>() ;
109             for(Object member : (List) value) {
110                 if(! (member instanceof DataValueNotification)) {
111                     //TODO LOG WARNING!
112                     return null ;
113                 }
114                 Map<String, ObjectNType> mapDVN = ((DataValueNotification)member).getTrendingMap() ;
115                 if(mapDVN != null) {
116                     mapres.putAll(mapDVN);
117                 }
118             }
119             return mapres ;
120         }
121         return null ;
122     }
123 
124     @Deprecated
125 	public void setValue(Object value) {
126 		this.value = value;
127 	}
128 
129     @Override
130     public boolean isOfWellKnownType() {
131         if(value instanceof ObjectNType) {
132             return ((ObjectNType) value).isOfWellKnownType();
133         }
134         if(value instanceof DataValueNotification) {
135             return ((DataValueNotification)value).isOfWellKnownType() ;
136         }
137         //TODO : is this true?
138         if(value instanceof List) {
139             return false ;
140         }
141         return true ;
142     }
143 
144     @Override
145     public boolean  isOfPrimitiveType() {
146         if(value instanceof ObjectNType) {
147             return ((ObjectNType) value).isOfPrimitiveType();
148         }
149         if(value instanceof DataValueNotification) {
150             return ((DataValueNotification)value).isOfPrimitiveType() ;
151         }
152         return false ;
153     }
154     @Override
155     public String getDataClassName() {
156         if(value instanceof DataValueNotification) {
157             return ((DataValueNotification)value).getObjectNType().getClassName() ;
158         }
159         return super.getDataClassName() ;
160     }
161 
162 	@Override
163 	public String toString() {
164         Object val = null ;
165         try {
166             val = getData() ;
167         } catch (ClassNotFoundException e) {
168             val = "object_class_not_found" ;
169         }
170         return "TrendingStatus(" + origin + ") @" + timeStamp + " : [" + state + "] "
171 				+ summary+ "("+ val +")";
172 	}
173 
174 }