Esempio n. 1
0
  public <S> S getBusinessObject(Object ejbRef, java.lang.Class<S> businessInterface) {

    EJBLocalObjectImpl localObjectImpl = getEJBLocalObject(ejbRef);

    if (localObjectImpl == null) {
      throw new IllegalStateException("Invalid ejb ref");
    }

    Container container = localObjectImpl.getContainer();
    EjbDescriptor ejbDesc = container.getEjbDescriptor();

    S businessObject = null;

    if (businessInterface != null) {
      String intfName = businessInterface.getName();
      if (ejbDesc.getLocalBusinessClassNames().contains(intfName)) {

        // Get proxy corresponding to this business interface.
        businessObject = (S) localObjectImpl.getClientObject(intfName);

      } else if (ejbDesc.isLocalBean()) {
        // If this is a no-interface view session bean, the bean
        // can be accessed through interfaces in its superclass as well
        boolean isValidBusinessInterface =
            ejbDesc.getNoInterfaceLocalBeanClasses().contains(intfName);
        if ((intfName.equals(ejbDesc.getEjbClassName())) || isValidBusinessInterface) {
          businessObject = (S) localObjectImpl.getClientObject(ejbDesc.getEjbClassName());
        }
      }
    }

    if (businessObject == null) {
      throw new IllegalStateException(
          "Unable to convert ejbRef for ejb "
              + ejbDesc.getName()
              + " to a business object of type "
              + businessInterface);
    }

    return businessObject;
  }
Esempio n. 2
0
  public boolean isRemoved(Object ejbRef) {

    EJBLocalObjectImpl localObjectImpl = getEJBLocalObject(ejbRef);

    if (localObjectImpl == null) {
      throw new UnsupportedOperationException("Invalid ejb ref");
    }

    Container container = localObjectImpl.getContainer();
    EjbDescriptor ejbDesc = container.getEjbDescriptor();
    boolean isStatefulBean = false;

    if (ejbDesc.getType().equals(EjbSessionDescriptor.TYPE)) {

      EjbSessionDescriptor sessionDesc = (EjbSessionDescriptor) ejbDesc;
      isStatefulBean = sessionDesc.isStateful();
    }

    if (!isStatefulBean) {

      // TODO 299 impl is incorrectly calling isRemoved for stateless/singleton
      // beans.  Until it's fixed just return false. Otherwise, any app acquiring
      // stateless/singleton references via 299 will fail until bug is fixed.
      return false;

      // TODO reenable this per SessionObjectReference.isRemoved SPI
      // throw new UnsupportedOperationException("ejbRef for ejb " +
      //   ejbDesc.getName() + " is not a stateful bean ");
    }

    boolean removed = false;

    try {
      ((BaseContainer) container).checkExists(localObjectImpl);
    } catch (Exception e) {
      removed = true;
    }

    return removed;
  }
Esempio n. 3
0
  public void remove(Object ejbRef) {

    EJBLocalObjectImpl localObjectImpl = getEJBLocalObject(ejbRef);

    if (localObjectImpl == null) {
      throw new UnsupportedOperationException("Invalid ejb ref");
    }

    Container container = localObjectImpl.getContainer();
    EjbDescriptor ejbDesc = container.getEjbDescriptor();
    boolean isStatefulBean = false;

    if (ejbDesc.getType().equals(EjbSessionDescriptor.TYPE)) {

      EjbSessionDescriptor sessionDesc = (EjbSessionDescriptor) ejbDesc;
      isStatefulBean = sessionDesc.isStateful();
    }

    if (!isStatefulBean) {

      // TODO 299 impl may incorrectly call this for stateless/singleton
      // beans.  Until it's fixed just treat it as a no-op. Otherwise, any app acquiring
      // stateless/singleton references via 299 could fail until bug is fixed.
      return;

      // TODO reenable this after bug is fixed
      // throw new UnsupportedOperationException("ejbRef for ejb " +
      //       ejbDesc.getName() + " is not a stateful bean ");
    }

    try {
      localObjectImpl.remove();
    } catch (EJBException e) {
      LogFacade.getLogger().log(Level.FINE, "EJBException during remove. ", e);
    } catch (javax.ejb.RemoveException re) {
      throw new NoSuchEJBException(re.getMessage(), re);
    }
  }