
nl.tue.buildingsmart.schema.EntityDefinition Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of buildingsmartlibrary Show documentation
Show all versions of buildingsmartlibrary Show documentation
Java implementation for the BuildingSMART standards IFC2x3TC1 and IFC4
package nl.tue.buildingsmart.schema;
/******************************************************************************
* Copyright (C) 2009-2016 BIMserver.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see {@literal }.
*****************************************************************************/
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
public class EntityDefinition extends NamedType {
// store each supertype in both a list and a hashtable for convenience
private ArrayList supertypes = new ArrayList();
private HashMap supertypesBN = new HashMap();
// store each attribute in both a list and a hashtable for convenience
private ArrayList attributes = new ArrayList();
private HashMap attributesBN = new HashMap();
private HashMap attributesPlusSuperBN;
private ArrayList attributesPlusSuper;
private ArrayList subtypes = new ArrayList();
private final Map derivedAttributes = new HashMap();
private final Set derivedAttributesOverride = new HashSet();
boolean complex;
boolean instantiable;
boolean independent;
public EntityDefinition(String name) {
super(name);
}
public boolean isDerived(String name) {
return derivedAttributes.containsKey(name);
}
public String toString() {
return this.getName();
}
public boolean addAttribute(Attribute a) {
a.setParent_entity(this);
attributes.add(a);
attributesBN.put(a.getName(), a);
return true;
}
public void addDerived(DerivedAttribute2 attribute, boolean firstOccurance) {
if (!derivedAttributes.containsKey(attribute.getName())) {
derivedAttributes.put(attribute.getName(), attribute);
} else {
if (firstOccurance) {
derivedAttributes.put(attribute.getName(), attribute);
}
}
for (EntityDefinition entityDefinition : supertypes) {
if (entityDefinition.getAttributeBNWithSuper(attribute.getName()) != null) {
derivedAttributesOverride.add(attribute.getName());
}
}
doSubtypes(attribute);
}
private void doSubtypes(DerivedAttribute2 attribute) {
for (EntityDefinition entityDefinition : subtypes) {
entityDefinition.addDerived(new DerivedAttribute2(attribute.getName(), attribute.getType(), attribute.getExpressCode(), attribute.isCollection(), true), false);
entityDefinition.doSubtypes(attribute);
}
}
public Attribute getAttributeBN(String name) {
return attributesBN.get(name);
}
public Attribute getAttributeBNWithSuper(String name) {
if (attributesBN.containsKey(name)) {
return attributesBN.get(name);
}
if (attributesPlusSuperBN == null) {
getAttributesCached(true);
}
if (attributesPlusSuperBN.containsKey(name)) {
return attributesPlusSuperBN.get(name);
}
return null;
}
public boolean addSupertype(EntityDefinition parent) {
supertypes.add(parent);
supertypesBN.put(parent.getName(), parent);
return true;
}
public ArrayList getAttributes() {
return attributes;
}
/**
* returns all Attirbutes of this ENTITY. Optionally also returns all
* inherited Attributes from the parents
*
* @param returnInherited
* if true also returns inherited attributs
* @return
*/
public ArrayList getAttributes(boolean returnInherited) {
if (!returnInherited)
return this.getAttributes();
else {
ArrayList tempAttribs = new ArrayList();
Iterator parentIter = this.getSupertypes().iterator();
while (parentIter.hasNext()) {
tempAttribs = parentIter.next().getAttributes(true);
}
Iterator attribIter = this.getAttributes().iterator();
while (attribIter.hasNext())
tempAttribs.add(attribIter.next());
return tempAttribs;
}
}
public ArrayList getAttributesCached(boolean returnInherited) {
if (!returnInherited)
return this.getAttributes();
else {
if (attributesPlusSuper == null) {
attributesPlusSuper = getAttributes(true);
attributesPlusSuperBN = new HashMap();
for (Attribute attribute : attributesPlusSuper) {
attributesPlusSuperBN.put(attribute.getName(), attribute);
}
}
return attributesPlusSuper;
}
}
public void setAttributes(ArrayList attributes) {
this.attributes = attributes;
}
public HashMap getAttributesBN() {
return attributesBN;
}
public void setAttributesBN(HashMap attributesBN) {
this.attributesBN = attributesBN;
}
public ArrayList getSupertypes() {
return supertypes;
}
public void setSupertypes(ArrayList supertypes) {
this.supertypes = supertypes;
}
public HashMap getSupertypesBN() {
return supertypesBN;
}
public void setSupertypesBN(HashMap supertypesBN) {
this.supertypesBN = supertypesBN;
}
public ArrayList getSubtypes() {
if (this.subtypes == null)
this.subtypes = new ArrayList();
return subtypes;
}
public void setSubtypes(ArrayList subtypes) {
this.subtypes = subtypes;
}
public void addSubtype(EntityDefinition subClass) {
this.subtypes.add(subClass);
}
public boolean isInstantiable() {
return instantiable;
}
public void setInstantiable(boolean instantiable) {
this.instantiable = instantiable;
}
public Map getDerivedAttributes() {
return derivedAttributes;
}
public boolean isDerivedOverride(String name) {
return derivedAttributesOverride.contains(name);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy