/** {@inheritDoc} */
 public Object processInvocation(final InterceptorContext context) throws Exception {
   Object target = targetReference.get().getInstance();
   if (target == null) {
     throw new IllegalStateException("No injection target found");
   }
   // if it's an optional injection and the injection source isn't available, then just proceed by
   // skipping the injection
   if (this.factory == null && this.optionalInjection) {
     return context.proceed();
   }
   ManagedReference reference = factory.getReference();
   boolean ok = false;
   try {
     valueReference.set(reference);
     method.invoke(target, reference.getInstance());
     Object result = context.proceed();
     ok = true;
     return result;
   } finally {
     if (!ok) {
       valueReference.set(null);
       reference.release();
     }
   }
 }
Esempio n. 2
0
 protected <T> T createViewInstanceProxy(
     final Class<T> viewInterface,
     final Map<Object, Object> contextData,
     final ServiceName serviceName) {
   final ServiceController<?> serviceController =
       CurrentServiceContainer.getServiceContainer().getRequiredService(serviceName);
   final ComponentView view = (ComponentView) serviceController.getValue();
   final ManagedReference instance = view.createInstance(contextData);
   return viewInterface.cast(instance.getInstance());
 }
Esempio n. 3
0
 protected <T> T createViewInstanceProxy(
     final Class<T> viewInterface,
     final Map<Object, Object> contextData,
     final ServiceName serviceName) {
   final ServiceController<?> serviceController =
       currentServiceContainer().getRequiredService(serviceName);
   final ComponentView view = (ComponentView) serviceController.getValue();
   final ManagedReference instance;
   try {
     instance = view.createInstance(contextData);
   } catch (Exception e) {
     // TODO: do we need to let the exception propagate here?
     throw new RuntimeException(e);
   }
   return viewInterface.cast(instance.getInstance());
 }