Downloads Documentation Community Contribute Demo






Show Sidebar
Login | Register
Show
Ignore:
Timestamp:
05/16/08 13:07:40 (4 months ago)
Author:
bmckown
Message:

complex_obs branch: Attempting to register ComplexObsHandlers with Map<String, ComplexObsHandler>. Only partially working. Ripped out rest of ConceptComplexHandler junk.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openmrs/branches/complex-obs/src/api/org/openmrs/api/impl/ObsServiceImpl.java

    r4166 r4239  
    6464         * This is filled via {@link #setHandlers(Map)} and spring's applicationContext-service.xml object 
    6565         */ 
    66         private static Map<Class<? extends ComplexObsHandler>, ComplexObsHandler> handlers = null; 
     66        private static Map<String, ComplexObsHandler> handlers = null; 
    6767         
    6868         
     
    199199        } 
    200200 
     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                 
    201208        /** 
    202209         * @see org.openmrs.api.ObsService#updateObs(org.openmrs.Obs) 
     
    450457         
    451458        /** 
    452          * Static convenience method to get the ComplexObsHandler associated with a 
     459         * Convenience method to get the ComplexObsHandler associated with a 
    453460         * complex Obs. Returns the ComplexObsHandler. Returns null if the 
    454461         * Obs.isComplexObs() is false or there is an error instantiating the 
     
    463470        public ComplexObsHandler getHandler(Obs obs) { 
    464471                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); 
    466475                } 
    467476                return null; 
     
    510519         * @see org.openmrs.api.ObsService#getHandler(java.lang.String) 
    511520         */ 
    512         public ComplexObsHandler getHandler(String className) { 
     521        public ComplexObsHandler getHandler(String key) { 
    513522                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); 
    515526                } 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); 
    517528                        return null; 
    518529                } 
     
    523534         * @see org.openmrs.api.ObsService#setHandlers(Map) 
    524535         */ 
    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()) { 
    527538                        registerHandler(entry.getKey(), entry.getValue()); 
    528539                } 
     
    532543         * @see org.openmrs.api.ObsService#getHandlers() 
    533544         */ 
    534         public Map<Class<? extends ComplexObsHandler>, ComplexObsHandler> getHandlers() throws APIException { 
     545        public Map<String, ComplexObsHandler> getHandlers() throws APIException { 
    535546                if (handlers == null) 
    536                         handlers = new LinkedHashMap<Class<? extends ComplexObsHandler>, ComplexObsHandler>(); 
     547                        handlers = new LinkedHashMap<String, ComplexObsHandler>(); 
    537548                 
    538549                return handlers; 
     
    542553         * @see org.openmrs.api.ObsService#registerHandler(java.lang.Class, org.openmrs.obs.ComplexObsHandler) 
    543554         */ 
    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); 
    546566        } 
    547567         
     
    550570         */ 
    551571        @SuppressWarnings("unchecked") 
    552     public void registerHandler(String handlerClass) throws APIException { 
     572    public void registerHandler(String key, String handlerClass) throws APIException { 
    553573                try { 
    554574                Class loadedClass = OpenmrsClassLoader.getInstance().loadClass(handlerClass); 
    555                 registerHandler(loadedClass, (ComplexObsHandler)loadedClass.newInstance()); 
     575                registerHandler(key, (ComplexObsHandler)loadedClass.newInstance()); 
    556576                 
    557577        } catch (Exception e) { 
     
    563583         * @see org.openmrs.api.ObsService#removeHandler(java.lang.Class) 
    564584         */ 
    565         public void removeHandler(Class<? extends ComplexObsHandler> renderingClass) { 
    566                 handlers.remove(renderingClass); 
     585        public void removeHandler(String key) { 
     586                handlers.remove(key); 
    567587        } 
    568588