1 16 17 package org.apache.jetspeed.om.registry.base; 18 19 import org.apache.jetspeed.om.registry.*; 20 21 import java.util.Vector ; 22 import java.util.Map ; 23 import java.util.Hashtable ; 24 import java.util.Iterator ; 25 import java.util.Enumeration ; 26 27 35 public abstract class BasePortletInfoEntry extends BaseRegistryEntry 36 { 37 38 protected String classname; 39 40 protected Vector parameter = new Vector (); 41 42 protected transient Map nameIdx = null; 43 44 protected Vector medias = new Vector (); 45 46 protected transient Map mediasIdx = null; 47 48 protected Vector tools = new Vector (); 49 50 protected transient Map toolsIdx = null; 51 52 56 public boolean equals(Object object) 57 { 58 if (object==null) 59 { 60 return false; 61 } 62 63 BasePortletInfoEntry obj = (BasePortletInfoEntry)object; 64 65 if (classname!=null) 66 { 67 if (!classname.equals(obj.getClassname())) 68 { 69 return false; 70 } 71 } 72 else 73 { 74 if (obj.getClassname()!=null) 75 { 76 return false; 77 } 78 } 79 80 Iterator i = parameter.iterator(); 81 Iterator i2 = obj.getParameters().iterator(); 82 while(i.hasNext()) 83 { 84 BaseParameter p1 = (BaseParameter)i.next(); 85 BaseParameter p2 = null; 86 87 if (i2.hasNext()) 88 { 89 p2 = (BaseParameter)i2.next(); 90 } 91 else 92 { 93 return false; 94 } 95 96 if (!p1.equals(p2)) 97 { 98 return false; 99 } 100 } 101 102 if (i2.hasNext()) 103 { 104 return false; 105 } 106 107 i = medias.iterator(); 108 i2 = obj.getMediaTypes().iterator(); 109 while(i.hasNext()) 110 { 111 BaseMediaType m1 = (BaseMediaType)i.next(); 112 BaseMediaType m2 = null; 113 114 if (i2.hasNext()) 115 { 116 m2 = (BaseMediaType)i2.next(); 117 } 118 else 119 { 120 return false; 121 } 122 123 if (!m1.equals(m2)) 124 { 125 return false; 126 } 127 } 128 129 if (i2.hasNext()) 130 { 131 return false; 132 } 133 134 i = tools.iterator(); 135 i2 = obj.getTools().iterator(); 136 while(i.hasNext()) 137 { 138 BaseToolDescriptor t1 = (BaseToolDescriptor)i.next(); 139 BaseToolDescriptor t2 = null; 140 141 if (i2.hasNext()) 142 { 143 t2 = (BaseToolDescriptor)i2.next(); 144 } 145 else 146 { 147 return false; 148 } 149 150 if (!t1.equals(t2)) 151 { 152 return false; 153 } 154 } 155 156 if (i2.hasNext()) 157 { 158 return false; 159 } 160 161 return super.equals(object); 162 } 163 164 165 public String getClassname() 166 { 167 return this.classname; 168 } 169 170 176 public void setClassname( String classname ) 177 { 178 this.classname = classname; 179 } 180 181 182 public Iterator getParameterNames() 183 { 184 synchronized (parameter) 185 { 186 if (nameIdx == null) 187 { 188 buildNameIndex(); 189 } 190 } 191 192 return nameIdx.keySet().iterator(); 193 } 194 195 196 202 public Parameter getParameter( String name ) 203 { 204 synchronized (parameter) 205 { 206 if (nameIdx == null) 207 { 208 buildNameIndex(); 209 } 210 } 211 212 if (name != null) 213 { 214 Integer pos = (Integer )nameIdx.get(name); 215 216 if (pos != null) 217 { 218 return (Parameter)parameter.elementAt(pos.intValue()); 219 } 220 } 221 222 return null; 223 } 224 225 226 229 public Map getParameterMap() 230 { 231 Hashtable params = new Hashtable (); 232 Enumeration en = parameter.elements(); 233 while(en.hasMoreElements()) 234 { 235 Parameter param = (Parameter)en.nextElement(); 236 String key = param.getName(); 237 String value = param.getValue(); 238 if(key != null && value != null) 239 { 240 params.put(key, value); 241 } 242 } 243 return params; 244 } 245 246 250 public void addParameter( String name, String value ) 251 { 252 if (name != null) 253 { 254 Parameter p = getParameter(name); 255 if (p == null) 256 { 257 if (this instanceof PortletEntry) 258 p = new BaseCachedParameter(); 259 else 260 p = new BaseParameter(); 261 p.setName(name); 262 } 263 264 p.setValue(value); 265 266 addParameter(p); 267 268 } 269 } 270 271 274 public void addParameter( Parameter param ) 275 { 276 synchronized (parameter) 277 { 278 if (parameter == null) 279 parameter = new Vector (); 280 281 if (nameIdx == null) 282 buildNameIndex(); 283 284 parameter.addElement( param ); 285 nameIdx.put( param.getName(), new Integer ( parameter.size()-1 ) ); 286 } 287 } 288 289 294 public void removeParameter( String name ) 295 { 296 if (name == null) return; 297 298 synchronized (parameter) 299 { 300 Iterator i = parameter.iterator(); 301 while(i.hasNext()) 302 { 303 Parameter param = (Parameter)i.next(); 304 if (param.getName().equals(name)) 305 { 306 i.remove(); 307 } 308 } 309 310 buildNameIndex(); 311 } 312 } 313 314 319 public Iterator listMediaTypes() 320 { 321 if (mediasIdx == null) 322 { 323 synchronized( medias ) 324 { 325 buildMediasIndex(); 326 } 327 } 328 329 return mediasIdx.keySet().iterator(); 330 } 331 332 339 public boolean hasMediaType(String name) 340 { 341 if (mediasIdx == null) 342 { 343 synchronized( medias ) 344 { 345 buildMediasIndex(); 346 } 347 } 348 return ((name!=null)&&(mediasIdx.get(name)!=null)); 349 } 350 351 356 public void addMediaType(String name) 357 { 358 if (name!=null) 359 { 360 synchronized (medias) 361 { 362 if (mediasIdx == null) 363 { 364 buildMediasIndex(); 365 } 366 367 BaseMediaType m = new BaseMediaType(); 368 m.setRef(name); 369 mediasIdx.put(name,new Integer (medias.size())); 370 medias.add(m); 371 } 372 } 373 } 374 375 380 public void removeMediaType(String name) 381 { 382 if (name != null) 383 { 384 synchronized (medias) 385 { 386 mediasIdx.remove(name); 387 388 BaseMediaType m = new BaseMediaType(); 389 m.setRef(name); 390 391 Iterator i = medias.iterator(); 392 while (i.hasNext()) 393 { 394 if (i.next().equals(m)) 395 { 396 i.remove(); 397 return; 398 } 399 } 400 } 401 } 402 } 403 404 406 409 public Vector getParameters() 410 { 411 return this.parameter; 412 } 413 414 public void setParameters(Vector parameters) 415 { 416 this.parameter = parameters; 417 } 418 419 public void setMediaTypes(Vector mediaTypes) 420 { 421 this.medias = mediaTypes; 422 } 423 424 427 public Vector getMediaTypes() 428 { 429 return this.medias; 430 } 431 432 public Vector getTools() 433 { 434 return this.tools; 435 } 436 437 public void setTools(Vector tools) 438 { 439 this.tools = tools; 440 } 441 442 447 protected void buildNameIndex() 448 { 449 Hashtable idx = new Hashtable (); 450 451 Iterator i = parameter.iterator(); 452 int count = 0; 453 while( i.hasNext() ) 454 { 455 Parameter p = (Parameter)i.next(); 456 idx.put( p.getName(), new Integer (count) ); 457 count++; 458 } 459 460 this.nameIdx = idx; 461 } 462 463 466 private void buildMediasIndex() 467 { 468 Hashtable idx = new Hashtable (); 469 470 Iterator i = medias.iterator(); 471 int count = 0; 472 while( i.hasNext() ) 473 { 474 BaseMediaType b = (BaseMediaType)i.next(); 475 idx.put( b.getRef(), new Integer (count) ); 476 count++; 477 } 478 479 this.mediasIdx = idx; 480 } 481 482 483 public Iterator getToolNames() 484 { 485 synchronized (tools) 486 { 487 if (toolsIdx == null) 488 { 489 buildToolsIndex(); 490 } 491 } 492 493 return toolsIdx.keySet().iterator(); 494 } 495 496 497 503 public ToolDescriptor getTool( String name ) 504 { 505 synchronized (tools) 506 { 507 if (toolsIdx == null) 508 { 509 buildToolsIndex(); 510 } 511 } 512 513 if (name != null) 514 { 515 Integer pos = (Integer )toolsIdx.get(name); 516 517 if (pos != null) 518 { 519 return (ToolDescriptor)tools.elementAt(pos.intValue()); 520 } 521 } 522 523 return null; 524 } 525 526 527 530 public Map getToolMap() 531 { 532 Hashtable map = new Hashtable (); 533 Enumeration en = tools.elements(); 534 while(en.hasMoreElements()) 535 { 536 ToolDescriptor desc = (ToolDescriptor)en.nextElement(); 537 map.put(desc.getName(),desc); 538 } 539 return map; 540 } 541 542 545 public void addTool( ToolDescriptor tool ) 546 { 547 synchronized (tools) 548 { 549 if (tools == null) 550 tools = new Vector (); 551 552 if (toolsIdx == null) 553 buildToolsIndex(); 554 555 tools.addElement( tool ); 556 toolsIdx.put( tool.getName(), new Integer ( tools.size()-1 ) ); 557 } 558 } 559 560 565 public void removeTool( String name ) 566 { 567 if (name == null) return; 568 569 synchronized (tools) 570 { 571 Iterator i = tools.iterator(); 572 while(i.hasNext()) 573 { 574 ToolDescriptor tool = (ToolDescriptor)i.next(); 575 if (tool.getName().equals(name)) 576 { 577 i.remove(); 578 } 579 } 580 581 buildToolsIndex(); 582 } 583 } 584 585 588 private void buildToolsIndex() 589 { 590 Hashtable idx = new Hashtable (); 591 592 Iterator i = tools.iterator(); 593 int count = 0; 594 while( i.hasNext() ) 595 { 596 ToolDescriptor b = (ToolDescriptor)i.next(); 597 idx.put( b.getName(), new Integer (count) ); 598 count++; 599 } 600 601 this.toolsIdx = idx; 602 } 603 604 } | Popular Tags |