Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 1ccac741bac36e551c5f22f23f0bcdac496d6d9e (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
/*******************************************************************************
 * Copyright (c) 2006, 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 org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.wst.common.internal.emf.resource.Translator;

/**
 * This translator is to be used for empty xml tags that correspond
 * to a boolean attribute in the emf model.  
 * cascade-persist is an example from the orm.xsd:
 * 
 * 	<persistence-unit-defaults>
 * 		<cascade-persist/>        
 * 	</persistence-unit-defaults>  ==>  cascadePersist == true
 * 
 * vs.
 * 
 * 	<persistence-unit-defaults>  
 * 	</persistence-unit-defaults>  ==>  cascadePersist == false
 * 
 */
public class EmptyTagBooleanTranslator extends Translator
{
	public EmptyTagBooleanTranslator(String domNameAndPath, EStructuralFeature feature) {
		super(domNameAndPath, feature, EMPTY_TAG | BOOLEAN_FEATURE);
	}

	public EmptyTagBooleanTranslator(String domNameAndPath, EStructuralFeature aFeature, int style) {
		super(domNameAndPath, aFeature, style | EMPTY_TAG | BOOLEAN_FEATURE);
	}
	
	@Override
	public Object getMOFValue(EObject mofObject) {
		// I am overriding this method.  This is so the tag will be removed when 
		// the value is false.
		// I'm not sure if this is a bug in the ecore or maybe in the translators, 
		// but I really don't think that we should have to depend on the boolean
		// being "unset" to remove the tag.
		Boolean value = (Boolean) super.getMOFValue(mofObject);
		return (value == true) ? value : null;
	}

}

Back to the top