package de.FeatureModellingTool.PatternBase;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import manager.IllegalParameterException;
import manager.ManagerInterface;
import component.FComponent;
import de.FeatureModellingTool.FeatureModel.CompositeConstraintEditor;
import de.FeatureModellingTool.FeatureModel.ConstraintModel;
import de.FeatureModellingTool.FeatureModel.ConstraintModelEditor;
import de.FeatureModellingTool.FeatureModel.FeatureEditor;
import de.FeatureModellingTool.FeatureModel.FeatureModel;
import de.FeatureModellingTool.FeatureModel.FeatureModelEditor;
import de.FeatureModellingTool.FeatureModel.FeatureModelPropertyEditor;
import de.FeatureModellingTool.FeatureModel.FeatureRelationManager;
import de.FeatureModellingTool.FeatureModel.GroupConstraintEditor;
import de.FeatureModellingTool.FeatureModel.VPConstraintEditor;
/**
* author:chenting
* date:2007-11-22
* time:����09:55:50
*/
class TempleteImplementation implements Templete{
protected String name;
protected String description;
protected Pattern parentPattern=null;
protected Templete parentTemplete=null;
protected List<Templete> childrenTempletes;
protected String parentType;
protected Parameter parameters;
protected FComponent featureModelFComponent = null;
protected FeatureModel featureModel = null;
protected FeatureEditor featureEditor = null;
protected FeatureModelEditor featureModelEditor = null;
protected FeatureModelPropertyEditor featureModelPropertyEditor = null;
protected FeatureRelationManager featureRelationManager = null;
protected ConstraintModel constraintModel = null;
protected ConstraintModelEditor constraintModelEditor = null;
protected CompositeConstraintEditor plConstraintEditor = null;
protected GroupConstraintEditor gConstraintEditor = null;
protected VPConstraintEditor vpConstraintEditor = null;
public TempleteImplementation(String templeteName){
name=templeteName;
description="";
childrenTempletes=new ArrayList<Templete>();
parameters=new ParameterImplementation();
ManagerInterface mi = de.FeatureModellingTool.FeatureModel.Manager.getInstance();
mi.getContext().putValue(de.FeatureModellingTool.FeatureModel.Manager.NAME_CONTEXT, name);
mi.getContext().putValue(de.FeatureModellingTool.FeatureModel.Manager.DESCRIPTION_CONTEXT, description);
try {
this.setFComponent((FComponent) mi.getInstance(de.FeatureModellingTool.FeatureModel.Manager.FEATURE_MODEL_NAME, FComponent.class));
// featureModelNGObject = (FComponent) mi.getInstance(de.FeatureModellingTool.FeatureModel.Manager.FEATURE_MODEL_NAME, FComponent.class);
} catch (IllegalParameterException ipe) {
System.out.println(ipe);
}
// featureModel = (FeatureModel) featureModelNGObject.getInterface(de.FeatureModellingTool.FeatureModel.Manager.FEATURE_MODEL_INTERFACE);
// featureEditor = (FeatureEditor) featureModelNGObject.getInterface(de.FeatureModellingTool.FeatureModel.Manager.FEATURE_EDITOR_INTERFACE);
// featureModelEditor = (FeatureModelEditor) featureModelNGObject.getInterface(de.FeatureModellingTool.FeatureModel.Manager.FEATURE_MODEL_EDITOR_INTERFACE);
// featureModelPropertyEditor = (FeatureModelPropertyEditor) featureModelNGObject.getInterface(de.FeatureModellingTool.FeatureModel.Manager.FEATURE_MODEL_PROPERTY_EDITOR_INTERFACE);
// featureRelationManager = (FeatureRelationManager) featureModelNGObject.getInterface(de.FeatureModellingTool.FeatureModel.Manager.FEATURE_RELATION_MANAGER_INTERFACE);
//
// constraintModel = (ConstraintModel) featureModelNGObject.getInterface(de.FeatureModellingTool.FeatureModel.Manager.CONSTRAINT_MODEL_INTERFACE);
// constraintModelEditor = (ConstraintModelEditor) featureModelNGObject.getInterface(de.FeatureModellingTool.FeatureModel.Manager.CONSTRAINT_MODEL_EDITOR_INTERFACE);
// plConstraintEditor = (CompositeConstraintEditor) featureModelNGObject.getInterface(de.FeatureModellingTool.FeatureModel.Manager.PL_CONSTRAINT_EDITOR_INTERFACE);
// gConstraintEditor = (GroupConstraintEditor) featureModelNGObject.getInterface(de.FeatureModellingTool.FeatureModel.Manager.GROUP_CONSTRAINT_EDITOR_INTERFACE);
// vpConstraintEditor = (VPConstraintEditor) featureModelNGObject.getInterface(de.FeatureModellingTool.FeatureModel.Manager.VP_CONSTRAINT_EDITOR_INTERFACE);
featureModelPropertyEditor.setName(name);
}
public String getName() {
return name;
}
public Object getParent(){
if(parentPattern==null)return parentTemplete;
return parentPattern;
}
public String getParentType(){
return parentType;
}
public boolean parentIsTemplete(){
if(parentPattern==null) return true;
return false;
}
public List<Templete> getChildrenTempletes(){
return childrenTempletes;
}
public List<Templete> getAllPosTempletes(){
List<Templete> allPosTempletes=new ArrayList<Templete>();
List<Templete> temp=new ArrayList<Templete>();
temp=getChildrenTempletes();
if(!temp.isEmpty()){
allPosTempletes.addAll(temp);
Iterator iterator=temp.iterator();
while(iterator.hasNext()){
Templete tempTep=(Templete)iterator.next();
allPosTempletes.addAll(tempTep.getAllPosTempletes());
}
}
return allPosTempletes;
}
public void resetPosTempParameters(String featureID,int n){
getParameters().setFeatureNum(featureID,n);
List<Templete> allPosTempletes=new ArrayList<Templete>();
allPosTempletes=getAllPosTempletes();
Iterator iterator=allPosTempletes.iterator();
while(iterator.hasNext()){
Templete tempTep=(Templete)iterator.next();
tempTep.getParameters().setFeatureNum(featureID, n);
}
}
public Parameter getParameters(){
return parameters;
}
public FComponent getFComponent(){
return featureModelFComponent;
}
public FeatureModel getFeatureModel(){
return featureModel;
}
public FeatureEditor getFeatureEditor(){
return featureEditor;
}
public FeatureModelEditor getFeatureModelEditor(){
return featureModelEditor;
}
public FeatureModelPropertyEditor getFeaturePropertyEditor(){
return featureModelPropertyEditor;
}
public FeatureRelationManager getFeatureRelationManager(){
return featureRelationManager;
}
public ConstraintModel getConstraintModel(){
return constraintModel;
}
public ConstraintModelEditor getConstraintModelEditor (){
return constraintModelEditor;
}
public CompositeConstraintEditor getPlConstraintEditor(){
return plConstraintEditor;
}
public GroupConstraintEditor getConstraintEditor(){
return gConstraintEditor;
}
public VPConstraintEditor getVpConstraintEditor() {
return vpConstraintEditor;
}
public void setName(String newName){
name=newName;
}
public void setDescription(String newDescription){
description=newDescription;
}
public void setParentPattern(Pattern aParentPattern){
parentPattern=aParentPattern;
setParentType("pattern");
}
public void setParentTemplete(Templete aParentTemplete){
parentTemplete=aParentTemplete;
setParentType("templete");
}
public void setFComponent(FComponent fComponent){
featureModelFComponent=fComponent;
featureModel = (FeatureModel) featureModelFComponent.getInterface(de.FeatureModellingTool.FeatureModel.Manager.FEATURE_MODEL_INTERFACE);
featureEditor = (FeatureEditor) featureModelFComponent.getInterface(de.FeatureModellingTool.FeatureModel.Manager.FEATURE_EDITOR_INTERFACE);
featureModelEditor = (FeatureModelEditor) featureModelFComponent.getInterface(de.FeatureModellingTool.FeatureModel.Manager.FEATURE_MODEL_EDITOR_INTERFACE);
featureModelPropertyEditor = (FeatureModelPropertyEditor) featureModelFComponent.getInterface(de.FeatureModellingTool.FeatureModel.Manager.FEATURE_MODEL_PROPERTY_EDITOR_INTERFACE);
featureRelationManager = (FeatureRelationManager) featureModelFComponent.getInterface(de.FeatureModellingTool.FeatureModel.Manager.FEATURE_RELATION_MANAGER_INTERFACE);
constraintModel = (ConstraintModel) featureModelFComponent.getInterface(de.FeatureModellingTool.FeatureModel.Manager.CONSTRAINT_MODEL_INTERFACE);
constraintModelEditor = (ConstraintModelEditor) featureModelFComponent.getInterface(de.FeatureModellingTool.FeatureModel.Manager.CONSTRAINT_MODEL_EDITOR_INTERFACE);
plConstraintEditor = (CompositeConstraintEditor) featureModelFComponent.getInterface(de.FeatureModellingTool.FeatureModel.Manager.PL_CONSTRAINT_EDITOR_INTERFACE);
gConstraintEditor = (GroupConstraintEditor) featureModelFComponent.getInterface(de.FeatureModellingTool.FeatureModel.Manager.GROUP_CONSTRAINT_EDITOR_INTERFACE);
vpConstraintEditor = (VPConstraintEditor) featureModelFComponent.getInterface(de.FeatureModellingTool.FeatureModel.Manager.VP_CONSTRAINT_EDITOR_INTERFACE);
}
public void addChildTemplete(Templete templete){
if(templete==null)return;
childrenTempletes.add(templete);
templete.setParentTemplete(this);
}
public void removeChildTemplete(Templete templete){
if(templete==null)return;
childrenTempletes.remove(templete);
}
protected void setParentType(String type){
parentType=type;
}
}