KickJava   Java API By Example, From Geeks To Geeks.

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


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  * BaseModuleRef.java
21  *
22  * Created on June 27, 2003, 1:32 PM
23  */

24
25 package org.netbeans.modules.j2ee.sun.share.configbean;
26
27 import javax.enterprise.deploy.model.DDBean JavaDoc;
28 import javax.enterprise.deploy.model.DDBeanRoot JavaDoc;
29 import javax.enterprise.deploy.model.DeployableObject JavaDoc;
30 import javax.enterprise.deploy.model.J2eeApplicationObject JavaDoc;
31 import javax.enterprise.deploy.spi.DConfigBean JavaDoc;
32 import javax.enterprise.deploy.spi.DeploymentConfiguration JavaDoc;
33 import javax.enterprise.deploy.spi.exceptions.ConfigurationException JavaDoc;
34
35
36 /**
37  *
38  * @author Peter Williams
39  */

40 abstract public class BaseModuleRef extends Base {
41
42     /** -----------------------------------------------------------------------
43      * Initialization
44      */

45     
46     /** Creates new BaseModuleRef
47      */

48     public BaseModuleRef() {
49         setDescriptorElement(bundle.getString("BDN_BaseModuleRef")); // NOI18N
50
}
51     
52     /**
53      * @param dDBean
54      * @param parent
55      * @throws ConfigurationException
56      */

57     protected void init(DDBean JavaDoc dDBean, Base parent) throws ConfigurationException JavaDoc {
58         super.init(dDBean, parent);
59         
60         // Depending on what actual type of ModuleRef this object is, there are
61
// different ways of initializing the URI field. And we need this to
62
// properly patch references, so initialize that field here, then call
63
// findRootDCB to handle reference patching correctly.
64
//
65
initModuleUri(dDBean);
66         
67         // initialize reference if we can
68
findRootDCB(moduleUri);
69     }
70     
71     /** Called from BaseModuleRef.init() to get the correct module URI field
72      * for the reference object. Overload it in the derived reference object
73      * if the module URI field is on a different DDBean (e.g. web modules
74      * use the child bean "web-uri" to store this information.)
75      */

76     protected void initModuleUri(DDBean JavaDoc dDBean) {
77         setModuleUri(dDBean);
78     }
79     
80     /** -----------------------------------------------------------------------
81      * Properties
82      */

83     
84     /** Holds value of property moduleUri. */
85     private DDBean JavaDoc moduleUri;
86     
87     /** Getter for displayName property
88      * @return String suitable for display
89      */

90     public String JavaDoc getDisplayName() {
91         StringBuffer JavaDoc buf = new StringBuffer JavaDoc(64);
92         
93         // This adds the name of the particular module, in the case of EARs where
94
// there could be multiple sub modules.
95
if(moduleUri != null) {
96             buf.append(getModuleUri());
97         }
98         buf.append(" [");
99         buf.append(getDescriptorElement());
100         buf.append("]");
101         
102         return buf.toString();
103     }
104     
105     /** Getter for customizer title fragment property
106      * @return String fragment for use in customizer title
107      *
108      */

109     public String JavaDoc getTitleFragment() {
110         return (J2EEVersion.J2EE_1_4.compareSpecification(getJ2EEModuleVersion()) >= 0) ?
111             bundle.getString("LBL_J2EETitleFragment") : // NOI18N
112
bundle.getString("LBL_JavaEETitleFragment"); // NOI18N
113
}
114     
115     /** Getter for property name.
116      * @return Value of property name.
117      *
118      */

119     public String JavaDoc getModuleUri() {
120         String JavaDoc moduleUriText = null;
121         
122         if(moduleUri != null) {
123             moduleUriText = moduleUri.getText();
124         }
125         
126         if(moduleUriText == null) {
127             moduleUriText = "(null)"; // FIXME - needs I18N
128
}
129         
130         return moduleUriText;
131     }
132     
133     protected void setModuleUri(DDBean JavaDoc uriBean) {
134         moduleUri = uriBean;
135     }
136     
137     /** Getter for property refIdentity.
138      * @return Value of property refIdentity.
139      *
140      */

141     public String JavaDoc getRefIdentity() {
142         String JavaDoc result = "(null)"; // FIXME - needs I18N
143
if(getReference() != null) {
144             result = getReference().getIdentity();
145         }
146         
147         return result;
148     }
149     
150     /** -----------------------------------------------------------------------
151      * Reference support
152      */

153     private BaseRoot referencedDCB = null;
154     
155     protected BaseRoot getReference() {
156         return referencedDCB;
157     }
158     
159     protected void setReference(BaseRoot ref) {
160         referencedDCB = ref;
161     }
162     
163     protected void findRootDCB(DDBean JavaDoc ddBean) {
164         // Locate DDBeanRoot for referenced module via old lookup method
165
SunONEDeploymentConfiguration dc = getConfig();
166         DDBeanRoot JavaDoc ddbRoot = getDDBeanRoot(ddBean, dc.getDeployableObject());
167         
168         // Then look in DCBCache for this DDBeanRoot
169
if(ddbRoot != null) {
170             Base dcb = getDCBInstance(ddbRoot);
171             if(dcb != null && dcb instanceof BaseRoot) {
172                 BaseRoot rootDCB = (BaseRoot) dcb;
173                 
174                 if(rootDCB.getReference() == null) {
175                     // Does this need to be synchronized (or a larger section)?
176
// Or is it just my paranoia... -- PW
177
setReference(rootDCB);
178                     rootDCB.setReference(this);
179                 } else {
180                     jsr88Logger.finer("ReferencePatcher: " + rootDCB + " already has reference " + rootDCB.getReference());
181                 }
182             }
183             
184             if(getReference() == null) {
185                 // if we're still unpatched here, we found a ddbRoot to patch
186
// with, but no DCB to match that root has been created yet.
187
// So add to "patch list" so we get patched on that DCB's
188
// creation step.
189
dc.getPatchList().put(ddbRoot, this);
190             }
191         }
192     }
193     
194     private DDBeanRoot JavaDoc getDDBeanRoot(DDBean JavaDoc dDBean, DeployableObject JavaDoc dplObj) {
195         DDBeanRoot JavaDoc innerDDBeanRoot = null;
196         
197         if(dplObj != null && dplObj instanceof J2eeApplicationObject JavaDoc) {
198             J2eeApplicationObject JavaDoc dplObjRoot = (J2eeApplicationObject JavaDoc) dplObj;
199
200             // !PW The uri string is used as an index by 'getDeployableObject' to
201
// find the DeployableObject we're looking for. The studio team has
202
// often changed the format of this index, so be wary of failures here
203
String JavaDoc uri = dDBean.getText();
204
205             if(uri != null) { // "/connector" still comes through as null
206
DeployableObject JavaDoc innerDObj = dplObjRoot.getDeployableObject(uri);
207                 if(innerDObj != null) {
208                     innerDDBeanRoot = innerDObj.getDDBeanRoot();
209                 } else {
210                     jsr88Logger.finer("ReferencePatcher: no deployable object found for URI='" + uri + "'");
211                 }
212             } else {
213                 jsr88Logger.finer("ReferencePatcher: no URI found for XPath='" + dDBean.getXpath() + "'");
214             }
215         }
216             
217         return innerDDBeanRoot;
218     }
219     
220 }
221
Popular Tags