@Override
  public <T> T getBusinessObject(SessionContext ctx, Class<T> businessInterface)
      throws IllegalStateException {
    if (businessInterface == null) {
      throw new IllegalStateException("Business interface type cannot be null");
    }

    final Serializable sessionId =
        ((SessionBeanComponentInstance.SessionBeanComponentInstanceContext) ctx).getId();

    if (viewServices.containsKey(businessInterface.getName())) {
      final ServiceController<?> serviceController =
          CurrentServiceRegistry.getServiceRegistry()
              .getRequiredService(viewServices.get(businessInterface.getName()));
      final ComponentView view = (ComponentView) serviceController.getValue();
      final ComponentViewInstance instance;
      if (sessionId != null) {
        instance =
            view.createInstance(
                Collections.<Object, Object>singletonMap(
                    StatefulSessionComponent.SESSION_ATTACH_KEY, sessionId));
      } else {
        instance = view.createInstance();
      }
      return (T) instance.createProxy();
    } else {
      throw new IllegalStateException(
          "View of type " + businessInterface + " not found on bean " + this);
    }
  }
Example #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());
 }
Example #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());
 }
 /**
  * Gets endpoint container lazily.
  *
  * @return endpoint container
  */
 protected ComponentView getComponentView() {
   // we need to check both, otherwise it is possible for
   // componentView to be initialized before reference
   if (componentView == null) {
     synchronized (this) {
       if (componentView == null) {
         componentView = getMSCService(componentViewName, ComponentView.class);
         if (componentView == null) {
           throw WSLogger.ROOT_LOGGER.cannotFindComponentView(componentViewName);
         }
         if (reference == null) {
           try {
             reference = componentView.createInstance();
           } catch (Exception e) {
             throw new RuntimeException(e);
           }
         }
       }
     }
   }
   return componentView;
 }