|
From: Andreas V. <a_...@us...> - 2004-04-29 18:45:53
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/item In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23719/src/org/cobricks/item Modified Files: Item.java Log Message: Index: Item.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/item/Item.java,v retrieving revision 1.26 retrieving revision 1.27 diff -u -d -r1.26 -r1.27 --- Item.java 26 Apr 2004 14:09:20 -0000 1.26 +++ Item.java 29 Apr 2004 18:45:41 -0000 1.27 @@ -35,27 +35,32 @@ public class Item extends org.cobricks.core.DataObject implements java.io.Serializable { private static final int OBJECT_TYPE = -1; + /** * This is the cobricks error code that is used if there is an exception * during instantiation. */ protected static final String XML_INSTANTIATION_EXCEPTION_CODE = "411"; + /** * Standard logger for logging events. */ private static Logger logger = Logger.getLogger(Item.class); + /** * This defines the format used in all internal string representations * of dates. */ public static final String INTERNAL_DATE_FORMAT = "yyyy.MM.dd"; + /** * This defines the format used in all internalt string representations * of time (mostly datetime = date + " " + time). */ public static final String INTERNAL_TIME_FORMAT = "HH:mm:ss.SSS"; - /** This constant defines the default maximum depth of recursive + /** + * This constant defines the default maximum depth of recursive * instantiations: -1 means infinite, 0 means no recursive instantion * (return id instead), >0 means the maximum number of instantiations before * only the id is returned. @@ -79,12 +84,14 @@ */ protected String itemclass; - /** This defines the default maximum depth of recursive + /** + * This defines the default maximum depth of recursive * instantiations: -1 means infinite, 0 means no recursive instantion * (return id instead), >0 means the maximum number of instantiations before * only the id is returned. */ private int recursiveLevel = Item.DEFAULT_RECURSIVE_LEVEL; + /** * The default language is used in all multi language attributes in case * no custom language is defined. @@ -235,6 +242,20 @@ throw new Exception("failed loading item"); */ } + + /** + * This method is an auxiliary method for some of the constructors. + * It extracts the attributes of an Item from a XML representation by + * calling the method extractFromXML(String, Map, Item, ItemManager) of the + * ItemAttrs class. + * Afterwards this method checks and sets the attributes. + * + * @param xml The XML representation of the Item to be initialized + * @param itemManager ItemManager, used to pass it to some auxiliary methods + * @throws CobricksException This can be thrown if the attributes that were + * extracted from the String "xml" didn't pass the check against the + * itemontology + */ private void initFromXML(String xml, ItemManager itemManager) throws CobricksException { @@ -253,22 +274,29 @@ } else { attrs.remove("itemclass"); } + this.annotations = (Map) attrs.get("annotations"); + attrs.remove("annotations"); + this.attachments = (Map) attrs.get("attachments"); + attrs.remove("attachments"); + + // Check the extracted attributes against the itemontology Map checkedAttrs = ItemAttrs.checkAttrsAgainstOntology(attrs, - itemManager,this.itemclass, false, this.getRecursiveLevel()); + itemManager, this.itemclass, false, this.getRecursiveLevel()); if (checkedAttrs != null) { logger.debug("item has the following attrs:" + attrs.keySet().toString()); this.setFromMap(checkedAttrs); this.usedLanguages.add(this.defaultLanguage); } else { - logger.warn("The item out of the XML didn't pass the ontology " - + "check. Possible reason: Inconsistency."); - throw new CobricksException(itemManager.getComponentId(), - Item.XML_INSTANTIATION_EXCEPTION_CODE, "Ontology check failed"); + logger.warn("The item out of the XML didn't pass the ontology " + + "check. Possible reason: Inconsistency."); + throw new CobricksException(itemManager.getComponentId(), + Item.XML_INSTANTIATION_EXCEPTION_CODE, + "Ontology check failed"); } - } } + /** * @see org.cobricks.core.DataObject#getObjectUri() */ @@ -298,7 +326,8 @@ return this.alreadyInstantiated; } - /** This defines the default maximum depth of recursive + /** + * This defines the default maximum depth of recursive * instantiations: -1 means infinite, 0 means no recursive instantion * (return id instead), >0 means the maximum number of instantiations before * only the id is returned. @@ -494,6 +523,7 @@ } public void removeAttribute(String aname, String userid) { + // TBD this.removeAttribute(aname); } @@ -608,11 +638,41 @@ } if (withAnnotations) { - //TBD: do something + List annotations = this.getAnnotations(); + + // Print out the id of every annotation + if ((annotations != null) && (!annotations.isEmpty())) { + xml.append("<annotations>\n"); + Iterator annIterator = annotations.iterator(); + + while (annIterator.hasNext()) { + ItemAnnotation annotation = + (ItemAnnotation) annIterator.next(); + xml.append(" <annotation id=\"" + annotation.getId() + + "\"/>\n"); + } + + xml.append("</annotations>\n"); + } } if (withAttachments) { - //TBD: do something + List attachments = this.getAttachments(); + + // Print out the id of every attachment + if ((attachments != null) && (!attachments.isEmpty())) { + xml.append("<attachments>\n"); + Iterator attIterator = attachments.iterator(); + + while (attIterator.hasNext()) { + ItemAttachment attachment = + (ItemAttachment) attIterator.next(); + xml.append(" <attachment id=\"" + attachment.getId() + + "\"/>\n"); + } + + xml.append("</attachments>\n"); + } } xml.append("</item>"); @@ -785,12 +845,19 @@ } } - + /** + * This method is a convenience method for calling the method + * getItemAttributeAsXML(String, boolean, Object). + * + * @param aname The name of the Object to be "transformed" + * @param withXMLDeclaration If set a XML declaration is added at the + * beginning of the returned String + * @return String that holds a XML representation of the item attribute + * specified by the parameter "aname" + */ protected String getItemAttributeAsXML(String aname, boolean withXMLDeclaration) { - return this.getItemAttributeAsXML(aname, withXMLDeclaration, - //this.getAttribute(aname)); - null); + return this.getItemAttributeAsXML(aname, withXMLDeclaration, null); } /** |