|
From: <j_m...@us...> - 2004-02-29 12:24:05
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11565/src/org/cobricks/core Modified Files: Ontology.java OntologyClass.java OntologyClassAttr.java Added Files: OntologyDataType.java Log Message: added isMultiLanguage, introduced OntologyDataType, introduced deriving of attributes --- NEW FILE: OntologyDataType.java --- package org.cobricks.core; /** * This method is a more detailed representation of the type keyword in the * OntologyClassAttr. It provides all necessary methods for handling an * ontology data type. * @author Johannes Mathes ma...@in... * */ public class OntologyDataType { /** * This constant contains all cobricks types defined in the specification. */ private static final String[] COBRICKS_TYPES = {"item", "category", "user"}; /** * The ontology type name. */ private String typeName; /** * The name of the sub type (in case there is one)- */ private String subtypeName; /** * Is this data type a set of elements? */ private boolean isSet = false; /** * Is this data type a list of elements? */ private boolean isList = false; /** * Is there a maximal length? */ private boolean hasMaxLength = false; /** * Has this data type a sub type constraint? */ private boolean hasSubtype = false; /** * The maximal length (in case there is one) */ private int maxLength; /** * Constructs a new instance of OntologyDataType using the given ontology * keyword * @param ontKeyWord The ontology keyword specifying the type (e.g. string[]) */ public OntologyDataType(String ontKeyWord) { typeName = ""; String inBrackets = ""; String inParenthesis = ""; boolean hasParenthesis; boolean hasBrackets; hasParenthesis = ontKeyWord.matches(".*\\(.*"); hasBrackets = ontKeyWord.matches(".*\\[.*"); if (hasParenthesis) { typeName = ontKeyWord.split("\\(")[0]; inParenthesis = ontKeyWord.substring(ontKeyWord.indexOf("(") + 1, ontKeyWord.indexOf(")")); if (hasBrackets) { inBrackets = ontKeyWord.substring(ontKeyWord.indexOf("[") + 1, ontKeyWord.indexOf("]")); } } else if (hasBrackets) { typeName = ontKeyWord.split("\\[")[0]; inBrackets = ontKeyWord.substring(ontKeyWord.indexOf("[") + 1, ontKeyWord.indexOf("]")); } else { typeName = ontKeyWord; } if (inParenthesis.length() > 0) { if (typeName.equals("string")) { //length constraint hasMaxLength = true; maxLength = Integer.parseInt(inParenthesis.trim()); } else { //sub type constraint hasSubtype = true; subtypeName = inParenthesis; } } if (hasBrackets) { //List or Set if (inBrackets.equals("$")) { isList = true; } else { isSet = true; } } } /** * In case the ontology data type is a Set or a List, you can use this method * to get the corresponding single data type, e.g. if the data type is set * of string (keyword: string[]), this method returns a new instance of * the string data type (keyword: string). * @return The generated data type of the collection elements. */ public final OntologyDataType getCollectionElementType() { OntologyDataType elementType = new OntologyDataType(this.getTypeName()); elementType.hasMaxLength = this.hasMaxLength(); elementType.hasSubtype = this.hasSubtype(); if (elementType.hasMaxLength) { elementType.maxLength = this.getMaxLength(); } if (elementType.hasSubtype) { elementType.subtypeName = this.getSubtypeName(); } return elementType; } /** * Is this data type a List of elements? According to the specification this * is only possible for strings. * @return true in case it is a list, false otherwise. */ public final boolean isList() { return isList; } /**Is this data type a Set of elements? * @return true in case it is a Set, false otherwise. */ public final boolean isSet() { return isSet; } /** In case there is a maximum length constraint (according to the * specification this is only possible for strings) this method returns * the maximal number of characters. * @return The maximal length in case there is one, -1 otherwise. */ public final int getMaxLength() { if (hasMaxLength) { return maxLength; } else { return -1; } } /** It is possible to define that a cobricks data type has to be a specific * sub type, e.g. the data type with the keyword item(date) is of general * type item and sub type named date (has to be defined in the ontology). * @return The sub type of a cobricks data type or null in case there is no * sub type (and / or the data type is no cobricks data type). */ public final String getSubtypeName() { if (hasSubtype) { return subtypeName; } else { return null; } } /** This method returns the name of the ontology data type (not the whole * ontology keyword), e.g. the ontology key word is int[] this method returns * "int". * @return The ontology name of this data type */ public final String getTypeName() { return typeName; } /** Is there a max length constraint for this data type? * @return true in case there is a constraint, false otherwise. */ public final boolean hasMaxLength() { return hasMaxLength; } /** Is there a sub type constraint? (Relevant for cobricks data types). * @return True in case the data type is a specific sub type of a data type, * e.g. the data type with the keyword item(date) has a sub type. */ public final boolean hasSubtype() { return hasSubtype; } /** * Is this data type a list or a set of element? * @return true in case it is a set / list, false otherwise. */ public final boolean isCollection() { return (isList || isSet); } /** * Is this data type a cobricks data type? * @return true in case it is a cobricks data type (e.g. user, category, item) * false otherwise. */ public final boolean isCobricksType() { boolean result = false; for (int i = 0; i < COBRICKS_TYPES.length; i++) { if (this.typeName.equals(COBRICKS_TYPES[i])) { result = true; } } return result; } /**@see Object.toString() * @return A String representation. */ public final String toString() { String string = typeName; if (hasSubtype) { string += ("(" + subtypeName + ")"); } if (hasMaxLength) { string += ("(" + maxLength + ")"); } if (isSet) { string += "[]"; } if (isList) { string += "[$]"; } return string; } } Index: Ontology.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/core/Ontology.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Ontology.java 12 Feb 2004 06:25:26 -0000 1.2 --- Ontology.java 29 Feb 2004 12:06:01 -0000 1.3 *************** *** 181,190 **** String name = ((Element)n).getAttribute("name"); String type = ((Element)n).getAttribute("type"); ! String isRequired = ((Element)n).getAttribute("required"); ! OntologyClassAttr oca = new OntologyClassAttr(name, type, currentClass); if (isRequired != null && isRequired.equals("true")) { oca.setIsRequired(true); } currentClass.addAttribute(oca); currentClassAttr = oca; --- 181,197 ---- String name = ((Element)n).getAttribute("name"); String type = ((Element)n).getAttribute("type"); ! String isRequired = ((Element) n).getAttribute("required"); ! String isMultiLanguage = ! ((Element) n).getAttribute("multilanguage"); ! OntologyClassAttr oca = new OntologyClassAttr(name, type, currentClass); + // Look for things that are not obligatory to define + // in the ontology XML. if (isRequired != null && isRequired.equals("true")) { oca.setIsRequired(true); } + if (isMultiLanguage != null && isMultiLanguage.equals("true")) { + oca.setIsMultiLanguage(true); + } currentClass.addAttribute(oca); currentClassAttr = oca; *************** *** 211,215 **** else if (tagname.equals("default")) { String tmps = n.getFirstChild().getNodeValue(); ! currentClassAttr.addValue(tmps); } else if (tagname.equals("contextclass")) { --- 218,224 ---- else if (tagname.equals("default")) { String tmps = n.getFirstChild().getNodeValue(); ! //TBD: How to handle this? ! //currentClassAttr.addValue(tmps); ! currentClassAttr.setDefault(tmps); } else if (tagname.equals("contextclass")) { Index: OntologyClass.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/core/OntologyClass.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** OntologyClass.java 12 Feb 2004 06:25:26 -0000 1.2 --- OntologyClass.java 29 Feb 2004 12:06:01 -0000 1.3 *************** *** 127,138 **** } ! public OntologyClassAttr getAttribute(String attrname) ! { ! return (OntologyClassAttr)attrs.get(attrname); } ! public Set getAttributeNames() ! { ! return attrs.keySet(); } --- 127,148 ---- } ! public OntologyClassAttr getAttribute(String attrname) { ! OntologyClassAttr oca = (OntologyClassAttr) attrs.get(attrname); ! if (this.getParent() != null && oca == null) { ! //there is a parent ontology class and the attribute was not found, ! //-->lookup at the parent ontology class. ! return this.getParent().getAttribute(attrname); ! } else { ! return oca; ! } } ! public Set getAttributeNames() { ! if (getParent()!= null) { ! return this.getParent().getAttributeNamesRecursive(attrs.keySet()); ! } else { ! return attrs.keySet(); ! } ! } *************** *** 165,167 **** --- 175,188 ---- } + protected Set getAttributeNamesRecursive(Set previous){ + Set tmp = new HashSet(previous); + //Because this method is only for attribute names, there is no problem + // with eventually overwriting entries with parent entries. + tmp.addAll(this.attrs.keySet()); + if (this.getParent() != null) { + return this.getParent().getAttributeNamesRecursive(tmp); + } else { + return tmp; + } + } } Index: OntologyClassAttr.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/core/OntologyClassAttr.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** OntologyClassAttr.java 12 Feb 2004 06:25:26 -0000 1.2 --- OntologyClassAttr.java 29 Feb 2004 12:06:01 -0000 1.3 *************** *** 38,49 **** protected OntologyClass oclass; ! protected String name; protected boolean required; - protected String type; protected String defaultValue; protected String contextClassName; protected List values; protected Map descriptions; --- 38,50 ---- protected OntologyClass oclass; ! protected String type; //TBD: Is it still necessary? protected String name; protected boolean required; protected String defaultValue; protected String contextClassName; protected List values; protected Map descriptions; + protected OntologyDataType ontologyDataType; + protected boolean multiLanguage; *************** *** 53,61 **** public OntologyClassAttr(String name, String type, OntologyClass oclass) { this.name = name; ! this.type = type; this.oclass = oclass; values = new ArrayList(); descriptions = new HashMap(); required = false; } --- 54,65 ---- public OntologyClassAttr(String name, String type, OntologyClass oclass) { this.name = name; ! this.ontologyDataType = new OntologyDataType(type); this.oclass = oclass; + this.type = type; values = new ArrayList(); descriptions = new HashMap(); required = false; + this.multiLanguage = false; + this.defaultValue = null; } *************** *** 73,82 **** } ! public String getType() { ! return type; } ! public void setType(String type) { ! this.type = type; } --- 77,86 ---- } ! public OntologyDataType getOntologyDataType() { ! return ontologyDataType; } ! public void setOntologyDataType(String type) { ! this.ontologyDataType = new OntologyDataType(type); } *************** *** 102,105 **** --- 106,110 ---- public List getValues() { + return values; } *************** *** 129,132 **** return this.required; } ! } --- 134,157 ---- return this.required; } ! public void setType(String type) { //TBD: Still necessary? ! this.type = type; ! this.ontologyDataType = new OntologyDataType(type); ! } ! public String getType(){ //TBD: Still necessary? ! return this.type; ! } ! /** Is this attribute used in multiple languages? ! * @return True in case it is a multiple language attribute, false otherwise ! */ ! public boolean isMultiLanguage() { ! return multiLanguage; ! } ! ! /** Sets if this attribute is used in multiple languages ! * @param b True in case it is a multiple language attribute, false otherwise ! */ ! public void setIsMultiLanguage(boolean b) { ! multiLanguage = b; ! } ! } |