KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > RelationRoleDescriptor


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24
25 package com.sun.enterprise.deployment;
26
27 import java.util.*;
28 import java.lang.reflect.*;
29 import com.sun.enterprise.util.LocalStringManagerImpl;
30
31
32 /**
33  * This class contains information about one of the partners in
34  * a relationship between EJB2.0 CMP EntityBeans.
35  * It represents information in the <ejb-relation-role> XML element.
36  *
37  * @author Sanjeev Krishnan
38  */

39
40 public final class RelationRoleDescriptor extends Descriptor {
41
42     private static LocalStringManagerImpl localStrings =
43             new LocalStringManagerImpl(RelationRoleDescriptor.class);
44
45     // Bean for owner (role-source) of this side of
46
// the relationship
47
private EjbCMPEntityDescriptor owner;
48     private PersistenceDescriptor pers;
49     private RelationshipDescriptor relnDesc;
50
51     private String JavaDoc roleSourceDescription;
52     private String JavaDoc cmrField; // CMR field name in owner's class
53
private String JavaDoc cmrFieldDescription;
54     private String JavaDoc cmrFieldType; // Java type of cmr-field
55
private boolean isMany;
56     private RelationRoleDescriptor partner;
57     private boolean cascadeDelete;
58     private CMRFieldInfo cmrFieldInfo;
59     private String JavaDoc relationRoleName;
60
61     public RelationRoleDescriptor() {}
62
63
64     /**
65      * May return null if the role-source for this relationship role
66      * is a remote-ejb-name
67      */

68     public PersistenceDescriptor getPersistenceDescriptor()
69     {
70         return pers;
71     }
72
73     /*
74      * Can be set to null if there is no associated persistence descriptor.
75      */

76     public void setPersistenceDescriptor(PersistenceDescriptor newPers)
77     {
78         if( this.pers != null ) {
79             // first invalidate cmr stuff in original persistence descriptor
80
this.pers.invalidate();
81         }
82
83         this.pers = newPers;
84         if( newPers != null ) {
85             this.owner = (EjbCMPEntityDescriptor)newPers.getParentDescriptor();
86         }
87         invalidateCMRFieldStuff();
88     }
89
90     private void invalidateCMRFieldStuff() {
91         cmrFieldInfo = null;
92         if( pers != null ) {
93             pers.invalidate();
94         }
95     }
96
97     public RelationshipDescriptor getRelationshipDescriptor()
98     {
99     return relnDesc;
100     }
101
102     public void setRelationshipDescriptor(RelationshipDescriptor relnDesc)
103     {
104     this.relnDesc = relnDesc;
105     }
106
107     public void setOwner(EjbCMPEntityDescriptor owner)
108     {
109     this.owner = owner;
110         invalidateCMRFieldStuff();
111     }
112
113     public EjbCMPEntityDescriptor getOwner()
114     {
115     return owner;
116     }
117
118     /**
119      * The other role in the relationship I participate in.
120      */

121     public RelationRoleDescriptor getPartner()
122     {
123         return partner;
124     }
125     public void setPartner(RelationRoleDescriptor partner)
126     {
127         this.partner = partner;
128     }
129
130     public String JavaDoc getRelationRoleName()
131     {
132         return relationRoleName;
133     }
134     public void setRelationRoleName(String JavaDoc relationRoleName)
135     {
136         this.relationRoleName = relationRoleName;
137     }
138
139     public void setRoleSourceDescription(String JavaDoc roleSourceDescription)
140     {
141         this.roleSourceDescription = roleSourceDescription;
142     }
143     public String JavaDoc getRoleSourceDescription()
144     {
145     if ( roleSourceDescription == null )
146         roleSourceDescription = "";
147         return roleSourceDescription;
148     }
149
150     /**
151      * Set to NULL to indicate no cmr field
152      */

153     public void setCMRField(String JavaDoc cmrField)
154     {
155     this.cmrField = cmrField;
156         invalidateCMRFieldStuff();
157     }
158     public String JavaDoc getCMRField()
159     {
160         return cmrField;
161     }
162
163     public void setCMRFieldDescription(String JavaDoc cmrFieldDescription)
164     {
165         this.cmrFieldDescription = cmrFieldDescription;
166     }
167     public String JavaDoc getCMRFieldDescription()
168     {
169     if ( cmrFieldDescription == null )
170         cmrFieldDescription = "";
171         return cmrFieldDescription;
172     }
173
174     /**
175      * Only applicable when partner is collection-valued.
176      * Set to NULL to indicate no field type is not applicable.
177      */

178     public void setCMRFieldType(String JavaDoc newCmrFieldType)
179     {
180         if( newCmrFieldType == null ) {
181             this.cmrFieldType = null;
182             invalidateCMRFieldStuff();
183         } else if ( newCmrFieldType.equals("java.util.Collection")
184                     || newCmrFieldType.equals("java.util.Set") ) {
185         this.cmrFieldType = newCmrFieldType;
186             invalidateCMRFieldStuff();
187     } else {
188         throw new IllegalArgumentException JavaDoc
189                 ("cmr-field-type is " + newCmrFieldType +
190                  ", must be java.util.Collection or java.util.Set");
191     }
192     }
193     public String JavaDoc getCMRFieldType()
194     {
195         return cmrFieldType;
196     }
197
198     public void setIsMany(boolean isMany)
199     {
200         this.isMany = isMany;
201         invalidateCMRFieldStuff();
202     }
203     public boolean getIsMany()
204     {
205         return isMany;
206     }
207
208     public void setCascadeDelete(boolean cascadeDelete)
209     {
210         this.cascadeDelete = cascadeDelete;
211     }
212     public boolean getCascadeDelete()
213     {
214         return cascadeDelete;
215     }
216
217     public void setCMRFieldInfo(CMRFieldInfo cmrFieldInfo)
218     {
219     this.cmrFieldInfo = cmrFieldInfo;
220     }
221     public CMRFieldInfo getCMRFieldInfo()
222     {
223     if ( cmrFieldInfo == null && pers != null )
224         pers.getCMRFieldInfo(); // tell pers to initialize its CMRFieldInfos
225
return cmrFieldInfo;
226     }
227     
228     public String JavaDoc composeReverseCmrFieldName() {
229         EjbCMPEntityDescriptor cmpDesc = getPartner().getOwner();
230         String JavaDoc reverseCmrFieldName = "_" + cmpDesc.getName() +
231             "_" + getPartner().getCMRField();
232         return reverseCmrFieldName;
233     }
234 }
235      
236
Popular Tags