Skip to main content
summaryrefslogtreecommitdiffstats
blob: c926b883d701a48bdf6f5ca2abca4ab81d2925f4 (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
/*******************************************************************************
 * Copyright (c) 2007 Oracle. 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: Oracle. - initial API and implementation
 *******************************************************************************/
package org.eclipse.jpt.core.internal.content.orm.resource;

import java.util.Collections;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.jpt.core.internal.mappings.EnumType;

/**
 * There is a bug in the translator framework that causes
 * enumerators in xml elements and enumerators in xml attributes
 * to be treated differently.  When the enumerator is an attribute
 * setting the model to the default causes the attribute to be removed.
 * With an element is causes the default literal to be placed in
 * the tag.
 * 
 * The problem is wrapped up in the emf unsettable attribute as well.
 * For attributes the eIsSet method returns false for the default value
 * For elements the eIsSet method returns true for the default value.
 * I don't want to have to use the unsettable option in emf since that would
 * require that I call different api.  I am not sure yet what the bug is in
 * the translator, so I have entered one ~KFM
 */
public class EnumeratedTypeElementTranslator extends EnumeratorTranslator
{
	
	public EnumeratedTypeElementTranslator(String domNameAndPath, EStructuralFeature aFeature, int style) {
		super(domNameAndPath, aFeature, style);
	}
	
	@Override
	public Object getMOFValue(EObject mofObject) {
		EnumType type = (EnumType)  super.getMOFValue(mofObject);
		if (type == EnumType.DEFAULT) {
			return null;
		}
		return type;
	}
 
	@Override
	public List getMOFChildren(EObject mofObject) {
		List result = super.getMOFChildren(mofObject);
		if(result != null && result.size() > 0) {
			EnumType type = (EnumType) result.get(0);
			if(type.getValue() == EnumType.DEFAULT_VALUE) 
				result = Collections.EMPTY_LIST;
		}
		return result;
	}
}

Back to the top