KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.enterprise.deploy.spi.exceptions.ConfigurationException JavaDoc;
27 import javax.enterprise.deploy.model.DDBean JavaDoc;
28 import javax.enterprise.deploy.model.XpathEvent JavaDoc;
29
30 import org.netbeans.modules.j2ee.sun.dd.api.CommonDDBean;
31 import org.netbeans.modules.j2ee.sun.dd.api.web.SunWebApp;
32 import org.netbeans.modules.j2ee.sun.share.configbean.Base.DefaultSnippet;
33
34
35 /**
36  *
37  * @author Peter Williams
38  */

39 public class MessageDestinationRef extends Base {
40     
41     /** property event names
42      */

43     public static final String JavaDoc MESSAGE_DESTINATION_REF_NAME = "messageDestinationRefName"; // NOI18N
44

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

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

65         messageDestinationRefNameDD = getNameDD("message-destination-ref-name");
66         
67         updateNamedBeanCache(SunWebApp.MESSAGE_DESTINATION_REF);
68         
69         loadFromPlanFile(getConfig());
70     }
71     
72     protected String JavaDoc getComponentName() {
73         return getMessageDestinationRefName();
74     }
75
76     /** -----------------------------------------------------------------------
77      * Validation implementation
78      */

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

119     public String JavaDoc getHelpId() {
120         return "AS_CFG_MessageDestinationRef";
121     }
122     
123     /** The DDBean (or one of it's children) that this DConfigBean is bound to
124      * has changed.
125      *
126      * @param xpathEvent
127      */

128     public void notifyDDChange(XpathEvent JavaDoc xpathEvent) {
129         super.notifyDDChange(xpathEvent);
130
131         if(messageDestinationRefNameDD == xpathEvent.getBean()) {
132             // name changed...
133
getPCS().firePropertyChange(MESSAGE_DESTINATION_REF_NAME, "", getMessageDestinationRefName());
134             getPCS().firePropertyChange(DISPLAY_NAME, "", getDisplayName());
135             
136             updateNamedBeanCache(SunWebApp.MESSAGE_DESTINATION_REF);
137         }
138     }
139
140     /** Getter for property messageDestinationRefName.
141      * @return Value of property messageDestinationRefNameDD.
142      *
143      */

144     public String JavaDoc getMessageDestinationRefName() {
145         return cleanDDBeanText(messageDestinationRefNameDD);
146     }
147     
148     /** Getter for property jndiName.
149      * @return Value of property jndiName.
150      *
151      */

152     public String JavaDoc getJndiName() {
153         return this.jndiName;
154     }
155     
156     /** Setter for property jndiName.
157      * @param jndiName New value of property jndiName.
158      *
159      * @throws PropertyVetoException
160      *
161      */

162     public void setJndiName(String JavaDoc jndiName) throws java.beans.PropertyVetoException JavaDoc {
163         String JavaDoc oldJndiName = this.jndiName;
164         getVCS().fireVetoableChange("jndiName", oldJndiName, jndiName);
165         this.jndiName = jndiName;
166         getPCS().firePropertyChange("jndiName", oldJndiName, jndiName);
167     }
168     
169     /* ------------------------------------------------------------------------
170      * Persistence support. Loads DConfigBeans from previously saved Deployment
171      * plan file.
172      */

173     Collection JavaDoc getSnippets() {
174         Collection JavaDoc snippets = new ArrayList JavaDoc();
175         Snippet snipOne = new DefaultSnippet() {
176             public CommonDDBean getDDSnippet() {
177                 org.netbeans.modules.j2ee.sun.dd.api.common.MessageDestinationRef mdRef =
178                     getConfig().getStorageFactory().createMessageDestinationRef();
179
180                 // write properties into parent bean
181
String JavaDoc messageDestinationRefName = getMessageDestinationRefName();
182                 if(messageDestinationRefName != null) {
183                     mdRef.setMessageDestinationRefName(messageDestinationRefName);
184                 }
185
186                 if(jndiName != null && jndiName.length() > 0) {
187                     mdRef.setJndiName(jndiName);
188                 }
189
190                 return mdRef;
191             }
192             
193             public boolean hasDDSnippet() {
194                 if(jndiName != null && jndiName.length() > 0) {
195                     return true;
196                 }
197                 
198                 return false;
199             }
200             
201             public String JavaDoc getPropertyName() {
202                 return SunWebApp.MESSAGE_DESTINATION_REF;
203             }
204         };
205         
206         snippets.add(snipOne);
207         return snippets;
208     }
209
210     private class MessageDestinationRefFinder extends NameBasedFinder {
211         public MessageDestinationRefFinder(String JavaDoc beanName) {
212             super(org.netbeans.modules.j2ee.sun.dd.api.common.MessageDestinationRef.MESSAGE_DESTINATION_REF_NAME,
213                   beanName, org.netbeans.modules.j2ee.sun.dd.api.common.MessageDestinationRef.class);
214         }
215     }
216     
217     boolean loadFromPlanFile(SunONEDeploymentConfiguration config) {
218         String JavaDoc uriText = getUriText();
219
220         org.netbeans.modules.j2ee.sun.dd.api.common.MessageDestinationRef beanGraph =
221             (org.netbeans.modules.j2ee.sun.dd.api.common.MessageDestinationRef) config.getBeans(uriText,
222             constructFileName(), getParser(), new MessageDestinationRefFinder(getMessageDestinationRefName()));
223         
224         clearProperties();
225         
226         if(beanGraph != null) {
227             jndiName = beanGraph.getJndiName();
228         } else {
229             setDefaultProperties();
230         }
231         
232         return (beanGraph != null);
233     }
234     
235     protected void clearProperties() {
236         jndiName = null;
237     }
238     
239     protected void setDefaultProperties() {
240 // // Set default JNDI name
241
// jndiName = messageDestinationRefNameDD.getText();
242
//
243
// // Prepend "ejb/" only if, the Ref name does not start with "ejb/"
244
// // By blue prints convention, Ref name always starts with "ejb/"
245
// if (!jndiName.startsWith("ejb/")) { // NOI18N
246
// jndiName = "ejb/" + jndiName; // NOI18N
247
// }
248
//
249
// getConfig().getMasterDCBRoot().setDirty();
250
}
251 }
252
Popular Tags