blob: af7d1b1602cad59fbcf0f37a18df77956a8c8584 [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 org.eclipse.epf.library.util.LibraryUtil;
import com.ibm.uma.Activity;
import com.ibm.uma.MethodConfiguration;
import com.ibm.uma.MethodElement;
import com.ibm.uma.RoleDescriptor;
import com.ibm.uma.TaskDescriptor;
import com.ibm.uma.VariabilityElement;
import com.ibm.uma.WorkProductDescriptor;
/**
* Realizes the element based on the configuration and realize options.
*
* @author Jinhua Xi
* @since 1.0
*/
public class ElementRealizer {
private MethodConfiguration config;
// note: discard contributor takes higher priority, if set to true,
// resolveContributor will be ignored
private boolean discardContributor = false;
private boolean resolveContributor = true;
private boolean resolveReplacer = true;
public ElementRealizer(MethodConfiguration config) {
this(config, true, true);
}
public ElementRealizer(MethodConfiguration config,
boolean resolveContributor, boolean resolveReplacer) {
this.config = config;
this.resolveContributor = resolveContributor;
this.resolveReplacer = resolveReplacer;
}
public void setDiscardContributor(boolean discardContributor) {
this.discardContributor = discardContributor;
}
public void setResolveContributor(boolean resolveContributor) {
this.resolveContributor = resolveContributor;
}
public void setResolveReplacer(boolean resolveReplacer) {
this.resolveReplacer = resolveReplacer;
}
public MethodElement realize(MethodElement element) {
// RATLC00384923 - CP with 'contributed' root activity does not show up
// in config view
// always show activity even if it's a contributor
if (element instanceof Activity) {
if (ConfigurationHelper.canShow(element, config)) {
return element;
} else {
return null;
}
}
if (element == null || !ConfigurationHelper.inConfig(element, config)) {
return null;
}
// RATLC00384820 - Work product descriptors that point to work products
// outside the configuration are still published
// linked element must be in config as well
MethodElement linkedElement = null;
if (element instanceof TaskDescriptor) {
linkedElement = ((TaskDescriptor) element).getTask();
} else if (element instanceof WorkProductDescriptor) {
linkedElement = ((WorkProductDescriptor) element).getWorkProduct();
} else if (element instanceof RoleDescriptor) {
linkedElement = ((RoleDescriptor) element).getRole();
}
if ((linkedElement != null)
&& !ConfigurationHelper.inConfig(linkedElement, config)) {
return null;
}
// if ( element instanceof CompositeRole)
// {
// List items = ((CompositeRole)element).getAggregatedRoles();
// if ( items.size() > 0 )
// {
//
// }
// }
// if no configuration is specified, don't calculate
if (config == null) {
return element;
}
if (element instanceof VariabilityElement) {
VariabilityElement ve = (VariabilityElement) element;
VariabilityElement e;
// if discardContributor set to true, discard the contributor and
// return null
if (discardContributor && ConfigurationHelper.isContributor(ve)) {
return null;
}
if (resolveContributor) {
// if the element is a contributor, resovle to it's base
while (ConfigurationHelper.isContributor(ve)) {
e = ve.getVariabilityBasedOnElement();
if (ConfigurationHelper.inConfig(e, config)) {
ve = e;
} else {
// if the base is not in the configuration, it's an
// error
System.out
.println("Configuration closure error: Base element '" + LibraryUtil.getTypeName(ve) + "' not in configuration"); //$NON-NLS-1$ //$NON-NLS-2$
break;
}
}
}
if (resolveReplacer) {
e = ConfigurationHelper.getReplacer(ve, config);
if (e != null) {
return e;
}
} else if (!ConfigurationHelper.inConfig(ve, config)) {
return null;
}
// can't return here, need to check canShow
// return ve;
if (ConfigurationHelper.canShow(ve, config)) {
return ve;
}
return null;
}
if (ConfigurationHelper.canShow(element, config)) {
return element;
}
return null;
}
}