1 16 17 package org.apache.jetspeed.om.registry.base; 18 19 import org.apache.jetspeed.om.registry.*; 20 21 import java.util.*; 22 23 31 public class BaseSkinEntry extends BaseRegistryEntry implements SkinEntry 32 { 33 34 private Vector parameter = new Vector(); 35 36 private transient Map nameIdx = null; 37 38 42 public boolean equals(Object object) 43 { 44 if (object==null) 45 { 46 return false; 47 } 48 49 BaseSkinEntry obj = (BaseSkinEntry)object; 50 51 Iterator i = parameter.iterator(); 52 Iterator i2 = obj.parameter.iterator(); 53 while(i.hasNext()) 54 { 55 BaseParameter c1 = (BaseParameter)i.next(); 56 BaseParameter c2 = null; 57 58 if (i2.hasNext()) 59 { 60 c2 = (BaseParameter)i2.next(); 61 } 62 else 63 { 64 return false; 65 } 66 67 if (!c1.equals(c2)) 68 { 69 return false; 70 } 71 } 72 73 if (i2.hasNext()) 74 { 75 return false; 76 } 77 78 return super.equals(object); 79 } 80 81 82 public Iterator getParameterNames() 83 { 84 synchronized (parameter) 85 { 86 if (nameIdx == null) 87 { 88 buildNameIndex(); 89 } 90 } 91 92 return nameIdx.keySet().iterator(); 93 } 94 95 101 public Parameter getParameter( String name ) 102 { 103 synchronized (parameter) 104 { 105 if (nameIdx == null) 106 { 107 buildNameIndex(); 108 } 109 } 110 111 if (name != null) 112 { 113 Integer pos = (Integer )nameIdx.get(name); 114 115 if (pos != null) 116 { 117 return (Parameter)parameter.elementAt(pos.intValue()); 118 } 119 } 120 121 return null; 122 } 123 124 125 128 public Map getParameterMap() 129 { 130 Hashtable params = new Hashtable(); 131 Enumeration en = parameter.elements(); 132 while(en.hasMoreElements()) 133 { 134 Parameter param = (Parameter)en.nextElement(); 135 params.put(param.getName(),param.getValue()); 136 } 137 138 return params; 139 140 } 141 142 146 public void addParameter( String name, String value ) 147 { 148 if (name != null) 149 { 150 Parameter p = getParameter(name); 151 if (p == null) 152 { 153 p = new BaseParameter(); 154 p.setName(name); 155 } 156 157 p.setValue(value); 158 159 addParameter(p); 160 161 } 162 } 163 164 167 public void addParameter( Parameter param ) 168 { 169 synchronized (parameter) 170 { 171 parameter.addElement( param ); 172 nameIdx.put( param.getName(), new Integer ( parameter.size()-1 ) ); 173 } 174 } 175 176 181 public void removeParameter( String name ) 182 { 183 if (name == null) return; 184 185 synchronized (parameter) 186 { 187 Iterator i = parameter.iterator(); 188 while(i.hasNext()) 189 { 190 Parameter param = (Parameter)i.next(); 191 if (param.getName().equals(name)) 192 { 193 i.remove(); 194 } 195 } 196 197 buildNameIndex(); 198 } 199 } 200 201 206 private void buildNameIndex() 207 { 208 Hashtable idx = new Hashtable(); 209 210 Iterator i = parameter.iterator(); 211 int count = 0; 212 while( i.hasNext() ) 213 { 214 Parameter p = (Parameter)i.next(); 215 idx.put( p.getName(), new Integer (count) ); 216 count++; 217 } 218 219 this.nameIdx = idx; 220 } 221 222 224 227 public Vector getParameters() 228 { 229 return this.parameter; 230 } 231 232 public void setParameters(Vector parameters) 233 { 234 this.parameter = parameters; 235 } 236 237 } | Popular Tags |