use of org.obeonetwork.dsl.environment.StructuredType in project InformationSystem by ObeoNetwork.
the class StructuredTypeImpl method isCyclicInheritance.
/**
* Checks that there is no cyclic inheritance if the given type becomes the
* super type of this type.
*
* @param superTypeCandidate
* the super type candidate.
* @return <code>true</true> if a cyclic inheritance appears if <code>superTypeCandidate</code>
* becomes the super type of this type.
*/
private boolean isCyclicInheritance(final StructuredType superTypeCandidate) {
// quick tests
if (superTypeCandidate == null) {
return false;
}
if (superTypeCandidate == this) {
return true;
}
// checks that this is not a super type of superTypeCandidate.
final Set<StructuredType> superTypesOfSuperTypeCandidate = new HashSet<StructuredType>();
StructuredType currentSuperType = superTypeCandidate.getSupertype();
while (currentSuperType != null && superTypesOfSuperTypeCandidate.add(currentSuperType)) {
if (currentSuperType == this) {
// cycle
return true;
}
// Iterate on supertypes
currentSuperType.getSupertype();
}
// it's ok, no cycle.
return false;
}
use of org.obeonetwork.dsl.environment.StructuredType in project InformationSystem by ObeoNetwork.
the class UseCaseServices method allDomainClasses.
/**
* Collect all domain classes referenced by a use case
* @param uc
* @return
*/
public List<DomainClass> allDomainClasses(UseCase uc) {
Set<DomainClass> classes = new HashSet<DomainClass>();
// Add domain classes directly references
classes.addAll(uc.getDomainClasses());
// Search for domain classes in referenced namespaces
for (Namespace ns : uc.getNamespaces()) {
collectClasses(ns, classes);
}
// This reference exists for compatibility with old metamodel version (before DomainClass)
for (StructuredType type : uc.getTypes()) {
if (type instanceof DomainClass) {
classes.add((DomainClass) type);
}
}
// Convert set to list
List<DomainClass> result = new ArrayList<>(classes);
// and sort by fully qualified names
Collections.sort(result, new Comparator<DomainClass>() {
@Override
public int compare(DomainClass arg0, DomainClass arg1) {
// Use a primary collator to ignore accents and case
Collator collator = Collator.getInstance();
collator.setStrength(Collator.PRIMARY);
return collator.compare(fullQualifiedName(arg0), fullQualifiedName(arg1));
}
});
return result;
}
use of org.obeonetwork.dsl.environment.StructuredType in project InformationSystem by ObeoNetwork.
the class BindingService method getAllBindableElements.
public Collection<StructuredType> getAllBindableElements(DSemanticDiagram diagram, StructuredType structuredType) {
// Collect all structured types
Collection<StructuredType> bindableElements = new ArrayList<StructuredType>();
// First get all structured types
bindableElements.addAll(getAllStructuredTypes(structuredType));
// Remove the target element
bindableElements.remove(structuredType);
// Remove elements already bound with the target
for (BindingInfo bindingInfo : getAllBindingInfosOnDiagram(diagram)) {
if (bindingInfo.getLeft() == structuredType) {
bindableElements.remove(bindingInfo.getRight());
}
if (bindingInfo.getRight() == structuredType) {
bindableElements.remove(bindingInfo.getLeft());
}
}
return bindableElements;
}
use of org.obeonetwork.dsl.environment.StructuredType in project InformationSystem by ObeoNetwork.
the class BindingService method getRelatedBindingInfos.
public Collection<BindingInfo> getRelatedBindingInfos(Namespace namespace) {
// Use of LinkedHashSet to keep order and avoid potential lock/unlock
// loops problems
Set<BindingInfo> results = new LinkedHashSet<BindingInfo>();
for (BindingRegistry bindingRegistry : namespace.getBindingRegistries()) {
results.addAll(bindingRegistry.getBindingInfos());
}
for (Type containedType : namespace.getTypes()) {
if (containedType instanceof StructuredType) {
StructuredType containedStructuredType = (StructuredType) containedType;
results.addAll(getRelatedBindingInfos(containedStructuredType));
}
}
return results;
}
use of org.obeonetwork.dsl.environment.StructuredType in project InformationSystem by ObeoNetwork.
the class DesignServices method isExistingDependency.
/**
* Checks whether a dependency should be displayed between 2 namespaces
* @param source
* @param target
* @return
*/
public static boolean isExistingDependency(Namespace source, Namespace target) {
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())) {
return true;
}
// Check references
for (Reference reference : structuredType.getOwnedReferences()) {
StructuredType referencedType = reference.getReferencedType();
if (referencedType != null && target.equals(referencedType.eContainer())) {
return true;
}
}
// Check attributes
for (Attribute attribute : structuredType.getOwnedAttributes()) {
DataType datatype = attribute.getType();
if (datatype instanceof Enumeration && target.equals(datatype.eContainer())) {
return true;
}
}
}
}
return false;
}
Aggregations