Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/flexstor/common/data/ActionData.java


1   /*
2    * ActionData.java
3    *
4    * Copyright $Date: 2003/08/11 02:22:35 $ FLEXSTOR.net Inc.
5    *
6    * This work is licensed for use and distribution under license terms found at
7    * http://www.flexstor.org/license.html
8    *
9    */
10  
11  package com.flexstor.common.data;
12  
13  import java.util.Date;
14  import java.util.Enumeration;
15  import java.util.Vector;
16  
17  import com.flexstor.common.constants.ActionPropertiesI;
18  import com.flexstor.common.services.ServiceListenerI;
19  import com.flexstor.common.util.FlexHashtable;
20  
21  /**
22  * A common data object used to send information among the client, the appserver and
23  * ejb server.
24  * ActionData contains a list of RecordData; which is the object containing all the 
25  * values and properties for performing an operation in a bucket, element, asset or asset_role.
26  */
27  public class ActionData
28     extends KeyedCollectionData
29     implements ActionPropertiesI
30  {
31     private     String             sUserId        = "";
32     private     int                nTransId       = -1;
33     private     int                nSubTransId    = -1;
34     private     String             sServiceName   = "";
35     private     Date               dServiceDate   = null;
36     private     boolean            hold           = false;
37     private     ServiceListenerI listener       = null;
38     private     Vector             records        = null; // A Vector of RecordData
39     
40     public void setUserId( String sUserId )
41     {
42        this.sUserId = sUserId;
43     }
44     
45     public String getUserId()
46     {
47        return sUserId;
48     }
49     
50     public void setTransId(int nTransId)
51     {
52        this.nTransId = nTransId;
53     }
54  
55     public int getTransId()
56     {
57        return nTransId;
58     }
59  
60     public void setSubTransId(int nSubTransId)
61     {
62        this.nSubTransId = nSubTransId;
63     }
64  
65     public int getSubTransId()
66     {
67        return nSubTransId;
68     }
69  
70     public String getServiceName()
71     {
72        return sServiceName;
73     }
74     
75     public void setServiceName(String sServiceName)
76     {
77        this.sServiceName = sServiceName;
78     }
79     
80     public String getServiceThreadName()
81     {
82        if ( sServiceName.lastIndexOf(".") != -1 )
83           return sServiceName.substring(sServiceName.lastIndexOf(".") + 1) + "-" + nTransId;
84        else
85           return sServiceName + "-" + nTransId;
86     }
87     
88     public void setDate(Date dServiceDate)
89     {
90        this.dServiceDate = dServiceDate;
91     }
92  
93     public Date getDate() 
94     {
95        return dServiceDate;
96     }
97     
98     public long getTime()
99     {
100       return dServiceDate.getTime();
101    }
102    
103    public void setTime(long time)
104    {
105       this.dServiceDate = new Date(time);
106    }
107    
108    public boolean isHeld()
109    {
110       return hold;
111    }
112 
113    public void setServiceListener(ServiceListenerI listener)
114    {
115       this.listener = listener;
116    }
117    
118    public ServiceListenerI getServiceListener()
119    {
120       return listener;
121    }
122    
123    public void setRecords( Vector records )
124    {
125       this.records = records;
126    }
127    
128    public Vector getRecords()
129    {
130       return records;
131    }
132    
133    public int getNumberOfRecords()
134    {
135       if(records != null)
136       {
137         return records.size();
138       }
139       else
140         return 0;
141    }
142    
143    public void addRecord( RecordData record )
144    {
145       if ( records == null )
146          records = new Vector();
147          
148       records.addElement( record );
149    }
150    
151    public void addRecords( Vector records)
152    {
153         Enumeration enumRecords = records.elements();
154         while(enumRecords.hasMoreElements())
155         {
156             addRecord((RecordData)enumRecords.nextElement());
157         }
158    }
159 
160    public boolean deleteRecord( RecordData record )
161    {
162       if ( records == null )
163          return false;
164       else
165          return records.removeElement( record );
166    }
167    
168    public RecordData getRecordPerId(long id)
169    {
170       RecordData aRecord = null;
171       boolean bRecordFound = false;
172       
173       if ( records == null )
174          return aRecord;
175          
176       Enumeration enumRecords = records.elements();
177       do
178       {
179          aRecord = (RecordData)enumRecords.nextElement();
180          if (aRecord.getRecordId() == id)
181          {
182             bRecordFound = true;
183             //break;
184          }
185       }
186       while(enumRecords.hasMoreElements() && bRecordFound == false);
187       if(bRecordFound)
188          return aRecord;
189       else
190          return null;
191    }
192    
193    public void setGlobalProperties( FlexHashtable properties )
194    {
195       super.setKeyedCollection( properties );
196    }
197    
198    public FlexHashtable getGlobalProperties()
199    {
200       return super.getKeyedCollection();
201    }
202    
203    public Object clone()
204    {
205       ActionData clone = new ActionData();
206       fillCloneInfo( clone );
207       return clone;
208    }
209 
210    protected void fillCloneInfo( ActionData clone )
211    {
212       // Copy everything in this class
213       clone.setUserId(this.sUserId );
214       clone.setTransId( this.nTransId );
215       clone.setSubTransId( this.nSubTransId );
216       clone.setServiceName( this.sServiceName) ;
217       clone.setDate( this.dServiceDate );
218       clone.setServiceListener( this.listener );
219       
220       //if ( records != null )
221       //   clone.setRecords( (Vector)this.records.clone() );
222       
223       // Copy everything in super class KeyedCollectionData
224       FlexHashtable keyedCollection = this.getKeyedCollection();
225       if ( keyedCollection != null )
226          clone.setKeyedCollection( (FlexHashtable)keyedCollection.clone() );
227       
228       // Copy everything in super class Data
229       clone.setModTime( this.getModTime() );
230    }
231 }