FileDocCategorySizeDatePackage
EjbSessionDescriptor.javaAPI DocGlassfish v2 API12175Fri May 04 22:31:22 BST 2007com.sun.enterprise.deployment

EjbSessionDescriptor

public final class EjbSessionDescriptor extends EjbDescriptor
Objects of this kind represent the deployment information describing a single Session Ejb, either stateful or stateless.
author
Danny Coward

Fields Summary
private boolean
isStateless
private int
timeout
private Set
postActivateDescs
private Set
prePassivateDescs
private Map
removeMethods
private Set
initMethods
public static final String
TYPE
The Session type String.
public static final String
STATELESS
The String to indicate stalessness.
public static final String
STATEFUL
Idicates statefullness of a session ejb.
private static com.sun.enterprise.util.LocalStringManagerImpl
localStrings
Constructors Summary
public EjbSessionDescriptor()
Default constructor.

 

       	
      
    
public EjbSessionDescriptor(EjbDescriptor other)
The copy constructor.

	super(other);
	if (other instanceof EjbSessionDescriptor) {
	    EjbSessionDescriptor session = (EjbSessionDescriptor) other;
	    this.isStateless = session.isStateless;
	    this.timeout = session.timeout;
	}
    
Methods Summary
public voidaddInitMethod(EjbInitInfo initInfo)

        initMethods.add(initInfo);
    
public voidaddPostActivateDescriptor(LifecycleCallbackDescriptor postActivateDesc)

        String className = postActivateDesc.getLifecycleCallbackClass();
        boolean found = false;
        for (LifecycleCallbackDescriptor next :
             getPostActivateDescriptors()) {
            if (next.getLifecycleCallbackClass().equals(className)) {
                found = true;
                break;
            }
        }
        if (!found) {
            getPostActivateDescriptors().add(postActivateDesc);
        }
    
public voidaddPrePassivateDescriptor(LifecycleCallbackDescriptor prePassivateDesc)

        String className = prePassivateDesc.getLifecycleCallbackClass();
        boolean found = false;
        for (LifecycleCallbackDescriptor next :
             getPrePassivateDescriptors()) {
            if (next.getLifecycleCallbackClass().equals(className)) {
                found = true;
                break;
            }
        }
        if (!found) {
            getPrePassivateDescriptors().add(prePassivateDesc);
        }
    
public voidaddRemoveMethod(EjbRemovalInfo removalInfo)

        removeMethods.put(removalInfo.getRemoveMethod(), removalInfo);
    
public java.util.SetgetAllRemovalInfo()

        return new HashSet<EjbRemovalInfo>(removeMethods.values());
    
public java.util.SetgetInitMethods()

        return new HashSet<EjbInitInfo>(initMethods);
    
public java.util.VectorgetPossibleTransactionAttributes()

        Vector txAttributes = super.getPossibleTransactionAttributes();

        // Session beans that implement SessionSynchronization interface
        // have a limited set of possible transaction attributes.
        if( isStateful() ) {
            try {
                EjbBundleDescriptor ejbBundle = getEjbBundleDescriptor();

                ClassLoader classLoader = ejbBundle.getClassLoader();
                Class ejbClass = classLoader.loadClass(getEjbClassName());
                Class sessionSynchClass = 
                    javax.ejb.SessionSynchronization.class;
                if( sessionSynchClass.isAssignableFrom(ejbClass) ) {
                    txAttributes = new Vector();
                    txAttributes.add(new ContainerTransaction
                        (ContainerTransaction.REQUIRED, ""));
                    txAttributes.add(new ContainerTransaction
                        (ContainerTransaction.REQUIRES_NEW, ""));
                    txAttributes.add(new ContainerTransaction
                        (ContainerTransaction.MANDATORY, ""));
                }
            } catch(Exception e) {
                // Don't treat this as a fatal error.  Just return full
                // set of possible transaction attributes.
            }
        }
        return txAttributes;
    
public LifecycleCallbackDescriptorgetPostActivateDescriptorByClass(java.lang.String className)


        for (LifecycleCallbackDescriptor next :
                 getPostActivateDescriptors()) {
            if (next.getLifecycleCallbackClass().equals(className)) {
                return next;
            }
        }
        return null;
    
public java.util.SetgetPostActivateDescriptors()

        if (postActivateDescs == null) {
            postActivateDescs = 
                new HashSet<LifecycleCallbackDescriptor>(); 
        }
        return postActivateDescs;
    
public LifecycleCallbackDescriptorgetPrePassivateDescriptorByClass(java.lang.String className)


        for (LifecycleCallbackDescriptor next :
                 getPrePassivateDescriptors()) {
            if (next.getLifecycleCallbackClass().equals(className)) {
                return next;
            }
        }
        return null;
    
public java.util.SetgetPrePassivateDescriptors()

        if (prePassivateDescs == null) {
            prePassivateDescs = 
                new HashSet<LifecycleCallbackDescriptor>(); 
        }
        return prePassivateDescs;
    
public EjbRemovalInfogetRemovalInfo(MethodDescriptor method)

return
remove method info for the given method or null if the given method is not a remove method for this stateful session bean.

        // first try to find the exact match
        for (MethodDescriptor methodDesc : removeMethods.keySet()) {
            if (methodDesc.equals(method)) {
                return removeMethods.get(methodDesc);
            }
        }

        // if nothing is found, try to find the loose match
        for (MethodDescriptor methodDesc : removeMethods.keySet()) {
            if (methodDesc.implies(method)) {
                return removeMethods.get(methodDesc);
            }
        }

        return null;
    
public java.lang.StringgetSessionType()
Returns the string STATELESS or STATEFUL according as to whether the bean is stateless or stateful.

	if (this.isStateless()) {
	    return STATELESS;
	} else {
	    return STATEFUL;
	}
    
public intgetTimeout()
Returns the timeout value of this bean.

	return this.timeout;
    
public java.lang.StringgetType()
Returns the type of this bean - always "Session".

	return TYPE;
    
public booleanhasInitMethods()

        return (!initMethods.isEmpty());
    
public booleanhasPostActivateMethod()

        return (getPostActivateDescriptors().size() > 0);
    
public booleanhasPrePassivateMethod()

        return (getPrePassivateDescriptors().size() > 0);
    
public booleanhasRemoveMethods()

        return (!removeMethods.isEmpty());
    
public booleanisStateful()

        return !isStateless();
    
public booleanisStateless()
Returns true if I am describing a stateless session bean.

	return isStateless;
    
public voidprint(java.lang.StringBuffer toStringBuffer)
Returns a formatted String of the attributes of this object.

	toStringBuffer.append("Session descriptor");
	toStringBuffer.append("\n isStateless ").append(isStateless);
	super.print(toStringBuffer);
    
public voidsetSessionType(java.lang.String sessionType)
Accepts the Strings STATELESS or STATEFUL.

	if (STATELESS.equals(sessionType)) {
	    this.setStateless(true);
	    return;
	}
	if (STATEFUL.equals(sessionType)) {
	    this.setStateless(false);
	    return;
	}
	if (this.isBoundsChecking()) {
	    throw new IllegalArgumentException(localStrings.getLocalString(
									   "enterprise.deployment.exceptionsessiontypenotlegaltype",
									   "{0} is not a legal session type for session ejbs. The type must be {1} or {2}", new Object[] {sessionType, STATEFUL, STATELESS}));
	}
    
public voidsetStateless(boolean isStateless)
Sets the isStateless attribute of this session bean.

	this.isStateless = isStateless;
	super.changed();
    
public voidsetTimeout(int timeout)
Sets the timeout value for this session bean.

	this.timeout = timeout;
    
public voidsetTransactionType(java.lang.String transactionType)
Sets the transaction type for this bean. Must be either BEAN_TRANSACTION_TYPE or CONTAINER_TRANSACTION_TYPE.

	boolean isValidType = (BEAN_TRANSACTION_TYPE.equals(transactionType) ||
				CONTAINER_TRANSACTION_TYPE.equals(transactionType));
				
	if (!isValidType && this.isBoundsChecking()) {
	    throw new IllegalArgumentException(localStrings.getLocalString(
									   "enterprise.deployment..exceptointxtypenotlegaltype",
									   "{0} is not a legal transaction type for session beans", new Object[] {transactionType}));
	} else {
	    super.transactionType = transactionType;
	    super.setMethodContainerTransactions(new Hashtable());
	    super.changed();
	}
    
public voidsetType(java.lang.String type)
Sets my type

	throw new IllegalArgumentException(localStrings.getLocalString(
								   "enterprise.deployment.exceptioncannotsettypeofsessionbean",
								   "Cannot set the type of a session bean"));