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


import org.eclipse.emf.ecore.EObject;
import org.eclipse.jst.j2ee.common.CommonFactory;
import org.eclipse.jst.j2ee.common.CommonPackage;
import org.eclipse.jst.j2ee.common.RunAsSpecifiedIdentity;
import org.eclipse.jst.j2ee.common.SecurityIdentity;
import org.eclipse.jst.j2ee.ejb.EjbPackage;
import org.eclipse.jst.j2ee.internal.model.translator.common.CommonTranslators;
import org.eclipse.jst.j2ee.internal.xml.EjbDeploymentDescriptorXmlMapperI;
import org.eclipse.wst.common.internal.emf.resource.GenericTranslator;
import org.eclipse.wst.common.internal.emf.resource.IDTranslator;
import org.eclipse.wst.common.internal.emf.resource.ReadAheadHelper;
import org.eclipse.wst.common.internal.emf.resource.Translator;

/**
 * @author schacher
 */
public class SecurityIdentityTranslator extends Translator implements EjbDeploymentDescriptorXmlMapperI {
	private static final CommonPackage COMMON_PKG = CommonPackage.eINSTANCE;
	
	private static final Translator[] RUN_AS_TRANSLATORS = createRunAsTranslators();
	
	private static final Translator[] USE_CALLER_TRANSLATORS = createUseCallerTranslators();
	
	
	private static Translator[] createRunAsTranslators() {
		GenericTranslator runAsTranslator = new GenericTranslator(RUN_AS, COMMON_PKG.getRunAsSpecifiedIdentity_Identity());
		runAsTranslator.setChildren(new Translator[] {
			new Translator(DESCRIPTION, COMMON_PKG.getIdentity_Description()),
			new Translator(ROLE_NAME, COMMON_PKG.getIdentity_RoleName())
		});
		return new Translator[] {
			IDTranslator.INSTANCE,
			new Translator(DESCRIPTION, COMMON_PKG.getSecurityIdentity_Description()),
			runAsTranslator
		};
	}
	
	private static Translator[] createUseCallerTranslators() {
		return new Translator[] {
			IDTranslator.INSTANCE,
			new Translator(DESCRIPTION, COMMON_PKG.getSecurityIdentity_Description()),
			new Translator(USE_CALLER_IDENTITY, null, EMPTY_TAG)
		};
	}

	/**
	 * @param domNameAndPath
	 * @param aFeature
	 */
	public SecurityIdentityTranslator() {
		super(SECURITY_IDENTITY, EjbPackage.eINSTANCE.getEnterpriseBean_SecurityIdentity());
		addReadAheadHelper(new ReadAheadHelper(SECURITY_IDENTITY, new String[] {RUN_AS, USE_CALLER_IDENTITY}, null));
	}
	
	/* (non-Javadoc)
	 * @see com.ibm.etools.emf2xml.impl.Translator#getChildren(java.lang.Object, int)
	 */
	public Translator[] getChildren(Object o, int versionID) {
		if (o == null)
			return CommonTranslators.EMPTY_CHILDREN;
		if (((SecurityIdentity)o).isRunAsSpecifiedIdentity())
			return RUN_AS_TRANSLATORS;
		else if (((SecurityIdentity)o).isUseCallerIdentity())
			return USE_CALLER_TRANSLATORS;
		else
			throw new IllegalStateException("Internal error: Security Identity Type expected"); //$NON-NLS-1$
	}


	/* (non-Javadoc)
	 * @see com.ibm.etools.emf2xml.impl.Translator#createEMFObject(java.lang.String, java.lang.String)
	 */
	public EObject createEMFObject(String nodeName, String readAheadName) {
		CommonFactory fact = CommonFactory.eINSTANCE; 
		if (RUN_AS.equals(readAheadName)) {
			RunAsSpecifiedIdentity result = fact.createRunAsSpecifiedIdentity();
			result.setIdentity(fact.createIdentity());
			return result;
		} else if (USE_CALLER_IDENTITY.equals(readAheadName))
			return fact.createUseCallerIdentity();
		else 
			return null;
	}

	public boolean isManagedByParent() {
		return false;
	}

}

Back to the top