KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_ejb > genic > VcCMRField


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999-2004 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: VcCMRField.java,v 1.16 2004/09/21 14:28:46 joaninh Exp $
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.jonas_ejb.genic;
26
27 import org.objectweb.jonas_ejb.deployment.api.EjbRelationshipRoleDesc;
28 import org.objectweb.jonas_ejb.deployment.api.EntityCmp2Desc;
29 import org.objectweb.jonas_ejb.lib.BeanNaming;
30
31
32 /**
33  * This class is used in the velocity context.
34  * It represents a CMR field.
35  *
36  * @author S.Chassande-Barrioz : Initial developer
37  * @author Helene Joanin
38  */

39 public class VcCMRField {
40
41     /**
42      * Name of the cmr field
43      */

44     private String JavaDoc name;
45     /**
46      * Name of cmr field with the first letter capitalized
47      */

48     private String JavaDoc uFLName;
49     /**
50      * Type's name of the cmr field
51      */

52     private String JavaDoc typeName;
53     /**
54      * First relationship-role of the cmr field
55      */

56     private EjbRelationshipRoleDesc rsr;
57     /**
58      * Second relationship-role of the cmr field
59      */

60     private EjbRelationshipRoleDesc rsr2;
61     /**
62      * Relation's type of the cmr field
63      */

64     private byte relationType = -1;
65     /**
66      * Name of the JORM genclass.
67      * This field has a non null value if the cmr field is a multivalued relation
68      */

69     private String JavaDoc genClassName = null;
70     /**
71      * Description of the cmr filed.
72      */

73     private EntityCmp2Desc element = null;
74
75     /**
76      * It builds a cmr field descriptor usable in velocity context.
77      * @param rsr The EjbRelationshipRoleDesc where this CMR field is defined
78      * @throws GenICException if the Deployment Decriptor is not conform
79      */

80     public VcCMRField(EjbRelationshipRoleDesc rsr) throws GenICException {
81         this.rsr = rsr;
82         name = rsr.getCmrFieldName();
83         uFLName = upperFL(name);
84         element = rsr.getTargetBean();
85         typeName = rsr.getCmrFieldType().getName();
86         if (rsr.isTargetMultiple()) {
87             if (java.util.Collection JavaDoc.class.equals(rsr.getCmrFieldType())) {
88                 // TODO : Even if Collection has been defined as CMRField Type, we use a Set
89
genClassName = "org.objectweb.jonas_ejb.container.jorm.Set";
90             } else if (java.util.Set JavaDoc.class.equals(rsr.getCmrFieldType())) {
91                 genClassName = "org.objectweb.jonas_ejb.container.jorm.Set";
92             } else {
93                 throw new GenICException("Unauthorized multivalued relation type:" + rsr.getCmrFieldType());
94             }
95         }
96         rsr2 = rsr.getOppositeRelationshipRole();
97         relationType = rsr.getRelationType();
98     }
99
100     /**
101      * @return the name of the cmr field.
102      */

103     public String JavaDoc getName() {
104         return name;
105     }
106
107     /**
108      * @return the type name of the cmr field.
109      * It is the referenced class if the relation is multiple,
110      * otherwise the type of the multivalued relation (java.util.Collection or java.util.Set).
111      */

112     public String JavaDoc getTypeName() {
113         return typeName;
114     }
115
116     /**
117      * This is used to generate method names relative to the CMR Field
118      * @return the name of cmr field with the first letter capitalized.
119      */

120     public String JavaDoc getUFLName() {
121         return uFLName;
122     }
123
124     /**
125      * @return the JOnAS meta object where the CMR field is defined
126      */

127     public EjbRelationshipRoleDesc getRsr() {
128         return rsr;
129     }
130
131     /**
132      * @return the name of opposite cmr field with the first letter capitalized.
133      */

134     public String JavaDoc getOppositeUFLCMRName() {
135         return upperFL(rsr2.getCmrFieldName());
136     }
137
138     /**
139      * CoherenceHelper class is used to manage coherence in relations.
140      * @return The JOnAS CoherenceHelper class name
141      */

142     public String JavaDoc getHelperClassName() {
143         return "JOnAS" + rsr.getSourceBeanName() + "CoherenceHelper";
144     }
145
146     /**
147      * CoherenceHelper class is used to manage coherence in relations.
148      * @return The Fully Qualified JOnAS CoherenceHelper class name
149      */

150     public String JavaDoc getHelperFQClassName() {
151         String JavaDoc pn = BeanNaming.getPackageName(rsr2.getTargetBean().getFullDerivedBeanName());
152         if (pn != null && pn.length() > 0) {
153             return pn + "." + getHelperClassName();
154         } else {
155             return getHelperClassName();
156         }
157     }
158
159     /**
160      * CoherenceHelper class is used to manage coherence in relations.
161      * @return The JOnAS CoherenceHelper class name for opposite bean
162      */

163     public String JavaDoc getOppositeHelperClassName() {
164         return "JOnAS" + rsr2.getSourceBeanName() + "CoherenceHelper";
165     }
166
167     /**
168      * CoherenceHelper class is used to manage coherence in relations.
169      * @return The JOnAS CoherenceHelper fully qualified class name for opposite bean
170      */

171     public String JavaDoc getOppositeHelperFQClassName() {
172         String JavaDoc pn = BeanNaming.getPackageName(rsr.getTargetBean().getFullDerivedBeanName());
173         if (pn != null && pn.length() > 0) {
174             return pn + "." + getOppositeHelperClassName();
175         } else {
176             return getOppositeHelperClassName();
177         }
178     }
179
180     /**
181      * @return the class name of the gen class which must be used if the cmr is multiple
182      * and return null otherwise.
183      * The class which the is returned implements the interface which the name is returned by the 'getTypeName' method.
184      */

185     public String JavaDoc getGenClassName() {
186         return genClassName;
187     }
188
189     /**
190      * @return the description of the field
191      */

192     public EntityCmp2Desc getElement() {
193         return element;
194     }
195
196     /**
197      * It capitalizes the first letter of a word.
198      * @param word is the input string to capitalize the first letter
199      * @return a String with first letter capitalized
200      */

201     public String JavaDoc upperFL(String JavaDoc word) {
202         return Character.toUpperCase(word.charAt(0)) + word.substring(1);
203     }
204
205     /**
206      * @return true if the relationship role is one-one unidirectional, false if not.
207      */

208     public boolean isOOu() {
209         return relationType == EjbRelationshipRoleDesc.OOU;
210     }
211
212     /**
213      * @return true if the relationship role is one-one bidirectional, false if not.
214      */

215     public boolean isOOb() {
216         return relationType == EjbRelationshipRoleDesc.OOB;
217     }
218
219     /**
220      * @return true if the relationship role is one-many unidirectional, false if not.
221      */

222     public boolean isOMu() {
223         return relationType == EjbRelationshipRoleDesc.OMU;
224     }
225
226     /**
227      * @return true if the relationship role is many-one unidirectional, false if not.
228      */

229     public boolean isMOu() {
230         return relationType == EjbRelationshipRoleDesc.MOU;
231     }
232
233     /**
234      * @return true if the relationship role is many-one bidirectional, false if not.
235      */

236     public boolean isMOb() {
237         return relationType == EjbRelationshipRoleDesc.MOB;
238     }
239
240     /**
241      * @return true if the relationship role is one-many bidirectional, false if not.
242      */

243     public boolean isOMb() {
244         return relationType == EjbRelationshipRoleDesc.OMB;
245     }
246
247     /**
248      * @return true if the relationship role is many-many unidirectional, false if not.
249      */

250     public boolean isMMu() {
251         return relationType == EjbRelationshipRoleDesc.MMU;
252     }
253
254     /**
255      * @return true if the relationship role is many-many bidirectional, false if not.
256      */

257     public boolean isMMb() {
258         return relationType == EjbRelationshipRoleDesc.MMB;
259     }
260
261     /**
262      * @return a string representation of the VcCMRField object for debug use
263      */

264     public String JavaDoc toString() {
265         StringBuffer JavaDoc ret = new StringBuffer JavaDoc();
266         ret.append("\n Name = " + getName());
267         ret.append("\n TypeName = " + getTypeName());
268         ret.append("\n UFLName = " + getUFLName());
269         ret.append("\n OppositeUFLCMRName = " + getOppositeUFLCMRName());
270         ret.append("\n HelperClassName = " + getHelperClassName());
271         ret.append("\n HelperFQClassName = " + getHelperFQClassName());
272         ret.append("\n OppositeHelperClassName = " + getOppositeHelperClassName());
273         ret.append("\n OppositeHelperFQClassName = " + getOppositeHelperFQClassName());
274         ret.append("\n GenClassName = " + getGenClassName());
275         ret.append("\n isOOu = " + isOOu());
276         ret.append("\n isOOb = " + isOOb());
277         ret.append("\n isOMu = " + isOMu());
278         ret.append("\n isOMb = " + isOMb());
279         ret.append("\n isMOb = " + isMOb());
280         ret.append("\n isMNu = " + isMMu());
281         ret.append("\n isMNb = " + isMMb());
282         return (ret.toString());
283     }
284 }
285
Popular Tags