1 23 24 25 package com.sun.enterprise.deployment.runtime; 26 27 import java.beans.*; 28 import java.util.List ; 29 import java.util.ArrayList ; 30 import com.sun.enterprise.deployment.Descriptor; 31 32 38 public abstract class RuntimeDescriptor extends Descriptor { 39 40 protected PropertyChangeSupport propListeners; 41 42 43 public RuntimeDescriptor(RuntimeDescriptor other) { 44 super(other); 45 propListeners = new PropertyChangeSupport(this); } 47 48 49 public RuntimeDescriptor() { 50 propListeners = new PropertyChangeSupport(this); 51 } 52 53 57 public void addPropertyChangeListener(PropertyChangeListener l) { 58 propListeners.addPropertyChangeListener(l); 59 } 60 61 65 public void removePropertyChangeListener(PropertyChangeListener l) { 66 propListeners.removePropertyChangeListener(l); 67 } 68 69 74 public void addPropertyChangeListener(String n, PropertyChangeListener l) { 75 propListeners.addPropertyChangeListener(n, l); 76 } 77 78 83 public void removePropertyChangeListener(String n, PropertyChangeListener l) { 84 propListeners.removePropertyChangeListener(n, l); 85 } 86 87 92 public void setValue(String name, Object value) { 93 Object oldValue = getExtraAttribute(name); 94 addExtraAttribute(name, value); 95 propListeners.firePropertyChange(name, oldValue, value); 96 } 97 98 101 public Object getValue(String name) { 102 return getExtraAttribute(name); 103 } 104 105 108 protected void setValue(String name, int index, Object value) { 109 List list = getIndexedProperty(name); 110 list.set(index, value); 111 setValue(name, list); 112 } 113 114 protected Object getValue(String name, int index) { 115 List list = getIndexedProperty(name); 116 return list.get(index); 117 } 118 119 protected int addValue(String name, Object value) { 120 List list = getIndexedProperty(name); 121 list.add(value); 122 setValue(name, list); 123 return list.indexOf(value); 124 } 125 126 protected int removeValue(String name, Object value) { 127 List list = getIndexedProperty(name); 128 int index = list.indexOf(value); 129 list.remove(index); 130 return index; 131 } 132 133 protected void removeValue(String name, int index) { 134 List list = getIndexedProperty(name); 135 list.remove(index); 136 } 137 138 protected void setValues(String name, Object [] values) { 139 List list = getIndexedProperty(name); 140 for (int i=0;i<values.length;) { 141 list.add(values[i]); 142 } 143 } 144 145 protected Object [] getValues(String name) { 146 List list = (List ) getValue(name); 147 if (list!=null && list.size()>0) { 148 Class c = list.get(0).getClass(); 149 Object array = java.lang.reflect.Array.newInstance(c, list.size()); 150 return list.toArray((Object []) array); 151 } 152 else 153 return null; 154 } 155 156 protected int size(String name) { 157 List list = (List ) getValue(name); 158 if (list!=null) 159 return list.size(); 160 else 161 return 0; 162 } 163 164 private List getIndexedProperty(String name) { 165 Object o = getValue(name); 166 if (o==null) { 167 return new ArrayList (); 168 } else { 169 return (List ) o; 170 } 171 } 172 173 public void setAttributeValue(String elementName, String attributeName, Object value) { 175 180 181 int index = 0; 182 while (getValue(elementName + "-" + index + "-" + attributeName)!=null) { 183 index++; 184 } 185 if (index==0) { 186 setValue(elementName + "-0-" + attributeName, value); 188 } else { 189 setValue(elementName + "-" + (index+1) + "-" + attributeName, value); 190 } 191 } 192 193 public String getAttributeValue(String elementName, String attributeName) { 194 return getAttributeValue(elementName,0, attributeName); 195 } 196 197 public void setAttributeValue(String attributeName, String value) { 199 setValue(attributeName, value); 200 } 201 202 public String getAttributeValue(String attributeName) { 203 return (String ) getValue(attributeName); 204 } 205 206 public void setAttributeValue(String elementName, int index, String attributeName, Object value) { 208 setValue(elementName + "-" + index + "-" + attributeName, value); 209 } 210 211 public String getAttributeValue(String elementName, int index, String attributeName) { 212 return (String ) getValue(elementName + "-" + index + "-" + attributeName); 213 } 214 } 215 | Popular Tags |