From: Xuan B. <med...@us...> - 2008-01-23 19:01:18
|
Update of /cvsroot/tm4j/tm4j/src/org/tm4j/topicmap/tmdm/tm4j1 In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv28197/src/org/tm4j/topicmap/tmdm/tm4j1 Added Files: OccurrenceImpl.java TM4J1Utils.java Log Message: Provide OccurenceImpl.java --- NEW FILE: TM4J1Utils.java --- package org.tm4j.topicmap.tmdm.tm4j1; import org.tm4j.net.LocatorFactoryException; import org.tm4j.net.LocatorFactory; import org.tm4j.net.Locator; /** @author <a href="mailto:xua...@pu...">Xuân Baldauf</a> */ public class TM4J1Utils { protected static String encodedIRIprefix = "tm4j1compatibilitylocator:"; public static String locatorToIRI(Locator locator) { String notation = locator.getNotation(); if (notation.equals("URI")) { return locator.getAddress(); } else { // We may return something like "tm4j1compatibilitylocator:${escape(locator.getNotation())}:${escape(locator.getAddress())}", however, it is quite probable that nobody needs it, because we only use URI locators anyways. throw new UnsupportedOperationException(); } } public static Locator iriToLocator(String iri,LocatorFactory locatorFactory) throws LocatorFactoryException { return locatorFactory.createLocator("URI",iri); } } /* Copyright (c) 2007-2008 Xuân Baldauf. This software is licensed, under the terms of * Apache 2 License * GPL v2 License * GPL v3 License * LGPL v2.1 License * MPL v1.1 License as well as each later version of these licenses. This means: (1) If you are using this software, you can choose any subset of the licenses mentioned, and you can choose any version of each of these licenses (starting with the respective version indicated). (Note that, however, choosing the empty set of licenses means that you do not have any right granted by any license at all.) (2) If you are committing contributions to this software (i.e. this software as part of the official TM4J sourcecode), then you agree to each of these licenses for your contribution (such that each user of this software has still at least the same set of rights and licenses when using this software together with you contribution compared to when using this software without your contribution). */ // :tabSize=2:indentSize=2: --- NEW FILE: OccurrenceImpl.java --- package org.tm4j.topicmap.tmdm.tm4j1; import java.util.Set; import java.util.Collection; import java.util.Collections; import java.util.Iterator; import java.beans.PropertyVetoException; import org.tm4j.net.LocatorFactoryException; import org.tm4j.net.LocatorFactory; import org.tm4j.net.Locator; import org.tm4j.topicmap.*; import org.tm4j.topicmap.tmdm.PSI; import org.tm4j.topicmap.tmdm.TMDMUtil; import org.tm4j.topicmap.tmdm.ReadableOccurrence; /** @author <a href="mailto:xua...@pu...">Xuân Baldauf</a> */ public class OccurrenceImpl extends ScopedObjectImpl<org.tm4j.topicmap.tmdm.Occurrence,org.tm4j.topicmap.tmdm.ReadableOccurrence> implements org.tm4j.topicmap.Occurrence { protected OccurrenceImpl(org.tm4j.topicmap.tmdm.Occurrence representedObject,TopicMapImpl container) { super(representedObject,container); } protected ReadableOccurrence getMergedObject() { return getContainer().getMergedTopicMapView().getMergedOccurrence(getRepresentedObject()); } // Get/Set type /** * Gets the Topic definition the type of this occurrence. * * @return The Topic defining the type of this Occurrence, or * <code>null</code> if no such Topic has been specified. */ public Topic getType() { return getContainer().unmergedToExternal(getRepresentedObject().getType()); } /** * Sets the Topic defining the type of this Occurrence. * * @param type The {@link Topic} defining the type of this occurrence. */ public void setType(Topic type) throws PropertyVetoException { getRepresentedObject().setType(getContainer().externalToUnmerged(type)); } /** * Determines whether the type of the occurrence is described by <code>type</code>. * * @return <code>true</code> if the type of this Occurrence is defined by the topic * <code>type</code>, <code>false</code> otherwise. */ public boolean isOfType(Topic type) { assert type!=null; assert getRepresentedObject().getType()!=null; return getContainer().externalToUnmerged(type).equals(getRepresentedObject().getType()); } /** * Returns the Locator of the resource referenced by this data object. * If the data object provides inline data, this method will return null. * * @return The resource locator, or <code>null</code> if this data object provides * inline character data. */ public Locator getDataLocator() { if (!isDataInline()) { return TM4J1Utils.iriToLocator(getRepresentedObject().getValue(),getContainer().getLocatorFactory()); } else { return null; } } /** * Sets the Locator of the resource referenced by this data object. * The new value overwrites any previous resource locator or data string. * * @param loc the resource locator. * @throws PropertyVetoException if the change to the data object is * vetoed by a listener. */ public void setDataLocator(Locator loc) throws PropertyVetoException { try { getRepresentedObject().setDatatypeAndValue(getContainer().getLocatorFactory().createLocator("URI",PSI.XMLSchema.IRI),TM4J1Utils.locatorToIRI(loc)); } catch (LocatorFactoryException e) { throw new RuntimeException("This should never happen.",e); } } /** * Sets the resource data string associated with this data object. The new value overwrites * any previous data strings or resource locators. * * @param data the character data to be provided by this data object. * @throws PropertyVetoException if the change to the data object is * vetoed by a listener. */ public void setData(String data) throws PropertyVetoException { try { getRepresentedObject().setDatatypeAndValue(getContainer().getLocatorFactory().createLocator("URI",PSI.XMLSchema.String),data); } catch (LocatorFactoryException e) { throw new RuntimeException("This should never happen.",e); } } /** * Gets the resource data string associated with this occurrence. This function returns * null if there is no resource data string associated with this occurrence. * * @return The resource data string, or <code>null</code> if this data object provides * a resource reference. */ public String getData() { if (isDataInline()) { return getRepresentedObject().getValue(); } else { return null; } } /** * Determines the type of resource data provided by this data object. * * @return <code>true</code> if this data object provides inline character data, * <code>false</code> if it refers to a remote resource. */ public boolean isDataInline() { return !TMDMUtil.locatorRepresentsURI(getRepresentedObject().getDatatype(),PSI.XMLSchema.IRI); } /** * Gets the topic which contains this occurrence. * * @return The Topic object which contains this occurrence, or * <code>null</code> if the * occurrence is not currently part of any topic. */ public Topic getParent() { return getContainer().unmergedToExternal(getRepresentedObject().getParent()); } } /* Copyright (c) 2007-2008 Xuân Baldauf. This software is licensed, under the terms of * Apache 2 License * GPL v2 License * GPL v3 License * LGPL v2.1 License * MPL v1.1 License as well as each later version of these licenses. This means: (1) If you are using this software, you can choose any subset of the licenses mentioned, and you can choose any version of each of these licenses (starting with the respective version indicated). (Note that, however, choosing the empty set of licenses means that you do not have any right granted by any license at all.) (2) If you are committing contributions to this software (i.e. this software as part of the official TM4J sourcecode), then you agree to each of these licenses for your contribution (such that each user of this software has still at least the same set of rights and licenses when using this software together with you contribution compared to when using this software without your contribution). */ // :tabSize=2:indentSize=2: |