1 15 package org.apache.hivemind.impl; 16 17 import java.util.List ; 18 19 import org.apache.hivemind.ApplicationRuntimeException; 20 import org.apache.hivemind.InterceptorStack; 21 import org.apache.hivemind.Location; 22 import org.apache.hivemind.Orderable; 23 import org.apache.hivemind.ServiceInterceptorFactory; 24 import org.apache.hivemind.definition.ServicePointDefinition; 25 import org.apache.hivemind.internal.AbstractServiceInterceptorConstructor; 26 import org.apache.hivemind.internal.Module; 27 import org.apache.hivemind.internal.ServicePoint; 28 import org.apache.hivemind.schema.Schema; 29 import org.apache.hivemind.util.Defense; 30 import org.apache.hivemind.util.InstanceCreationUtils; 31 import org.apache.hivemind.xml.definition.impl.XmlServicePointDefinitionImpl; 32 33 37 public final class InvokeFactoryInterceptorConstructor extends AbstractServiceInterceptorConstructor implements 38 Orderable 39 { 40 private String _factoryServiceId; 41 42 private ServiceInterceptorFactory _factory; 43 44 45 private List _parameters; 46 47 48 private Object _convertedParameters; 49 50 private String _precedingInterceptorIds; 51 52 private String _followingInterceptorIds; 53 54 public InvokeFactoryInterceptorConstructor(Location location) 55 { 56 super(location); 57 } 58 59 62 public String getName() 63 { 64 return _factoryServiceId; 65 } 66 67 public void constructServiceInterceptor(InterceptorStack stack, Module contributingModule) 68 { 69 setup(contributingModule); 70 71 _factory.createInterceptor(stack, contributingModule, _convertedParameters); 72 } 73 74 78 private synchronized void setup(Module contributingModule) 79 { 80 if (_factory == null) 81 { 82 ServicePoint factoryPoint = contributingModule.getServicePoint(_factoryServiceId); 83 84 _factory = (ServiceInterceptorFactory) factoryPoint 85 .getService(ServiceInterceptorFactory.class); 86 87 ServicePointDefinition spd = factoryPoint.getServicePointDefinition(); 88 if (!(spd instanceof XmlServicePointDefinitionImpl)) { 89 throw new ApplicationRuntimeException("ServicePoint used as InterceptorFactory must be of type XmlServicePointDefinitionImpl"); 91 } 92 XmlServicePointDefinitionImpl xmlServicePoint = (XmlServicePointDefinitionImpl) spd; 93 Schema schema = xmlServicePoint.getParametersSchema(); 94 if (schema != null) { 95 96 SchemaProcessorImpl processor = new SchemaProcessorImpl(factoryPoint.getErrorLog(), 97 schema); 98 99 _convertedParameters = constructParametersContainer(schema.getRootElementClassName(), factoryPoint.getModule()); 100 processor.process(_convertedParameters, _parameters, contributingModule); 101 } 102 } 103 } 104 105 public List getParameters() 106 { 107 return _parameters; 108 } 109 110 public void setParameters(List list) 111 { 112 _parameters = list; 113 } 114 115 public void setFactoryServiceId(String string) 116 { 117 _factoryServiceId = string; 118 } 119 120 public Object constructParametersContainer(String containerClassName, Module definingModule) 121 { 122 Defense.notNull(containerClassName, "containerClassName"); 123 124 return InstanceCreationUtils.createInstance( 125 definingModule, 126 containerClassName, 127 getLocation()); 128 } 129 130 public void setFollowingInterceptorIds(String ids) 131 { 132 _followingInterceptorIds = ids; 133 } 134 135 public void setPrecedingInterceptorIds(String ids) 136 { 137 _precedingInterceptorIds = ids; 138 } 139 140 public String getFollowingNames() 141 { 142 return _followingInterceptorIds; 143 } 144 145 public String getPrecedingNames() 146 { 147 return _precedingInterceptorIds; 148 } 149 } | Popular Tags |