1 9 10 package org.nanocontainer.script; 11 12 import org.picocontainer.Parameter; 13 import org.nanocontainer.ClassNameKey; 14 import org.nanocontainer.NanoContainer; 15 16 17 public class ComponentElementHelper { 18 19 public static void makeComponent(Object cnkey, Object key, Parameter[] parameters, Object klass, NanoContainer current, Object instance) { 20 if (cnkey != null) { 21 key = new ClassNameKey((String )cnkey); 22 } 23 24 if (klass instanceof Class ) { 25 Class clazz = (Class ) klass; 26 key = key == null ? clazz : key; 27 current.getPico().registerComponentImplementation(key, clazz, parameters); 28 } else if (klass instanceof String ) { 29 String className = (String ) klass; 30 key = key == null ? className : key; 31 try { 32 current.registerComponentImplementation(key, className, parameters); 33 } catch (ClassNotFoundException e) { 34 throw new NanoContainerMarkupException("ClassNotFoundException: " + e.getMessage(), e); 35 } 36 } else if (instance != null) { 37 key = key == null ? instance.getClass() : key; 38 current.getPico().registerComponentInstance(key, instance); 39 } else { 40 throw new NanoContainerMarkupException("Must specify a 'class' attribute for a component as a class name (string) or Class."); 41 } 42 } 43 44 45 } 46 | Popular Tags |