1 23 24 29 30 package com.sun.enterprise.tools.common.beans; 31 32 import java.util.ResourceBundle ; 33 34 import java.beans.PropertyVetoException ; 35 import java.beans.VetoableChangeSupport ; 36 import java.beans.VetoableChangeListener ; 37 import java.beans.PropertyChangeSupport ; 38 import java.beans.PropertyChangeListener ; 39 import java.beans.PropertyChangeEvent ; 40 import org.netbeans.modules.schema2beans.BaseBean; 41 45 public abstract class BasicIasBean { 46 47 protected static VetoableChangeListener greaterThanNegOne = 48 new PositiveValueListener(); 49 protected static VetoableChangeListener notNull = 50 new NotEmptyValueListener(); 51 52 private PropertyChangeSupport pcs; 53 private VetoableChangeSupport vcs; 54 55 protected static ResourceBundle bundle = 56 ResourceBundle.getBundle("com.sun.enterprise.tools.common.beans.Bundle"); 58 59 60 protected BasicIasBean() { 61 } 62 63 public PropertyChangeSupport getPCS() { 64 if (null == pcs) 65 pcs = new PropertyChangeSupport (this); 66 return pcs; 67 } 68 69 public VetoableChangeSupport getVCS() { 70 if (null == vcs) 71 vcs = new VetoableChangeSupport (this); 72 return vcs; 73 } 74 75 protected void doAttrSetProcessing(BaseBean bean, String newVal, String attrName, String propName) 76 throws PropertyVetoException { 77 String oldName = bean.getAttributeValue(attrName); fireMyVetoableChange(propName, oldName, newVal); 79 bean.setAttributeValue(attrName,newVal); fireMyPropertyChange(propName, oldName, newVal); 81 } 82 83 protected void doElementSetProcessing(BaseBean bean, String newVal, String subElement, String propName) 84 throws PropertyVetoException { 85 String oldName = (String ) bean.getValue(subElement); 86 fireMyVetoableChange(propName, oldName, newVal); 87 bean.setValue(subElement,newVal); 88 fireMyPropertyChange(propName, oldName, newVal); 89 } 90 91 protected void doAttrSetProcessing(BaseBean bean, int newVal, String attrName, String propName) 92 throws PropertyVetoException { 93 int oldVal = Integer.parseInt(bean.getAttributeValue(attrName)); fireMyVetoableChange(propName, oldVal, newVal); 95 bean.setAttributeValue(attrName, ""+newVal); fireMyPropertyChange(propName, oldVal, newVal); 97 } 98 99 protected void fireMyVetoableChange(String name, Object oldV, Object newV) throws PropertyVetoException { 100 if (null == vcs) { 101 vcs = new VetoableChangeSupport (this); 102 } 103 vcs.fireVetoableChange(name,oldV,newV); 104 } 105 106 protected void fireMyVetoableChange(String name, int oldV, int newV) throws PropertyVetoException { 107 if (null == vcs) { 108 vcs = new VetoableChangeSupport (this); 109 } 110 vcs.fireVetoableChange(name,oldV,newV); 111 } 112 113 protected void fireMyPropertyChange(String name, Object oldV, Object newV) { if (null == pcs) { 115 pcs = new PropertyChangeSupport (this); 116 } 117 pcs.firePropertyChange(name,oldV,newV); 118 } 119 120 protected void fireMyPropertyChange(String name, int oldV, int newV) { if (null == pcs) { 122 pcs = new PropertyChangeSupport (this); 123 } 124 pcs.firePropertyChange(name,oldV,newV); 125 } 126 127 130 public void addPropertyChangeListener(PropertyChangeListener pcl) { 131 if (null == pcs) 132 pcs = new PropertyChangeSupport (this); 133 pcs.addPropertyChangeListener(pcl); 134 } 135 136 139 public void removePropertyChangeListener(PropertyChangeListener pcl) { 140 if (null != pcs) 141 pcs.removePropertyChangeListener(pcl); 142 } 143 144 147 public void addVetoableChangeListener(VetoableChangeListener pcl) { 148 if (null == vcs) 149 vcs = new VetoableChangeSupport (this); 150 vcs.addVetoableChangeListener(pcl); 151 } 152 153 156 public void removeVetoableChangeListener(VetoableChangeListener pcl) { 157 if (null != vcs) 158 vcs.removeVetoableChangeListener(pcl); 159 } 160 161 163 public abstract void outTo(java.io.OutputStream os) throws java.io.IOException ; 164 165 static class PositiveValueListener implements VetoableChangeListener { 166 public void vetoableChange(PropertyChangeEvent pce) throws PropertyVetoException { 167 try { 168 Integer valI= (Integer ) pce.getNewValue(); 169 int val = valI.intValue(); 170 if (0 > val) { 171 String messFormat = bundle.getString("ERROR_MUST_BE_POSITIVE"); 172 String mess = java.text.MessageFormat.format(messFormat, new Object [] { pce.getPropertyName() }); 173 throw new PropertyVetoException (mess, pce); 174 } 175 } 176 catch (Throwable t) { 177 throw new PropertyVetoException (t.getLocalizedMessage(), pce); 178 } 179 } 180 } 181 182 static class NotEmptyValueListener implements VetoableChangeListener { 183 public void vetoableChange(PropertyChangeEvent pce) throws PropertyVetoException { 184 try { 185 String val= (String ) pce.getNewValue(); 186 if (null == val || val.trim().length() == 0) { 188 String messFormat = bundle.getString("ERROR_MUST_HAVE_VALUE"); 189 String mess = java.text.MessageFormat.format(messFormat, new Object [] { pce.getPropertyName() }); 190 throw new PropertyVetoException (mess, pce); 191 } 192 } 193 catch (Throwable t) { 194 throw new PropertyVetoException (t.getLocalizedMessage(), pce); 195 } 196 } 197 } 198 199 } 200 | Popular Tags |