KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.ArrayList JavaDoc;
23 import java.util.Collection JavaDoc;
24 import java.text.MessageFormat JavaDoc;
25
26 import org.netbeans.modules.schema2beans.BaseBean;
27
28 import javax.enterprise.deploy.spi.DConfigBean JavaDoc;
29 import javax.enterprise.deploy.spi.DeploymentConfiguration JavaDoc;
30 import javax.enterprise.deploy.spi.exceptions.ConfigurationException JavaDoc;
31 import javax.enterprise.deploy.model.DDBean JavaDoc;
32 import javax.enterprise.deploy.model.XpathEvent JavaDoc;
33
34 import org.netbeans.modules.j2ee.sun.dd.api.CommonDDBean;
35 import org.netbeans.modules.j2ee.sun.dd.api.web.SunWebApp;
36
37
38 /**
39  *
40  * @author Peter Williams
41  */

42 public class ResourceEnvRef extends Base {
43     
44     /** property event names
45      */

46     public static final String JavaDoc RESOURCE_ENV_REF_NAME = "resourceEnvRefName"; // NOI18N
47

48     /** Holds value of property resourceEnvRef. */
49     private DDBean JavaDoc resourceEnvRefNameDD;
50     
51     /** Holds value of property jndiName. */
52     private String JavaDoc jndiName;
53     
54     /** Creates a new instance of ResourceEnvRef */
55     public ResourceEnvRef() {
56         setDescriptorElement(bundle.getString("BDN_ResourceEnvRef")); // NOI18N
57
}
58
59     /** Override init to enable grouping support for this bean
60      * @param dDBean DDBean matching this bean
61      * @param parent Parent DConfigBean in the tree
62      */

63     protected void init(DDBean JavaDoc dDBean, Base parent) throws ConfigurationException JavaDoc {
64         super.init(dDBean, parent);
65 // !PW Disable grouping code for now, spec non-compliance.
66
// initGroup(dDBean, parent);
67

68         resourceEnvRefNameDD = getNameDD("resource-env-ref-name");
69         
70         updateNamedBeanCache(SunWebApp.RESOURCE_ENV_REF);
71         
72         loadFromPlanFile(getConfig());
73     }
74     
75     protected String JavaDoc getComponentName() {
76         return getResourceEnvRefName();
77     }
78     
79     /** -----------------------------------------------------------------------
80      * Validation implementation
81      */

82     
83     // relative xpaths (double as field id's)
84
public static final String JavaDoc FIELD_JNDI_NAME="jndi-name";
85     
86     protected void updateValidationFieldList() {
87         super.updateValidationFieldList();
88         validationFieldList.add(FIELD_JNDI_NAME);
89     }
90     
91     public boolean validateField(String JavaDoc fieldId) {
92         ValidationError error = null;
93         boolean result = true;
94
95         if(fieldId.equals(FIELD_JNDI_NAME)) {
96             // validation version will be:
97
// expand relative field id to full xpath id based on current context
98
// lookup validator for this field in field validator DB
99
// execute validator
100
J2EEBaseVersion moduleVersion = getJ2EEModuleVersion();
101             if(moduleVersion.compareSpecification(J2EEVersion.JAVAEE_5_0) < 0) {
102                 String JavaDoc absoluteFieldXpath = getAbsoluteXpath(fieldId);
103                 if(!Utils.notEmpty(jndiName)) {
104                     Object JavaDoc [] args = new Object JavaDoc[1];
105                     args[0] = FIELD_JNDI_NAME;
106                     String JavaDoc message = MessageFormat.format(bundle.getString("ERR_SpecifiedFieldIsEmpty"), args); // NOI18N
107
error = ValidationError.getValidationError(absoluteFieldXpath, message);
108                 } else {
109                     error = ValidationError.getValidationErrorMask(absoluteFieldXpath);
110                 }
111             }
112         }
113         
114         if(error != null) {
115             getMessageDB().updateError(error);
116         }
117         
118         // return true if there was no error added
119
return (error == null || !Utils.notEmpty(error.getMessage()));
120     }
121     
122     /** Getter for helpId property
123      * @return Help context ID for this DConfigBean
124      */

125     public String JavaDoc getHelpId() {
126         return "AS_CFG_ResourceEnvRef";
127     }
128     
129     /** The DDBean (or one of it's children) that this DConfigBean is bound to
130      * has changed.
131      *
132      * @param xpathEvent
133      */

134     public void notifyDDChange(XpathEvent JavaDoc xpathEvent) {
135         super.notifyDDChange(xpathEvent);
136
137         if(resourceEnvRefNameDD == xpathEvent.getBean()) {
138             // name changed...
139
getPCS().firePropertyChange(RESOURCE_ENV_REF_NAME, "", getResourceEnvRefName());
140             getPCS().firePropertyChange(DISPLAY_NAME, "", getDisplayName());
141
142             updateNamedBeanCache(SunWebApp.RESOURCE_ENV_REF);
143         }
144     }
145     
146     /** Getter for property resourceEnvRefName.
147      * @return Value of property resourceEnvRefName.
148      *
149      */

150     public String JavaDoc getResourceEnvRefName() {
151         return cleanDDBeanText(resourceEnvRefNameDD);
152     }
153     
154     /** Getter for property jndiName.
155      * @return Value of property jndiName.
156      *
157      */

158     public String JavaDoc getJndiName() {
159         return this.jndiName;
160     }
161     
162     /** Setter for property jndiName.
163      * @param jndiName New value of property jndiName.
164      *
165      * @throws PropertyVetoException
166      *
167      */

168     public void setJndiName(String JavaDoc jndiName) throws java.beans.PropertyVetoException JavaDoc {
169         String JavaDoc oldJndiName = this.jndiName;
170         getVCS().fireVetoableChange("jndiName", oldJndiName, jndiName);
171         this.jndiName = jndiName;
172         getPCS().firePropertyChange("jndiName", oldJndiName, jndiName);
173     }
174     
175     /* ------------------------------------------------------------------------
176      * Persistence support. Loads DConfigBeans from previously saved Deployment
177      * plan file.
178      */

179     Collection JavaDoc getSnippets() {
180         Collection JavaDoc snippets = new ArrayList JavaDoc();
181         Snippet snipOne = new DefaultSnippet() {
182             
183             public CommonDDBean getDDSnippet() {
184                 org.netbeans.modules.j2ee.sun.dd.api.common.ResourceEnvRef ref =
185                     getConfig().getStorageFactory().createResourceEnvRef();
186
187                 // write properties into Servlet bean
188
String JavaDoc resourceEnvRefName = getResourceEnvRefName();
189                 if(resourceEnvRefName != null) {
190                     ref.setResourceEnvRefName(resourceEnvRefName);
191                 }
192
193                 if(jndiName != null && jndiName.length() > 0) {
194                     ref.setJndiName(jndiName);
195                 }
196
197                 return ref;
198             }
199             
200             public boolean hasDDSnippet() {
201                 if(jndiName != null && jndiName.length() > 0) {
202                     return true;
203                 }
204                 
205                 return false;
206             }
207             
208             public String JavaDoc getPropertyName() {
209                 return SunWebApp.RESOURCE_ENV_REF;
210             }
211             
212         };
213         
214         snippets.add(snipOne);
215         return snippets;
216     }
217     
218 /*
219     private class ResourceEnvRefFinder implements ConfigFinder {
220         private String beanName;
221
222         public ResourceEnvRefFinder(String beanName) {
223             this.beanName = beanName;
224         }
225
226         public Object find(Object obj) {
227             org.netbeans.modules.j2ee.sun.dd.api.common.ResourceEnvRef resEnvRef = null;
228             CommonDDBean root = (CommonDDBean) obj;
229             
230             String[] props = root.findPropertyValue(
231                 org.netbeans.modules.j2ee.sun.dd.api.common.ResourceEnvRef.RESOURCE_ENV_REF_NAME, beanName);
232             
233             for (int i = 0; i < props.length; i++) {
234                 CommonDDBean candidate = root.graphManager().getPropertyParent(props[i]);
235                 if (candidate instanceof org.netbeans.modules.j2ee.sun.dd.api.common.ResourceEnvRef) {
236                     resEnvRef = (org.netbeans.modules.j2ee.sun.dd.api.common.ResourceEnvRef) candidate;
237                     break;
238                 }
239             }
240             
241             return resEnvRef;
242         }
243     }
244  */

245     
246     private class ResourceEnvRefFinder extends NameBasedFinder {
247         public ResourceEnvRefFinder(String JavaDoc beanName) {
248             super(org.netbeans.modules.j2ee.sun.dd.api.common.ResourceEnvRef.RESOURCE_ENV_REF_NAME,
249                 beanName, org.netbeans.modules.j2ee.sun.dd.api.common.ResourceEnvRef.class);
250         }
251     }
252     
253     boolean loadFromPlanFile(SunONEDeploymentConfiguration config) {
254         String JavaDoc uriText = getUriText();
255
256         org.netbeans.modules.j2ee.sun.dd.api.common.ResourceEnvRef beanGraph =
257             (org.netbeans.modules.j2ee.sun.dd.api.common.ResourceEnvRef) config.getBeans(uriText,
258             constructFileName(), getParser(), new ResourceEnvRefFinder(getResourceEnvRefName()));
259
260         clearProperties();
261         
262         if(beanGraph != null) {
263             jndiName = beanGraph.getJndiName();
264         } else {
265             setDefaultProperties();
266         }
267         
268         return (beanGraph != null);
269     }
270     
271     protected void clearProperties() {
272         jndiName = null;
273     }
274     
275     protected void setDefaultProperties() {
276         // no defaults
277
}
278 }
279
Popular Tags