Skip to main content
summaryrefslogtreecommitdiffstats
blob: ef05ac4a996104e825afbec2c49a5cb312b36eff (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*******************************************************************************
 * Copyright (c) 2001, 2004 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 31, 2003
 *
 */
package org.eclipse.jst.j2ee.internal.model.translator.ejb;

import java.util.Collections;
import java.util.List;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.jst.j2ee.ejb.EjbFactory;
import org.eclipse.jst.j2ee.internal.model.translator.common.BooleanTranslator;
import org.eclipse.jst.j2ee.internal.model.translator.common.JavaClassTranslator;
import org.eclipse.wst.common.internal.emf.resource.Translator;

/**
 * @author schacher
 */
public class EntityTranslator extends AbstractEJBTranslator {

	private static Translator[] children13;
	private static Translator[] children14;

	private class PersistenceTypeTranslator extends Translator {

		public PersistenceTypeTranslator() {
			super(PERSISTENCE_TYPE, (EStructuralFeature) null);
		}

		/* (non-Javadoc)
		 * @see com.ibm.etools.emf2xml.impl.Translator#extractStringValue(org.eclipse.emf.ecore.EObject)
		 */
		public String extractStringValue(EObject emfObject) {
			return getPersistenceType();
		}

		/* (non-Javadoc)
			   * @see com.ibm.etools.emf2xml.impl.Translator#convertValueToString(java.lang.Object, org.eclipse.emf.ecore.EObject)
			   */
		public String convertValueToString(Object value, EObject owner) {
			return getPersistenceType();
		}
		
		/* (non-Javadoc)
		 * @see com.ibm.etools.emf2xml.impl.Translator#getMOFChildren(org.eclipse.emf.ecore.EObject)
		 */
		public List getMOFChildren(EObject mofObject) {
			return Collections.singletonList(getPersistenceType());
		}


	}

	protected String getPersistenceType() {
		return BEAN;
	}
	/**
	 * @param domNameAndPath
	 * @param aFeature
	 */
	public EntityTranslator() {
		super(ENTERPRISE_BEANS + '/' + ENTITY);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jst.j2ee.internal.internal.model.translator.ejb.AbstractEJBTranslator#getSpecificMaps()
	 */
	protected Translator[] getSpecificMaps(int versionID) {
		Translator reentrantTranslator = null;
		switch (versionID) {
			case J2EE_1_2_ID :
			case J2EE_1_3_ID :
				reentrantTranslator = new Translator(REENTRANT, EJB_PKG.getEntity_Reentrant(), UNSET_IF_NULL);
				break;
			case J2EE_1_4_ID :
				reentrantTranslator = new BooleanTranslator(REENTRANT, EJB_PKG.getEntity_Reentrant());
			default :
				break;
		}
		return new Translator[] { new PersistenceTypeTranslator(), new JavaClassTranslator(PRIM_KEY_CLASS, EJB_PKG.getEntity_PrimaryKey()), reentrantTranslator };
	}

	/* (non-Javadoc)
	 * @see com.ibm.etools.emf2xml.impl.Translator#createEMFObject(java.lang.String, java.lang.String)
	 */
	public EObject createEMFObject(String nodeName, String readAheadName) {
		return EjbFactory.eINSTANCE.createEntity();
	}

	/* (non-Javadoc)
	 * @see com.ibm.etools.emf2xml.impl.Translator#getChildren(java.lang.Object, int)
	 */
	public Translator[] getChildren(Object o, int versionID) {
		switch (versionID) {
			case (J2EE_1_2_ID) :
			case (J2EE_1_3_ID) :
				if (children13 == null)
					children13 = create13Children();
				return children13;
			default :
				if (children14 == null)
					children14 = create14Children();
				return children14;
		}
	}

}

Back to the top