All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nl.tue.buildingsmart.schema.SchemaDefinition Maven / Gradle / Ivy

There is a newer version: 1.0.13
Show newest version
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.Iterator;

/**
 * Holds the definitions of TYPEs(see {@link BaseType} and its
 * implementations), ENTITYs (see {@link EntityDefinition}) and
 * their ATTRIBUTEs (see {@link Attribute} as defined in a ISO
 * 10303 EXPRESS schema.
 * 
 * @author Jakob Beetz
 * 
 */
@SuppressWarnings("all")
public class SchemaDefinition implements Schema {

	/**
	 * the name of the schema
	 */
	private String name;

	/**
	 * a map of all {@link EntityDefinition}s by their UPPERCASE names as keys
	 * in this schema
	 */
	private HashMap entitiesBN = new HashMap();
	/**
	 * a list of all {@link EntityDefinition}s in this schema
	 */
	private ArrayList entities = new ArrayList();

	/**
	 * a hash map of all EXPRESS TYPE definitions in this schema
	 * with the UPPERCASE name of the type as its keys
	 */
	private HashMap typesBN = new HashMap();

	/**
	 * a List of all EXPRESS TYPE definitions in this schema
	 */

	private ArrayList types = new ArrayList();

	/**
	 * hash map of an ordered list of all parents of an ENTITY
	 * definition. First element is the direct supertype, last the root
	 * supertype
	 */
	private HashMap> parents = new HashMap>();

	/**
	 * hash map of all relations that are defined in the EXPRESS
	 * ATTRIBUTEs defined locally to a given
	 * {@link EntityDefinition}. 
Note:ArrayList does not include * relations to other entities defined in supertypes */ private HashMap> entityRelations = new HashMap>(); private byte[] schemaData; /** * @param ent * the {@link EntityDefinition} to be added to the schema * @return true if adding the definition to the schema succeeded * */ public boolean addEntity(EntityDefinition ent) { // TODO exception handling String entName = ent.getName(); entities.add(ent); entitiesBN.put(entName.toUpperCase(), ent); return true; } /** * @param type * the {@link DefinedType} to be added to the total list of types * defined in this schema * @return true if successfully added the type definition */ public boolean addType(DefinedType type) { types.add(type); typesBN.put(type.getName().toUpperCase(), type); return true; } public DefinedType getTypeBN(String name) { return typesBN.get(name.toUpperCase()); } public void constructEntityRelationsMap() { entityRelations.clear(); Iterator ei = entities.iterator(); while (ei.hasNext()) { EntityDefinition ent = (EntityDefinition) ei.next(); if (!ent.getAttributes().isEmpty()) { Iterator ai = ent.getAttributes().iterator(); while (ai.hasNext()) { Attribute at = (Attribute) ai.next(); if (at instanceof ExplicitAttribute) { BaseType bt = ((ExplicitAttribute) at).getDomain(); if (bt instanceof EntityDefinition) { ArrayList rels = entityRelations.get(ent); if (rels == null) { entityRelations.put(ent, new ArrayList()); rels = entityRelations.get(ent); } rels.add((EntityDefinition) bt); } } } } } } public void constructHirarchyMap() { parents.clear(); this.parents = new HashMap>(); Iterator ei = entities.iterator(); while (ei.hasNext()) { EntityDefinition ent = (EntityDefinition) ei.next(); if (!ent.getSupertypes().isEmpty()) { Iterator iter = ent.getSupertypes().iterator(); while (iter.hasNext()) { EntityDefinition parent = (EntityDefinition) iter.next(); if (parents.get(parent) == null) parents.put(parent, new ArrayList()); ArrayList children = parents.get(parent); children.add(ent); parent.addSubtype(ent); // System.out.println("adding "+ent.getName()+ " to "+ // parent.getName()); } } } } /** * * @param name * @return a BaseType with the given Name (can be a TYPE or an ENTITY) */ public BaseType getBaseTypeBN(String name) { BaseType bt; bt = typesBN.get(name.toUpperCase()); if (bt == null) bt = entitiesBN.get(name.toUpperCase()); if (bt == null && name.equalsIgnoreCase("real")) return new RealType(); if (bt == null && name.equalsIgnoreCase("integer")) return new IntegerType(); if (bt == null && name.equalsIgnoreCase("binary")) return new BinaryType(); if (bt == null && name.equalsIgnoreCase("string")) return new StringType(); if (bt == null && name.equalsIgnoreCase("logical")) return new LogicalType(); return bt; } public EntityDefinition getEntityBN(String name) { return entitiesBN.get(name.toUpperCase()); } public EntityDefinition getEntityBNNoCaseConvert(String name) { return entitiesBN.get(name); } public HashMap getEnitiesBN() { return entitiesBN; } public void setEnitiesBN(HashMap enitiesBN) { this.entitiesBN = enitiesBN; } public ArrayList getEntities() { return entities; } public void setEntities(ArrayList entities) { this.entities = entities; } public String getName() { return name; } public void setName(String name) { this.name = name; } public HashMap getTypesBN() { return typesBN; } public void setTypesBN(HashMap types) { this.typesBN = types; } public ArrayList getTypes() { return types; } public void setTypes(ArrayList typesBN) { this.types = typesBN; } public SchemaDefinition(String name) throws Exception { super(); this.name = name; } public SchemaDefinition() { super(); } public HashMap> getParents() { return parents; } public ArrayList getEntityChildren(EntityDefinition ent) { return parents.get(ent); } public ArrayList getEntityRelations(EntityDefinition ent) { if (entityRelations.get(ent) == null) return new ArrayList(); else return entityRelations.get(ent); } public byte[] getSchemaData() { return schemaData; } public void setSchemaData(byte[] schemaData) { this.schemaData = schemaData; } // TODO add rules and external schemas }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy