KickJava   Java API By Example, From Geeks To Geeks.

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


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 package com.sun.enterprise.deployment;
25
26 import java.util.*;
27 import java.lang.reflect.*;
28 import com.sun.enterprise.util.LocalStringManagerImpl;
29 import java.util.logging.*;
30 import com.sun.logging.*;
31 import com.sun.enterprise.deployment.util.LogDomains;
32
33 /**
34  * This class contains deployment information for an EntityBean with
35  * bean-managed persistence.
36  * Subclasses contains additional information for EJB1.1/EJB2.0 CMP EntityBeans.
37  *
38  * @author Danny Coward
39  * @author Sanjeev Krishnan
40  * @author Vivek Nagar
41  */

42
43 public class EjbEntityDescriptor extends EjbDescriptor {
44
45     public static String JavaDoc TYPE = "Entity";
46     public static String JavaDoc BEAN_PERSISTENCE = "Bean";
47     public static String JavaDoc CONTAINER_PERSISTENCE = "Container";
48     public static String JavaDoc TRUE = "true";
49     public static String JavaDoc FALSE = "false";
50
51     // EntityBean attributes
52
protected String JavaDoc persistenceType;
53     protected boolean isReentrant = false;
54     protected String JavaDoc primaryKeyClassName;
55
56     private static LocalStringManagerImpl localStrings =
57         new LocalStringManagerImpl(EjbEntityDescriptor.class);
58
59                static Logger _logger = LogDomains.getLogger(LogDomains.DPL_LOGGER);
60  
61
62     
63     /**
64      * The default constructor.
65      */

66     public EjbEntityDescriptor() {
67     }
68     
69     /**
70      * The copy constructor.
71      */

72     public EjbEntityDescriptor(EjbDescriptor other) {
73     super(other);
74     if (other instanceof EjbEntityDescriptor) {
75         EjbEntityDescriptor entity = (EjbEntityDescriptor) other;
76         this.persistenceType = entity.persistenceType;
77         this.isReentrant = entity.isReentrant;
78         this.primaryKeyClassName = entity.primaryKeyClassName;
79     }
80     }
81
82     /**
83      * Replace all pointers to the old EntityDescriptor in this app
84      * with myself. Used when user switches from BMP to CMP or vice versa
85      * in deploytool wizard.
86      */

87     public void replaceEntityDescriptor(EjbEntityDescriptor oldEntityDesc)
88     {
89     // first replace in bundleDesc
90
EjbBundleDescriptor bundle = oldEntityDesc.getEjbBundleDescriptor();
91     bundle.replaceEjb(oldEntityDesc, this);
92
93     // now replace in all EjbReferences to the old Ejb in this app
94
Iterator refs = oldEntityDesc.getAllEjbReferencers().iterator();
95     while ( refs.hasNext() ) {
96         EjbReferenceDescriptor ref = (EjbReferenceDescriptor)refs.next();
97         ref.setEjbDescriptor(this);
98     }
99     }
100  
101
102     /**
103      * Gets the container transaction type for this entity bean. Entity
104      * beans always have CONTAINER_TRANSACTION_TYPE transaction type.
105      */

106     public String JavaDoc getTransactionType() {
107     return super.transactionType;
108     }
109     
110     /**
111      * Sets the transaction type for this entity bean.
112      * Throws an illegal argument exception if this type is not
113      * CONTAINER_TRANSACTION_TYPE.
114      */

115     public void setTransactionType(String JavaDoc transactionType) {
116     if (!CONTAINER_TRANSACTION_TYPE.equals(transactionType)
117         && this.isBoundsChecking()) {
118         throw new IllegalArgumentException JavaDoc(localStrings.getLocalString(
119           "enterprise.deployment.exceptionentitybeancanonlyhavecntnrtxtype",
120           "Entity beans can only have Container transaction type. The type was being set to {0}", new Object JavaDoc[] {transactionType}));
121     }
122     super.transactionType = transactionType;
123     }
124     
125     
126     /**
127      * Return true if this entity bean is reentrant, false else.
128      */

129     public boolean isReentrant() {
130     return this.isReentrant;
131     }
132     
133     public String JavaDoc getReentrant() {
134     if (this.isReentrant()) {
135         return TRUE;
136     } else {
137         return FALSE;
138     }
139     }
140     
141     public void setReentrant(String JavaDoc reentrantString) {
142     if (TRUE.equalsIgnoreCase(reentrantString)) {
143         this.setReentrant(true);
144         return;
145     }
146     if (FALSE.equalsIgnoreCase(reentrantString)) {
147         this.setReentrant(false);
148         return;
149     }
150     if (this.isBoundsChecking()) {
151         throw new IllegalArgumentException JavaDoc(localStrings.getLocalString(
152                                        "enterprise.deployment.exceptionstringnotlegalvalue",
153                                       "{0} is not a legal value for entity reentrancy", new Object JavaDoc[] {reentrantString}));
154     }
155     }
156     
157     /**
158      * Sets the isReentrant flag for this bean.
159      */

160     public void setReentrant(boolean isReentrant) {
161     this.isReentrant = isReentrant;
162     super.changed();
163     }
164     
165     /**
166      * Returns the persistence type for this entity bean. Defaults to BEAN_PERSISTENCE.
167      */

168     public String JavaDoc getPersistenceType() {
169     if (this.persistenceType == null) {
170         this.persistenceType = BEAN_PERSISTENCE;
171     }
172     return this.persistenceType;
173     }
174     
175     /**
176      * Sets the persistence type for this entity bean. Allowable values are BEAN_PERSISTENCE
177      * or CONTAINER_PERSISTENCE, or else an IllegalArgumentException is thrown.
178      */

179     public void setPersistenceType(String JavaDoc persistenceType) {
180     boolean isValidChange = (BEAN_PERSISTENCE.equals(persistenceType) || CONTAINER_PERSISTENCE.equals(persistenceType));
181     if (isValidChange || !this.isBoundsChecking()) {
182         this.persistenceType = persistenceType;
183         super.changed();
184     } else {
185             //_logger.log(Level.FINE,"Warning " + persistenceType + " is not an allowed persistence type");
186
throw new IllegalArgumentException JavaDoc(localStrings.getLocalString(
187                                        "enterprise.deployment.exceptionpersistenceisnotallowedtype",
188                                        "{0} is not an allowed persistence type", new Object JavaDoc[] {persistenceType}));
189     }
190     }
191     
192     /**
193      * Return the classname of the primary key for this bean, or the empty
194      * string if none has been set.
195      */

196     public String JavaDoc getPrimaryKeyClassName() {
197     if (this.primaryKeyClassName == null) {
198         this.primaryKeyClassName = Object JavaDoc.class.getName();
199     }
200     return this.primaryKeyClassName;
201     }
202     
203     /**
204      * Set the classname of the primary key used by this bean.
205      */

206     public void setPrimaryKeyClassName(String JavaDoc primaryKeyClassName) {
207     this.primaryKeyClassName = primaryKeyClassName;
208     super.changed();
209     }
210     
211     /**
212      * Returns the type of this bean. EjbEntityDescriptor.TYPE
213      */

214     public String JavaDoc getType() {
215     return TYPE;
216     }
217     
218     /**
219      * Sets my type String.
220      */

221     public void setType(String JavaDoc type) {
222     throw new IllegalArgumentException JavaDoc(localStrings.getLocalString(
223            "enterprise.deployment.exceptioncannotsettypeonentitybean",
224            "Cannon set type on an entity bean"));
225     }
226     
227     /**
228      * Return my formatted string representation.
229      */

230     public void print(StringBuffer JavaDoc toStringBuffer) {
231     super.print(toStringBuffer);
232     toStringBuffer.append("\n Entity descriptor");
233     toStringBuffer.append("\n isReentrant ").append(isReentrant);
234     toStringBuffer.append("\n primaryKeyClassName ").append(primaryKeyClassName);
235     toStringBuffer.append("\n persistenceType ").append(persistenceType);
236     }
237 }
238
Popular Tags