From: <lh...@us...> - 2009-03-10 14:28:38
|
Revision: 285 http://tinytim.svn.sourceforge.net/tinytim/?rev=285&view=rev Author: lheuer Date: 2009-03-10 14:28:29 +0000 (Tue, 10 Mar 2009) Log Message: ----------- Added XTM10Utils to convert XTM 1.0 reification to TMDM reification Added Paths: ----------- tinytim/trunk/src/main/java/org/tinytim/utils/XTM10Utils.java Added: tinytim/trunk/src/main/java/org/tinytim/utils/XTM10Utils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/utils/XTM10Utils.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/utils/XTM10Utils.java 2009-03-10 14:28:29 UTC (rev 285) @@ -0,0 +1,75 @@ +/* + * Copyright 2008 - 2009 Lars Heuer (heuer[at]semagia.com). All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.tinytim.utils; + +import java.util.logging.Logger; + +import org.tmapi.core.Construct; +import org.tmapi.core.Locator; +import org.tmapi.core.Reifiable; +import org.tmapi.core.Topic; +import org.tmapi.core.TopicMap; + +/** + * Utility functions to convert XTM 1.0 legacy features into the TMDM equivalent. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public class XTM10Utils { + + private static final Logger LOG = Logger.getLogger(XTM10Utils.class.getName()); + + /** + * Converts the XTM 1.0 reification mechanism into TMDM reification. + * <p> + * In XTM 1.0 a construct was reified if it has a source locator (item + * identifier) equals to a subject identifier of a topic. In TMDM, the + * reification of constructs modelled as a property. + * </p> + * <p> + * This function converts the XTM 1.0 reification mechansim into the TMDM + * reification mechanism by setting the property of reified constructs to + * the reifying topic. The item identifier and subject identifier which + * establish the XTM 1.0 reification will be removed. + * </p> + * + * @param topicMap The {@link TopicMap} to convert. + */ + public static void convertReification(final TopicMap topicMap) { + for (Topic topic: topicMap.getTopics()) { + if (topic.getReified() != null) { + continue; + } + for (Locator sid: topic.getSubjectIdentifiers()) { + Construct construct = (Construct) topicMap.getConstructByItemIdentifier(sid); + if (construct == null || construct instanceof Topic) { + continue; + } + Reifiable reifiable = (Reifiable) construct; + if (reifiable.getReifier() != null) { + LOG.info("Skipping reifiable construct " + reifiable.getId() + " since it is reified"); + continue; + } + reifiable.setReifier(topic); + reifiable.removeItemIdentifier(sid); + topic.removeSubjectIdentifier(sid); + break; + } + } + } + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/utils/XTM10Utils.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |