KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > services > version > ContentObjectEntryState


1 //
2
// ____.
3
// __/\ ______| |__/\. _______
4
// __ .____| | \ | +----+ \
5
// _______| /--| | | - \ _ | : - \_________
6
// \\______: :---| : : | : | \________>
7
// |__\---\_____________:______: :____|____:_____\
8
// /_____|
9
//
10
// . . . i n j a h i a w e t r u s t . . .
11
//
12

13 package org.jahia.services.version;
14
15 import java.io.Serializable JavaDoc;
16
17
18
19 /**
20  * This class is just a bean holding one "entry state information" entity
21  * concerning a single field
22  */

23 /** @todo This class should be moved to version package and rename it 'EntryState' */
24 public class ContentObjectEntryState implements EntryStateable, Comparable JavaDoc, Cloneable JavaDoc, Serializable JavaDoc
25 {
26     public static final int WORKFLOW_STATE_ACTIVE = 1; // active state
27
public static final int WORKFLOW_STATE_START_STAGING = 2; // start status for staging/wf
28
public static final int WORKFLOW_STATE_VERSIONING_DELETED = -1; // delete flag
29
public static final int WORKFLOW_STATE_VERSIONED = 0; // versioned (archived) state
30

31     private int workflowState;
32     private int versionID;
33     private String JavaDoc languageCode;
34
35     public ContentObjectEntryState (int workflowState, int versionID, String JavaDoc languageCode)
36     {
37         this.workflowState = workflowState;
38         this.versionID = versionID;
39         this.languageCode = languageCode;
40     }
41
42     /**
43      * Copy constructor.
44      * @param entryStateable
45      */

46     public ContentObjectEntryState (EntryStateable entryStateable) {
47         this.workflowState = entryStateable.getWorkflowState();
48         this.versionID = entryStateable.getVersionID();
49         this.languageCode = entryStateable.getLanguageCode();
50     }
51
52     public int getWorkflowState() { return workflowState; }
53     public int getVersionID() { return versionID; }
54     public String JavaDoc getLanguageCode() { return languageCode; }
55
56     protected void setVersionID(int versionID)
57        { this.versionID = versionID; }
58
59     public boolean isActive() { return (workflowState==1)?true:false; }
60     public boolean isStaging() { return (workflowState>1)?true:false; }
61     public boolean isVersioning() { return (workflowState<1)?true:false; }
62
63     /**
64      * Needed when a ContentFieldVersionInfo is used as a Hashtable key
65      */

66     public boolean equals(Object JavaDoc cfv)
67     {
68         if (cfv instanceof ContentObjectEntryState)
69         {
70             if ((((ContentObjectEntryState)cfv).getWorkflowState()==this.workflowState) &&
71                (((ContentObjectEntryState)cfv).getVersionID()==this.versionID) &&
72                (((ContentObjectEntryState)cfv).getLanguageCode().equals(this.languageCode)))
73             return true;
74         }
75         return false;
76     }
77
78     /**
79      * Comparator use mostly to sort ContentFieldEntryState when used to
80      * display them or other operations. The keys for sorting are the
81      * following :
82      * 1. Workflow state
83      * 2. Version ID
84      * 3. Language code
85      * @param o the Object to be compared.
86      * @return a negative integer, zero, or a positive integer as this object
87      * is less than, equal to, or greater than the specified object.
88      */

89     public int compareTo(Object JavaDoc o) {
90         ContentObjectEntryState rightEntryState = (ContentObjectEntryState) o;
91         if (getWorkflowState() != rightEntryState.getWorkflowState()) {
92             Integer JavaDoc leftState = new Integer JavaDoc(getWorkflowState());
93             Integer JavaDoc rightState = new Integer JavaDoc(rightEntryState.getWorkflowState());
94             return leftState.compareTo(rightState);
95         } else {
96             if (getVersionID() != rightEntryState.getVersionID()) {
97                 // version IDs are different
98
Integer JavaDoc leftVersionID = new Integer JavaDoc(getVersionID());
99                 Integer JavaDoc rightVersionID = new Integer JavaDoc(rightEntryState.getVersionID());
100                 return leftVersionID.compareTo(rightVersionID);
101             } else {
102                 // version IDs are equals, let's compare the language codes
103
return getLanguageCode().compareTo(rightEntryState.getLanguageCode());
104             }
105         }
106     }
107
108     /**
109      * Needed when a ContentFieldVersionInfo is used as a Hashtable key
110      */

111     public int hashCode()
112     {
113         return languageCode.hashCode()+versionID+workflowState+1237*workflowState;
114     }
115
116     public String JavaDoc toString()
117     {
118         StringBuffer JavaDoc buf = new StringBuffer JavaDoc("[ENTRY:workFlowState=");
119         buf.append(getWorkflowState());
120         buf.append(", versionID=");
121         buf.append(getVersionID());
122         buf.append(", languageCode=");
123         buf.append(getLanguageCode());
124         buf.append("]");
125         return buf.toString();
126     }
127
128
129     /**
130      * Returns the workflow state depending of the version ID
131      * @param versionID
132      * @return
133      */

134     public static int getWorkflowState(int versionID){
135         int ws = WORKFLOW_STATE_VERSIONED;
136         switch ( versionID )
137         {
138             case -1 : return WORKFLOW_STATE_START_STAGING;
139             case 0 : return WORKFLOW_STATE_START_STAGING;
140             case 1 : return WORKFLOW_STATE_ACTIVE;
141         }
142         return ws;
143     }
144
145     /**
146      * Return an entry state for a given versionID and a languageCode
147      *
148      * @param versionID 1 = active, -1 or 0 = staging, other
149      * @param languageCode
150      * @return
151      */

152     public static ContentObjectEntryState getEntryState(int versionID, String JavaDoc languageCode){
153
154         ContentObjectEntryState entryState = null;
155         int ws = WORKFLOW_STATE_VERSIONED;
156         int v = versionID;
157
158         switch ( versionID )
159         {
160             case -1 : ws = WORKFLOW_STATE_START_STAGING;
161                       v = 0;
162                       break;
163             case 0 : ws = WORKFLOW_STATE_START_STAGING;
164                       v = 0;
165                       break;
166             case 1 : ws = WORKFLOW_STATE_ACTIVE;
167                       v = 0;
168         }
169         return entryState = new ContentObjectEntryState(ws,v,languageCode);
170     }
171
172     public Object JavaDoc clone () {
173         ContentObjectEntryState clone =
174             new ContentObjectEntryState (this.getWorkflowState(),
175                                          this.getVersionID(),
176                                          this.getLanguageCode());
177         return clone;
178     }
179
180 }
181
Popular Tags