Skip to main content
summaryrefslogtreecommitdiffstats
blob: cf6ec62067d3025a84c01d69493e51fcd86cf80d (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
/*******************************************************************************
 * 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
 *******************************************************************************/
package org.eclipse.jst.j2ee.internal.model.translator.common;


import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.jst.j2ee.common.CommonPackage;
import org.eclipse.jst.j2ee.internal.xml.DeploymentDescriptorXmlMapperI;
import org.eclipse.wst.common.internal.emf.resource.IDTranslator;
import org.eclipse.wst.common.internal.emf.resource.Translator;

public class EnvEntryTranslator extends Translator implements DeploymentDescriptorXmlMapperI {
	private boolean isJ2EE14;
	private static Translator[] children;
	private static Translator[] reorderedChildren;
	//Hacks because of inconsistencies in the servlet spec
	boolean typeBeforeValue = true;
	/**
	 * Constructor for EnvEntryTranslator.
	 * @param domNameAndPath
	 * @param aFeature
	 */
	public EnvEntryTranslator(EStructuralFeature aFeature, boolean writeTypeBeforeValue, boolean isJ2EE14) {
		super(ENV_ENTRY, aFeature);
		typeBeforeValue = writeTypeBeforeValue;
		this.isJ2EE14 = isJ2EE14;
	}

	/**
	 * @see com.ibm.etools.emf2xml.impl.Translator#getChildren()
	 */
	public Translator[] getChildren(Object obj, int versionID) {
		//Hava to you create a different one each time
		children = createChildren();
		setReorderedChildren();
		
		if (typeBeforeValue)
			return children;
		
		return reorderedChildren;
	}

	protected Translator[] createChildren() {
		CommonPackage ePackageCommon = CommonPackage.eINSTANCE;
		Translator descriptionTranslator;
		if (isJ2EE14)
			descriptionTranslator = CommonTranslators.createDescriptionTranslator(ePackageCommon.getEnvEntry_Descriptions()); 
		else 
			descriptionTranslator = new Translator(DESCRIPTION, ePackageCommon.getEnvEntry_Description());
			
		return new Translator[] {
			IDTranslator.INSTANCE,				
			descriptionTranslator,
			new Translator(ENV_ENTRY_NAME, ePackageCommon.getEnvEntry_Name()),
			new EnvEntryTypeTranslator(), 
			new Translator(ENV_ENTRY_VALUE, ePackageCommon.getEnvEntry_Value())
		};
	}
	
	protected void setReorderedChildren() {
		reorderedChildren = new Translator[children.length];
		System.arraycopy(children, 0, reorderedChildren, 0, children.length);
		Translator temp = reorderedChildren[3];
		reorderedChildren[3] = reorderedChildren[4];
		reorderedChildren[4] = temp;
	}


}

Back to the top