Skip to main content
summaryrefslogtreecommitdiffstats
blob: eba27c161fe8448429f7de42e86a20313cf56211 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*******************************************************************************
 * Copyright (c) 2001, 2005 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
 *******************************************************************************/
/*
 * Created on Mar 27, 2003
 *
 */
package org.eclipse.jst.j2ee.internal.model.translator.ejb;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.jst.j2ee.ejb.EjbPackage;
import org.eclipse.jst.j2ee.internal.xml.EjbDeploymentDescriptorXmlMapperI;
import org.eclipse.wst.common.internal.emf.resource.MultiObjectTranslator;
import org.eclipse.wst.common.internal.emf.resource.ReadAheadHelper;
import org.eclipse.wst.common.internal.emf.resource.Translator;

/**
 * @author schacher
 */
public class EnterpriseBeansTranslator extends MultiObjectTranslator implements EjbDeploymentDescriptorXmlMapperI {
	public static final String ENTERPRISE_BEANS_PATH = ENTERPRISE_BEANS+'/'+ENTITY+','+SESSION+','+MESSAGE_DRIVEN;
    private static final EjbPackage EJB_PKG = EjbPackage.eINSTANCE;
	private static final SessionTranslator SESSION_TRANSLATOR = new SessionTranslator();
	private static final EntityTranslator BMP_TRANSLATOR = new EntityTranslator();
	private static final ContainerManagedEntityTranslator CMP_TRANSLATOR= new ContainerManagedEntityTranslator();
	private static final MessageDrivenTranslator MESSAGE_DRIVEN_TRANSLATOR = new MessageDrivenTranslator();
	private static Map delegates;
	static {
		delegates = new HashMap(7);
		delegates.put(SESSION, SESSION_TRANSLATOR);
		delegates.put(BEAN, BMP_TRANSLATOR);
		delegates.put(CONTAINER, CMP_TRANSLATOR);
		delegates.put(MESSAGE_DRIVEN, MESSAGE_DRIVEN_TRANSLATOR);
	}
	
	/**
	 * @param domNameAndPath
	 * @param eClass
	 */
	public EnterpriseBeansTranslator() {
		super(ENTERPRISE_BEANS_PATH, EJB_PKG.getEJBJar_EnterpriseBeans());
		addReadAheadHelper(new ReadAheadHelper(ENTITY, new String[] {BEAN, CONTAINER}, PERSISTENCE_TYPE ));
	}
	
	/* (non-Javadoc)
	 * @see com.ibm.etools.emf2xml.impl.MultiObjectTranslator#getDelegateFor(org.eclipse.emf.ecore.EObject)
	 */
	public Translator getDelegateFor(EObject o) {
		switch (o.eClass().getClassifierID()) {
			case EjbPackage.SESSION :
				return SESSION_TRANSLATOR;
			case EjbPackage.ENTITY:
				return BMP_TRANSLATOR;
			case EjbPackage.CONTAINER_MANAGED_ENTITY:
				return CMP_TRANSLATOR;
			case EjbPackage.MESSAGE_DRIVEN:
				return MESSAGE_DRIVEN_TRANSLATOR;
		}
		throw new IllegalStateException("Bean type delegate expected"); //$NON-NLS-1$
	}

	public Translator getDelegateFor(String domName, String readAheadName) {
		Translator result = null;
		if (readAheadName != null)
			result = (Translator) delegates.get(readAheadName);
		else 
			result = (Translator) delegates.get(domName);
		
		if (result == null) 
			throw new IllegalStateException("Bean type delegate expected"); //$NON-NLS-1$
		
		return result;
	}
	

	
}

Back to the top