/*******************************************************************************
 * Copyright (c) 2001, 2006 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.j2ee.ejb.internal.impl;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;

import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.Enumerator;
import org.eclipse.emf.ecore.EAnnotation;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.util.InternalEList;
import org.eclipse.jem.java.JavaClass;
import org.eclipse.jem.java.JavaHelpers;
import org.eclipse.jem.java.JavaParameter;
import org.eclipse.jem.java.JavaRefFactory;
import org.eclipse.jem.java.JavaRefPackage;
import org.eclipse.jem.java.Method;
import org.eclipse.jst.j2ee.common.EJBLocalRef;
import org.eclipse.jst.j2ee.common.EjbRef;
import org.eclipse.jst.j2ee.common.SecurityIdentity;
import org.eclipse.jst.j2ee.common.SecurityRoleRef;
import org.eclipse.jst.j2ee.common.internal.impl.JNDIEnvRefsGroupImpl;
import org.eclipse.jst.j2ee.ejb.EJBJar;
import org.eclipse.jst.j2ee.ejb.EjbFactory;
import org.eclipse.jst.j2ee.ejb.EjbMethodElementComparator;
import org.eclipse.jst.j2ee.ejb.EjbPackage;
import org.eclipse.jst.j2ee.ejb.EnterpriseBean;
import org.eclipse.jst.j2ee.ejb.MethodElement;
import org.eclipse.jst.j2ee.ejb.MethodElementKind;
import org.eclipse.jst.j2ee.ejb.MethodPermission;
import org.eclipse.jst.j2ee.ejb.MethodTransaction;
import org.eclipse.jst.j2ee.internal.J2EEVersionConstants;
import org.eclipse.jst.j2ee.internal.common.J2EEVersionResource;
import org.eclipse.wst.common.internal.emf.utilities.Revisit;

/**
 * @generated
 * EnterpriseJavaBean is a class.  It can have instances, someone could write an instance document containing Departments and Employees.  It also has attributes, operations, and associations.  These are actually derived//filtered from its implementation classes and interfaces.  For mapping and browsing purposes, though, you would like the EJB to appear as a class.  
 * 
 * In this light, even Session Beans can have associations and properties implemented by their bean.  For example, it would be meaningful to describe associations from a Session to the Entities which it uses to perform its work.
 */
public abstract class EnterpriseBeanImpl extends JNDIEnvRefsGroupImpl implements EnterpriseBean {

	protected final static Method[] EMPTY_METHOD_ARRAY = new Method[0];
	protected static final String METHOD_ELEMENT_NAME = "MethodElement"; //$NON-NLS-1$
	/**
	 * The default value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected static final String NAME_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected String name = NAME_EDEFAULT;

	/**
	 * @generated This field/method will be replaced during code generation.
	 */
	protected EList securityRoleRefs = null;
	/**
	 * @generated This field/method will be replaced during code generation.
	 */
	protected JavaClass ejbClass = null;
	/**
	 * @generated This field/method will be replaced during code generation.
	 */
	protected JavaClass homeInterface = null;
	/**
	 * @generated This field/method will be replaced during code generation.
	 */
	protected JavaClass remoteInterface = null;
	/**
	 * @generated This field/method will be replaced during code generation.
	 */
	protected SecurityIdentity securityIdentity = null;
	/**
	 * @generated This field/method will be replaced during code generation.
	 */
	protected JavaClass localHomeInterface = null;
	/**
	 * @generated This field/method will be replaced during code generation.
	 */
	protected JavaClass localInterface = null;
	protected EjbMethodElementComparator defaultMethodElementComparator;
	public EnterpriseBeanImpl() {
		super();
	}
	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return EjbPackage.Literals.ENTERPRISE_BEAN;
	}

	/**
	 * createClassRef - return a JavaURL reference to the named Java class
	 */
	public JavaClass createClassRef(String targetName) {
		return getJavaRefFactory().createClassRef(targetName);
	}

	protected List createMethodElements(List signatures, Enumerator aType) {
		return createMethodElements(METHOD_ELEMENT_NAME, signatures, aType);
	}
	
	protected List createMethodElements(String meTypeName, List signatures, Enumerator aType) {
		int size = signatures.size();
		List methodElements = new ArrayList(size);
		String signature;
		MethodElement me;
		for (int i = 0; i < size; i++) {
			signature = (String) signatures.get(i);
			me = (MethodElement) getEjbFactory().create((EClass)getEjbPackage().getEClassifier(meTypeName));
			me.setEnterpriseBean(this);
			me.setType((MethodElementKind)aType);
			me.initializeFromSignature(signature);
			methodElements.add(me);
		}
		return methodElements;
	}

	public List createMethodElements(List someMethods, JavaClass anInterface) {
		return createMethodElements(METHOD_ELEMENT_NAME, someMethods, anInterface);
	}
	
	public List createMethodElements(String meTypeName, List someMethods, JavaClass anInterface) {
		if (anInterface == null)
			return Collections.EMPTY_LIST;
		List signatures = getMethodElementSignatures(someMethods);
		Collections.sort(signatures);
		Enumerator enumerator = getMethodElementKindLiteral(anInterface);
		return createMethodElements(meTypeName, signatures, enumerator);
	}
	
	protected Enumerator getMethodElementKindLiteral(JavaClass anInterface) {
		Enumerator enumerator = MethodElementKind.UNSPECIFIED_LITERAL;
		if (anInterface == getHomeInterface())
			enumerator = MethodElementKind.HOME_LITERAL;
		else if (anInterface == getRemoteInterface())
			enumerator = MethodElementKind.REMOTE_LITERAL;
		else if (anInterface == getLocalHomeInterface())
			enumerator = MethodElementKind.LOCAL_HOME_LITERAL;
		else if (anInterface == getLocalInterface())
			enumerator = MethodElementKind.LOCAL_LITERAL;
		return enumerator;
	}
	
	protected List getMethodElementSignatures(List someMethods) {
		int size = someMethods.size();
		List signatures = new ArrayList(size);
		Method method;
		for (int i = 0; i < size; i++) {
			method = (Method) someMethods.get(i);
			signatures.add(method.getMethodElementSignature());
		}
		return signatures;
	}
	/**
	 * This method will return a List of newly created MethodElements
	 * that represent all the possible MethodElements that can be created
	 * and are common to both the Home and Remote interfaces.  These MethodElements are not contained and will
	 * not be serialized and should not be added to the model.  Their intention is
	 * solely for comparing with actual MethodElements contained in the model.
	 * @deprecated use getAvailableUnspecifiedMethodElements();
	 */
	public List getAvailableCommonMethodElements() {
		return getAvailableUnspecifiedMethodElements();
	}
	/**
	 * This method will return a List of newly created MethodElements
	 * that represent all the possible MethodElements that can be created
	 * and are common to both the Home and Remote interfaces.  These MethodElements are not contained and will
	 * not be serialized and should not be added to the model.  Their intention is
	 * solely for comparing with actual MethodElements contained in the model.
	 */
	public List getAvailableUnspecifiedMethodElements() {
		List commonSigs = getAvailableUnspecifiedMethodElementSignatures();
		return createMethodElements(commonSigs, MethodElementKind.UNSPECIFIED_LITERAL);
	}
	protected List gatherCommonSignatures(List sigCollections) {
		if (sigCollections.isEmpty()) return sigCollections;
		List first = (List)sigCollections.get(0);
		if (sigCollections.size() == 1) return first;
		List result = new ArrayList(first.size());
		sigCollections.remove(0);
		String sig = null;
		boolean contains = false;
		for (int i = 0; i < first.size(); i++) {
			contains = false;
			sig = (String) first.get(i);
			List list = null;
			for (int j = 0; j < sigCollections.size(); j++) {
				list = (List) sigCollections.get(j);
				if (list.contains(sig))
					contains = true;
			}
			if (contains)
				result.add(sig);
		}
		return result;
	}
	/**
	 * Return a List of MethodElements that are set for a particular EObject
	 * which can be a MethodTransaction or a MethodPermission.
	 */
	protected List getExistingMethodElements(EObject refObject) {
		if (refObject != null) {
			EjbPackage pack = getEjbPackage();
			if (refObject.eClass() == pack.getMethodTransaction())
				return ((MethodTransaction)refObject).getMethodElements(this);
			if (refObject.eClass() == pack.getMethodPermission())
				return ((MethodPermission)refObject).getMethodElements(this);
		}
		return Collections.EMPTY_LIST;
	}
	/**
	 * This method will return a List of MethodElements signatures
	 * that represent all the possible MethodElements that can be created
	 * and are common to both the Home and Remote interfaces.
	 * @deprecated use getAvailableUnspecifiedMethodElementSignatures();
	 */
	public List getAvailableCommonMethodElementSignatures() {
		return getAvailableUnspecifiedMethodElementSignatures();
	}
	/**
	 * This method will return a List of MethodElements signatures
	 * that represent all the possible MethodElements that can be created
	 * and are common to both the Home and Remote interfaces.
	 */
	public List getAvailableUnspecifiedMethodElementSignatures() {
		List sigCollections = new ArrayList();
		if (getHomeInterface() != null)
			sigCollections.add(getHomeInterface().getMethodElementSignatures());
		if (getRemoteInterface() != null)
			sigCollections.add(getRemoteInterface().getMethodElementSignatures());
		if (getLocalHomeInterface() != null)
			sigCollections.add(getLocalHomeInterface().getMethodElementSignatures());
		if (getLocalInterface() != null)
			sigCollections.add(getLocalInterface().getMethodElementSignatures());	
		return gatherCommonSignatures(sigCollections);
	}
	/**
	 * This method will return a List of newly created MethodElements
	 * that represent all the possible MethodElements that can be created
	 * for the Home interface.  These MethodElements are not contained and will
	 * not be serialized and should not be added to the model.  Their intention is
	 * solely for comparing with actual MethodElements contained in the model.
	 */
	public List getAvailableHomeMethodElements() {
		return getAvailableMethodElements(getHomeInterface(), MethodElementKind.HOME_LITERAL);
	}
	/**
	 * This method will return a List of newly created MethodElements
	 * that represent all the possible MethodElements that can be created
	 * for the Local Home interface.  These MethodElements are not contained and will
	 * not be serialized and should not be added to the model.  Their intention is
	 * solely for comparing with actual MethodElements contained in the model.
	 */
	public List getAvailableLocalHomeMethodElements() {
		return getAvailableMethodElements(getLocalHomeInterface(), MethodElementKind.LOCAL_HOME_LITERAL);
	}
	/**
	 * This method will return a List of newly created MethodElements
	 * that represent all the possible MethodElements that can be created
	 * for the Local interface.  These MethodElements are not contained and will
	 * not be serialized and should not be added to the model.  Their intention is
	 * solely for comparing with actual MethodElements contained in the model.
	 */
	public List getAvailableLocalMethodElements() {
		return getAvailableMethodElements(getLocalInterface(), MethodElementKind.LOCAL_LITERAL);
	}

	public List getAvailableServiceEndpointMethodElements(){
		return getAvailableMethodElements(getServiceEndpoint(), MethodElementKind.SERVICE_ENDPOINT_LITERAL);
	}
	
	protected List getAvailableMethodElements(JavaClass anInterface, Enumerator aType) {
		if (anInterface == null)
			return Collections.EMPTY_LIST;
		List signatures = anInterface.getMethodElementSignatures();
		return createMethodElements(signatures, aType);
	}
	/**
	 * This method will return a List of newly created MethodElements
	 * that represent all the possible MethodElements that can be created
	 * for the Remote interface.  These MethodElements are not contained and will
	 * not be serialized and should not be added to the model.  Their intention is
	 * solely for comparing with actual MethodElements contained in the model.
	 */
	public List getAvailableRemoteMethodElements() {
		return getAvailableMethodElements(getRemoteInterface(), MethodElementKind.REMOTE_LITERAL);
	}
	
	/*
	 * See EnterpriseBean#getExistingOrAvailableMethodElements(EObject, Comparator);
	 */
	public List getExistingOrAvailableMethodElements(EObject refObject, Comparator comparator) {
		List result = new ArrayList();
		result.addAll(getAvailableHomeMethodElements());
		result.addAll(getAvailableRemoteMethodElements());
		result.addAll(getAvailableLocalHomeMethodElements());
		result.addAll(getAvailableLocalMethodElements());
		result.addAll(getAvailableServiceEndpointMethodElements());
		result.addAll(getAvailableUnspecifiedMethodElements());
		
		List list = getEjbClass().getImplementsInterfaces();
		Iterator it = list.iterator();
		while( it.hasNext()){
			JavaClass  interfaceClass = (JavaClass)it.next();
			String interfaceName = interfaceClass.getQualifiedName();
			if( !interfaceName.equals("javax.ejb.MessageDrivenBean") &&  //$NON-NLS-1$
					!interfaceName.equals("javax.ejb.EntityBean")&& //$NON-NLS-1$
					!interfaceName.equals("javax.ejb.SessionBean")){ //$NON-NLS-1$
				result.addAll( getAvailableMethodElements(interfaceClass, MethodElementKind.UNSPECIFIED_LITERAL));
			}
		}
		
		unionMethodElements(result, getExistingMethodElements(refObject));
		Collections.sort(result, comparator);
		return result;
	}
	/*
	 * See EnterpriseBean#getExistingOrAvailableMethodElements(EObject);
	 */
	public List getExistingOrAvailableMethodElements(EObject refObject) {
		return getExistingOrAvailableMethodElements(refObject, getDefaultMethodElementComparator());	
	}
	
	protected EjbMethodElementComparator getDefaultMethodElementComparator() {
		if (defaultMethodElementComparator == null)
			defaultMethodElementComparator = new EjbMethodElementComparator();
		return defaultMethodElementComparator;
	}
	protected void unionMethodElements(List sourceMethodElements, List additionalMethodElements) {
		MethodElement sourceME, additionalME;
		int sourceSize, addSize;
		sourceSize = sourceMethodElements.size();
		addSize = additionalMethodElements.size();
		List foundElements = new ArrayList(addSize);
		boolean found = false;
		for (int i = 0; i < addSize; i++){
			found = false;
			additionalME = (MethodElement) additionalMethodElements.get(i);
			sourceME = null;
			for (int ii = 0; ii < sourceSize; ii++){
				sourceME = (MethodElement) sourceMethodElements.get(ii);
				if (sourceME.isEquivalent(additionalME)) {
					found = true;
					break;
				}
			}
			if (found)
				foundElements.add(sourceME);
		}
		sourceMethodElements.removeAll(foundElements);
		sourceMethodElements.addAll(additionalMethodElements);
	}
	public String getEjbClassName() {
		getEjbClass();
		return (ejbClass == null) ? null : ejbClass.getQualifiedName();
	}
	protected EjbPackage getEjbPackage() {
		return EjbFactoryImpl.getPackage();
	}
	protected EjbFactory getEjbFactory() {
		return ((EjbPackage)EPackage.Registry.INSTANCE.getEPackage(EjbPackage.eNS_URI)).getEjbFactory();
	}
	public EjbRef getEquivalentEjbRef(EjbRef anEjbRef) {
		return getEquivalentEjbRef(anEjbRef, getEjbRefs());
	}
	public EJBLocalRef getEquivalentEJBLocalRef(EJBLocalRef anEjbLocalRef) {
		return (EJBLocalRef) getEquivalentEjbRef(anEjbLocalRef, getEjbLocalRefs());
	}
	private EjbRef getEquivalentEjbRef(EjbRef anEjbRef, List someRefs) {
		if (anEjbRef == null)
			return null;
		int size = someRefs.size();
		EjbRef ref;
		for (int i = 0; i < size; i++) {
			ref = (EjbRef) someRefs.get(i);
			if (ref.isEquivalent(anEjbRef))
				return ref;
		}
		return null;
	}
	public String getHomeInterfaceName() {
		getHomeInterface();
		return homeInterface == null ? null : homeInterface.getQualifiedName();
	}
	/**
	 * See <code>getMethods<code> for comment
	 */
	public Method[] getHomeMethodsForDeployment() {
		return (getHomeInterface() != null ? getMethods(getHomeInterface()) : EMPTY_METHOD_ARRAY);
	}
	private JavaRefFactory getJavaRefFactory() {
		return ((JavaRefPackage)EPackage.Registry.INSTANCE.getEPackage(JavaRefPackage.eNS_URI)).getJavaRefFactory();
	}
	public EjbRef getLinkedEJBReference(EnterpriseBean anEJB) {
		return getLinkedEJBReference(anEJB, getEjbRefs());
	}
	public EJBLocalRef getLinkedEJBLocalReference(EnterpriseBean anEJB) {
		return (EJBLocalRef) getLinkedEJBReference(anEJB, getEjbLocalRefs());
	}
	private EjbRef getLinkedEJBReference(EnterpriseBean anEJB, List someRefs) {
		if (anEJB == null)
			return null;
		int size = someRefs.size();
		EjbRef ref;
		for (int i = 0; i < size; i++) {
			ref = (EjbRef) someRefs.get(i);
			if (ref.isLinked(anEJB))
				return ref;
		}
		return null;
	}
	public String getLocalHomeInterfaceName() {
		getLocalHomeInterface();
		return localHomeInterface == null ? null : localHomeInterface.getQualifiedName();
	}
	/**
	 * See <code>getMethods<code> for comment
	 */
	public Method[] getLocalHomeMethodsForDeployment() {
		return (getLocalHomeInterface() != null ? getMethods(getLocalHomeInterface()) : EMPTY_METHOD_ARRAY);
	}
	public String getLocalInterfaceName() {
		getLocalInterface();
		return localInterface == null ? null : localInterface.getQualifiedName();
	}
	/**
	 * Retrieve an ordered list of methods for the given JavaClass.
	 * The list should include all non-static, public methods that are
	 * not inherited from javax.ejb.EJBObject
	 * This uses the algorithm that web sphere currently uses, and could
	 * be subject to change
	 * Creation date: (8/21/00 1:41:03 PM)
	 * @param intf JavaClass
	 */
	public static Method[] getMethods(JavaClass intf) {
		Method[] allMethods = intf.listMethodExtended();
		java.util.Vector resultVector = new java.util.Vector(allMethods.length);
		java.util.Hashtable methodNameTable = new java.util.Hashtable();

		//----------------------------------------------------------------
		// Iterate over the list returned by "listMethodExtended" and
		// filter out methods belonging to the EJBObject interface
		// and method synonyms. 
		//
		// Method synonyms correspond to overrides. For all synonyms
		// keep the method instance declared on the most specific class. 
		// How do you determine the most specific class? Don't know.
		// For now, if the method is declared on the interface class
		// it always overrides others.
		//----------------------------------------------------------------

		Method[] result = null;

		for (int i = 0; i < allMethods.length; i++) {
			Method m = allMethods[i];

			//---------------------------
			// Filter out static methods
			//---------------------------

			if (m.isStatic()) {
				continue;
			}

			String mKey = methodKey(m);

			String interfaceName = m.getContainingJavaClass().getJavaName();
			if (!interfaceName.equals("javax.ejb.EJBObject")) { //$NON-NLS-1$
				Method synonym = (Method) methodNameTable.get(mKey);
				if (synonym == null) {
					methodNameTable.put(mKey, m);
					resultVector.addElement(m);
				} else {
					//---------------------------------------------
					// Method declared on most specific class wins
					//---------------------------------------------
					JavaClass mClass = m.getContainingJavaClass();
					JavaClass sClass = synonym.getContainingJavaClass();
					if (sClass.implementsInterface(mClass)) {
						resultVector.removeElement(synonym);
						methodNameTable.put(mKey, m);
						resultVector.addElement(m);
					}
				}
			}
		}

		result = new Method[resultVector.size()];
		resultVector.copyInto(result);
		return sortMethods(result);
	}
	public String getRemoteInterfaceName() {
		getRemoteInterface();
		return remoteInterface == null ? null : remoteInterface.getQualifiedName();
	}
	/**
	 * See <code>getMethods<code> for comment
	 */
	public Method[] getRemoteMethodsForDeployment() {
		return getMethods(getRemoteInterface());
	}
	/**
	 * Return true if @aJavaClass as equal to the
	 * home, remote, bean class, or key class.
	 */
	public boolean hasJavaReference(JavaClass aJavaClass) {
		if (aJavaClass != null) {
			return aJavaClass.equals(getEjbClass())||
					aJavaClass.equals(getRemoteInterface()) || 
					aJavaClass.equals(getHomeInterface()) || 
					aJavaClass.equals(getLocalInterface()) ||
					aJavaClass.equals(getLocalHomeInterface());
		}
		return false;
	}
	/**
	 * Return true if this ejb has BeanManagedPersistance.
	 */
	public boolean isBeanManagedEntity() {
		return isEntity() && !isContainerManagedEntity();
	}
	/**
	 * isContainerManagedEntity method comment.
	 */
	public boolean isContainerManagedEntity() {
		return false;
	}
	//Return false by default
	public boolean isEntity() {
		return false;
	}
	//Return false by default
	public boolean isMessageDriven() {
		return false;
	}
	//Return false by default
	public boolean isSession() {
		return false;
	}
	/**
	 * @deprecated - Use getEjbJar().getVersionID()
	 * isVersion1_X method comment.
	 */
	public boolean isVersion1_X() {
		if (getEjbJar() != null)
			return getEjbJar().getVersionID() <= J2EEVersionConstants.EJB_1_1_ID;
		Revisit.revisit(); //jsholl this should throw an exception. if there is not JAR then the version is undefined
		return false;
	}
	/**
	 * @deprecated - Use getEjbJar().getVersionID()
	 * isVersion2_X method comment.
	 */
	public boolean isVersion2_X() {
		if (getEjbJar() != null) {
			return getEjbJar().getVersionID() >= J2EEVersionConstants.EJB_1_1_ID;
		}
		Revisit.revisit(); //jsholl this should throw an exception. if there is not JAR then the version is undefined
		return false;
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.jst.j2ee.internal.ejb.EnterpriseBean#getVersionID()
	 */
	public int getVersionID() throws IllegalStateException {
		J2EEVersionResource res = (J2EEVersionResource) eResource();
		if (res == null) throw new IllegalStateException();
		return res.getModuleVersionID();
	}

	
	/*
	 * @see EnterpriseBean#hasLocalClient()
	 */
	public boolean hasLocalClient() {
		return getLocalInterface() != null && getLocalHomeInterface() != null;
	}

	/*
	 * @see EnterpriseBean#hasRemoteClient()
	 */
	public boolean hasRemoteClient() {
		return getRemoteInterface() != null && getHomeInterface() != null;
	}
	
	/**
	 *  Get method name string of form: 
	 *  methodName(class name of arg1,class name of arg2,...)
	 * Creation date: (8/24/00 1:21:10 PM)
	 * @return String
	 * @param m Method
	 */
	private static String methodKey(Method m) {
		StringBuffer result = new StringBuffer(m.getName());

		result.append("("); //$NON-NLS-1$

		java.util.List args = m.getParameters();
		JavaParameter arg;
		for (int i = 0; i < args.size(); i++) {
			arg = (JavaParameter) args.get(i);
			result.append(((JavaHelpers) arg.getEType()).getJavaName());
			result.append(","); //$NON-NLS-1$
		}
		result.append(")"); //$NON-NLS-1$
		return result.toString();
	}
	public Object primRefValue(EObject feature) {
		switch (eDerivedStructuralFeatureID(((EStructuralFeature)feature).getFeatureID(), ((EStructuralFeature)feature).getContainerClass())) {
			case EjbPackage.ENTERPRISE_BEAN__DESCRIPTION :
				return getDescription();
			case EjbPackage.ENTERPRISE_BEAN__DISPLAY_NAME :
				return getDisplayName();
			case EjbPackage.ENTERPRISE_BEAN__SMALL_ICON :
				return getSmallIcon();
			case EjbPackage.ENTERPRISE_BEAN__LARGE_ICON :
				return getLargeIcon();
			case EjbPackage.ENTERPRISE_BEAN__RESOURCE_REFS :
				return getResourceRefs();
			case EjbPackage.ENTERPRISE_BEAN__EJB_CLASS :
				return getEjbClass();
			case EjbPackage.ENTERPRISE_BEAN__HOME_INTERFACE :
				return getHomeInterface();
			case EjbPackage.ENTERPRISE_BEAN__REMOTE_INTERFACE :
				return getRemoteInterface();
			case EjbPackage.ENTERPRISE_BEAN__ENVIRONMENT_PROPERTIES :
				return getEnvironmentProperties();
			case EjbPackage.ENTERPRISE_BEAN__SECURITY_ROLE_REFS :
				return getSecurityRoleRefs();
			case EjbPackage.ENTERPRISE_BEAN__EJB_REFS :
				return getEjbRefs();
			case EjbPackage.ENTERPRISE_BEAN__EJB_LOCAL_REFS :
				return getEjbLocalRefs();
			case EjbPackage.ENTERPRISE_BEAN__RESOURCE_ENV_REFS :
				return getResourceEnvRefs();
			case EjbPackage.ENTERPRISE_BEAN__SECURITY_IDENTITY :
				return getSecurityIdentity();
			case EjbPackage.ENTERPRISE_BEAN__NAME :
				return getName();
		}
		return null;
	}
	/**
	 * @see org.eclipse.jst.j2ee.internal.ejb.EnterpriseBean
	 */
	public void reSyncSecurityRoleRef(java.lang.String existingRoleName, java.lang.String newRoleName) {
		List roleRefs = getSecurityRoleRefs();
		for (int i = 0; i < roleRefs.size(); i++) {
			SecurityRoleRef roleRef = (SecurityRoleRef) roleRefs.get(i);
			if (roleRef.getLink() != null && roleRef.getLink().equals(existingRoleName))
				roleRef.setLink(newRoleName);
		}
	}
	public void setEjbClassName(String ejbClassName) {
		eSet(EjbPackage.eINSTANCE.getEnterpriseBean_EjbClass(), createClassRef(ejbClassName));
	}
	public void setHomeInterfaceName(String homeInterfaceName) {
		eSet(EjbPackage.eINSTANCE.getEnterpriseBean_HomeInterface(), createClassRef(homeInterfaceName));
	}
	public void setLocalHomeInterfaceName(String localHomeInterfaceName) {
		eSet(EjbPackage.eINSTANCE.getEnterpriseBean_LocalHomeInterface(), createClassRef(localHomeInterfaceName));
	}
	public void setLocalInterfaceName(String localInterfaceName) {
		eSet(EjbPackage.eINSTANCE.getEnterpriseBean_LocalInterface(), createClassRef(localInterfaceName));
	}
	public void setRemoteInterfaceName(String remoteInterfaceName) {
		eSet(EjbPackage.eINSTANCE.getEnterpriseBean_RemoteInterface(), createClassRef(remoteInterfaceName));
	}
	/**
	 * Insert the method's description here.
	 * Creation date: (8/24/00 1:32:13 PM)
	 * @return Method[]
	 * @param methods Method[]
	 */
	private static Method[] sortMethods(Method[] methods) {
		Method result[] = new Method[methods.length];

		/**
		 *  Insert each element of given list of methods into result
		 *  arary in sorted order
		 */

		for (int i = 0; i < methods.length; i++) {
			Method currMethod = methods[i];
			String currMethodName = currMethod.getSignature();
			int insertIndex = 0;
			while (insertIndex < i) {
				if (currMethodName.compareTo(result[insertIndex].getSignature()) <= 0) {
					break;
				}
				insertIndex++;
			}

			for (int j = insertIndex; j <= i; j++) {
				Method tmpMethod = result[j];
				result[j] = currMethod;
				currMethod = tmpMethod;
			}
		}
		return result;
	}
	@Override
	public String toString() {
		return getClass().getName() + "(" + getName() + ")"; //$NON-NLS-1$ //$NON-NLS-2$
	}
	/**
	 *
	 */
	@Override
	public void setDisplayName(String newDisplayName) {
		super.setDisplayName(newDisplayName);
	}
	
	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getName() {
		return name;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setName(String newName) {
		String oldName = name;
		name = newName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, EjbPackage.ENTERPRISE_BEAN__NAME, oldName, name));
	}

	/**
	 * @generated This field/method will be replaced during code generation 
	 */
	public EList getSecurityRoleRefs() {
		if (securityRoleRefs == null) {
			securityRoleRefs = new EObjectContainmentEList(SecurityRoleRef.class, this, EjbPackage.ENTERPRISE_BEAN__SECURITY_ROLE_REFS);
		}
		return securityRoleRefs;
	}

    /**
     * Handwritten version of getEjbClass():
     */
 
 
    public JavaClass getEjbClass()  { 
       if (ejbClass != null && ejbClass.eIsProxy()) { 
          JavaClass oldEjbClass = ejbClass; 
          JavaClass resolved = (JavaClass)EcoreUtil.resolve(ejbClass, this); 
          resolved(this.ejbClass, resolved);
          this.ejbClass = resolved;
          if (ejbClass != oldEjbClass) { 
             if (eNotificationRequired()) 
                eNotify(new ENotificationImpl(this, Notification.RESOLVE, EjbPackage.ENTERPRISE_BEAN__EJB_CLASS, oldEjbClass, ejbClass)); 
          } 
       } 
       return ejbClass; 
    } 
 
         

	/**
	 * @generated This field/method will be replaced during code generation.
	 */
	public void setEjbClass(JavaClass newEjbClass) {
		JavaClass oldEjbClass = ejbClass;
		ejbClass = newEjbClass;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, EjbPackage.ENTERPRISE_BEAN__EJB_CLASS, oldEjbClass, ejbClass));
	}

	/**
	 * @generated This field/method will be replaced during code generation 
	 */
	public JavaClass getHomeInterface() {
		if (homeInterface != null && homeInterface.eIsProxy()) {
			InternalEObject oldHomeInterface = (InternalEObject)homeInterface;
			homeInterface = (JavaClass)eResolveProxy(oldHomeInterface);
			if (homeInterface != oldHomeInterface) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, EjbPackage.ENTERPRISE_BEAN__HOME_INTERFACE, oldHomeInterface, homeInterface));
			}
		}
		return homeInterface;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public JavaClass basicGetHomeInterface() {
		return homeInterface;
	}

	/**
	 * @generated This field/method will be replaced during code generation.
	 */
	public void setHomeInterface(JavaClass newHomeInterface) {
		JavaClass oldHomeInterface = homeInterface;
		homeInterface = newHomeInterface;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, EjbPackage.ENTERPRISE_BEAN__HOME_INTERFACE, oldHomeInterface, homeInterface));
	}

	/**
	 * @generated This field/method will be replaced during code generation 
	 */
	public JavaClass getRemoteInterface() {
		if (remoteInterface != null && remoteInterface.eIsProxy()) {
			InternalEObject oldRemoteInterface = (InternalEObject)remoteInterface;
			remoteInterface = (JavaClass)eResolveProxy(oldRemoteInterface);
			if (remoteInterface != oldRemoteInterface) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, EjbPackage.ENTERPRISE_BEAN__REMOTE_INTERFACE, oldRemoteInterface, remoteInterface));
			}
		}
		return remoteInterface;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public JavaClass basicGetRemoteInterface() {
		return remoteInterface;
	}

	/**
	 * @generated This field/method will be replaced during code generation.
	 */
	public void setRemoteInterface(JavaClass newRemoteInterface) {
		JavaClass oldRemoteInterface = remoteInterface;
		remoteInterface = newRemoteInterface;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, EjbPackage.ENTERPRISE_BEAN__REMOTE_INTERFACE, oldRemoteInterface, remoteInterface));
	}

	/**
	 * @generated This field/method will be replaced during code generation 
	 */
	public EJBJar getEjbJar() {
		if (eContainerFeatureID != EjbPackage.ENTERPRISE_BEAN__EJB_JAR) return null;
		return (EJBJar)eContainer();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetEjbJar(EJBJar newEjbJar, NotificationChain msgs) {
		msgs = eBasicSetContainer((InternalEObject)newEjbJar, EjbPackage.ENTERPRISE_BEAN__EJB_JAR, msgs);
		return msgs;
	}

	/**
	 * @generated This field/method will be replaced during code generation.
	 */
	public void setEjbJar(EJBJar newEjbJar) {
		if (newEjbJar != eInternalContainer() || (eContainerFeatureID != EjbPackage.ENTERPRISE_BEAN__EJB_JAR && newEjbJar != null)) {
			if (EcoreUtil.isAncestor(this, newEjbJar))
				throw new IllegalArgumentException("Recursive containment not allowed for " + toString()); //$NON-NLS-1$
			NotificationChain msgs = null;
			if (eInternalContainer() != null)
				msgs = eBasicRemoveFromContainer(msgs);
			if (newEjbJar != null)
				msgs = ((InternalEObject)newEjbJar).eInverseAdd(this, EjbPackage.EJB_JAR__ENTERPRISE_BEANS, EJBJar.class, msgs);
			msgs = basicSetEjbJar(newEjbJar, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, EjbPackage.ENTERPRISE_BEAN__EJB_JAR, newEjbJar, newEjbJar));
	}

	/**
	 * @generated This field/method will be replaced during code generation 
	 * The security-identity element specifies whether the caller's security identity is to be used for the execution of the methods of the enterprise bean or whether a specific run-as identity is to be used. It
	 * contains an optional description and a specification of the security identity to be used.
	 */
	public SecurityIdentity getSecurityIdentity() {
		return securityIdentity;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetSecurityIdentity(SecurityIdentity newSecurityIdentity, NotificationChain msgs) {
		SecurityIdentity oldSecurityIdentity = securityIdentity;
		securityIdentity = newSecurityIdentity;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, EjbPackage.ENTERPRISE_BEAN__SECURITY_IDENTITY, oldSecurityIdentity, newSecurityIdentity);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * @generated This field/method will be replaced during code generation.
	 */
	public void setSecurityIdentity(SecurityIdentity newSecurityIdentity) {
		if (newSecurityIdentity != securityIdentity) {
			NotificationChain msgs = null;
			if (securityIdentity != null)
				msgs = ((InternalEObject)securityIdentity).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - EjbPackage.ENTERPRISE_BEAN__SECURITY_IDENTITY, null, msgs);
			if (newSecurityIdentity != null)
				msgs = ((InternalEObject)newSecurityIdentity).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - EjbPackage.ENTERPRISE_BEAN__SECURITY_IDENTITY, null, msgs);
			msgs = basicSetSecurityIdentity(newSecurityIdentity, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, EjbPackage.ENTERPRISE_BEAN__SECURITY_IDENTITY, newSecurityIdentity, newSecurityIdentity));
	}

	/**
	 * @generated This field/method will be replaced during code generation 
	 */
	public JavaClass getLocalHomeInterface() {
		if (localHomeInterface != null && localHomeInterface.eIsProxy()) {
			InternalEObject oldLocalHomeInterface = (InternalEObject)localHomeInterface;
			localHomeInterface = (JavaClass)eResolveProxy(oldLocalHomeInterface);
			if (localHomeInterface != oldLocalHomeInterface) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, EjbPackage.ENTERPRISE_BEAN__LOCAL_HOME_INTERFACE, oldLocalHomeInterface, localHomeInterface));
			}
		}
		return localHomeInterface;
	}

	public JavaClass getServiceEndpoint() {
		return null;
	}
	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public JavaClass basicGetLocalHomeInterface() {
		return localHomeInterface;
	}

	/**
	 * @generated This field/method will be replaced during code generation.
	 */
	public void setLocalHomeInterface(JavaClass newLocalHomeInterface) {
		JavaClass oldLocalHomeInterface = localHomeInterface;
		localHomeInterface = newLocalHomeInterface;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, EjbPackage.ENTERPRISE_BEAN__LOCAL_HOME_INTERFACE, oldLocalHomeInterface, localHomeInterface));
	}

	/**
	 * @generated This field/method will be replaced during code generation 
	 */
	public JavaClass getLocalInterface() {
		if (localInterface != null && localInterface.eIsProxy()) {
			InternalEObject oldLocalInterface = (InternalEObject)localInterface;
			localInterface = (JavaClass)eResolveProxy(oldLocalInterface);
			if (localInterface != oldLocalInterface) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, EjbPackage.ENTERPRISE_BEAN__LOCAL_INTERFACE, oldLocalInterface, localInterface));
			}
		}
		return localInterface;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public JavaClass basicGetLocalInterface() {
		return localInterface;
	}

	/**
	 * @generated This field/method will be replaced during code generation.
	 */
	public void setLocalInterface(JavaClass newLocalInterface) {
		JavaClass oldLocalInterface = localInterface;
		localInterface = newLocalInterface;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, EjbPackage.ENTERPRISE_BEAN__LOCAL_INTERFACE, oldLocalInterface, localInterface));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case EjbPackage.ENTERPRISE_BEAN__EJB_JAR:
				if (eInternalContainer() != null)
					msgs = eBasicRemoveFromContainer(msgs);
				return basicSetEjbJar((EJBJar)otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case EjbPackage.ENTERPRISE_BEAN__SECURITY_ROLE_REFS:
				return ((InternalEList)getSecurityRoleRefs()).basicRemove(otherEnd, msgs);
			case EjbPackage.ENTERPRISE_BEAN__EJB_JAR:
				return basicSetEjbJar(null, msgs);
			case EjbPackage.ENTERPRISE_BEAN__SECURITY_IDENTITY:
				return basicSetSecurityIdentity(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eBasicRemoveFromContainerFeature(NotificationChain msgs) {
		switch (eContainerFeatureID) {
			case EjbPackage.ENTERPRISE_BEAN__EJB_JAR:
				return eInternalContainer().eInverseRemove(this, EjbPackage.EJB_JAR__ENTERPRISE_BEANS, EJBJar.class, msgs);
		}
		return super.eBasicRemoveFromContainerFeature(msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case EjbPackage.ENTERPRISE_BEAN__NAME:
				return getName();
			case EjbPackage.ENTERPRISE_BEAN__SECURITY_ROLE_REFS:
				return getSecurityRoleRefs();
			case EjbPackage.ENTERPRISE_BEAN__EJB_CLASS:
				if (resolve) return getEjbClass();
				return basicGetEjbClass();
			case EjbPackage.ENTERPRISE_BEAN__HOME_INTERFACE:
				if (resolve) return getHomeInterface();
				return basicGetHomeInterface();
			case EjbPackage.ENTERPRISE_BEAN__REMOTE_INTERFACE:
				if (resolve) return getRemoteInterface();
				return basicGetRemoteInterface();
			case EjbPackage.ENTERPRISE_BEAN__EJB_JAR:
				return getEjbJar();
			case EjbPackage.ENTERPRISE_BEAN__SECURITY_IDENTITY:
				return getSecurityIdentity();
			case EjbPackage.ENTERPRISE_BEAN__LOCAL_HOME_INTERFACE:
				if (resolve) return getLocalHomeInterface();
				return basicGetLocalHomeInterface();
			case EjbPackage.ENTERPRISE_BEAN__LOCAL_INTERFACE:
				if (resolve) return getLocalInterface();
				return basicGetLocalInterface();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case EjbPackage.ENTERPRISE_BEAN__NAME:
				setName((String)newValue);
				return;
			case EjbPackage.ENTERPRISE_BEAN__SECURITY_ROLE_REFS:
				getSecurityRoleRefs().clear();
				getSecurityRoleRefs().addAll((Collection)newValue);
				return;
			case EjbPackage.ENTERPRISE_BEAN__EJB_CLASS:
				setEjbClass((JavaClass)newValue);
				return;
			case EjbPackage.ENTERPRISE_BEAN__HOME_INTERFACE:
				setHomeInterface((JavaClass)newValue);
				return;
			case EjbPackage.ENTERPRISE_BEAN__REMOTE_INTERFACE:
				setRemoteInterface((JavaClass)newValue);
				return;
			case EjbPackage.ENTERPRISE_BEAN__EJB_JAR:
				setEjbJar((EJBJar)newValue);
				return;
			case EjbPackage.ENTERPRISE_BEAN__SECURITY_IDENTITY:
				setSecurityIdentity((SecurityIdentity)newValue);
				return;
			case EjbPackage.ENTERPRISE_BEAN__LOCAL_HOME_INTERFACE:
				setLocalHomeInterface((JavaClass)newValue);
				return;
			case EjbPackage.ENTERPRISE_BEAN__LOCAL_INTERFACE:
				setLocalInterface((JavaClass)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case EjbPackage.ENTERPRISE_BEAN__NAME:
				setName(NAME_EDEFAULT);
				return;
			case EjbPackage.ENTERPRISE_BEAN__SECURITY_ROLE_REFS:
				getSecurityRoleRefs().clear();
				return;
			case EjbPackage.ENTERPRISE_BEAN__EJB_CLASS:
				setEjbClass((JavaClass)null);
				return;
			case EjbPackage.ENTERPRISE_BEAN__HOME_INTERFACE:
				setHomeInterface((JavaClass)null);
				return;
			case EjbPackage.ENTERPRISE_BEAN__REMOTE_INTERFACE:
				setRemoteInterface((JavaClass)null);
				return;
			case EjbPackage.ENTERPRISE_BEAN__EJB_JAR:
				setEjbJar((EJBJar)null);
				return;
			case EjbPackage.ENTERPRISE_BEAN__SECURITY_IDENTITY:
				setSecurityIdentity((SecurityIdentity)null);
				return;
			case EjbPackage.ENTERPRISE_BEAN__LOCAL_HOME_INTERFACE:
				setLocalHomeInterface((JavaClass)null);
				return;
			case EjbPackage.ENTERPRISE_BEAN__LOCAL_INTERFACE:
				setLocalInterface((JavaClass)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case EjbPackage.ENTERPRISE_BEAN__NAME:
				return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
			case EjbPackage.ENTERPRISE_BEAN__SECURITY_ROLE_REFS:
				return securityRoleRefs != null && !securityRoleRefs.isEmpty();
			case EjbPackage.ENTERPRISE_BEAN__EJB_CLASS:
				return ejbClass != null;
			case EjbPackage.ENTERPRISE_BEAN__HOME_INTERFACE:
				return homeInterface != null;
			case EjbPackage.ENTERPRISE_BEAN__REMOTE_INTERFACE:
				return remoteInterface != null;
			case EjbPackage.ENTERPRISE_BEAN__EJB_JAR:
				return getEjbJar() != null;
			case EjbPackage.ENTERPRISE_BEAN__SECURITY_IDENTITY:
				return securityIdentity != null;
			case EjbPackage.ENTERPRISE_BEAN__LOCAL_HOME_INTERFACE:
				return localHomeInterface != null;
			case EjbPackage.ENTERPRISE_BEAN__LOCAL_INTERFACE:
				return localInterface != null;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * @generated This field/method will be replaced during code generation.
	 */
	public String toStringGen() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (name: "); //$NON-NLS-1$
		result.append(name);
		result.append(')');
		return result.toString();
	}

	/**
	 * Preserve adapters when object is resolved.
	 */
	protected void resolved(EObject originalObject, EObject resolvedObject) {
		if (originalObject != null && resolvedObject != null && originalObject != resolvedObject) {
			Collection col = originalObject.eAdapters();
			if (!col.isEmpty()) {
				Iterator it = col.iterator();
				Adapter a;
				while (it.hasNext()) {
					a = (Adapter) it.next();
					if (a == null) continue;
					resolvedObject.eAdapters().add(a);
				}
			}
		}
	}
	/**
	 * @generated This field/method will be replaced during code generation 
	 */
	public JavaClass getEjbClassGen() {
		if (ejbClass != null && ejbClass.eIsProxy()) {
			InternalEObject oldEjbClass = (InternalEObject)ejbClass;
			ejbClass = (JavaClass)eResolveProxy(oldEjbClass);
			if (ejbClass != oldEjbClass) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, EjbPackage.ENTERPRISE_BEAN__EJB_CLASS, oldEjbClass, ejbClass));
			}
		}
		return ejbClass;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public JavaClass basicGetEjbClass() {
		return ejbClass;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.emf.ecore.EModelElement#getEAnnotation(java.lang.String)
	 */
	public EAnnotation getEAnnotation(String source) {
		return null;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.emf.ecore.EModelElement#getEAnnotations()
	 */
	public EList getEAnnotations() {
		return null;
	}

}






