use of org.obeonetwork.dsl.environment.Reference in project InformationSystem by ObeoNetwork.
the class DesignServices method getNbDependencies.
/**
* Returns the number of dependencies between 2 namespaces
* @param source
* @param target
* @return
*/
public static int getNbDependencies(Namespace source, Namespace target) {
int count = 0;
for (Type type : source.getTypes()) {
if (type instanceof StructuredType) {
StructuredType structuredType = (StructuredType) type;
// Check inheritance
StructuredType supertype = structuredType.getSupertype();
if (supertype != null && target.equals(supertype.eContainer())) {
count += 1;
}
// Check references
for (Reference reference : structuredType.getOwnedReferences()) {
StructuredType referencedType = reference.getReferencedType();
if (referencedType != null && target.equals(referencedType.eContainer())) {
count += 1;
}
}
// Check attributes
for (Attribute attribute : structuredType.getOwnedAttributes()) {
DataType datatype = attribute.getType();
if (datatype instanceof Enumeration && target.equals(datatype.eContainer())) {
count += 1;
}
}
}
}
return count;
}
use of org.obeonetwork.dsl.environment.Reference in project InformationSystem by ObeoNetwork.
the class ReferencesService method reconnectBidiReferenceTarget.
public Reference reconnectBidiReferenceTarget(Reference reference, StructuredType source, StructuredType target) {
Reference oppositeOf = reference.getOppositeOf();
reference.setReferencedType(target);
oppositeOf.setContainingType(target);
reference.setOppositeOf(oppositeOf);
return reference;
}
use of org.obeonetwork.dsl.environment.Reference in project InformationSystem by ObeoNetwork.
the class ReferencesService method getOppositeReferences.
public List<Reference> getOppositeReferences(DSemanticDiagram diagram) {
Collection<StructuredType> structuredTypes = DesignServices.getDisplayedStructuredTypes(diagram);
Set<Reference> references = Sets.newLinkedHashSet();
for (StructuredType structuredType : structuredTypes) {
references.addAll(structuredType.getOwnedReferences());
}
Map<String, Reference> map = new HashMap<String, Reference>();
for (Reference ref : references) {
if (ref.getOppositeOf() != null) {
String key1 = ref.getOppositeOf().hashCode() + "" + ref.hashCode();
String key2 = ref.hashCode() + "" + ref.getOppositeOf().hashCode();
if (map.get(key1) == null && map.get(key2) == null) {
map.put(key1, ref);
}
}
}
return new ArrayList<Reference>(map.values());
}
use of org.obeonetwork.dsl.environment.Reference in project InformationSystem by ObeoNetwork.
the class TypesServices method getAllReferencedStructuredTypes.
public Collection<StructuredType> getAllReferencedStructuredTypes(Namespace namespace, DSemanticDiagram diagram) {
Set<StructuredType> types = DesignServices.getDisplayedStructuredTypes(diagram);
types.retainAll(namespace.getTypes());
Collection<StructuredType> referencedTypes = new HashSet<StructuredType>();
for (StructuredType existingType : types) {
referencedTypes.add(existingType.getSupertype());
for (Reference reference : existingType.getOwnedReferences()) {
referencedTypes.add(reference.getReferencedType());
}
referencedTypes.addAll(getAllReferencingStructuredTypes(existingType));
}
referencedTypes.removeAll(namespace.getTypes());
return referencedTypes;
}
use of org.obeonetwork.dsl.environment.Reference in project InformationSystem by ObeoNetwork.
the class ReferenceSpec method setOppositeOf.
@Override
public void setOppositeOf(Reference newOppositeOf) {
Reference oldOppositeOf = getOppositeOf();
super.setOppositeOf(newOppositeOf);
// If an opposite was specified, we have to unset it
if (oldOppositeOf != null && (newOppositeOf == null || !newOppositeOf.eIsProxy()) && !oldOppositeOf.equals(newOppositeOf)) {
oldOppositeOf.setOppositeOf(null);
}
// If a new opposite is specified, we have to ensure consistency
if (newOppositeOf != null && !newOppositeOf.eIsProxy() && (newOppositeOf.getOppositeOf() == null || !newOppositeOf.getOppositeOf().equals(this))) {
newOppositeOf.setOppositeOf(this);
}
}
Aggregations