@Override protected void initRegistries() { super.initRegistries(); InjectableFactory.setInstance(new TuscanyInjectableFactory()); }
public void handleRequest(MessageContext context, HandlersChain chain) throws Throwable { SearchResult result = context.getAttribute(SearchResult.class); // create and save the invocation parameters for the found method List<Injectable> formal = result.getMethod().getMetadata().getFormalParameters(); logger.trace("Formal Injectable parameters list is: {}", formal); //$NON-NLS-1$ Object[] parameters = InjectableFactory.getInstance().instantiate(formal, context); if(logger.isTraceEnabled()) { if(parameters == null) { logger.trace("Actual parameters list to inject is: null"); //$NON-NLS-1$ } else { logger.trace("Actual parameters list to inject is: {}", parameters); //$NON-NLS-1$ } } result.setInvocationParameters(parameters); chain.doChain(context); }
private void createFormalParameters() { formalParameters = new LinkedList<Injectable>(); Annotation[][] parameterAnnotations = method.getParameterAnnotations(); Type[] paramTypes = method.getGenericParameterTypes(); for (int pos = 0, limit = paramTypes.length; pos < limit; pos++) { Injectable fp = InjectableFactory.getInstance().create(paramTypes[pos], parameterAnnotations[pos], method, false, null); formalParameters.add(fp); } }
@Override protected Injectable parseAccessibleObject(AccessibleObject field, Type fieldType) { Context context = field.getAnnotation(Context.class); if (context != null) { return InjectableFactory.getInstance().createContextParam(GenericsUtils .getClassType(fieldType, ((Member) field).getDeclaringClass()), field.getAnnotations(), (Member)field); } return null; }
createMatrixParam(matrix.value(), classType, genericType, annotations, member); } else if (path != null) { injectable = createPathParam(path.value(), classType, genericType, annotations, member); } else if (query != null) { injectable = createQueryParam(query.value(), classType, genericType, annotations, member); } else if (header != null) { injectable = createHeaderParam(header.value(), classType, genericType, annotations, member); } else if (cookie != null) { injectable = createCookieParam(cookie.value(), classType, genericType, annotations, member); } else if (form != null) { injectable = createFormParam(form.value(), classType, genericType, annotations, member); } else if (context != null) { injectable = createContextParam(classType, annotations, member); } else { injectable = createEntityParam(classType, genericType, annotations, member);
InjectableFactory.getInstance().instantiate(method.getFormalParameters(), context); try {
@Override protected final Injectable parseAccessibleObject(AccessibleObject field, Type fieldType) { logger.trace("parseAccessibleObject({}, {})", field, fieldType); Injectable injectable = InjectableFactory.getInstance().create(fieldType, field.getAnnotations(), (Member)field, getMetadata().isEncoded(), null); logger.trace("Injectable is {}", injectable); if (injectable.getParamType() == Injectable.ParamType.ENTITY) { // EntityParam should be ignored for fields (see JSR-311 3.2) logger.trace("parseAccessibleObject() returning null"); return null; } logger.trace("parseAccessibleObject() returning {}", injectable); return injectable; }
@Override protected void initRegistries() { super.initRegistries(); InjectableFactory.setInstance(new TuscanyInjectableFactory()); }
/** * creates object (StaticResource or Provider) based on its ClassMetadata * * @param metadata * @param runtimeContext * @return created object */ static Object createObject(ClassMetadata metadata, RuntimeContext runtimeContext) { try { // use constructor to create a prototype ConstructorMetadata constructorMetadata = metadata.getConstructor(); Constructor<?> constructor = constructorMetadata.getConstructor(); List<Injectable> formalParameters = constructorMetadata.getFormalParameters(); Object[] params = InjectableFactory.getInstance().instantiate(formalParameters, runtimeContext); Object object = constructor.newInstance(params); injectFields(object, metadata, runtimeContext); return object; } catch (RuntimeException e) { throw e; } catch (InvocationTargetException e) { Throwable targetException = e.getTargetException(); if (targetException instanceof RuntimeException) { throw (RuntimeException)targetException; } throw new ObjectCreationException(targetException); } catch (Exception e) { throw new ObjectCreationException(e); } }
@Override protected final Injectable parseAccessibleObject(AccessibleObject field, Type fieldType) { Injectable injectable = InjectableFactory.getInstance().create(fieldType, field.getAnnotations(), (Member)field, getMetadata().isEncoded(), null); if (injectable.getParamType() == Injectable.ParamType.ENTITY) { // EntityParam should be ignored for fields (see JSR-311 3.2) return null; } return injectable; }
/** * Initializes registries. Usually there should be no need to override this * method. When creating Resources or Providers registry, ensure that they * use the same instance of the ApplicationValidator. */ protected void initRegistries() { InjectableFactory.setInstance(new ServerInjectableFactory()); if (ofFactoryRegistry == null) { ofFactoryRegistry = new LifecycleManagersRegistry(); ofFactoryRegistry.addFactoryFactory(new ScopeLifecycleManager<Object>()); ofFactoryRegistry.addFactoryFactory(new JSR250LifecycleManager<Object>()); } ApplicationValidator applicationValidator = new ApplicationValidator(); providersRegistry = new ProvidersRegistry(ofFactoryRegistry, applicationValidator); resourceRegistry = new ResourceRegistry(ofFactoryRegistry, applicationValidator, properties); }
InjectableFactory.getInstance().instantiate(method.getFormalParameters(), context); try {
private void mergeFormalParameterMetadata(MethodMetadata metadata, Method method) { logger.trace("mergeFormalParameterMetadata({})", new Object[] {metadata, method}); Type[] parameterTypes = method.getGenericParameterTypes(); List<Injectable> currentParameters = new ArrayList<Injectable>(metadata.getFormalParameters()); metadata.getFormalParameters().clear(); int i = 0; for (Injectable injectable : currentParameters) { Injectable fp = InjectableFactory.getInstance().create(parameterTypes[i], injectable.getAnnotations(), method, getMetadata().isEncoded() || metadata .isEncoded(), metadata.getDefaultValue()); metadata.getFormalParameters().add(fp); ++i; } logger.trace("mergeFormalParameterMetadata exit"); }
private void parseMethodParameters(Method method, MethodMetadata methodMetadata) { logger.trace("parseMethodParameters({}, {}), entry", method, methodMetadata); Annotation[][] parameterAnnotations = method.getParameterAnnotations(); Type[] paramTypes = getParamTypesFilterByXmlElementAnnotation(method); boolean entityParamExists = false; for (int pos = 0, limit = paramTypes.length; pos < limit; pos++) { Injectable fp = InjectableFactory.getInstance().create(paramTypes[pos], parameterAnnotations[pos], method, getMetadata().isEncoded() || methodMetadata .isEncoded(), methodMetadata.getDefaultValue()); if (fp.getParamType() == Injectable.ParamType.ENTITY) { if (entityParamExists) { // we are allowed to have only one entity parameter String methodName = method.getDeclaringClass().getName() + "." + method.getName(); //$NON-NLS-1$ throw new IllegalStateException(Messages .getMessage("resourceMethodMoreThanOneEntityParam", methodName)); //$NON-NLS-1$ } entityParamExists = true; } methodMetadata.getFormalParameters().add(fp); logger.trace("Adding formal parameter {}", fp); } logger.trace("parseMethodParameters(), exit"); }
InjectableFactory.getInstance() .create(paramTypes[pos], parameterAnnotations[pos], constructor,