1 6 7 package org.jfox.ioc; 8 9 import org.jfox.ioc.depend.Dependency; 10 import org.jfox.ioc.depend.DependencyPack; 11 import org.jfox.ioc.exception.ComponentException; 12 import org.jfox.ioc.ext.InterceptableComponent; 13 import org.jfox.ioc.factory.ComponentFactory; 14 import org.jfox.ioc.factory.ConstrComponentFactory; 15 import org.jfox.ioc.factory.DynProxyComponentFactory; 16 import org.jfox.ioc.factory.InstanceComponentFactory; 17 import org.jfox.ioc.factory.PropertyComponentFactory; 18 19 24 25 public class ComponentMetaFactory { 26 27 32 public static ComponentMeta getComponentMeta(Component component) { 33 return new ComponentMeta(new InstanceComponentFactory(component)); 34 } 35 36 43 public static ComponentMeta getComponentMeta(Class implementation) throws ComponentException { 44 return getComponentMeta(implementation,implementation); 45 } 46 47 public static ComponentMeta getComponentMeta(Class superClass,Class implementation) throws ComponentException { 48 return getComponentMeta(superClass,implementation, Dependency.EMPTY_PARAMETERS); 49 } 50 51 public static ComponentMeta getComponentMeta(Class implementation, Dependency[] constructorTypes) throws ComponentException { 52 return getComponentMeta(implementation,implementation,constructorTypes,DependencyPack.EMPTY_PARAMETER_PACKS,true,false); 53 } 54 55 public static ComponentMeta getComponentMeta(Class superClass,Class implementation, Dependency[] constructorTypes) throws ComponentException { 56 return getComponentMeta(superClass,implementation, constructorTypes, DependencyPack.EMPTY_PARAMETER_PACKS, true, false); 57 } 58 59 public static ComponentMeta getComponentMeta(Class superClass, 60 Class implementation, 61 Dependency[] constructTypes, 62 DependencyPack[] setterParams, 63 boolean singleton, 64 boolean typeSingleton) throws ComponentException { 65 ComponentName name = ComponentName.newInstance(superClass); 66 return getComponentMeta(name,implementation,constructTypes,setterParams,singleton,typeSingleton); 67 } 68 69 75 public static ComponentMeta getComponentMeta(Component component, boolean typeSingleton) { 76 ComponentMeta meta = getComponentMeta(component); 77 meta.setTypeSingleton(typeSingleton); 78 return meta; 79 } 80 81 87 public static ComponentMeta getComponentMeta(ComponentName name) 88 throws ComponentException { 89 return getComponentMeta(name,name.getType()); 90 } 91 92 public static ComponentMeta getComponentMeta(ComponentName name, Class implementation) 93 throws ComponentException { 94 return getComponentMeta(name,implementation,Dependency.EMPTY_PARAMETERS); 95 } 96 97 public static ComponentMeta getComponentMeta(ComponentName name, 98 Dependency[] constructorTypes) 99 throws ComponentException { 100 return getComponentMeta(name,name.getType(),constructorTypes); 101 } 102 103 public static ComponentMeta getComponentMeta(ComponentName name, 104 Class implementation, 105 Dependency[] constructorTypes) 106 throws ComponentException { 107 return getComponentMeta(name,implementation,constructorTypes, DependencyPack.EMPTY_PARAMETER_PACKS); 108 } 109 116 public static ComponentMeta getComponentMeta(ComponentName name, 117 Class implementation, 118 Dependency[] constructorTypes, 119 DependencyPack[] setterParams 120 ) throws ComponentException { 121 return getComponentMeta(name,implementation,constructorTypes,setterParams,true,false); 122 } 123 124 public static ComponentMeta getComponentMeta(ComponentName name, 125 Dependency[] constructCompParamPack, 126 DependencyPack[] setterParams, 127 boolean singleton, 128 boolean typeSingleton 129 ) 130 131 throws ComponentException { 132 return getComponentMeta(name,name.getType(),constructCompParamPack,setterParams,singleton,typeSingleton); 133 } 134 135 public static ComponentMeta getComponentMeta(ComponentName name, 136 Class implementation, 137 Dependency[] constrctCompParamPack, 138 DependencyPack[] setterParams, 139 boolean singleton, 140 boolean typeSingleton) 141 142 throws ComponentException { 143 ComponentFactory componentFactory = null; 144 Class superClass = name.getType(); 145 if(!superClass.isAssignableFrom(implementation)){ 146 throw new ComponentException("component name " + name + " 's super class " + superClass.getName() + " is not the superClass the implementation class " + implementation.getName()); 147 } 148 149 if(InterceptableComponent.class.isAssignableFrom(implementation)) { 150 componentFactory = new DynProxyComponentFactory(name, implementation, constrctCompParamPack); 151 } 152 else { 153 componentFactory = new ConstrComponentFactory(name, implementation, constrctCompParamPack); 154 } 155 if(setterParams != null && setterParams.length != 0) { 156 componentFactory = new PropertyComponentFactory((ConstrComponentFactory) componentFactory, setterParams); 157 } 158 159 ComponentMeta meta = new ComponentMeta(componentFactory); 160 meta.setTypeSingleton(typeSingleton); 161 meta.setSingleton(singleton); 162 return meta; 163 } 164 165 public static void main(String [] args) { 166 167 } 168 } 169 170 | Popular Tags |