KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > share > configbean > EntityEjbDCBFactory


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.sun.share.configbean;
21
22 import javax.enterprise.deploy.spi.DConfigBean JavaDoc;
23 import javax.enterprise.deploy.spi.DeploymentConfiguration JavaDoc;
24 import javax.enterprise.deploy.spi.exceptions.ConfigurationException JavaDoc;
25 import javax.enterprise.deploy.model.DDBean JavaDoc;
26 import javax.enterprise.deploy.model.DDBeanRoot JavaDoc;
27 import javax.enterprise.deploy.model.DeployableObject JavaDoc;
28 import javax.enterprise.deploy.model.J2eeApplicationObject JavaDoc;
29
30 /** This factory creates instances of DCB's that depend on the value of the
31  * persistence-type element.
32  *
33  * Includes attempted default value manipulation for the EjbJarRoot, if the jar
34  * will contain a cmp bean.
35  *
36  * This introduces a "stateful"-ness to this factory
37  *
38  * @author Peter Williams
39  * @author vkraemer
40  */

41 public class EntityEjbDCBFactory extends AbstractDCBFactory { // implements DCBFactory {
42

43     static final String JavaDoc PERSISTENCE_TYPE_KEY = "persistence-type"; // NOI18N
44
static final String JavaDoc CONTAINER = "Container"; // NOI18N
45
static final String JavaDoc BEAN = "Bean"; // NOI18N
46

47     private EjbJarRoot parent;
48
49     /** Create the factory related to a specific EjbJarRoot DCB
50      *
51      * @param parent The EjbJarRoot bean
52      */

53     public EntityEjbDCBFactory(EjbJarRoot parent) {
54         this.parent = parent;
55     }
56
57     protected Class JavaDoc getClass(DDBean JavaDoc ddBean, Base dcbParent) throws ConfigurationException JavaDoc {
58         Class JavaDoc dcbClass;
59         String JavaDoc testRet[] = ddBean.getText(PERSISTENCE_TYPE_KEY);
60
61         if(null != testRet && 1 == testRet.length && testRet[0].indexOf(CONTAINER) > -1) {
62             dcbClass = CmpEntityEjb.class;
63
64             // FIXME !PW is there a better place to put this???
65
//
66
// if the Jar hasn't had the CmpResourceJndiName property set
67
// get a default value and set it.
68
//
69
// Picking this well should make the server easier to build
70
// cmp beans for.
71
parent.addCmpResourceIfNotPresent();
72             /*if(null == parent.getCmpResourceJndiName()) {
73                 try {
74                     parent.setCmpResourceJndiName(Utils.getDefaultCmpResourceJndiName(parent));
75                 }
76                 catch(java.beans.PropertyVetoException pve) {
77                     jsr88Logger.severe("bug in Utils.getDefaultCmpResourceJndiName");
78                 }
79             }*/

80         } else if(null != testRet && 1 == testRet.length && testRet[0].indexOf(BEAN) > -1) {
81             dcbClass = EntityEjb.class;
82         } else {
83             throw Utils.makeCE("ERR_UnknownPersistenceType", testRet, null);
84         }
85         
86         return dcbClass;
87     }
88     
89     /*
90     public Base createDCB(DDBean ddBean, Base dcbParent) throws ConfigurationException {
91         System.out.println("EntityEjbDCBFactory: createDCB");
92         System.out.println("dDBean.getXpath()=="+ddBean.getXpath());
93         //System.out.println(" .getText()=="+((ddBean.getText() != null) ? ddBean.getText() : "(null)"));
94
95         Base newDCB = null;
96
97         Class dcbClass = Object.class;
98         String testRet[] = ddBean.getText("persistence-type");
99         if (null != testRet && 1 == testRet.length && testRet[0].indexOf("Container") > -1) {
100             newDCB = new CmpEntityEjb();
101             dcbClass = CmpEntityEjb.class;
102         } else if (null != testRet && 1 == testRet.length && testRet[0].indexOf("Bean") > -1) {
103             newDCB = new EntityEjb();
104             dcbClass = EntityEjb.class;
105         } else {
106             System.out.println("Error: Unknown persistence-type element value in deployment descriptor");
107             // throw exception?
108         }
109
110         if(newDCB != null) {
111             newDCB.init(ddBean, dcbParent);
112         }
113         else {
114             newDCB = new Error(this, dcbClass, null);
115         }
116         return newDCB;
117     }
118     **/

119 }
120
Popular Tags