KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.netbeans.modules.j2ee.sun.share.configbean;
20
21 import java.util.ArrayList JavaDoc;
22 import java.util.Collection JavaDoc;
23 import javax.enterprise.deploy.model.DDBean JavaDoc;
24 import javax.enterprise.deploy.model.XpathEvent JavaDoc;
25 import javax.enterprise.deploy.spi.exceptions.ConfigurationException JavaDoc;
26
27 import java.beans.VetoableChangeListener JavaDoc;
28 import java.beans.PropertyChangeEvent JavaDoc;
29 import java.beans.PropertyVetoException JavaDoc;
30
31 import org.netbeans.modules.j2ee.sun.dd.api.CommonDDBean;
32 import org.netbeans.modules.j2ee.sun.dd.api.ejb.Ejb;
33 import org.openide.ErrorManager;
34
35
36
37 /**
38  *
39  * @author vkraemer
40  */

41 public class EntityEjb extends BaseEjb {
42     
43     /** Holds value of property isReadOnlyBean. */
44     private String JavaDoc isReadOnlyBean;
45     
46     /** Holds value of property refreshPeriodInSeconds. */
47     private String JavaDoc refreshPeriodInSeconds;
48     
49     /** Holds value of property commitOption. */
50     private String JavaDoc commitOption;
51
52     
53     /** Creates a new instance of SunONEEntityDConfigBean */
54     public EntityEjb() {
55     }
56     
57     protected void init(DDBean JavaDoc dDBean, Base parent) throws ConfigurationException JavaDoc {
58         super.init(dDBean, parent);
59         addVetoableChangeListener(new VetoRefreshPeriodChange());
60         addPropertyChangeListener(new KeepRefreshPeriodValid());
61     }
62
63     /* ------------------------------------------------------------------------
64      * XPath to Factory mapping support
65      */

66 /*
67     private HashMap entityEjbFactoryMap;
68
69     protected java.util.Map getXPathToFactoryMap() {
70         if(entityEjbFactoryMap == null) {
71             entityEjbFactoryMap = (HashMap) super.getXPathToFactoryMap();
72
73             // add child DCB's specific to Entity Beans
74         }
75
76         return entityEjbFactoryMap;
77     }
78  */

79
80     /* ------------------------------------------------------------------------
81      * Persistence support. Loads DConfigBeans from previously saved Deployment
82      * plan file.
83      */

84     protected class EntityEjbSnippet extends BaseEjb.BaseEjbSnippet {
85         public CommonDDBean getDDSnippet() {
86             Ejb ejb = (Ejb) super.getDDSnippet();
87
88             if(isReadOnlyBean != null){
89                 ejb.setIsReadOnlyBean(isReadOnlyBean);
90             }
91
92             if(refreshPeriodInSeconds != null){
93                 ejb.setRefreshPeriodInSeconds(refreshPeriodInSeconds);
94             }
95
96             if(commitOption != null){
97                 ejb.setCommitOption(commitOption);
98             }
99
100             return ejb;
101         }
102
103         public boolean hasDDSnippet() {
104             if(super.hasDDSnippet()){
105                 return true;
106             }
107
108             if(isReadOnlyBean != null){
109                 return true; }
110
111             if(refreshPeriodInSeconds != null){
112                 return true;
113             }
114
115             if(commitOption != null){
116                 return true;
117             }
118             return false;
119         }
120     }
121
122
123     java.util.Collection JavaDoc getSnippets() {
124         Collection JavaDoc snippets = new ArrayList JavaDoc();
125         snippets.add(new EntityEjbSnippet());
126         return snippets;
127     }
128
129
130     protected void loadEjbProperties(Ejb savedEjb) {
131         super.loadEjbProperties(savedEjb);
132
133         isReadOnlyBean = savedEjb.getIsReadOnlyBean();
134         refreshPeriodInSeconds = savedEjb.getRefreshPeriodInSeconds();
135         commitOption = savedEjb.getCommitOption();
136     }
137     
138     protected void clearProperties() {
139         super.clearProperties();
140         
141         isReadOnlyBean = null;
142         refreshPeriodInSeconds = null;
143         commitOption = null;
144     }
145     
146     public void fireXpathEvent(XpathEvent JavaDoc xpathEvent) {
147         super.fireXpathEvent(xpathEvent);
148 // dumpNotification("EntityEjb.fireXpathEvent", xpathEvent);
149

150         DDBean JavaDoc eventBean = xpathEvent.getBean();
151         String JavaDoc xpath = eventBean.getXpath();
152
153         if("/ejb-jar/enterprise-beans/entity/remote".equals(xpath)) { // NOI18N
154
try {
155                 if(xpathEvent.isAddEvent()) {
156                     setJndiName(getDefaultJndiName());
157                 } else if(xpathEvent.isRemoveEvent()) {
158                     setJndiName(null);
159                 }
160             } catch(PropertyVetoException JavaDoc ex) {
161                 // should never happen.
162
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
163             }
164         }
165     }
166
167     
168     /** Getter for property isReadOnlyBean.
169      * @return Value of property isReadOnlyBean.
170      *
171      */

172     public String JavaDoc getIsReadOnlyBean() {
173         return this.isReadOnlyBean;
174     }
175
176
177     class VetoRefreshPeriodChange implements VetoableChangeListener JavaDoc {
178         
179         /** This method gets called when a constrained property is changed.
180          *
181          * @param evt a <code>PropertyChangeEvent</code> object describing the
182          * event source and the property that has changed.
183          * @exception PropertyVetoException if the recipient wishes the property
184          * change to be rolled back.
185          *
186          */

187         public void vetoableChange(PropertyChangeEvent JavaDoc evt) throws PropertyVetoException JavaDoc {
188             boolean acceptable = true;
189             String JavaDoc failureMessage = "bad things happen";
190             try {
191                 String JavaDoc propName = evt.getPropertyName();
192                 if (propName.indexOf("refreshPeriodInSeconds") > -1) {
193                     if (null == isReadOnlyBean || isReadOnlyBean.equals("false")) //NOI18N
194
if (evt.getNewValue() != null) {
195                             //PropertyVetoException pve = new PropertyVetoException();
196
//throw new PropertyVetoException("property only valid for read-only beans", evt);
197
failureMessage = "property only valid for read-only beans";
198                         }
199                 }
200             }
201             catch (Exception JavaDoc ex) {
202                 acceptable = false;
203             }
204             if (!acceptable) {
205                 throw new PropertyVetoException JavaDoc(failureMessage,evt);
206             }
207         }
208         
209     }
210
211
212     public class KeepRefreshPeriodValid implements java.beans.PropertyChangeListener JavaDoc {
213         /** This method gets called when a bound property is changed.
214          * @param evt A PropertyChangeEvent object describing the event source
215          * and the property that has changed.
216          *
217          */

218         public void propertyChange(PropertyChangeEvent JavaDoc evt) {
219             try {
220                 String JavaDoc propName = evt.getPropertyName();
221                 if (propName.indexOf("isReadOnlyBean") > -1) {
222                     Object JavaDoc oldValue = evt.getOldValue();
223                     Object JavaDoc newValue = evt.getNewValue();
224                     if (newValue.equals(Boolean.TRUE)) {
225                         setRefreshPeriodInSeconds("60");
226                     }
227                     if (newValue.equals(Boolean.FALSE)) {
228                         setRefreshPeriodInSeconds(null);
229                     }
230                 }
231             }
232             catch (Throwable JavaDoc t) {
233             }
234         }
235     }
236     
237     
238     /** Setter for property isReadOnlyBean.
239      * @param isReadOnlyBean New value of property isReadOnlyBean.
240      *
241      * @throws PropertyVetoException
242      *
243      */

244     public void setIsReadOnlyBean(String JavaDoc isReadOnlyBean) throws java.beans.PropertyVetoException JavaDoc {
245         String JavaDoc oldIsReadOnlyBean = this.isReadOnlyBean;
246         getVCS().fireVetoableChange("isReadOnlyBean", oldIsReadOnlyBean, isReadOnlyBean);
247         this.isReadOnlyBean = isReadOnlyBean;
248         getPCS().firePropertyChange("isReadOnlyBean", oldIsReadOnlyBean, isReadOnlyBean);
249     }
250     
251     /** Getter for property refreshPeriodInSeconds.
252      * @return Value of property refreshPeriodInSeconds.
253      *
254      */

255     public String JavaDoc getRefreshPeriodInSeconds() {
256         return this.refreshPeriodInSeconds;
257     }
258     
259     /** Setter for property refreshPeriodInSeconds.
260      * @param refreshPeriodInSeconds New value of property refreshPeriodInSeconds.
261      *
262      * @throws PropertyVetoException
263      *
264      */

265     public void setRefreshPeriodInSeconds(String JavaDoc refreshPeriodInSeconds) throws java.beans.PropertyVetoException JavaDoc {
266         String JavaDoc oldRefreshPeriodInSeconds = this.refreshPeriodInSeconds;
267         getVCS().fireVetoableChange("refreshPeriodInSeconds", oldRefreshPeriodInSeconds, refreshPeriodInSeconds);
268         this.refreshPeriodInSeconds = refreshPeriodInSeconds;
269         getPCS().firePropertyChange("refreshPeriodInSeconds", oldRefreshPeriodInSeconds, refreshPeriodInSeconds);
270     }
271     
272     /** Getter for property commitOption.
273      * @return Value of property commitOption.
274      *
275      */

276     public String JavaDoc getCommitOption() {
277         return this.commitOption;
278     }
279     
280     /** Setter for property commitOption.
281      * @param commitOption New value of property commitOption.
282      *
283      * @throws PropertyVetoException
284      *
285      */

286     public void setCommitOption(String JavaDoc commitOption) throws java.beans.PropertyVetoException JavaDoc {
287         String JavaDoc oldCommitOption = this.commitOption;
288         getVCS().fireVetoableChange("commitOption", oldCommitOption, commitOption);
289         this.commitOption = commitOption;
290         getPCS().firePropertyChange("commitOption", oldCommitOption, commitOption);
291     }
292
293     public String JavaDoc getHelpId() {
294         return "AS_CFG_EntityEjb"; //NOI18N
295
}
296 }
297
Popular Tags