KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > data > containers > JahiaContainerStructure


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 //
14
// JahiaContainerStructure
15
//
16
// getctndefid
17
// getObjectType
18
// getObjectDefID
19
// getObjectDef
20
// getRank
21
// setctndefid
22
//
23
// equals
24
//
25

26
27 package org.jahia.data.containers;
28
29
30 import org.jahia.data.fields.JahiaFieldDefinition;
31 import org.jahia.exceptions.JahiaException;
32 import org.jahia.registries.JahiaContainerDefinitionsRegistry;
33 import org.jahia.registries.JahiaFieldDefinitionsRegistry;
34 import org.jahia.registries.ServicesRegistry;
35 import org.jahia.services.pages.JahiaPageDefinition;
36 import org.jahia.utils.JahiaConsole;
37 import java.io.Serializable JavaDoc;
38
39
40 public class JahiaContainerStructure implements Serializable JavaDoc {
41
42
43     public static final int JAHIA_FIELD = 1;
44     public static final int JAHIA_CONTAINER = 2;
45     public static final int ALL_TYPES = -1;
46
47
48     private int subctndefid;
49     private int objectType;
50     private Object JavaDoc objectDef;
51     private int objectDefID;
52     private int rank;
53
54
55     /***
56         * constructor
57         *
58         */

59     public JahiaContainerStructure( int subctndefid,
60                                     int objectType,
61                                     int objectDefID,
62                                     int rank )
63     throws JahiaException
64     {
65         this.subctndefid = subctndefid;
66         this.objectType = objectType;
67         this.objectDefID = objectDefID;
68         this.rank = rank;
69         switch (objectType) {
70             case (JAHIA_FIELD) :
71                 this.objectDef = JahiaFieldDefinitionsRegistry.getInstance().
72                         getDefinition(objectDefID);
73                 break;
74             case (JAHIA_CONTAINER) :
75                 this.objectDef = JahiaContainerDefinitionsRegistry.getInstance().
76                     getDefinition(objectDefID);
77                 break;
78         }
79     } // end constructor
80

81
82
83     /***
84         * constructor - by objectName and ctndefid
85         *
86         */

87     public JahiaContainerStructure( String JavaDoc objectName,
88                                     int subctndefid,
89                                     int rank,
90                                     int pageDefID )
91     throws JahiaException
92     {
93         this.subctndefid = subctndefid;
94         this.rank = rank;
95
96         JahiaPageDefinition pageDef = ServicesRegistry.getInstance().getJahiaPageTemplateService().lookupPageTemplate(pageDefID);
97
98         if ( pageDef != null ){
99
100             // determines structure object type (field or container ?) and definition id
101
JahiaFieldDefinition fDef = JahiaFieldDefinitionsRegistry.getInstance(
102                                             ).getDefinition(pageDef.getJahiaID(),objectName);
103             if ((fDef != null) && (!fDef.getTitle(pageDefID).equals(""))) {
104                 this.objectType = JahiaContainerStructure.JAHIA_FIELD;
105                 this.objectDefID = fDef.getID();
106                 this.objectDef = fDef;
107             } else {
108
109                 JahiaContainerDefinition cDef = JahiaContainerDefinitionsRegistry.getInstance(
110                                             ).getDefinition(pageDef.getJahiaID(), objectName);
111                 if (cDef != null) {
112                     this.objectType = JahiaContainerStructure.JAHIA_CONTAINER;
113                     this.objectDefID = cDef.getID();
114                     this.objectDef = cDef;
115                 } else {
116                     String JavaDoc errorMsg = objectName + " is neither a field or a container -> not declared !";
117                     JahiaConsole.println( "JahiaContainerStructure", errorMsg + " -> BAILING OUT" );
118                     throw new JahiaException( "Cannot synchronize fields with database",
119                                         errorMsg, JahiaException.DATABASE_ERROR, JahiaException.CRITICAL_SEVERITY );
120                 }
121             }
122         } else {
123             String JavaDoc errorMsg = " cannot found objectName's " + " page definition !";
124             JahiaConsole.println( "JahiaContainerStructure", errorMsg + " -> BAILING OUT" );
125             throw new JahiaException( "Cannot synchronize fields with database",
126                                 errorMsg, JahiaException.DATABASE_ERROR, JahiaException.CRITICAL_SEVERITY );
127         }
128     } // end constructor
129

130
131     /**
132      * No arg constructor required for serialization support.
133      */

134     protected JahiaContainerStructure() {
135
136     }
137
138     /***
139         * accessor methods
140         *
141         */

142     public int getSubctndefid() { return subctndefid; }
143     public int getObjectType() { return objectType; }
144     public int getObjectDefID() { return objectDefID; }
145     public Object JavaDoc getObjectDef() { return objectDef; }
146     public int getRank() { return rank; }
147     public void setSubctndefid( int defID ) { this.subctndefid = defID; }
148
149     // end accessor methods
150

151
152
153     /***
154         * equals
155         *
156         */

157     public boolean equals( JahiaContainerStructure theStruct )
158     {
159         if ((theStruct.getSubctndefid() == this.getSubctndefid()) &&
160             (theStruct.getObjectType() == this.getObjectType()) &&
161             (theStruct.getObjectDefID() == this.getObjectDefID()) &&
162             (theStruct.getRank() == this.getRank())) {
163             return true;
164         } else {
165             return false;
166         }
167     } // end equals
168

169
170 } // end JahiaContainerStructure
171
Popular Tags