- Timestamp:
- 05/16/08 13:07:40 (4 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
openmrs/branches/complex-obs/src/api/org/openmrs/api/impl/ObsServiceImpl.java
r4166 r4239 64 64 * This is filled via {@link #setHandlers(Map)} and spring's applicationContext-service.xml object 65 65 */ 66 private static Map< Class<? extends ComplexObsHandler>, ComplexObsHandler> handlers = null;66 private static Map<String, ComplexObsHandler> handlers = null; 67 67 68 68 … … 199 199 } 200 200 201 /** 202 * @see org.openmrs.api.ObsService#getComplexData(org.openmrs.Obs) 203 */ 204 public ComplexData getComplexData(Obs obs) throws APIException { 205 return this.getComplexObs(obs.getObsId()).getComplexData(); 206 } 207 201 208 /** 202 209 * @see org.openmrs.api.ObsService#updateObs(org.openmrs.Obs) … … 450 457 451 458 /** 452 * Static convenience method to get the ComplexObsHandler associated with a459 * Convenience method to get the ComplexObsHandler associated with a 453 460 * complex Obs. Returns the ComplexObsHandler. Returns null if the 454 461 * Obs.isComplexObs() is false or there is an error instantiating the … … 463 470 public ComplexObsHandler getHandler(Obs obs) { 464 471 if (obs.getConcept().isComplex()) { 465 return getHandler( ((ConceptComplex)obs.getConcept()).getHandler() ); 472 // return getHandler( 473 String key = ((ConceptComplex)obs.getConcept()).getHandler(); 474 return this.getHandler(key); 466 475 } 467 476 return null; … … 510 519 * @see org.openmrs.api.ObsService#getHandler(java.lang.String) 511 520 */ 512 public ComplexObsHandler getHandler(String className) {521 public ComplexObsHandler getHandler(String key) { 513 522 try { 514 return handlers.get(OpenmrsClassLoader.getInstance().loadClass(className)); 523 //System.out.println(this.getHandler(key).getClass().getCanonicalName()); 524 //return handlers.get(OpenmrsClassLoader.getInstance().loadClass(this.getHandler(key).getClass().getCanonicalName())); 525 return handlers.get(key); 515 526 } catch (Exception ex) { 516 log.error("Failed to get report renderer for " + className, ex);527 log.error("Failed to get ComplexObsHandler for " + this.getHandler(key).getClass().getCanonicalName(), ex); 517 528 return null; 518 529 } … … 523 534 * @see org.openmrs.api.ObsService#setHandlers(Map) 524 535 */ 525 public void setHandlers(Map< Class<? extends ComplexObsHandler>, ComplexObsHandler> newHandlers) throws APIException {526 for (Map.Entry< Class<? extends ComplexObsHandler>, ComplexObsHandler> entry : newHandlers.entrySet()) {536 public void setHandlers(Map<String, ComplexObsHandler> newHandlers) throws APIException { 537 for (Map.Entry<String, ComplexObsHandler> entry : newHandlers.entrySet()) { 527 538 registerHandler(entry.getKey(), entry.getValue()); 528 539 } … … 532 543 * @see org.openmrs.api.ObsService#getHandlers() 533 544 */ 534 public Map< Class<? extends ComplexObsHandler>, ComplexObsHandler> getHandlers() throws APIException {545 public Map<String, ComplexObsHandler> getHandlers() throws APIException { 535 546 if (handlers == null) 536 handlers = new LinkedHashMap< Class<? extends ComplexObsHandler>, ComplexObsHandler>();547 handlers = new LinkedHashMap<String, ComplexObsHandler>(); 537 548 538 549 return handlers; … … 542 553 * @see org.openmrs.api.ObsService#registerHandler(java.lang.Class, org.openmrs.obs.ComplexObsHandler) 543 554 */ 544 public void registerHandler(Class<? extends ComplexObsHandler> handlerClass, ComplexObsHandler handler) throws APIException { 545 getHandlers().put(handlerClass, handler); 555 public void registerHandler(String key, ComplexObsHandler handler) throws APIException { 556 /*TODO: 557 * This is a total hack in order to register the ComplexObsHandler by a "key" word instead of the class name. 558 * Spring seems to insist on using the className no matter how you map it in Application-context.xml 559 * 560 */ 561 //String[] keys = key.split("."); 562 //String name = (keys.length < 2) ? keys[0] : keys[keys.length-1]; 563 System.out.println(key + " ---> " + handler.toString()); 564 System.out.println(key.substring(key.lastIndexOf(".")+1, key.length()) + " ---> " + handler.toString()); 565 getHandlers().put(key.substring(key.lastIndexOf(".")+1, key.length()), handler); 546 566 } 547 567 … … 550 570 */ 551 571 @SuppressWarnings("unchecked") 552 public void registerHandler(String handlerClass) throws APIException {572 public void registerHandler(String key, String handlerClass) throws APIException { 553 573 try { 554 574 Class loadedClass = OpenmrsClassLoader.getInstance().loadClass(handlerClass); 555 registerHandler( loadedClass, (ComplexObsHandler)loadedClass.newInstance());575 registerHandler(key, (ComplexObsHandler)loadedClass.newInstance()); 556 576 557 577 } catch (Exception e) { … … 563 583 * @see org.openmrs.api.ObsService#removeHandler(java.lang.Class) 564 584 */ 565 public void removeHandler( Class<? extends ComplexObsHandler> renderingClass) {566 handlers.remove( renderingClass);585 public void removeHandler(String key) { 586 handlers.remove(key); 567 587 } 568 588