Skip to main content
summaryrefslogtreecommitdiffstats
blob: 7861a6fe251199ab3e7c60c82009e5a4977d9858 (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
/*******************************************************************************
 * 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 Apr 2, 2003
 *
 * To change the template for this generated file go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
package org.eclipse.jst.j2ee.internal.model.translator.ejb;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.jst.j2ee.ejb.CMPAttribute;
import org.eclipse.jst.j2ee.ejb.ContainerManagedEntity;
import org.eclipse.jst.j2ee.ejb.EjbPackage;
import org.eclipse.jst.j2ee.internal.J2EEVersionConstants;
import org.eclipse.jst.j2ee.internal.xml.EjbDeploymentDescriptorXmlMapperI;
import org.eclipse.wst.common.internal.emf.resource.IDTranslator;
import org.eclipse.wst.common.internal.emf.resource.Translator;

/**
 * @author administrator
 *
 * To change the template for this generated type comment go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
public class CMPFieldTranslator extends Translator implements EjbDeploymentDescriptorXmlMapperI {
	public static EjbPackage EJB_PKG = EjbPackage.eINSTANCE;
	public static Translator[] children;
	public CMPFieldTranslator(){
		super(CMP_FIELD, EJB_PKG.getContainerManagedEntity_PersistentAttributes());
	}
	
	/* (non-Javadoc)
	 * @see com.ibm.etools.emf2xml.impl.Translator#getChildren()
	 */
	protected Translator[] getChildren() {
		if (children == null)
			children = createChildren();
		return children;
	}

	protected Translator[] createChildren(){
		return new Translator[] {
			IDTranslator.INSTANCE,
			new Translator(DESCRIPTION,EJB_PKG.getCMPAttribute_Description()),
			new Translator(FIELD_NAME, EcorePackage.eINSTANCE.getENamedElement_Name())	
		};
	}
	
	/* (non-Javadoc)
	 * @see com.ibm.etools.emf2xml.impl.Translator#getMOFChildren(org.eclipse.emf.ecore.EObject)
	 */
	public List getMOFChildren(EObject mofObject) {
		switch(((ContainerManagedEntity)mofObject).getVersionID()) {  
			
			case J2EEVersionConstants.EJB_1_0_ID:
			case J2EEVersionConstants.EJB_1_1_ID:
	
				return super.getMOFChildren(mofObject);
				
			case J2EEVersionConstants.EJB_2_0_ID:
			case J2EEVersionConstants.EJB_2_1_ID: default:
	
				return get20CMPAttributes((ContainerManagedEntity)mofObject);
		}  
	}
	
	public List get20CMPAttributes(ContainerManagedEntity cmp) {
		List allAttributes, removed, result;
		removed = null;
		allAttributes = cmp.getPersistentAttributes();
		int size = allAttributes.size();
		CMPAttribute att = null;
		for (int i = 0; i < size; i++) {
			att = (CMPAttribute) allAttributes.get(i);
			if (att.isDerived()) {
				if (removed == null)
					removed = new ArrayList();
				removed.add(att);
			}
		}
		if (removed != null) {
			result = new ArrayList(size);
			result.addAll(allAttributes);
			result.removeAll(removed);
		} else
			result = allAttributes;
		return result;
	}

}

Back to the top