blob: 4ffffdeb9a5aa391434fe53c0ae8f6155d6b86e8 [file] [log] [blame]
//------------------------------------------------------------------------------
// Copyright (c) 2005, 2006 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 implementation
//------------------------------------------------------------------------------
package org.eclipse.epf.library.configuration;
import java.util.List;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.epf.library.edit.IConfigurationApplicator;
import org.eclipse.epf.uma.ContentDescription;
import org.eclipse.epf.uma.MethodConfiguration;
import org.eclipse.epf.uma.MethodElement;
import org.eclipse.epf.uma.VariabilityElement;
import org.eclipse.epf.uma.ecore.util.OppositeFeature;
/**
* @author Phong Nguyen Le
* @since 1.1
*/
public class ConfigurationApplicator implements IConfigurationApplicator {
public Object getAttribute(VariabilityElement ve,
EAttribute attribute, MethodConfiguration config) {
return ConfigurationHelper
.calcAttributeFeatureValue(ve, attribute,
config);
}
public Object getReference(VariabilityElement ve,
EReference ref, MethodConfiguration config) {
if (ConfigurationHelper.is0nFeature(ref)) {
return ConfigurationHelper.calc0nFeatureValue(
ve, ref, new DefaultElementRealizer(
config));
} else if (ConfigurationHelper.is01Feature(ref)) {
return ConfigurationHelper.calc01FeatureValue(
ve, ref, new DefaultElementRealizer(
config));
}
return null;
}
public Object getReference(ContentDescription desc,
MethodElement owner, EReference ref,
MethodConfiguration config) {
List values = ConfigurationHelper
.calc0nFeatureValue(desc, owner, ref,
new DefaultElementRealizer(config));
if (ref.isMany()) {
return values;
}
if (values.isEmpty())
return null;
return values;
}
public Object getReference(MethodElement element,
OppositeFeature feature,
MethodConfiguration config) {
List values = ConfigurationHelper
.calc0nFeatureValue(element, feature,
new DefaultElementRealizer(config));
return values;
}
public Object resolve(Object object,
MethodConfiguration config) {
if (object instanceof MethodElement) {
Object resolved = ConfigurationHelper
.getCalculatedElement(
(MethodElement) object, config);
if (resolved == null) {
return object;
} else {
return resolved;
}
} else {
return object;
}
}
}