blob: 3a99ed1e846b8277a5935912bafa9ae834c06831 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2004-2008 Andras Schmidt, Andras Balogh, Istvan Rath and Daniel Varro
* 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:
* Andras Schmidt, Andras Balogh, Istvan Rath - initial API and implementation
*******************************************************************************/
package org.eclipse.viatra2.modelChecker;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.viatra2.core.IEntity;
import org.eclipse.viatra2.core.IModelElement;
import org.eclipse.viatra2.core.IRelation;
import org.eclipse.viatra2.modelChecker.impl.ConsistencyErrorMessages;
import org.eclipse.viatra2.tags.InfoTag;
import org.eclipse.viatra2.tags.TagKind;
/**
* POJO implementing problem carriers.
* @author Andras Schmidt, Istvan Rath
*
*/
public class Problem extends InfoTag implements IProblem {
IModelElement endPoint;
IRelation rel;
IRelation relType;
IEntity otherEntity;
EProblemType problemType;
public Problem(IModelElement point, IRelation rel, IRelation type,
EProblemType problemType) {
super("", null, 3, 1);
endPoint = point;
this.rel = rel;
relType = type;
otherEntity = null;
this.problemType = problemType;
generateErrorMessage();
}
public Problem(IModelElement point, IRelation rel, IEntity otherEntity,
EProblemType problemType) {
super("", null, 3, 1);
endPoint = point;
this.rel = rel;
relType = null;
this.otherEntity = otherEntity;
this.problemType = problemType;
generateErrorMessage();
}
public IModelElement getEndPoint() {
return endPoint;
}
public IRelation getRelation() {
return rel;
}
public IRelation getRelationType() {
return relType;
}
public EProblemType getProblemType() {
return problemType;
}
public String getMessage() {
return message;
}
protected void generateErrorMessage() {
if (problemType.compareTo(EProblemType.INVALID_RELATION_SOURCE_TYPE) == 0) {
message = ConsistencyErrorMessages.INVALID_RELATION_SOURCE_TYPE;
String[] context = new String[] { endPoint.getFullyQualifiedName(),
rel.getFullyQualifiedName(),
relType.getFrom().getFullyQualifiedName(),
relType.getFullyQualifiedName(), };
bind(context);
} else if (problemType
.compareTo(EProblemType.INVALID_RELATION_TARGET_TYPE) == 0) {
message = ConsistencyErrorMessages.INVALID_RELATION_TARGET_TYPE;
String[] context = new String[] { endPoint.getFullyQualifiedName(),
rel.getFullyQualifiedName(),
relType.getTo().getFullyQualifiedName(),
relType.getFullyQualifiedName(), };
bind(context);
} else if (problemType.compareTo(EProblemType.AGGREGATION_INVALID) == 0) {
message = ConsistencyErrorMessages.AGGREGATION_INVALID;
String[] context = new String[] { relType.getFullyQualifiedName(),
rel.getFullyQualifiedName(),
rel.getTo().getFullyQualifiedName(),
endPoint.getFullyQualifiedName() };
bind(context);
} else if (problemType.compareTo(EProblemType.INVALID_RELATION_SOURCE) == 0) {
message = ConsistencyErrorMessages.INVALID_RELATION_SOURCE;
String[] context = new String[] { rel.getFullyQualifiedName() };
bind(context);
} else if (problemType.compareTo(EProblemType.INVALID_RELATION_TARGET) == 0) {
message = ConsistencyErrorMessages.INVALID_RELATION_TARGET;
String[] context = new String[] { rel.getFullyQualifiedName() };
bind(context);
} else if (problemType
.compareTo(EProblemType.OUTGOING_MULTIPLICITY_CONSTRAINT_VIOLATED) == 0) {
message = ConsistencyErrorMessages.OUTGOING_MULTIPLICITY_CONSTRAINT_VIOLATED;
String[] context = new String[] { rel.getFullyQualifiedName(),
relType.getMultiplicity().toString(),
endPoint.getFullyQualifiedName() };
bind(context);
} else if (problemType
.compareTo(EProblemType.INCOMING_MULTIPLICITY_CONSTRAINT_VIOLATED) == 0) {
message = ConsistencyErrorMessages.INCOMING_MULTIPLICITY_CONSTRAINT_VIOLATED;
String[] context = new String[] { rel.getFullyQualifiedName(),
relType.getMultiplicity().toString(),
endPoint.getFullyQualifiedName() };
bind(context);
} else if (problemType
.compareTo(EProblemType.MULTIPLICITY_REFINEMENT_INVALID) == 0) {
message = ConsistencyErrorMessages.MULTIPLICITY_REFINEMENT_INVALID;
String[] context = new String[] { rel.getFullyQualifiedName(),
rel.getMultiplicity().toString(),
relType.getFullyQualifiedName(),
relType.getMultiplicity().toString() };
bind(context);
} else if (problemType
.compareTo(EProblemType.AGGREGATION_REFINEMENT_INVALID) == 0) {
message = ConsistencyErrorMessages.AGGREGATION_REFINEMENT_INVALID;
String[] context = new String[] { rel.getFullyQualifiedName(),
relType.getFullyQualifiedName() };
bind(context);
} else if (problemType
.compareTo(EProblemType.INVALID_REFINEMENT_SOURCE_TYPE) == 0) {
message = ConsistencyErrorMessages.INVALID_REFINEMENT_SOURCE_TYPE;
String[] context = new String[] { rel.getFullyQualifiedName(),
relType.getFullyQualifiedName() };
bind(context);
} else if (problemType
.compareTo(EProblemType.INVALID_REFINEMENT_TARGET_TYPE) == 0) {
message = ConsistencyErrorMessages.INVALID_REFINEMENT_TARGET_TYPE;
String[] context = new String[] { rel.getFullyQualifiedName(),
relType.getFullyQualifiedName() };
bind(context);
} else if (problemType
.compareTo(EProblemType.INVALID_REFINEMENT) == 0) {
message = ConsistencyErrorMessages.INVALID_REFINEMENT;
String[] context = new String[] { rel.getFullyQualifiedName(),
otherEntity.getFullyQualifiedName() };
bind(context);
}
}
// try {
// String str = (String)
// this.getClass().getDeclaredField(problemType.name()).get(null);
// message = str;
// } catch (IllegalArgumentException e) {
// e.printStackTrace();
// message = "";
// } catch (SecurityException e) {
// e.printStackTrace();
// message = "";
// } catch (IllegalAccessException e) {
// e.printStackTrace();
// message = "";
// } catch (NoSuchFieldException e) {
// e.printStackTrace();
// message = "";
// }
/**
* Binding the '{N}' (N = 1..4) strings to contextual conditions in
* 'context'
*
* @param context
* : array of context-sensitive Strings
*/
public void bind(String[] context) {
if (context.length >= 1) {
message = message.replace("{1}", context[0]);
}
if (context.length >= 2) {
message = message.replace("{2}", context[1]);
}
if (context.length >= 3) {
message = message.replace("{3}", context[2]);
}
if (context.length >= 4) {
message = message.replace("{4}", context[3]);
}
}
public Set<IModelElement> getAssociatedElements() {
HashSet<IModelElement> r = new HashSet<IModelElement>();
if (this.endPoint!=null) r.add(endPoint);
if (this.rel!=null) r.add(this.rel);
if (this.relType!=null) r.add(this.relType);
return r;
}
public TagKind getKind() {
return TagKind.MODELING_PROBLEM;
}
}