1 19 package org.netbeans.modules.j2ee.sun.share.configbean; 20 21 import java.util.ArrayList ; 22 import java.util.Collection ; 23 import javax.enterprise.deploy.model.DDBean ; 24 import javax.enterprise.deploy.model.XpathEvent ; 25 import javax.enterprise.deploy.spi.exceptions.ConfigurationException ; 26 27 import java.beans.VetoableChangeListener ; 28 import java.beans.PropertyChangeEvent ; 29 import java.beans.PropertyVetoException ; 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 41 public class EntityEjb extends BaseEjb { 42 43 44 private String isReadOnlyBean; 45 46 47 private String refreshPeriodInSeconds; 48 49 50 private String commitOption; 51 52 53 54 public EntityEjb() { 55 } 56 57 protected void init(DDBean dDBean, Base parent) throws ConfigurationException { 58 super.init(dDBean, parent); 59 addVetoableChangeListener(new VetoRefreshPeriodChange()); 60 addPropertyChangeListener(new KeepRefreshPeriodValid()); 61 } 62 63 66 79 80 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 getSnippets() { 124 Collection snippets = new ArrayList (); 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 xpathEvent) { 147 super.fireXpathEvent(xpathEvent); 148 150 DDBean eventBean = xpathEvent.getBean(); 151 String xpath = eventBean.getXpath(); 152 153 if("/ejb-jar/enterprise-beans/entity/remote".equals(xpath)) { try { 155 if(xpathEvent.isAddEvent()) { 156 setJndiName(getDefaultJndiName()); 157 } else if(xpathEvent.isRemoveEvent()) { 158 setJndiName(null); 159 } 160 } catch(PropertyVetoException ex) { 161 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 163 } 164 } 165 } 166 167 168 172 public String getIsReadOnlyBean() { 173 return this.isReadOnlyBean; 174 } 175 176 177 class VetoRefreshPeriodChange implements VetoableChangeListener { 178 179 187 public void vetoableChange(PropertyChangeEvent evt) throws PropertyVetoException { 188 boolean acceptable = true; 189 String failureMessage = "bad things happen"; 190 try { 191 String propName = evt.getPropertyName(); 192 if (propName.indexOf("refreshPeriodInSeconds") > -1) { 193 if (null == isReadOnlyBean || isReadOnlyBean.equals("false")) if (evt.getNewValue() != null) { 195 failureMessage = "property only valid for read-only beans"; 198 } 199 } 200 } 201 catch (Exception ex) { 202 acceptable = false; 203 } 204 if (!acceptable) { 205 throw new PropertyVetoException (failureMessage,evt); 206 } 207 } 208 209 } 210 211 212 public class KeepRefreshPeriodValid implements java.beans.PropertyChangeListener { 213 218 public void propertyChange(PropertyChangeEvent evt) { 219 try { 220 String propName = evt.getPropertyName(); 221 if (propName.indexOf("isReadOnlyBean") > -1) { 222 Object oldValue = evt.getOldValue(); 223 Object 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 t) { 233 } 234 } 235 } 236 237 238 244 public void setIsReadOnlyBean(String isReadOnlyBean) throws java.beans.PropertyVetoException { 245 String oldIsReadOnlyBean = this.isReadOnlyBean; 246 getVCS().fireVetoableChange("isReadOnlyBean", oldIsReadOnlyBean, isReadOnlyBean); 247 this.isReadOnlyBean = isReadOnlyBean; 248 getPCS().firePropertyChange("isReadOnlyBean", oldIsReadOnlyBean, isReadOnlyBean); 249 } 250 251 255 public String getRefreshPeriodInSeconds() { 256 return this.refreshPeriodInSeconds; 257 } 258 259 265 public void setRefreshPeriodInSeconds(String refreshPeriodInSeconds) throws java.beans.PropertyVetoException { 266 String oldRefreshPeriodInSeconds = this.refreshPeriodInSeconds; 267 getVCS().fireVetoableChange("refreshPeriodInSeconds", oldRefreshPeriodInSeconds, refreshPeriodInSeconds); 268 this.refreshPeriodInSeconds = refreshPeriodInSeconds; 269 getPCS().firePropertyChange("refreshPeriodInSeconds", oldRefreshPeriodInSeconds, refreshPeriodInSeconds); 270 } 271 272 276 public String getCommitOption() { 277 return this.commitOption; 278 } 279 280 286 public void setCommitOption(String commitOption) throws java.beans.PropertyVetoException { 287 String oldCommitOption = this.commitOption; 288 getVCS().fireVetoableChange("commitOption", oldCommitOption, commitOption); 289 this.commitOption = commitOption; 290 getPCS().firePropertyChange("commitOption", oldCommitOption, commitOption); 291 } 292 293 public String getHelpId() { 294 return "AS_CFG_EntityEjb"; } 296 } 297 | Popular Tags |