Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: 5286650f4c8993d1f4a8fbc02af28800a11f43df (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
/*******************************************************************************
 * 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 Apr 30, 2003
 *
 */
package org.eclipse.jst.j2ee.internal.model.translator.common;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.jst.j2ee.common.ResAuthTypeBase;
import org.eclipse.jst.j2ee.common.ResourceRef;
import org.eclipse.jst.j2ee.internal.J2EEVersionConstants;
import org.eclipse.jst.j2ee.internal.common.CommonPackage;
import org.eclipse.jst.j2ee.internal.xml.DeploymentDescriptorXmlMapperI;
import org.eclipse.jst.j2ee.webapplication.WebApp;
import org.eclipse.wst.common.internal.emf.resource.Translator;
/**
 * @author schacher
 */
public class ResAuthTranslator extends Translator implements DeploymentDescriptorXmlMapperI {

	private static final String CONTAINER_AUTH = "CONTAINER"; //$NON-NLS-1$
	private static final String SERVLET_AUTH = "SERVLET"; //$NON-NLS-1$
	public ResAuthTranslator() {
		super(RES_AUTH, CommonPackage.eINSTANCE.getResourceRef_Auth());
	}

	/* (non-Javadoc)
	 * @see com.ibm.etools.emf2xml.impl.Translator#convertStringToValue(java.lang.String, org.eclipse.emf.ecore.EObject)
	 */
	public Object convertStringToValue(String strValue, EObject owner) {
		if (isWeb((ResourceRef)owner))
			return convertWebStringToValue(strValue, owner);
		
		return super.convertStringToValue(strValue, owner);
	}
	
	/**
	 * @param strValue
	 * @param owner
	 * @return
	 */
	private Object convertWebStringToValue(String strValue, EObject owner) {
		if (SERVLET_AUTH.equals(strValue)) 
			return ResAuthTypeBase.APPLICATION_LITERAL;
		else if (CONTAINER_AUTH.equals(strValue)) 
			return ResAuthTypeBase.CONTAINER_LITERAL;
		else 
			return super.convertStringToValue(strValue, owner);
	}

	/* (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) {
		if (isWeb22(((ResourceRef)owner)))
			return convertWebValueToString(value, owner);
		 
		return super.convertValueToString(value, owner);
	}
	
	/**
	 * @param value
	 * @param owner
	 */
	private String convertWebValueToString(Object value, EObject owner) {
		if (ResAuthTypeBase.APPLICATION_LITERAL == value)
			return SERVLET_AUTH;
		else if (ResAuthTypeBase.CONTAINER_LITERAL == value)
			return CONTAINER_AUTH;
		else 
			return super.convertValueToString(value, owner);
	}

	protected boolean isWeb(ResourceRef ref) {
		EObject owner = ref.eContainer();
		return (owner instanceof WebApp);
	}
	protected boolean isWeb22(ResourceRef ref) { 
		return isWeb(ref) && ((WebApp)ref.eContainer()).getVersionID() <= J2EEVersionConstants.WEB_2_2_ID;
	}


}

Back to the top