From: <lh...@us...> - 2009-07-15 11:12:55
|
Revision: 314 http://tinytim.svn.sourceforge.net/tinytim/?rev=314&view=rev Author: lheuer Date: 2009-07-15 11:12:44 +0000 (Wed, 15 Jul 2009) Log Message: ----------- Applied patch provided by Hannes Niederhausen (CTMWriter & co). Modified Paths: -------------- tinytim-mio/trunk/build.xml tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMTopicMapWriter.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTMCLPreprocessor.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTemplate.java Added Paths: ----------- tinytim-mio/trunk/lib/tinytim-2.0.0a5-snapshot-200907151305.jar Removed Paths: ------------- tinytim-mio/trunk/lib/tinytim-2.0.0a5-snapshot-20090702.jar Modified: tinytim-mio/trunk/build.xml =================================================================== --- tinytim-mio/trunk/build.xml 2009-07-14 15:54:26 UTC (rev 313) +++ tinytim-mio/trunk/build.xml 2009-07-15 11:12:44 UTC (rev 314) @@ -10,7 +10,7 @@ <property name="lib.junit" value="${dir.lib}/junit-4.5.jar"/> <property name="lib.tmapi" value="${dir.lib}/tmapi-2.0a2.jar"/> - <property name="lib.tinytim" value="${dir.lib}/tinytim-2.0.0a5-snapshot-20090702.jar"/> + <property name="lib.tinytim" value="${dir.lib}/tinytim-2.0.0a5-snapshot-200907151305.jar"/> <property name="lib.tinytim.tests" value="${dir.lib}/tinytim-2.0.0a4-tests.jar"/> <property name="lib.logging" value="${dir.lib}/slf4j-api-1.5.8.jar"/> <property name="lib.mio" value="${dir.lib}/semagia-mio-0.9.4.jar"/> @@ -131,7 +131,6 @@ <javac destdir="${dir.build.classes}" debug="${debug}" target="1.5" - excludes="**/CTMTopicMapWriter.java, **/internal/**" > <classpath> <pathelement location="${lib.tmapi}"/> Deleted: tinytim-mio/trunk/lib/tinytim-2.0.0a5-snapshot-20090702.jar =================================================================== (Binary files differ) Added: tinytim-mio/trunk/lib/tinytim-2.0.0a5-snapshot-200907151305.jar =================================================================== (Binary files differ) Property changes on: tinytim-mio/trunk/lib/tinytim-2.0.0a5-snapshot-200907151305.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMTopicMapWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMTopicMapWriter.java 2009-07-14 15:54:26 UTC (rev 313) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMTopicMapWriter.java 2009-07-15 11:12:44 UTC (rev 314) @@ -68,6 +68,7 @@ * representation. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @author Hannes Niederhausen * @version $Rev$ - $Date$ */ public class CTMTopicMapWriter implements TopicMapWriter { @@ -541,33 +542,32 @@ case TOPIC: { if (_tmcl) { toFilter = new Locator[] { + // Topic types TMCL.TOPIC_TYPE, - TMCL.OCCURRENCE_TYPE, TMCL.ASSOCIATION_TYPE, TMCL.ROLE_TYPE, + TMCL.OCCURRENCE_TYPE, TMCL.NAME_TYPE, TMCL.SCOPE_TYPE, + + // Model topics + TMCL.SCHEMA, TMCL.CONSTRAINT, + // Constraint types - TMCL.TOPIC_TYPE_CONSTRAINT, - TMCL.ASSOCIATION_TYPE_CONSTRAINT, - TMCL.ASSOCIATION_ROLE_TYPE, - TMCL.OCCURRENCE_TYPE_CONSTRAINT, - TMCL.NAME_TYPE_CONSTRAINT, TMCL.ABSTRACT_TOPIC_TYPE_CONSTRAINT, - TMCL.EXCLUSIVE_INSTANCE, + TMCL.OVERLAP_DECLARATION, TMCL.SUBJECT_IDENTIFIER_CONSTRAINT, TMCL.SUBJECT_LOCATOR_CONSTRAINT, - TMCL.NAME_TYPE, - TMCL.NAME_TYPE_SCOPE_CONSTRAINT, - TMCL.TOPIC_OCCURRENCE_TYPE, - TMCL.ASSOCIATION_TYPE_SCOPE_CONSTRAINT, - TMCL.OCCURRENCE_DATATYPE_CONSTRAINT, + TMCL.TOPIC_NAME_CONSTRAINT, TMCL.TOPIC_OCCURRENCE_CONSTRAINT, + TMCL.ROLE_PLAYER_CONSTRAINT, TMCL.SCOPE_CONSTRAINT, + TMCL.REIFIER_CONSTRAINT, TMCL.ASSOCIATION_ROLE_CONSTRAINT, - TMCL.ASSOCIATION_ROLE_PLAYER, - TMCL.OTHERROLE_CONSTRAINT, - TMCL.UNIQUE_OCCURRENCE_CONSTRAINT, + TMCL.OTHER_ROLE_CONSTRAINT, + TMCL.OCCURRENCE_DATATYPE_CONSTRAINT, + TMCL.UNIQUE_VALUE_CONSTRAINT, + TMCL.REGULAR_EXPRESSION_CONSTRAINT }; } break; @@ -578,7 +578,16 @@ toFilter = new Locator[] { toFilter[0], toFilter[1], - TMCL.APPLIES_TO + // Association types - applies-to is no more + TMCL.CONSTRAINED_TOPIC_TYPE, + TMCL.CONSTRAINED_STATEMENT, + TMCL.CONSTRAINED_ROLE, + TMCL.OVERLAPS, + TMCL.ALLOWED_SCOPE, + TMCL.ALLOWED_REIFIER, + TMCL.OTHER_CONSTRAINED_TOPIC_TYPE, + TMCL.OTHER_CONSTRAINED_ROLE, + TMCL.BELONGS_TO_SCHEMA, }; } break; @@ -587,14 +596,13 @@ toFilter = new Locator[] {TMDM.TYPE, TMDM.INSTANCE, TMDM.SUPERTYPE, TMDM.SUBTYPE}; if (_tmcl) { toFilter = new Locator[] {toFilter[0], toFilter[1], toFilter[2], toFilter[3], - TMCL.TOPIC_TYPE_ROLE, - TMCL.OCCURRENCE_TYPE_ROLE, - TMCL.ASSOCIATION_TYPE_ROLE, - TMCL.ROLE_TYPE_ROLE, - TMCL.OTHERROLE_TYPE_ROLE, - TMCL.NAME_TYPE_ROLE, - TMCL.SCOPE_TYPE_ROLE, - TMCL.CONSTRAINT_ROLE + // Role types + TMCL.ALLOWS, + TMCL.ALLOWED, + TMCL.CONSTRAINS, + TMCL.CONSTRAINED, + TMCL.CONTAINER, + TMCL.CONTAINEE }; } break; @@ -606,7 +614,7 @@ TMCL.CARD_MAX, TMCL.DATATYPE, TMCL.REGEXP, - TMCL.VALIDATION_EXPRESSION, + TMCL.VALIDATION_EXPRESSION }; } break; @@ -793,10 +801,7 @@ _writeSupertypeSubtype(supertype, wantSemicolon); wantSemicolon = true; } - for (ITemplate tpl: _getTemplates(topic)) { - _writeTemplate(tpl, wantSemicolon); - wantSemicolon = true; - } + for (Name name: _getNames(topic)) { _writeName((IName) name, wantSemicolon); wantSemicolon = true; @@ -813,6 +818,10 @@ _writeTopicRef(slo, wantSemicolon); wantSemicolon = true; } + for (ITemplate tpl: _getTemplates(topic)) { + _writeTemplate(tpl, wantSemicolon); + wantSemicolon = true; + } if (_exportIIDs) { for (Reference iid: _getItemIdentifiers(topic)) { _writeTopicRef(iid, wantSemicolon); Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTMCLPreprocessor.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTMCLPreprocessor.java 2009-07-14 15:54:26 UTC (rev 313) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTMCLPreprocessor.java 2009-07-15 11:12:44 UTC (rev 314) @@ -19,17 +19,18 @@ import java.util.Collection; import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.logging.Logger; -import org.tinytim.mio.internal.ctm.ITMCLPreprocessor; -import org.tinytim.mio.internal.ctm.ITemplate; +import org.tinytim.core.value.Literal; import org.tinytim.internal.api.IIndexManagerAware; import org.tinytim.internal.api.ILiteral; import org.tinytim.internal.api.IOccurrence; +import org.tinytim.mio.internal.ctm.ITMCLPreprocessor; +import org.tinytim.mio.internal.ctm.ITemplate; import org.tinytim.voc.TMCL; - import org.tmapi.core.Association; import org.tmapi.core.Locator; import org.tmapi.core.Occurrence; @@ -42,20 +43,46 @@ * * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @author Hannes Niederhausen + * @version $Rev$ - $Date$ */ public class DefaultTMCLPreprocessor implements ITMCLPreprocessor { - private static final Logger LOG = Logger.getLogger(DefaultTMCLPreprocessor.class.getName()); + private static final Logger LOG = Logger + .getLogger(DefaultTMCLPreprocessor.class.getName()); private final Map<Topic, Collection<ITemplate>> _topic2Templates; - private Topic _topicType; + private Topic _constrains; - private Topic _appliesTo; + private Topic _constrained; - private Topic _constraintRole; + private Topic _container; + private Topic _containee; + + private Topic _constrained_topic_type; + + private Topic _other_constrained_topic_type; + + private Topic _constrained_statement; + + private Topic _constrained_role; + + private Topic _belongs_to_schema; + + private Topic _other_constrained_role; + + private Topic _overlaps; + + private Topic _allowed_scope; + + private Topic _allowed_reifier; + + private Topic _allowed; + + private Topic _allows; + private Topic _cardMin; private Topic _cardMax; @@ -64,19 +91,21 @@ private Topic _regEx; - private Topic _topicTypeRole; + private ILiteral _cardMinDefault; - private Topic _scopeTypeRole; + private ILiteral _cardMaxDefault; - private Topic _assocTypeRole; + private ILiteral _regExDefault; - public DefaultTMCLPreprocessor() { _topic2Templates = new HashMap<Topic, Collection<ITemplate>>(); } - /* (non-Javadoc) - * @see org.tinytim.mio.internal.ctm.ITMCLPreprocessor#getSuppressableSubjectIdentifiers() + /* + * (non-Javadoc) + * + * @seeorg.tinytim.mio.internal.ctm.ITMCLPreprocessor# + * getSuppressableSubjectIdentifiers() */ @Override public Set<Locator> getSuppressableSubjectIdentifiers() { @@ -84,68 +113,176 @@ return null; } - /* (non-Javadoc) - * @see org.tinytim.mio.internal.ctm.ITMCLPreprocessor#getTopicToTemplatesMapping() + /* + * (non-Javadoc) + * + * @see + * org.tinytim.mio.internal.ctm.ITMCLPreprocessor#getTopicToTemplatesMapping + * () */ @Override public Map<Topic, Collection<ITemplate>> getTopicToTemplatesMapping() { - return _topic2Templates; + return _topic2Templates; } - /* (non-Javadoc) - * @see org.tinytim.mio.internal.ctm.ITMCLPreprocessor#process(org.tmapi.core.TopicMap, java.util.Collection, java.util.Collection) + /* + * (non-Javadoc) + * + * @see + * org.tinytim.mio.internal.ctm.ITMCLPreprocessor#process(org.tmapi.core + * .TopicMap, java.util.Collection, java.util.Collection) */ @Override public void process(TopicMap topicMap, Collection<Topic> topics, Collection<Association> assocs) { _init(topicMap); - TypeInstanceIndex tiIdx = ((IIndexManagerAware) topicMap).getIndexManager().getTypeInstanceIndex(); + TypeInstanceIndex tiIdx = ((IIndexManagerAware) topicMap) + .getIndexManager().getTypeInstanceIndex(); if (!tiIdx.isAutoUpdated()) { tiIdx.reindex(); } _processAbstractTopicConstraints(topicMap, tiIdx, topics, assocs); + _processUniqueConstraints(topicMap, tiIdx, topics, assocs); + _processDatatypeConstraints(topicMap, tiIdx, topics, assocs); + _processRegExConstraints(topicMap, tiIdx, topics, assocs); _processSubjectIdentifierConstraints(topicMap, tiIdx, topics, assocs); _processSubjectLocatorConstraints(topicMap, tiIdx, topics, assocs); - _processAssociationTypeScopeConstraints(topicMap, tiIdx, topics, assocs); - _processRoleConstraints(topicMap, tiIdx, topics, assocs); - _processPlayerConstraints(topicMap, tiIdx, topics, assocs); + _processOverlapConstraints(topicMap, tiIdx, topics, assocs); + _processAssociationRoleConstraints(topicMap, tiIdx, topics, assocs); + _processRolePlayerConstraints(topicMap, tiIdx, topics, assocs); + _processOtherRoleConstraints(topicMap, tiIdx, topics, assocs); _processOccurrenceConstraints(topicMap, tiIdx, topics, assocs); - _processOccurrenceTypeScopeConstraints(topicMap, tiIdx, topics, assocs); _processNameConstraints(topicMap, tiIdx, topics, assocs); - _processNameTypeScopeConstraints(topicMap, tiIdx, topics, assocs); + _processScopeConstraints(topicMap, tiIdx, topics, assocs); + _processReifierConstraints(topicMap, tiIdx, topics, assocs); + _processBelongsToSchema(topicMap, tiIdx, topics, assocs); } - private Collection<Topic> _getConstraintInstances(TopicMap topicMap, TypeInstanceIndex tiIdx, Locator subjectIdentifier) { - final Topic constraintType = topicMap.getTopicBySubjectIdentifier(subjectIdentifier); + private Collection<Topic> _getConstraintInstances(TopicMap topicMap, + TypeInstanceIndex tiIdx, Locator subjectIdentifier) { + final Topic constraintType = topicMap + .getTopicBySubjectIdentifier(subjectIdentifier); if (constraintType == null) { return Collections.emptySet(); } return tiIdx.getTopics(constraintType); } - private Collection<Topic> _getTopicTypeRolePlayers(Topic constraint, Collection<Association> assocs) { - return _getPlayers(constraint, _constraintRole, _topicTypeRole, assocs); + private Topic _getConstrainedTopicTypePlayer(Topic constraint, + Collection<Association> assocs) { + for (Role role : constraint.getRolesPlayed(_constrains, + _constrained_topic_type)) { + Association assoc = role.getParent(); + if (!_isBinary(assoc)) { + continue; + } + for (Role otherRole : assoc.getRoles(_constrained)) { + assocs.remove(assoc); + return otherRole.getPlayer(); + } + } + return null; } - private Collection<Topic> _getPlayers(Topic constraint, Topic constraintRoleType, Topic otherRoleType, Collection<Association> assocs) { - Collection<Topic> result = new ArrayList<Topic>(); - for (Role role: constraint.getRolesPlayed(constraintRoleType, _appliesTo)) { + private Topic _getConstrainedRolePlayer(Topic constraint, + Collection<Association> assocs) { + for (Role role : constraint.getRolesPlayed(_constrains, + _constrained_role)) { Association assoc = role.getParent(); if (!_isBinary(assoc)) { continue; } - for (Role otherRole: assoc.getRoles(otherRoleType)) { + for (Role otherRole : assoc.getRoles(_constrained)) { assocs.remove(assoc); - result.add(otherRole.getPlayer()); + return otherRole.getPlayer(); } } - return result; + return null; } + private Topic _getOtherConstrainedTopicTypePlayer(Topic constraint, + Collection<Association> assocs) { + for (Role role : constraint.getRolesPlayed(_constrains, + _other_constrained_topic_type)) { + Association assoc = role.getParent(); + if (!_isBinary(assoc)) { + continue; + } + for (Role otherRole : assoc.getRoles(_constrained)) { + assocs.remove(assoc); + return otherRole.getPlayer(); + } + } + return null; + } + + private Topic _getOtherConstrainedRolePlayer(Topic constraint, + Collection<Association> assocs) { + for (Role role : constraint.getRolesPlayed(_constrains, + _other_constrained_role)) { + Association assoc = role.getParent(); + if (!_isBinary(assoc)) { + continue; + } + for (Role otherRole : assoc.getRoles(_constrained)) { + assocs.remove(assoc); + return otherRole.getPlayer(); + } + } + return null; + } + + private Topic _getConstrainedStatementPlayer(Topic constraint, + Collection<Association> assocs) { + Topic player = null; + for (Role role : constraint.getRolesPlayed(_constrains, + _constrained_statement)) { + Association assoc = role.getParent(); + if (!_isBinary(assoc)) { + continue; + } + + player = assoc.getRoles(_constrained).iterator().next().getPlayer(); + assocs.remove(assoc); + } + return player; + } + + private Topic _getAllowedScopePlayer(Topic constraint, + Collection<Association> assocs) { + Topic player = null; + for (Role role : constraint.getRolesPlayed(_allows, _allowed_scope)) { + Association assoc = role.getParent(); + if (!_isBinary(assoc)) { + continue; + } + + player = assoc.getRoles(_allowed).iterator().next().getPlayer(); + assocs.remove(assoc); + } + return player; + } + + private Topic _getAllowedReifierPlayer(Topic constraint, + Collection<Association> assocs) { + Topic player = null; + for (Role role : constraint.getRolesPlayed(_allows, _allowed_reifier)) { + Association assoc = role.getParent(); + if (!_isBinary(assoc)) { + continue; + } + + player = assoc.getRoles(_allowed).iterator().next().getPlayer(); + assocs.remove(assoc); + } + return player; + } + private void _processAbstractTopicConstraints(TopicMap topicMap, TypeInstanceIndex tiIdx, Collection<Topic> topics, Collection<Association> assocs) { - for (Topic constraint: _getConstraintInstances(topicMap, tiIdx, TMCL.ABSTRACT_TOPIC_TYPE_CONSTRAINT)) { + for (Topic constraint : _getConstraintInstances(topicMap, tiIdx, + TMCL.ABSTRACT_TOPIC_TYPE_CONSTRAINT)) { _processAbstractTopicConstraint(constraint, topics, assocs); } } @@ -153,213 +290,397 @@ private void _processAbstractTopicConstraint(Topic constraint, Collection<Topic> topics, Collection<Association> assocs) { ITemplate tpl = new DefaultTemplate("isAbstract"); - Collection<Topic> players = _getTopicTypeRolePlayers(constraint, assocs); - for (Topic player: players) { - _registerTemplate(player, tpl); - } - if (players.size() == constraint.getRolesPlayed().size() - && constraint.getOccurrences().isEmpty() - && constraint.getNames().isEmpty() - && constraint.getTypes().size() == 1 - && constraint.getSubjectLocators().isEmpty() - && constraint.getSubjectIdentifiers().isEmpty()) { - topics.remove(constraint); - } + Topic player = _getConstrainedTopicTypePlayer(constraint, assocs); + _registerTemplate(player, tpl); + removeConstraint(constraint, topics, 0); } - private void _processSubjectIdentifierConstraints(TopicMap topicMap, + private void _processAssociationRoleConstraints(TopicMap topicMap, TypeInstanceIndex tiIdx, Collection<Topic> topics, Collection<Association> assocs) { - _processLocatorConstraints(topicMap, tiIdx, "has-subjectidentifier", TMCL.SUBJECT_IDENTIFIER_CONSTRAINT, topics, assocs); + for (Topic constraint : _getConstraintInstances(topicMap, tiIdx, + TMCL.ASSOCIATION_ROLE_CONSTRAINT)) { + _processAssociationRoleConstraint(constraint, topics, assocs); + } + } - private void _processSubjectLocatorConstraints(TopicMap topicMap, + private void _processAssociationRoleConstraint(Topic constraint, + Collection<Topic> topics, Collection<Association> assocs) { + Topic player = _getConstrainedStatementPlayer(constraint, assocs); + Topic roleType = _getConstrainedRolePlayer(constraint, assocs); + + DefaultTemplate tpl = new DefaultTemplate("has-role"); + tpl.addParameter(roleType); + + int occCounter = _assignCardinality(constraint, tpl, 2); + + _registerTemplate(player, tpl); + removeConstraint(constraint, topics, occCounter); + } + + private void _processBelongsToSchema(TopicMap topicMap, TypeInstanceIndex tiIdx, Collection<Topic> topics, Collection<Association> assocs) { - _processLocatorConstraints(topicMap, tiIdx, "has-subjectlocator", TMCL.SUBJECT_LOCATOR_CONSTRAINT, topics, assocs); + for (Topic schema : _getConstraintInstances(topicMap, tiIdx, + TMCL.SCHEMA)) { + _processBelongsToSchema(schema, topics, assocs); + } } - private void _processLocatorConstraints(TopicMap topicMap, - TypeInstanceIndex tiIdx, String templateName, Locator constraintSID, Collection<Topic> topics, + private void _processBelongsToSchema(Topic schema, + Collection<Topic> topics, Collection<Association> assocs) { + + DefaultTemplate tpl = new DefaultTemplate("belongs-to"); + tpl.addParameter(schema); + + for (Role role : schema.getRolesPlayed(_container, _belongs_to_schema)) { + Association assoc = role.getParent(); + if (!_isBinary(assoc)) { + continue; + } + Topic construct = assoc.getRoles(_containee).iterator().next() + .getPlayer(); + + _registerTemplate(construct, tpl); + } + } + + private void _processReifierConstraints(TopicMap topicMap, + TypeInstanceIndex tiIdx, Collection<Topic> topics, Collection<Association> assocs) { - for (Topic constraint: _getConstraintInstances(topicMap, tiIdx, constraintSID)) { - _processLocatorConstraint(constraint, templateName, constraintSID, topics, assocs); + for (Topic constraint : _getConstraintInstances(topicMap, tiIdx, + TMCL.BELONGS_TO_SCHEMA)) { + _processReifierConstraint(constraint, topics, assocs); } + } - private void _processLocatorConstraint(Topic constraint, - String templateName, Locator constraintSID, Collection<Topic> topics, - Collection<Association> assocs) { + private void _processReifierConstraint(Topic constraint, + Collection<Topic> topics, Collection<Association> assocs) { + Topic reifierType = _getConstrainedStatementPlayer(constraint, assocs); + Topic reifiableType = _getAllowedReifierPlayer(constraint, assocs); + ILiteral cardMin = _getCardMin(constraint); ILiteral cardMax = _getCardMax(constraint); - ILiteral regEx = _getRegEx(constraint); - //TODO: Default values? - if (cardMin == null || cardMax == null || regEx == null) { - return; + DefaultTemplate tpl = null; + if (cardMin.getValue().equals(cardMax.getValue())) { + if (cardMin.getValue().equals("0")) { + tpl = new DefaultTemplate("cannot-have-reifier"); + } + else { + tpl = new DefaultTemplate("must-have-reifier"); + tpl.addParameter(reifierType); + } } - DefaultTemplate tpl = new DefaultTemplate(templateName); - tpl.addParameter(cardMin); - tpl.addParameter(cardMax); - tpl.addParameter(regEx); - Collection<Topic> players = _getTopicTypeRolePlayers(constraint, assocs); - for (Topic player: players) { - _registerTemplate(player, tpl); + else { + tpl = new DefaultTemplate("may-have-reifier"); + tpl.addParameter(reifierType); + } - if (players.size() == constraint.getRolesPlayed().size() - && constraint.getOccurrences().size() == 3 - && constraint.getNames().isEmpty() - && constraint.getTypes().size() == 1 - && constraint.getSubjectLocators().isEmpty() - && constraint.getSubjectIdentifiers().isEmpty()) { - topics.remove(constraint); + + _registerTemplate(reifiableType, tpl); + removeConstraint(constraint, topics, 2); + } + + private void _processRolePlayerConstraints(TopicMap topicMap, + TypeInstanceIndex tiIdx, Collection<Topic> topics, + Collection<Association> assocs) { + for (Topic constraint : _getConstraintInstances(topicMap, tiIdx, + TMCL.ROLE_PLAYER_CONSTRAINT)) { + _processRolePlayerConstraint(constraint, topics, assocs); } + } - private void _processAssociationTypeScopeConstraints(TopicMap topicMap, + private void _processRolePlayerConstraint(Topic constraint, + Collection<Topic> topics, Collection<Association> assocs) { + Topic type = _getConstrainedTopicTypePlayer(constraint, assocs); + Topic assocType = _getConstrainedStatementPlayer(constraint, assocs); + Topic roleType = _getConstrainedRolePlayer(constraint, assocs); + + DefaultTemplate tpl = new DefaultTemplate("plays-role"); + tpl.addParameter(roleType); + tpl.addParameter(assocType); + int occCounter = _assignCardinality(constraint, tpl, 2); + + _registerTemplate(type, tpl); + removeConstraint(constraint, topics, occCounter); + } + + private void _processOtherRoleConstraints(TopicMap topicMap, TypeInstanceIndex tiIdx, Collection<Topic> topics, Collection<Association> assocs) { - final Topic type = topicMap.getTopicBySubjectIdentifier(TMCL.ASSOCIATION_TYPE_ROLE); - if (type == null) { - return; + for (Topic constraint : _getConstraintInstances(topicMap, tiIdx, + TMCL.OTHER_ROLE_CONSTRAINT)) { + _processOtherRoleConstraint(constraint, topics, assocs); } - for (Topic constraint: _getConstraintInstances(topicMap, tiIdx, TMCL.ASSOCIATION_TYPE_SCOPE_CONSTRAINT)) { - _processTypeScopeConstraint(constraint, "has-association-scope", type, topics, assocs); + + } + + private void _processOtherRoleConstraint(Topic constraint, + Collection<Topic> topics, Collection<Association> assocs) { + Topic type = _getConstrainedTopicTypePlayer(constraint, assocs); + Topic assocType = _getConstrainedStatementPlayer(constraint, assocs); + Topic roleType = _getConstrainedRolePlayer(constraint, assocs); + Topic otherRole = _getOtherConstrainedRolePlayer(constraint, assocs); + Topic otherPlayer = _getOtherConstrainedTopicTypePlayer(constraint, + assocs); + + DefaultTemplate tpl = new DefaultTemplate("other-role"); + tpl.addParameter(roleType); + tpl.addParameter(type); + tpl.addParameter(otherRole); + tpl.addParameter(otherPlayer); + + _registerTemplate(assocType, tpl); + removeConstraint(constraint, topics, 0); + } + + private void _processUniqueConstraints(TopicMap topicMap, + TypeInstanceIndex tiIdx, Collection<Topic> topics, + Collection<Association> assocs) { + for (Topic constraint : _getConstraintInstances(topicMap, tiIdx, + TMCL.UNIQUE_VALUE_CONSTRAINT)) { + _processUniqueConstraint(constraint, topics, assocs); } } - private void _processRoleConstraints(TopicMap topicMap, + private void _processUniqueConstraint(Topic constraint, + Collection<Topic> topics, Collection<Association> assocs) { + ITemplate tpl = new DefaultTemplate("is-unique"); + Topic player = _getConstrainedStatementPlayer(constraint, assocs); + + _registerTemplate(player, tpl); + topics.remove(constraint); + + } + + private void _processDatatypeConstraints(TopicMap topicMap, TypeInstanceIndex tiIdx, Collection<Topic> topics, Collection<Association> assocs) { - final Topic type = topicMap.getTopicBySubjectIdentifier(TMCL.ROLE_TYPE_ROLE); - if (type == null) { - return; + for (Topic constraint : _getConstraintInstances(topicMap, tiIdx, + TMCL.OCCURRENCE_DATATYPE_CONSTRAINT)) { + _processDatatypeConstraint(constraint, topics, assocs); } - for (Topic constraint: _getConstraintInstances(topicMap, tiIdx, TMCL.ASSOCIATION_ROLE_CONSTRAINT)) { - _processRoleConstraint(constraint, type, topics, assocs); - } } - //TODO: Merge with {@link #_processTypeScopeConstraint} - private void _processRoleConstraint(Topic constraint, Topic type, Collection<Topic> topics, + private void _processDatatypeConstraint(Topic constraint, + Collection<Topic> topics, Collection<Association> assocs) { + + ILiteral datatype = _getDatatype(constraint); + DefaultTemplate tpl = new DefaultTemplate("has-datatype"); + tpl.addParameter(datatype); + + Topic player = _getConstrainedStatementPlayer(constraint, assocs); + + _registerTemplate(player, tpl); + + removeConstraint(constraint, topics, 1); + } + + private void _processRegExConstraints(TopicMap topicMap, + TypeInstanceIndex tiIdx, Collection<Topic> topics, Collection<Association> assocs) { - Topic topic = _getRolePlayer(constraint, type, assocs); - ILiteral cardMin = _getCardMin(constraint); - ILiteral cardMax = _getCardMax(constraint); - if (topic == null || cardMin == null || cardMax == null) { - return; + for (Topic constraint : _getConstraintInstances(topicMap, tiIdx, + TMCL.REGULAR_EXPRESSION_CONSTRAINT)) { + _processRegExConstraint(constraint, topics, assocs); } - DefaultTemplate tpl = new DefaultTemplate("has-role"); - tpl.addParameter(topic); - tpl.addParameter(cardMin); - tpl.addParameter(cardMax); - Collection<Topic> players = _getPlayers(constraint, _constraintRole, _assocTypeRole, assocs); - for (Topic player: players) { - _registerTemplate(player, tpl); - } - if (players.size() * 2 == constraint.getRolesPlayed().size() - && constraint.getOccurrences().size() == 2 - && constraint.getNames().isEmpty() - && constraint.getTypes().size() == 1 - && constraint.getSubjectLocators().isEmpty() - && constraint.getSubjectIdentifiers().isEmpty()) { - topics.remove(constraint); - } } - private void _processPlayerConstraints(TopicMap topicMap, + private void _processRegExConstraint(Topic constraint, + Collection<Topic> topics, Collection<Association> assocs) { + + ILiteral regExp = _getRegEx(constraint); + DefaultTemplate tpl = new DefaultTemplate("matches-regexp"); + tpl.addParameter(regExp); + + Topic player = _getConstrainedStatementPlayer(constraint, assocs); + + _registerTemplate(player, tpl); + // removing instance from topics if it has no further informations + removeConstraint(constraint, topics, 1); + } + + private void _processOverlapConstraints(TopicMap topicMap, TypeInstanceIndex tiIdx, Collection<Topic> topics, Collection<Association> assocs) { - final Topic type = topicMap.getTopicBySubjectIdentifier(TMCL.ROLE_TYPE_ROLE); - if (type == null) { - return; + for (Topic constraint : _getConstraintInstances(topicMap, tiIdx, + TMCL.OVERLAP_DECLARATION)) { + _processOverlapConstraint(constraint, topics, assocs); } - for (Topic constraint: _getConstraintInstances(topicMap, tiIdx, TMCL.ASSOCIATION_ROLE_CONSTRAINT)) { - _processRoleConstraint(constraint, type, topics, assocs); + + } + + private void _processOverlapConstraint(Topic constraint, + Collection<Topic> topics, Collection<Association> assocs) { + + List<Topic> players = new ArrayList<Topic>(2); + for (Role role : constraint.getRolesPlayed(_allows, _overlaps)) { + Association assoc = role.getParent(); + players.add(assoc.getRoles(_allowed).iterator().next().getPlayer()); + + assocs.remove(assoc); } + DefaultTemplate tpl = new DefaultTemplate("overlaps"); + tpl.addParameter(players.get(1)); + + _registerTemplate(players.get(0), tpl); + removeConstraint(constraint, topics, 0); + } - private void _processOccurrenceConstraints(TopicMap topicMap, + private void _processSubjectIdentifierConstraints(TopicMap topicMap, TypeInstanceIndex tiIdx, Collection<Topic> topics, Collection<Association> assocs) { - final Topic type = topicMap.getTopicBySubjectIdentifier(TMCL.OCCURRENCE_TYPE_ROLE); - if (type == null) { - return; + _processLocatorConstraints(topicMap, tiIdx, "has-subject-identifier", + TMCL.SUBJECT_IDENTIFIER_CONSTRAINT, topics, assocs); + } + + private void _processSubjectLocatorConstraints(TopicMap topicMap, + TypeInstanceIndex tiIdx, Collection<Topic> topics, + Collection<Association> assocs) { + _processLocatorConstraints(topicMap, tiIdx, "has-subject-locator", + TMCL.SUBJECT_LOCATOR_CONSTRAINT, topics, assocs); + } + + private void _processLocatorConstraints(TopicMap topicMap, + TypeInstanceIndex tiIdx, String templateName, + Locator constraintSID, Collection<Topic> topics, + Collection<Association> assocs) { + for (Topic constraint : _getConstraintInstances(topicMap, tiIdx, + constraintSID)) { + _processLocatorConstraint(constraint, templateName, constraintSID, + topics, assocs); } - for (Topic constraint: _getConstraintInstances(topicMap, tiIdx, TMCL.TOPIC_OCCURRENCE_CONSTRAINT)) { - _processHasTopicChildConstraint(constraint, "has-occurrence", type, topics, assocs); + } + + private void _processLocatorConstraint(Topic constraint, + String templateName, Locator constraintSID, + Collection<Topic> topics, Collection<Association> assocs) { + + int occCounter = 3; + + ILiteral regEx = _getRegEx(constraint); + if (regEx == null) { + regEx = _regExDefault; + occCounter--; } + + DefaultTemplate tpl = new DefaultTemplate(templateName); + tpl.addParameter(regEx); + + occCounter = _assignCardinality(constraint, tpl, occCounter); + + Topic player = _getConstrainedTopicTypePlayer(constraint, assocs); + _registerTemplate(player, tpl); + removeConstraint(constraint, topics, occCounter); } - private void _processOccurrenceTypeScopeConstraints(TopicMap topicMap, + private void _processScopeConstraints(TopicMap topicMap, TypeInstanceIndex tiIdx, Collection<Topic> topics, Collection<Association> assocs) { - final Topic type = topicMap.getTopicBySubjectIdentifier(TMCL.OCCURRENCE_TYPE_ROLE); + final Topic type = topicMap + .getTopicBySubjectIdentifier(TMCL.SCOPE_TYPE); if (type == null) { return; } - for (Topic constraint: _getConstraintInstances(topicMap, tiIdx, TMCL.TOPIC_OCCURRENCE_TYPE)) { - _processTypeScopeConstraint(constraint, "has-occurrence-scope", type, topics, assocs); + for (Topic constraint : _getConstraintInstances(topicMap, tiIdx, + TMCL.SCOPE_CONSTRAINT)) { + _processScopeConstraint(constraint, type, topics, assocs); } } - private void _processTypeScopeConstraint(Topic constraint, String templateName, Topic type, + private void _processScopeConstraint(Topic constraint, Topic type, Collection<Topic> topics, Collection<Association> assocs) { - Topic topic = _getRolePlayer(constraint, type, assocs); - ILiteral cardMin = _getCardMin(constraint); - ILiteral cardMax = _getCardMax(constraint); - if (topic == null || cardMin == null || cardMax == null) { + Topic scope = _getAllowedScopePlayer(constraint, assocs); + + DefaultTemplate tpl = new DefaultTemplate("has-scope"); + tpl.addParameter(scope); + + int occCounter = _assignCardinality(constraint, tpl, 2); + + Topic player = _getConstrainedStatementPlayer(constraint, assocs); + _registerTemplate(player, tpl); + removeConstraint(constraint, topics, occCounter); + } + + private void _processOccurrenceConstraints(TopicMap topicMap, + TypeInstanceIndex tiIdx, Collection<Topic> topics, + Collection<Association> assocs) { + final Topic type = topicMap + .getTopicBySubjectIdentifier(TMCL.OCCURRENCE_TYPE); + if (type == null) { return; } - DefaultTemplate tpl = new DefaultTemplate(templateName); - tpl.addParameter(topic); - tpl.addParameter(cardMin); - tpl.addParameter(cardMax); - Collection<Topic> players = _getPlayers(constraint, _constraintRole, _scopeTypeRole, assocs); - for (Topic player: players) { - _registerTemplate(player, tpl); + for (Topic constraint : _getConstraintInstances(topicMap, tiIdx, + TMCL.TOPIC_OCCURRENCE_CONSTRAINT)) { + _processHasTopicChildConstraint(constraint, "has-occurrence", type, + topics, assocs); } - if (players.size() * 2 == constraint.getRolesPlayed().size() - && constraint.getOccurrences().size() == 2 - && constraint.getNames().isEmpty() - && constraint.getTypes().size() == 1 - && constraint.getSubjectLocators().isEmpty() - && constraint.getSubjectIdentifiers().isEmpty()) { - topics.remove(constraint); - } } private void _processNameConstraints(TopicMap topicMap, TypeInstanceIndex tiIdx, Collection<Topic> topics, Collection<Association> assocs) { - final Topic type = topicMap.getTopicBySubjectIdentifier(TMCL.NAME_TYPE_ROLE); + final Topic type = topicMap.getTopicBySubjectIdentifier(TMCL.NAME_TYPE); if (type == null) { return; } - for (Topic constraint: _getConstraintInstances(topicMap, tiIdx, TMCL.NAME_TYPE)) { - _processHasTopicChildConstraint(constraint, "has-name", type, topics, assocs); + for (Topic constraint : _getConstraintInstances(topicMap, tiIdx, + TMCL.TOPIC_NAME_CONSTRAINT)) { + _processHasTopicChildConstraint(constraint, "has-name", type, + topics, assocs); } } - private void _processHasTopicChildConstraint(Topic constraint, String templateName, - Topic type, Collection<Topic> topics, Collection<Association> assocs) { - Topic topic = _getRolePlayer(constraint, type, assocs); - ILiteral cardMin = _getCardMin(constraint); - ILiteral cardMax = _getCardMax(constraint); - ILiteral regEx = _getRegEx(constraint); - if (topic == null || cardMin == null || cardMax == null || regEx == null) { + private void _processHasTopicChildConstraint(Topic constraint, + String templateName, Topic type, Collection<Topic> topics, + Collection<Association> assocs) { + Topic topic = _getConstrainedStatementPlayer(constraint, assocs); + + if (topic == null) { return; } + DefaultTemplate tpl = new DefaultTemplate(templateName); tpl.addParameter(topic); + + int occCounter = _assignCardinality(constraint, tpl, 2); + + Topic player = _getConstrainedTopicTypePlayer(constraint, assocs); + + _registerTemplate(player, tpl); + + removeConstraint(constraint, topics, occCounter); + } + + private int _assignCardinality(Topic constraint, DefaultTemplate tpl, + int counter) { + ILiteral cardMin = _getCardMin(constraint); + ILiteral cardMax = _getCardMax(constraint); + + int occCounter = counter; + + if (cardMin == null) { + occCounter--; + cardMin = _cardMinDefault; + } + if (cardMax == null) { + occCounter--; + cardMax = _cardMaxDefault; + } tpl.addParameter(cardMin); tpl.addParameter(cardMax); - tpl.addParameter(regEx); - Collection<Topic> players = _getTopicTypeRolePlayers(constraint, assocs); - for (Topic player: players) { - _registerTemplate(player, tpl); - } - if (players.size() * 2 == constraint.getRolesPlayed().size() - && constraint.getOccurrences().size() == 3 + return occCounter; + } + + /* + * removing instance from topics if it has no further informations + */ + private void removeConstraint(Topic constraint, Collection<Topic> topics, + int expectedOccurrences) { + if (constraint.getOccurrences().size() == expectedOccurrences && constraint.getNames().isEmpty() && constraint.getTypes().size() == 1 && constraint.getSubjectLocators().isEmpty() @@ -368,23 +689,6 @@ } } - private void _processNameTypeScopeConstraints(TopicMap topicMap, - TypeInstanceIndex tiIdx, Collection<Topic> topics, - Collection<Association> assocs) { - final Topic type = topicMap.getTopicBySubjectIdentifier(TMCL.NAME_TYPE_ROLE); - if (type == null) { - return; - } - for (Topic constraint: _getConstraintInstances(topicMap, tiIdx, TMCL.NAME_TYPE_SCOPE_CONSTRAINT)) { - _processTypeScopeConstraint(constraint, "has-name-scope", type, topics, assocs); - } - } - - private Topic _getRolePlayer(Topic constraint, Topic roleType, Collection<Association> assocs) { - Collection<Topic> players = _getPlayers(constraint, _constraintRole, roleType, assocs); - return players.isEmpty() ? null : players.iterator().next(); - } - private ILiteral _getValue(Topic topic, Topic type) { if (type == null) { return null; @@ -400,6 +704,10 @@ return _getValue(constraint, _cardMin); } + private ILiteral _getDatatype(Topic constraint) { + return _getValue(constraint, _datatype); + } + private ILiteral _getCardMax(Topic constraint) { return _getValue(constraint, _cardMax); } @@ -413,15 +721,39 @@ } private void _init(TopicMap topicMap) { - _appliesTo = topicMap.getTopicBySubjectIdentifier(TMCL.APPLIES_TO); - _constraintRole = topicMap.getTopicBySubjectIdentifier(TMCL.CONSTRAINT_ROLE); + _overlaps = topicMap.getTopicBySubjectIdentifier(TMCL.OVERLAPS); + _constrained_statement = topicMap + .getTopicBySubjectIdentifier(TMCL.CONSTRAINED_STATEMENT); + _constrained_topic_type = topicMap + .getTopicBySubjectIdentifier(TMCL.CONSTRAINED_TOPIC_TYPE); + _constrained_role = topicMap + .getTopicBySubjectIdentifier(TMCL.CONSTRAINED_ROLE); + _other_constrained_topic_type = topicMap + .getTopicBySubjectIdentifier(TMCL.OTHER_CONSTRAINED_TOPIC_TYPE); + _other_constrained_role = topicMap + .getTopicBySubjectIdentifier(TMCL.OTHER_CONSTRAINED_ROLE); + _belongs_to_schema = topicMap + .getTopicBySubjectIdentifier(TMCL.BELONGS_TO_SCHEMA); + + _allowed_scope = topicMap + .getTopicBySubjectIdentifier(TMCL.ALLOWED_SCOPE); + _allowed_reifier = topicMap + .getTopicBySubjectIdentifier(TMCL.ALLOWED_REIFIER); + _allowed = topicMap.getTopicBySubjectIdentifier(TMCL.ALLOWED); + _allows = topicMap.getTopicBySubjectIdentifier(TMCL.ALLOWS); + _constrained = topicMap.getTopicBySubjectIdentifier(TMCL.CONSTRAINED); + _constrains = topicMap.getTopicBySubjectIdentifier(TMCL.CONSTRAINS); + _containee = topicMap.getTopicBySubjectIdentifier(TMCL.CONTAINEE); + _container = topicMap.getTopicBySubjectIdentifier(TMCL.CONTAINER); + _cardMin = topicMap.getTopicBySubjectIdentifier(TMCL.CARD_MIN); _cardMax = topicMap.getTopicBySubjectIdentifier(TMCL.CARD_MAX); _datatype = topicMap.getTopicBySubjectIdentifier(TMCL.DATATYPE); _regEx = topicMap.getTopicBySubjectIdentifier(TMCL.REGEXP); - _topicTypeRole = topicMap.getTopicBySubjectIdentifier(TMCL.TOPIC_TYPE_ROLE); - _scopeTypeRole = topicMap.getTopicBySubjectIdentifier(TMCL.SCOPE_TYPE_ROLE); - _assocTypeRole = topicMap.getTopicBySubjectIdentifier(TMCL.ASSOCIATION_TYPE_ROLE); + + _cardMinDefault = Literal.create(0); + _cardMaxDefault = Literal.create("*", "ctm:integer"); + _regExDefault = Literal.create(".*"); } private void _registerTemplate(Topic topic, ITemplate tpl) { Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTemplate.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTemplate.java 2009-07-14 15:54:26 UTC (rev 313) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTemplate.java 2009-07-15 11:12:44 UTC (rev 314) @@ -24,7 +24,7 @@ * * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public class DefaultTemplate implements ITemplate { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2009-07-22 16:26:39
|
Revision: 322 http://tinytim.svn.sourceforge.net/tinytim/?rev=322&view=rev Author: lheuer Date: 2009-07-22 16:26:19 +0000 (Wed, 22 Jul 2009) Log Message: ----------- Updated tinyTiM Modified Paths: -------------- tinytim-mio/trunk/build.xml Added Paths: ----------- tinytim-mio/trunk/lib/tinytim-2.0.0a5-snapshot-200907221824.jar Removed Paths: ------------- tinytim-mio/trunk/lib/tinytim-2.0.0a5-snapshot-200907151305.jar Modified: tinytim-mio/trunk/build.xml =================================================================== --- tinytim-mio/trunk/build.xml 2009-07-22 16:19:50 UTC (rev 321) +++ tinytim-mio/trunk/build.xml 2009-07-22 16:26:19 UTC (rev 322) @@ -10,7 +10,7 @@ <property name="lib.junit" value="${dir.lib}/junit-4.5.jar"/> <property name="lib.tmapi" value="${dir.lib}/tmapi-2.0a2.jar"/> - <property name="lib.tinytim" value="${dir.lib}/tinytim-2.0.0a5-snapshot-200907151305.jar"/> + <property name="lib.tinytim" value="${dir.lib}/tinytim-2.0.0a5-snapshot-200907221824.jar"/> <property name="lib.tinytim.tests" value="${dir.lib}/tinytim-2.0.0a4-tests.jar"/> <property name="lib.logging" value="${dir.lib}/slf4j-api-1.5.8.jar"/> <property name="lib.mio" value="${dir.lib}/semagia-mio-0.9.4.jar"/> Deleted: tinytim-mio/trunk/lib/tinytim-2.0.0a5-snapshot-200907151305.jar =================================================================== (Binary files differ) Added: tinytim-mio/trunk/lib/tinytim-2.0.0a5-snapshot-200907221824.jar =================================================================== (Binary files differ) Property changes on: tinytim-mio/trunk/lib/tinytim-2.0.0a5-snapshot-200907221824.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2009-07-23 17:02:09
|
Revision: 334 http://tinytim.svn.sourceforge.net/tinytim/?rev=334&view=rev Author: lheuer Date: 2009-07-23 17:01:57 +0000 (Thu, 23 Jul 2009) Log Message: ----------- Preparing release Modified Paths: -------------- tinytim-mio/trunk/CHANGES.txt tinytim-mio/trunk/build.properties tinytim-mio/trunk/build.xml Added Paths: ----------- tinytim-mio/trunk/lib/tinytim-2.0.0a5-tests.jar tinytim-mio/trunk/lib/tinytim-2.0.0a5.jar Removed Paths: ------------- tinytim-mio/trunk/lib/tinytim-2.0.0a4-tests.jar tinytim-mio/trunk/lib/tinytim-2.0.0a5-snapshot-200907221908.jar Modified: tinytim-mio/trunk/CHANGES.txt =================================================================== --- tinytim-mio/trunk/CHANGES.txt 2009-07-23 16:49:53 UTC (rev 333) +++ tinytim-mio/trunk/CHANGES.txt 2009-07-23 17:01:57 UTC (rev 334) @@ -2,7 +2,7 @@ Changes Log =========== -2.0.0 a5 (xx.07.2009) +2.0.0 a5 (23.07.2009) --------------------- * JTMTopicMapReader / JTMTopicMapWriter implement the new JSON Topic Maps specification (<http://www.cerny-online.com/jtm/1.0/> Modified: tinytim-mio/trunk/build.properties =================================================================== --- tinytim-mio/trunk/build.properties 2009-07-23 16:49:53 UTC (rev 333) +++ tinytim-mio/trunk/build.properties 2009-07-23 17:01:57 UTC (rev 334) @@ -1,5 +1,5 @@ version=2.0.0 version_suffix=a5 -#release_type= +release_type= debug=off optimize=on Modified: tinytim-mio/trunk/build.xml =================================================================== --- tinytim-mio/trunk/build.xml 2009-07-23 16:49:53 UTC (rev 333) +++ tinytim-mio/trunk/build.xml 2009-07-23 17:01:57 UTC (rev 334) @@ -6,14 +6,23 @@ <property name="dir.src" value="${basedir}/src/main/java"/> <property name="dir.test" value="${basedir}/src/test/java"/> + <property name="dir.cxtm" value="${basedir}/src/test/cxtm/"/> <property name="dir.lib" value="${basedir}/lib"/> <property name="lib.junit" value="${dir.lib}/junit-4.5.jar"/> <property name="lib.tmapi" value="${dir.lib}/tmapi-2.0a2.jar"/> - <property name="lib.tinytim" value="${dir.lib}/tinytim-2.0.0a5-snapshot-200907221908.jar"/> - <property name="lib.tinytim.tests" value="${dir.lib}/tinytim-2.0.0a4-tests.jar"/> + <property name="lib.tinytim" value="${dir.lib}/tinytim-2.0.0a5.jar"/> + <property name="lib.tinytim.tests" value="${dir.lib}/tinytim-2.0.0a5-tests.jar"/> <property name="lib.logging" value="${dir.lib}/slf4j-api-1.5.8.jar"/> + <property name="lib.logger" value="${dir.lib}/slf4j-jdk14-1.5.8.jar"/> + <property name="lib.jing" value="${dir.lib}/jing.jar"/> <property name="lib.mio" value="${dir.lib}/semagia-mio-0.9.4.jar"/> + <property name="lib.jtm" value="${dir.lib}/semagia-mio-jtm-0.9.3.jar"/> + <property name="lib.ltm" value="${dir.lib}/semagia-mio-ltm-0.9.4.jar"/> + <property name="lib.rdf" value="${dir.lib}/semagia-mio-rdf-0.9.3.jar"/> + <property name="lib.snello" value="${dir.lib}/semagia-mio-snello-0.9.3.jar"/> + <property name="lib.tmxml" value="${dir.lib}/semagia-mio-tmxml-0.9.3.jar"/> + <property name="lib.xtm" value="${dir.lib}/semagia-mio-xtm-0.9.4.jar"/> <target name="help"> <echo message="------------------------"/> @@ -74,6 +83,9 @@ noindex="false" windowtitle="tinyTiM MIO API v${dist.version}" doctitle="tinyTiM API MIO v${dist.version}"> + <fileset dir="${dir.src}"> + <exclude name="org/tinytim/mio/internal/**"/> + </fileset> <!-- <doclet name="net.gleamynode.apiviz.APIviz" path="${dir.lib}/apiviz-1.2.5.GA.jar"> @@ -105,6 +117,7 @@ </javac> <junit printsummary="true" showoutput="false" errorProperty="test.failed" failureProperty="test.failed"> + <sysproperty key="org.tinytim.cxtm-test-dir" value="${dir.cxtm}"/> <classpath> <pathelement location="${dir.build.classes}"/> <pathelement location="${dir.build.tests}"/> @@ -112,14 +125,19 @@ <pathelement location="${lib.tmapi}"/> <pathelement location="${lib.tinytim}"/> <pathelement location="${lib.tinytim.tests}"/> + <pathelement location="${lib.logging}"/> + <pathelement location="${lib.logger}"/> + <pathelement location="${lib.jing}"/> <pathelement location="${lib.mio}"/> + <pathelement location="${lib.jtm}"/> + <pathelement location="${lib.ltm}"/> + <pathelement location="${lib.rdf}"/> + <pathelement location="${lib.snello}"/> + <pathelement location="${lib.tmxml}"/> + <pathelement location="${lib.xtm}"/> </classpath> <formatter type="brief" usefile="false"/> - <batchtest fork="no" todir="${dir.build}"> - <fileset dir="${dir.build.tests}/"> - <include name="**/Test**.class"/> - </fileset> - </batchtest> + <test name="org.tinytim.mio.AllTests"/> </junit> <fail message="Tests failed. Check test output." if="test.failed"/> </target> Deleted: tinytim-mio/trunk/lib/tinytim-2.0.0a4-tests.jar =================================================================== (Binary files differ) Deleted: tinytim-mio/trunk/lib/tinytim-2.0.0a5-snapshot-200907221908.jar =================================================================== (Binary files differ) Added: tinytim-mio/trunk/lib/tinytim-2.0.0a5-tests.jar =================================================================== (Binary files differ) Property changes on: tinytim-mio/trunk/lib/tinytim-2.0.0a5-tests.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: tinytim-mio/trunk/lib/tinytim-2.0.0a5.jar =================================================================== (Binary files differ) Property changes on: tinytim-mio/trunk/lib/tinytim-2.0.0a5.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2009-07-23 17:05:19
|
Revision: 336 http://tinytim.svn.sourceforge.net/tinytim/?rev=336&view=rev Author: lheuer Date: 2009-07-23 17:05:14 +0000 (Thu, 23 Jul 2009) Log Message: ----------- trunk represents next release now Modified Paths: -------------- tinytim-mio/trunk/CHANGES.txt tinytim-mio/trunk/build.properties Modified: tinytim-mio/trunk/CHANGES.txt =================================================================== --- tinytim-mio/trunk/CHANGES.txt 2009-07-23 17:03:09 UTC (rev 335) +++ tinytim-mio/trunk/CHANGES.txt 2009-07-23 17:05:14 UTC (rev 336) @@ -2,6 +2,11 @@ Changes Log =========== +2.0.0 a6 (xx.yy.2009) +--------------------- + + + 2.0.0 a5 (23.07.2009) --------------------- * JTMTopicMapReader / JTMTopicMapWriter implement the new JSON Topic Maps Modified: tinytim-mio/trunk/build.properties =================================================================== --- tinytim-mio/trunk/build.properties 2009-07-23 17:03:09 UTC (rev 335) +++ tinytim-mio/trunk/build.properties 2009-07-23 17:05:14 UTC (rev 336) @@ -1,5 +1,5 @@ version=2.0.0 -version_suffix=a5 -release_type= +version_suffix=a6 +#release_type= debug=off optimize=on This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2009-07-29 10:38:06
|
Revision: 341 http://tinytim.svn.sourceforge.net/tinytim/?rev=341&view=rev Author: lheuer Date: 2009-07-29 10:37:58 +0000 (Wed, 29 Jul 2009) Log Message: ----------- Better LTM Unicode support (passes now all CXTM tests) Modified Paths: -------------- tinytim-mio/trunk/build.xml Added Paths: ----------- tinytim-mio/trunk/lib/semagia-mio-ltm-0.9.5.jar Removed Paths: ------------- tinytim-mio/trunk/lib/semagia-mio-ltm-0.9.4.jar Modified: tinytim-mio/trunk/build.xml =================================================================== --- tinytim-mio/trunk/build.xml 2009-07-28 11:14:03 UTC (rev 340) +++ tinytim-mio/trunk/build.xml 2009-07-29 10:37:58 UTC (rev 341) @@ -18,7 +18,7 @@ <property name="lib.jing" value="${dir.lib}/jing.jar"/> <property name="lib.mio" value="${dir.lib}/semagia-mio-0.9.4.jar"/> <property name="lib.jtm" value="${dir.lib}/semagia-mio-jtm-0.9.3.jar"/> - <property name="lib.ltm" value="${dir.lib}/semagia-mio-ltm-0.9.4.jar"/> + <property name="lib.ltm" value="${dir.lib}/semagia-mio-ltm-0.9.5.jar"/> <property name="lib.rdf" value="${dir.lib}/semagia-mio-rdf-0.9.3.jar"/> <property name="lib.snello" value="${dir.lib}/semagia-mio-snello-0.9.3.jar"/> <property name="lib.tmxml" value="${dir.lib}/semagia-mio-tmxml-0.9.3.jar"/> Deleted: tinytim-mio/trunk/lib/semagia-mio-ltm-0.9.4.jar =================================================================== (Binary files differ) Added: tinytim-mio/trunk/lib/semagia-mio-ltm-0.9.5.jar =================================================================== (Binary files differ) Property changes on: tinytim-mio/trunk/lib/semagia-mio-ltm-0.9.5.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2009-08-14 11:59:34
|
Revision: 348 http://tinytim.svn.sourceforge.net/tinytim/?rev=348&view=rev Author: lheuer Date: 2009-08-14 11:59:23 +0000 (Fri, 14 Aug 2009) Log Message: ----------- Removed unused Logger, committed forgotten code changes Modified Paths: -------------- tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractXTMTopicMapReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTMCLPreprocessor.java Added Paths: ----------- tinytim-mio/trunk/lib/tinytim-2.0.0a6-snapshot-200908141400.jar Removed Paths: ------------- tinytim-mio/trunk/lib/tinytim-2.0.0a6-snapshot-200908121355.jar Deleted: tinytim-mio/trunk/lib/tinytim-2.0.0a6-snapshot-200908121355.jar =================================================================== (Binary files differ) Added: tinytim-mio/trunk/lib/tinytim-2.0.0a6-snapshot-200908141400.jar =================================================================== (Binary files differ) Property changes on: tinytim-mio/trunk/lib/tinytim-2.0.0a6-snapshot-200908141400.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractXTMTopicMapReader.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractXTMTopicMapReader.java 2009-08-14 11:43:24 UTC (rev 347) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractXTMTopicMapReader.java 2009-08-14 11:59:23 UTC (rev 348) @@ -35,29 +35,46 @@ */ abstract class AbstractXTMTopicMapReader extends AbstractTopicMapReader { + /** + * The underlying topic map. + * + * This can be <tt>null</tt> if + * {@link #AbstractXTMTopicMapReader(IMapHandler, Syntax, Source)} + * was used to create an instance of this class and the provided handler + * is not an instance of {@link TinyTimMapInputHandler}. + */ + protected TopicMap _tm; + protected AbstractXTMTopicMapReader(TopicMap topicMap, Syntax syntax, File source) throws IOException { super(topicMap, syntax, source); + _tm = topicMap; } protected AbstractXTMTopicMapReader(TopicMap topicMap, Syntax syntax, File source, String docIRI) throws IOException { super(topicMap, syntax, source, docIRI); + _tm = topicMap; } protected AbstractXTMTopicMapReader(TopicMap topicMap, Syntax syntax, InputStream source, String docIRI) { super(topicMap, syntax, source, docIRI); + _tm = topicMap; } protected AbstractXTMTopicMapReader(TopicMap topicMap, Syntax syntax, Source source) { super(topicMap, syntax, source); + _tm = topicMap; } protected AbstractXTMTopicMapReader(IMapHandler handler, Syntax syntax, Source source) { super(handler, syntax, source); + if (handler instanceof TinyTimMapInputHandler) { + _tm = ((TinyTimMapInputHandler) handler).getTopicMap(); + } } /** Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTMCLPreprocessor.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTMCLPreprocessor.java 2009-08-14 11:43:24 UTC (rev 347) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTMCLPreprocessor.java 2009-08-14 11:59:23 UTC (rev 348) @@ -22,7 +22,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import java.util.logging.Logger; import org.tinytim.core.value.Literal; import org.tinytim.internal.api.IIndexManagerAware; @@ -48,11 +47,6 @@ */ public class DefaultTMCLPreprocessor implements ITMCLPreprocessor { - @SuppressWarnings("unused") - // TODO can we remove it, if we don't use it? - private static final Logger LOG = Logger - .getLogger(DefaultTMCLPreprocessor.class.getName()); - private final Map<Topic, Collection<ITemplate>> _topic2Templates; private Topic _constrains; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: Markus U. <mar...@gm...> - 2009-08-14 12:12:08
|
lh...@us... schrieb: > Revision: 348 > http://tinytim.svn.sourceforge.net/tinytim/?rev=348&view=rev > Author: lheuer > Date: 2009-08-14 11:59:23 +0000 (Fri, 14 Aug 2009) > > Log Message: > ----------- > Removed unused Logger, committed forgotten code changes > Yay, it works again! ;) Ad astra, Markus |
From: <bo...@us...> - 2009-08-18 08:55:45
|
Revision: 353 http://tinytim.svn.sourceforge.net/tinytim/?rev=353&view=rev Author: bosso Date: 2009-08-18 08:55:32 +0000 (Tue, 18 Aug 2009) Log Message: ----------- ctm export fixes Modified Paths: -------------- tinytim-mio/trunk/build.properties tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMTopicMapWriter.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTMCLPreprocessor.java Added Paths: ----------- tinytim-mio/trunk/lib/tinytim-2.0.0a6-snapshot-200908171257.jar Removed Paths: ------------- tinytim-mio/trunk/lib/tinytim-2.0.0a6-snapshot-200908141400.jar Modified: tinytim-mio/trunk/build.properties =================================================================== --- tinytim-mio/trunk/build.properties 2009-08-17 20:08:59 UTC (rev 352) +++ tinytim-mio/trunk/build.properties 2009-08-18 08:55:32 UTC (rev 353) @@ -1,5 +1,5 @@ version=2.0.0 version_suffix=a6 #release_type= -debug=off +debug=on optimize=on Deleted: tinytim-mio/trunk/lib/tinytim-2.0.0a6-snapshot-200908141400.jar =================================================================== (Binary files differ) Added: tinytim-mio/trunk/lib/tinytim-2.0.0a6-snapshot-200908171257.jar =================================================================== (Binary files differ) Property changes on: tinytim-mio/trunk/lib/tinytim-2.0.0a6-snapshot-200908171257.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMTopicMapWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMTopicMapWriter.java 2009-08-17 20:08:59 UTC (rev 352) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMTopicMapWriter.java 2009-08-18 08:55:32 UTC (rev 353) @@ -140,7 +140,8 @@ ASSOCIATION, ROLE, OCCURRENCE, - NAME + NAME, + SUBJECT } /** @@ -468,6 +469,13 @@ _newline(); _writeSection("INSTANCES"); _writeSection("Topics"); + // remove tmdm:subject, because filter below doesn't work. tmdm:subject plays a role, so + // _omitTopic returns false - we definitly don't want "tmdm:subject ." in our ctm file, do we? + Topic topic = topicMap.createTopicBySubjectIdentifier(TMDM.SUBJECT); + if ( (topic!=null) && (topics.contains(topic)) ) { + topics.remove(topic); + } + _writeTopics(topics); if (!assocs.isEmpty()) { Association[] assocArray = assocs.toArray(new Association[assocs.size()]); @@ -536,6 +544,7 @@ _topic2Templates.putAll(tmclProcessor.getTopicToTemplatesMapping()); } + @SuppressWarnings("deprecation") private Locator[] _getSubjectIdentifiersToFilter(TypeFilter mode) { Locator[] toFilter = new Locator[0]; switch (mode) { @@ -616,7 +625,8 @@ TMCL.CARD_MAX, TMCL.DATATYPE, TMCL.REGEXP, - TMCL.VALIDATION_EXPRESSION + TMCL.VALIDATION_EXPRESSION, + TMDM.SUBJECT // the occurrence }; } break; @@ -660,7 +670,6 @@ && topic.getTypes().isEmpty() && topic.getNames().isEmpty() && topic.getOccurrences().isEmpty() - && topic.getRolesPlayed().isEmpty() && topic.getReified() == null; } Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTMCLPreprocessor.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTMCLPreprocessor.java 2009-08-17 20:08:59 UTC (rev 352) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTMCLPreprocessor.java 2009-08-18 08:55:32 UTC (rev 353) @@ -30,6 +30,7 @@ import org.tinytim.mio.internal.ctm.ITMCLPreprocessor; import org.tinytim.mio.internal.ctm.ITemplate; import org.tinytim.voc.TMCL; +import org.tinytim.voc.TMDM; import org.tmapi.core.Association; import org.tmapi.core.Locator; import org.tmapi.core.Occurrence; @@ -278,7 +279,7 @@ TypeInstanceIndex tiIdx, Collection<Topic> topics, Collection<Association> assocs) { for (Topic constraint : _getConstraintInstances(topicMap, tiIdx, - TMCL.ABSTRACT_TOPIC_TYPE_CONSTRAINT)) { + TMCL.ABSTRACT_CONSTRAINT)) { _processAbstractTopicConstraint(constraint, topics, assocs); } } @@ -614,7 +615,7 @@ TypeInstanceIndex tiIdx, Collection<Topic> topics, Collection<Association> assocs) { final Topic type = topicMap - .getTopicBySubjectIdentifier(TMCL.SCOPE_TYPE); + .getTopicBySubjectIdentifier(TMCL.TOPIC_TYPE); if (type == null) { return; } @@ -641,10 +642,12 @@ private void _processOccurrenceConstraints(TopicMap topicMap, TypeInstanceIndex tiIdx, Collection<Topic> topics, Collection<Association> assocs) { - final Topic type = topicMap - .getTopicBySubjectIdentifier(TMCL.OCCURRENCE_TYPE); + Topic type = topicMap.getTopicBySubjectIdentifier(TMCL.OCCURRENCE_TYPE); if (type == null) { - return; + // try tmdm:subject + type = topicMap.getTopicBySubjectIdentifier(TMDM.SUBJECT); + if (type==null) + return; } for (Topic constraint : _getConstraintInstances(topicMap, tiIdx, TMCL.TOPIC_OCCURRENCE_CONSTRAINT)) { @@ -656,9 +659,12 @@ private void _processNameConstraints(TopicMap topicMap, TypeInstanceIndex tiIdx, Collection<Topic> topics, Collection<Association> assocs) { - final Topic type = topicMap.getTopicBySubjectIdentifier(TMCL.NAME_TYPE); + Topic type = topicMap.getTopicBySubjectIdentifier(TMCL.NAME_TYPE); if (type == null) { - return; + // try default name-type + type = topicMap.getTopicBySubjectIdentifier(TMDM.TOPIC_NAME); + if (type==null) + return; } for (Topic constraint : _getConstraintInstances(topicMap, tiIdx, TMCL.TOPIC_NAME_CONSTRAINT)) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2009-08-27 15:47:41
|
Revision: 357 http://tinytim.svn.sourceforge.net/tinytim/?rev=357&view=rev Author: lheuer Date: 2009-08-27 15:47:32 +0000 (Thu, 27 Aug 2009) Log Message: ----------- tinyTiM / mio update Modified Paths: -------------- tinytim-mio/trunk/build.xml Added Paths: ----------- tinytim-mio/trunk/lib/semagia-mio-0.9.5.jar tinytim-mio/trunk/lib/tinytim-2.0.0a6-snapshot-200908271522.jar Removed Paths: ------------- tinytim-mio/trunk/lib/semagia-mio-0.9.4.jar tinytim-mio/trunk/lib/tinytim-2.0.0a6-snapshot-200908171257.jar Modified: tinytim-mio/trunk/build.xml =================================================================== --- tinytim-mio/trunk/build.xml 2009-08-27 13:08:17 UTC (rev 356) +++ tinytim-mio/trunk/build.xml 2009-08-27 15:47:32 UTC (rev 357) @@ -17,7 +17,7 @@ <!-- Libs --> <property name="lib.jing" value="${dir.lib}/jing.jar"/> <property name="lib.junit" value="${dir.lib}/junit-4.5.jar"/> - <property name="lib.mio" value="${dir.lib}/semagia-mio-0.9.4.jar"/> + <property name="lib.mio" value="${dir.lib}/semagia-mio-0.9.5.jar"/> <property name="lib.jtm" value="${dir.lib}/semagia-mio-jtm-0.9.3.jar"/> <property name="lib.ltm" value="${dir.lib}/semagia-mio-ltm-0.9.5.jar"/> <property name="lib.rdf" value="${dir.lib}/semagia-mio-rdf-0.9.3.jar"/> Deleted: tinytim-mio/trunk/lib/semagia-mio-0.9.4.jar =================================================================== (Binary files differ) Added: tinytim-mio/trunk/lib/semagia-mio-0.9.5.jar =================================================================== (Binary files differ) Property changes on: tinytim-mio/trunk/lib/semagia-mio-0.9.5.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Deleted: tinytim-mio/trunk/lib/tinytim-2.0.0a6-snapshot-200908171257.jar =================================================================== (Binary files differ) Added: tinytim-mio/trunk/lib/tinytim-2.0.0a6-snapshot-200908271522.jar =================================================================== (Binary files differ) Property changes on: tinytim-mio/trunk/lib/tinytim-2.0.0a6-snapshot-200908271522.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2009-11-04 18:29:32
|
Revision: 361 http://tinytim.svn.sourceforge.net/tinytim/?rev=361&view=rev Author: lheuer Date: 2009-11-04 18:29:23 +0000 (Wed, 04 Nov 2009) Log Message: ----------- Updated tinyTiM, removed CXTMWriter (part of tinyTiM now) Added Paths: ----------- tinytim-mio/trunk/lib/tinytim-2.0.0a6-snapshot-200911041800.jar tinytim-mio/trunk/lib/tmapi-2.0RC1.jar Removed Paths: ------------- tinytim-mio/trunk/lib/tinytim-2.0.0a6-snapshot-200908271522.jar tinytim-mio/trunk/lib/tmapi-2.0a2.jar tinytim-mio/trunk/src/main/java/org/tinytim/mio/CXTMTopicMapWriter.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/XMLC14NWriter.java Deleted: tinytim-mio/trunk/lib/tinytim-2.0.0a6-snapshot-200908271522.jar =================================================================== (Binary files differ) Added: tinytim-mio/trunk/lib/tinytim-2.0.0a6-snapshot-200911041800.jar =================================================================== (Binary files differ) Property changes on: tinytim-mio/trunk/lib/tinytim-2.0.0a6-snapshot-200911041800.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: tinytim-mio/trunk/lib/tmapi-2.0RC1.jar =================================================================== (Binary files differ) Property changes on: tinytim-mio/trunk/lib/tmapi-2.0RC1.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Deleted: tinytim-mio/trunk/lib/tmapi-2.0a2.jar =================================================================== (Binary files differ) Deleted: tinytim-mio/trunk/src/main/java/org/tinytim/mio/CXTMTopicMapWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/CXTMTopicMapWriter.java 2009-11-04 16:58:30 UTC (rev 360) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/CXTMTopicMapWriter.java 2009-11-04 18:29:23 UTC (rev 361) @@ -1,1226 +0,0 @@ -/* - * Copyright 2008 Lars Heuer (heuer[at]semagia.com) - * - * 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.mio; - -import java.io.IOException; -import java.io.OutputStream; -import java.util.AbstractSet; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.NoSuchElementException; -import java.util.Set; -import java.util.logging.Logger; - -import org.tinytim.internal.api.IIndexManagerAware; -import org.tinytim.internal.utils.CollectionFactory; -import org.tinytim.utils.DuplicateRemovalUtils; -import org.tinytim.voc.TMDM; -import org.tinytim.voc.XSD; -import org.tmapi.core.Association; -import org.tmapi.core.Construct; -import org.tmapi.core.DatatypeAware; -import org.tmapi.core.Locator; -import org.tmapi.core.Name; -import org.tmapi.core.Occurrence; -import org.tmapi.core.Reifiable; -import org.tmapi.core.Role; -import org.tmapi.core.Scoped; -import org.tmapi.core.Topic; -import org.tmapi.core.TopicInUseException; -import org.tmapi.core.TopicMap; -import org.tmapi.core.Typed; -import org.tmapi.core.Variant; -import org.tmapi.index.TypeInstanceIndex; - -import org.xml.sax.Attributes; -import org.xml.sax.helpers.AttributesImpl; - -/** - * Provides serialization of topic maps into Canonical XTM (CXTM). - * <p> - * CXTM is a format that guarantees that two equivalent Topic Maps Data Model - * instances [ISO/IEC 13250-2] will always produce byte-by-byte identical - * serializations, and that non-equivalent instances will always produce - * different serializations. - * </p> - * <p> - * See <a href="http://www.isotopicmaps.org/cxtm/">http://www.isotopicmaps.org/cxtm/</a> - * for details. - * </p> - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -public final class CXTMTopicMapWriter implements TopicMapWriter { - - private static final Logger LOG = Logger.getLogger(CXTMTopicMapWriter.class.getName()); - - private static final Role[] _EMPTY_ROLES = new Role[0]; - - private final AttributesImpl _attrs; - - private Topic _type; - private Topic _instance; - private Topic _typeInstance; - - private final XMLC14NWriter _out; - private final String _normBase; - private final Map<Construct, Integer> _construct2Id; - private final Map<Topic, List<Role>> _topic2Roles; - private final Map<Locator, String> _locator2Norm; - private final Map<Association, Role[]> _assoc2Roles; - - private final Comparator<Topic> _topicComparator; - private final Comparator<Association> _assocComparator; - private final Comparator<Role> _roleComparator; - private final Comparator<Occurrence> _occComparator; - private final Comparator<Name> _nameComparator; - private final Comparator<Variant> _variantComparator; - private final Comparator<Set<Locator>> _locSetComparator; - private final Comparator<Locator> _locComparator; - private final Comparator<Set<Topic>> _scopeComparator; - - /** - * Creates a canonicalizer. - * - * @param out The stream the CXTM is written onto. - * @param baseLocator The base locator which is used to resolve IRIs against. - * @throws IOException If an error occurs. - */ - public CXTMTopicMapWriter(OutputStream out, String baseLocator) throws IOException { - if (baseLocator == null) { - throw new IllegalArgumentException("The base locator must not be null"); - } - _out = new XMLC14NWriter(out); - _attrs = new AttributesImpl(); - _normBase = _normalizeBaseLocator(baseLocator); - _construct2Id = CollectionFactory.createIdentityMap(); - _locator2Norm = CollectionFactory.createIdentityMap(); - _assoc2Roles = CollectionFactory.createIdentityMap(); - _topic2Roles = CollectionFactory.createIdentityMap(); - _topicComparator = new TopicComparator(); - _assocComparator = new AssociationComparator(); - _roleComparator = new RoleComparator(); - _occComparator = new OccurrenceComparator(); - _nameComparator = new NameComparator(); - _variantComparator = new VariantComparator(); - _locSetComparator = new LocatorSetComparator(); - _locComparator = new LocatorComparator(); - _scopeComparator = new ScopeComparator(); - } - - /** - * Serializes the specified <tt>topicMap</tt> into the CXTM format. - * <p> - * <em>CAUTION</em>: This method MAY modify the topic map since duplicate - * Topic Maps constructs (if any) are removed in advance. - * </p> - * - * @param topicMap The topic map to serialize. - * @throws IOException If an error occurs. - */ - public void write(TopicMap topicMap) throws IOException { - DuplicateRemovalUtils.removeDuplicates(topicMap); - TypeInstanceIndex typeInstanceIndex = ((IIndexManagerAware)topicMap).getIndexManager().getTypeInstanceIndex(); - if (!typeInstanceIndex.isAutoUpdated()) { - typeInstanceIndex.reindex(); - } - Topic[] topics = _fetchTopics(topicMap, typeInstanceIndex); - Association[] assocs = _fetchAssociations(topicMap, typeInstanceIndex); - typeInstanceIndex.close(); - _createIndex(topics, assocs); - _out.startDocument(); - _attrs.clear(); - _addReifier(_attrs, topicMap); - _out.startElement("topicMap", _attrs); - _out.newline(); - _writeItemIdentifiers(topicMap); - for (Topic topic: topics) { - _writeTopic(topic); - } - for (Association assoc: assocs) { - _writeAssociation(assoc); - } - _out.endElement("topicMap"); - _out.newline(); - _out.endDocument(); - _attrs.clear(); - _construct2Id.clear(); - _topic2Roles.clear(); - _locator2Norm.clear(); - _assoc2Roles.clear(); - } - - /** - * Returns an unsorted array of topics which should be included into - * the output. - * <p> - * This method may return more topics than {@link TopicMap#getTopics()} - * since this method creates virtual topics to model type-instance - * relationships properly. - * </p> - * - * @param topicMap The topic map from which the topic should be serialized. - * @param idx A (upto date) type instance index. - * @return All topics which must be included into the output. - */ - private Topic[] _fetchTopics(final TopicMap topicMap, final TypeInstanceIndex idx) { - Collection<Topic> types = idx.getTopicTypes(); - if (types.isEmpty()) { - Set<Topic> topics = topicMap.getTopics(); - return topics.toArray(new Topic[topics.size()]); - } - else { - List<Topic> topics = CollectionFactory.createList(topicMap.getTopics()); - _typeInstance = _getTopicBySubjectIdentifier(topicMap, topics, TMDM.TYPE_INSTANCE); - _type = _getTopicBySubjectIdentifier(topicMap, topics, TMDM.TYPE); - _instance = _getTopicBySubjectIdentifier(topicMap, topics, TMDM.INSTANCE); - return topics.toArray(new Topic[topics.size()]); - } - } - - /** - * Returns a topic by its subject identifier. If the topic is null, a - * {@link TypeInstanceTopic} is created, added to the <tt>topics</tt> - * and returned. - * - * @param tm The topic map to fetch the topic from. - * @param topics A modifiable collection of topics. - * @param sid The subject identifier. - * @return A topic with the specified subject identifier. - */ - private Topic _getTopicBySubjectIdentifier(TopicMap tm, Collection<Topic> topics, Locator sid) { - Topic topic = tm.getTopicBySubjectIdentifier(sid); - if (topic == null) { - topic = new TypeInstanceTopic(sid); - topics.add(topic); - } - return topic; - } - - /** - * Returns an unsorted array of associations which should be serialized. - * - * This method may return more association than {@link TopicMap#getAssociations()} - * since this method may create virtual associations which are used to - * model type-instance relationships properly. - * - * @param tm The topic map from which the associations should be serialized. - * @param idx A (upto date) type instance index. - * @return An unsorted array of associations which must be included into the output. - */ - private Association[] _fetchAssociations(final TopicMap tm, final TypeInstanceIndex idx) { - Collection<Topic> types = idx.getTopicTypes(); - if (types.isEmpty()) { - Set<Association> assocs = tm.getAssociations(); - return assocs.toArray(new Association[assocs.size()]); - } - else { - List<Association> assocs = CollectionFactory.createList(tm.getAssociations()); - for (Topic type: types) { - for (Topic instance: idx.getTopics(type)) { - assocs.add(new TypeInstanceAssociation(type, instance)); - } - } - return assocs.toArray(new Association[assocs.size()]); - } - } - - /** - * Creates the index on which the canonicalizer operates. - * - * As sideeffect, the provided topic and association arrays get sorted. - * - * @param topics An array of topics. - * @param assocs An array of associations. - */ - private void _createIndex(Topic[] topics, Association[] assocs) { - Arrays.sort(topics, _topicComparator); - Topic topic = null; - for (int i=0; i < topics.length; i++) { - topic = topics[i]; - _construct2Id.put(topic, Integer.valueOf(i+1)); - } - Arrays.sort(assocs, _assocComparator); - Association assoc = null; - for (int i=0; i < assocs.length; i++) { - assoc = assocs[i]; - _construct2Id.put(assoc, Integer.valueOf(i+1)); - Set<Role> roles_ = assoc.getRoles(); - Role[] roles = roles_.toArray(new Role[roles_.size()]); - Arrays.sort(roles, _roleComparator); - _assoc2Roles.put(assoc, roles); - for (int j=0; j < roles.length; j++) { - _construct2Id.put(roles[j], Integer.valueOf(j+1)); - } - } - } - - /** - * Returns a sorted array of roles of the provided association. - * - * @param assoc The association to retrieve the roles from. - * @return A (maybe empty) sorted array of roles. - */ - private Role[] _getRoles(final Association assoc) { - Role[] roles = _assoc2Roles.get(assoc); - return roles != null ? roles : _EMPTY_ROLES; - } - - /** - * Returns a sorted array of names of the provided topic. - * - * @param topic The topic to retrieve the names from. - * @return A (maybe empty) sorted array of names. - */ - private Name[] _getNames(final Topic topic) { - Set<Name> names_ = topic.getNames(); - Name[] names = names_.toArray(new Name[names_.size()]); - Arrays.sort(names, _nameComparator); - return names; - } - - /** - * Returs a sorted array of variants of the provided name. - * - * @param name The name to retrieve the variants from. - * @return A (maybe empty) sorted array of variants. - */ - private Variant[] _getVariants(final Name name) { - Set<Variant> variants_ = name.getVariants(); - Variant[] variants = variants_.toArray(new Variant[variants_.size()]); - Arrays.sort(variants, _variantComparator); - return variants; - } - - /** - * Returns a sorted array of occurrences of the provided topic. - * - * @param topic The topic to retrieve the occurrences from. - * @return A (maybe emtpy) sorted array of occurrences. - */ - private Occurrence[] _getOccurrences(final Topic topic) { - Set<Occurrence> occs_ = topic.getOccurrences(); - Occurrence[] occs = occs_.toArray(new Occurrence[occs_.size()]); - Arrays.sort(occs, _occComparator); - return occs; - } - - /** - * Returns the index of the provided Topic Maps construct. - * - * The "index" is <cite>"[...] the string encoding of the position of this - * information item in the canonically ordered list of the values from - * that set".</cite> (CXTM 3.20 Constructing the number attribute). - * - * @param tmo The Topic Maps construct to return the index of. - * @return The index of the Topic Maps construct. - */ - private int _indexOf(final Construct tmo) { - return _construct2Id.get(tmo).intValue(); - } - - /** - * Serializes the <tt>topic</tt>. - * - * @param topic The topic to serialize. - * @throws IOException If an error occurs. - */ - private void _writeTopic(final Topic topic) throws IOException { - _attrs.clear(); - _attrs.addAttribute("", "number", "", "CDATA", Integer.toString(_indexOf(topic))); - _out.startElement("topic", _attrs); - _out.newline(); - _writeLocatorSet("subjectIdentifiers", topic.getSubjectIdentifiers()); - _writeLocatorSet("subjectLocators", topic.getSubjectLocators()); - _writeItemIdentifiers(topic); - Name[] names = _getNames(topic); - for (int i=0; i < names.length; i++) { - _writeName(names[i], i+1); - } - Occurrence[] occs = _getOccurrences(topic); - for (int i=0; i < occs.length; i++) { - _writeOccurrence(occs[i], i+1); - } - List<Role> roles_ = CollectionFactory.createList(topic.getRolesPlayed()); - List<Role> alienRoles = _topic2Roles.get(topic); - if (alienRoles != null) { - roles_.addAll(alienRoles); - } - Role[] roles = roles_.toArray(new Role[roles_.size()]); - Arrays.sort(roles, _roleComparator); - StringBuilder sb = new StringBuilder(20); - for (int i=0; i < roles.length; i++) { - sb.append("association.") - .append(_indexOf(roles[i].getParent())) - .append(".role.") - .append(_indexOf(roles[i])); - _attrs.clear(); - _attrs.addAttribute("", "ref", "", "CDATA", sb.toString()); - _out.startElement("rolePlayed", _attrs); - _out.endElement("rolePlayed"); - _out.newline(); - sb.setLength(0); - } - _out.endElement("topic"); - _out.newline(); - } - - /** - * Serializes an association. - * - * @param assoc The association to serialize. - * @throws IOException If an error occurs. - */ - private void _writeAssociation(final Association assoc) throws IOException { - _out.startElement("association", _attributes(assoc, _indexOf(assoc))); - _out.newline(); - _writeType(assoc); - for (Role role: _getRoles(assoc)) { - _out.startElement("role", _attributes(role, _indexOf(role))); - _out.newline(); - _out.startElement("player", _topicRef(role.getPlayer())); - _out.endElement("player"); - _out.newline(); - _writeType(role); - _writeItemIdentifiers(role); - _out.endElement("role"); - _out.newline(); - } - _writeScope(assoc); - _writeItemIdentifiers(assoc); - _out.endElement("association"); - _out.newline(); - } - - /** - * Serializes an occurrence. - * - * @param occ The occurrence to serialize. - * @param pos The position of the occurrence within the parent container. - * @throws IOException If an error occurs. - */ - private void _writeOccurrence(final Occurrence occ, int pos) throws IOException { - _out.startElement("occurrence", _attributes(occ, pos)); - _out.newline(); - _writeDatatyped(occ); - _writeType(occ); - _writeScope(occ); - _writeItemIdentifiers(occ); - _out.endElement("occurrence"); - _out.newline(); - } - - /** - * Writes the value/datatype pair of an occurrence or variant. - * - * @param obj The construct to serialize. - * @throws IOException If an error occurs. - */ - private void _writeDatatyped(final DatatypeAware obj) throws IOException { - final String value = XSD.ANY_URI.equals(obj.getDatatype()) - ? _normalizeLocator(obj.locatorValue()) - : obj.getValue(); - _out.startElement("value"); - _out.characters(value); - _out.endElement("value"); - _out.newline(); - _out.startElement("datatype"); - _out.characters(obj.getDatatype().getReference()); - _out.endElement("datatype"); - _out.newline(); - } - - /** - * Serializes a topic name. - * - * @param name The name to serialize. - * @param pos The position of the name within the parent container. - * @throws IOException If an error occurs. - */ - private void _writeName(final Name name, int pos) throws IOException { - _out.startElement("name", _attributes(name, pos)); - _out.newline(); - _out.startElement("value"); - _out.characters(name.getValue()); - _out.endElement("value"); - _out.newline(); - _writeType(name); - _writeScope(name); - Variant[] variants = _getVariants(name); - Variant variant = null; - for (int i=0; i<variants.length; i++) { - variant = variants[i]; - _out.startElement("variant", _attributes(variant, i+1)); - _out.newline(); - _writeDatatyped(variant); - _writeScope(variant); - _writeItemIdentifiers(variant); - _out.endElement("variant"); - _out.newline(); - } - _writeItemIdentifiers(name); - _out.endElement("name"); - _out.newline(); - } - - /** - * Serializes the type of a typed Topic Maps construct. - * - * @param typed The typed Topic Maps construct from which the type should be - * serialized. - * @throws IOException If an error occurs. - */ - private void _writeType(final Typed typed) throws IOException { - _out.startElement("type", _topicRef(typed.getType())); - _out.endElement("type"); - _out.newline(); - } - - /** - * Serializes the scope of a scoped Topic Maps construct. - * - * If the scope is unconstrained, this method does nothing. - * - * @param scoped The scoped Topic Maps construct. - * @throws IOException If an error occurs. - */ - private void _writeScope(final Scoped scoped) throws IOException { - Set<Topic> scope = scoped.getScope(); - if (scope.isEmpty()) { - return; - } - _out.startElement("scope"); - _out.newline(); - Topic[] themes = scope.toArray(new Topic[scope.size()]); - Arrays.sort(themes, _topicComparator); - for (int i=0; i < themes.length; i++) { - _out.startElement("scopingTopic", _topicRef(themes[i])); - _out.endElement("scopingTopic"); - _out.newline(); - } - _out.endElement("scope"); - _out.newline(); - } - - /** - * Serializes a locator. - * - * A normalized locator value is created which is serialized. - * - * @param loc The locator to serialize. - * @throws IOException If an error occurs. - */ - private void _writeLocator(final Locator loc) throws IOException { - _out.startElement("locator"); - _out.characters(_normalizeLocator(loc)); - _out.endElement("locator"); - _out.newline(); - } - - /** - * Serializes the item identifiers of the specified Topic Maps construct. - * - * @param tmo The Topic Maps construct to take the item identifiers from. - * @throws IOException If an error occurs. - */ - private void _writeItemIdentifiers(final Construct tmo) throws IOException { - _writeLocatorSet("itemIdentifiers", tmo.getItemIdentifiers()); - } - - /** - * Serializes the <tt>locators</tt> using the <tt>localName</tt> as - * element name. - * <p> - * If the set of <tt>locators</tt> is empty, this method does nothing. - * </p> - * - * @param localName The element's name. - * @param locators The locators to serialize. - * @throws IOException If an error occurs. - */ - private void _writeLocatorSet(final String localName, final Set<Locator> locators) throws IOException { - if (locators.isEmpty()) { - return; - } - Locator[] locs = locators.toArray(new Locator[locators.size()]); - Arrays.sort(locs, _locComparator); - _out.startElement(localName); - _out.newline(); - for (int i=0; i < locs.length; i++) { - _writeLocator(locs[i]); - } - _out.endElement(localName); - _out.newline(); - } - - /** - * Returns attributes which contains a reference to the provided topic. - * - * @param topic The topic to which the reference should point to. - * @return Attributes with a topic reference. - */ - private Attributes _topicRef(final Topic topic) { - if (topic == null) { - _reportInvalid("The topic reference is null"); - return XMLC14NWriter.EMPTY_ATTRS; - } - _attrs.clear(); - _attrs.addAttribute("", "topicref", "", "CDATA", Integer.toString(_indexOf(topic))); - return _attrs; - } - - /** - * Returns attributes which contain the reifier (if any) and the number - * of the provided Topic Maps construct (not a topic). - * - * @param reifiable The Topic Maps construct. - * @param pos The position of the reifiable within the parent container. - * @return Attributes which contain a reference to the reifier (if any) and - * the number of the provided Topic Maps construct. - */ - private Attributes _attributes(final Reifiable reifiable, int pos) { - _attrs.clear(); - _addReifier(_attrs, reifiable); - _attrs.addAttribute("", "number", "", "CDATA", Integer.toString(pos)); - return _attrs; - } - - /** - * Adds a reference to the reifier of the Topic Maps construct to the - * provided attributes. If the Topic Maps construct has no reifier, the - * provided attributes are not modified. - * - * @param attrs The attributes. - * @param reifiable The reifiable Topic Maps construct. - */ - private void _addReifier(final AttributesImpl attrs, final Reifiable reifiable) { - Topic reifier = reifiable.getReifier(); - if (reifier != null) { - attrs.addAttribute("", "reifier", "", "CDATA", Integer.toString(_indexOf(reifier))); - } - } - - /** - * Normalizes the locator according to CXTM 3.19. - * - * @param locator The locator to normalize. - * @return A normalized representation of the locator. - */ - private String _normalizeLocator(final Locator locator) { - String normLoc = _locator2Norm.get(locator); - if (normLoc != null) { - return normLoc; - } - normLoc = locator.getReference(); - if (normLoc.startsWith(_normBase)) { - normLoc = normLoc.substring(_normBase.length()); - } - else { - int i = 0; - int slashPos = -1; - final int max = Math.min(_normBase.length(), normLoc.length()); - while(i < max && _normBase.charAt(i) == normLoc.charAt(i)) { - if (_normBase.charAt(i) == '/') { - slashPos = i; - } - i++; - } - if (slashPos > -1) { - normLoc = normLoc.substring(slashPos); - } - } - if (normLoc.charAt(0) == '/') { - normLoc = normLoc.substring(1); - } - _locator2Norm.put(locator, normLoc); - return normLoc; - } - - /** - * Normalizes the base locator according to the following procedure - * (CXTM 3.19 - 1.): - * <cite>[...] the base locator with any fragment identifier and query - * removed and any trailing "/" character removed.[...]</cite> - * - * @param baseLocator - * @return - */ - private static String _normalizeBaseLocator(final String baseLocator) { - String loc = baseLocator; - int i = loc.indexOf('#'); - if (i > 0) { - loc = loc.substring(0, i); - } - i = loc.indexOf('?'); - if (i > 0) { - loc = loc.substring(0, i); - } - if (loc.endsWith("/")) { - loc = loc.substring(0, loc.length()-1); - } - return loc; - } - - /** - * Writes a warning msg to the log. - * - * This method is used to inform the user that the serialized topic map - * is not valid acc. to CXTM. - * - * @param msg The warning message. - */ - private static void _reportInvalid(final String msg) { - LOG.warning("Invalid CXTM: '" + msg + "'"); - } - - - /* - * Comparators. - */ - - private final class TopicComparator implements Comparator<Topic> { - - public int compare(Topic o1, Topic o2) { - if (o1 == o2) { - return 0; - } - if (o1 != null && o2 == null) { - _reportInvalid("Comparing topics where one topic is null"); - return +1; - } - else if (o1 == null && o2 != null) { - _reportInvalid("Comparing topics where one topic is null"); - return -1; - } - int res = _locSetComparator.compare(o1.getSubjectIdentifiers(), o2.getSubjectIdentifiers()); - if (res == 0) { - res = _locSetComparator.compare(o1.getSubjectLocators(), o2.getSubjectLocators()); - if (res == 0) { - res = _locSetComparator.compare(o1.getItemIdentifiers(), o2.getItemIdentifiers()); - } - } - return res; - } - } - - /** - * Abstract comparator that provides some utility methods which handle common - * comparisons. - */ - private abstract class AbstractComparator<T> implements Comparator<T> { - int compareString(String o1, String o2) { - if (o1 == null && o2 != null) { - _reportInvalid("The first string value is null"); - return -1; - } - if (o1 != null && o2 == null) { - _reportInvalid("The second string value is null"); - return +1; - } - return o1.compareTo(o2); - } - /** - * Extracts the type of the typed Topic Maps constructs and compares - * the topics. - * - * @param o1 The first typed Topic Maps construct. - * @param o2 The second typed Topic Maps construct. - * @return A negative integer, zero, or a positive integer as the - * first argument is less than, equal to, or greater than the - * second. - */ - int compareType(Typed o1, Typed o2) { - return _topicComparator.compare(o1.getType(), o2.getType()); - } - /** - * Extracts the scope of the scoped Topic Maps constructs and compares - * them. - * - * @param o1 The first scoped Topic Maps construct. - * @param o2 The second scoped Topic Maps construct. - * @return A negative integer, zero, or a positive integer as the - * first argument is less than, equal to, or greater than the - * second. - */ - int compareScope(Scoped o1, Scoped o2) { - return _scopeComparator.compare(o1.getScope(), o2.getScope()); - } - } - - /** - * Enhances the {@link AbstractComparator} with a method to compare the - * value and datatype of an occurrence or variant. - */ - private abstract class AbstractDatatypeAwareComparator<T> extends AbstractComparator<T> { - /** - * Compares the value and datatype of the occurrences / variants. - * - * @param o1 The first occurrence / variant. - * @param o2 The second occurrence / variant. - * @return A negative integer, zero, or a positive integer as the - * first argument is less than, equal to, or greater than the - * second. - */ - int _compareValueDatatype(DatatypeAware o1, DatatypeAware o2) { - int res = compareString(o1.getValue(), o2.getValue()); - if (res == 0) { - res = compareString(o1.getDatatype().getReference(), o2.getDatatype().getReference()); - } - return res; - } - } - - /** - * Canonical sort order: - * 1. [type] - * 2. [roles] - * 3. [scope] - * 4. [parent] - */ - private final class AssociationComparator extends AbstractComparator<Association> { - - private Comparator<Set<Role>> _roleSetComparator; - - AssociationComparator() { - _roleSetComparator = new RoleSetComparator(); - } - - public int compare(Association o1, Association o2) { - if (o1 == o2) { - return 0; - } - int res = compareType(o1, o2); - if (res == 0) { - res = _roleSetComparator.compare(o1.getRoles(), o2.getRoles()); - if (res == 0) { - res = compareScope(o1, o2); - } - } - return res; - } - } - - /** - * Role comparator which ignores the parent association. This comparator - * is meant to be used for roles where the parent is known to be equal or - * unequal. - */ - private class RoleIgnoreParentComparator extends AbstractComparator<Role> { - - public int compare(Role o1, Role o2) { - if (o1 == o2) { - return 0; - } - int res = _topicComparator.compare(o1.getPlayer(), o2.getPlayer()); - if (res == 0) { - res = compareType(o1, o2); - } - return res; - } - } - - /** - * Canonical sort order: - * 1. [player] - * 2. [type] - * 3. [parent] - */ - private final class RoleComparator extends RoleIgnoreParentComparator { - - public int compare(Role o1, Role o2) { - if (o1 == o2) { - return 0; - } - int res = super.compare(o1, o2); - if (res == 0) { - res = _assocComparator.compare(o1.getParent(), o2.getParent()); - } - return res; - } - } - - /** - * Canonical sort order: - * 1. [value] - * 2. [datatype] - * 3. [type] - * 4. [scope] - * 5. [parent] - */ - private final class OccurrenceComparator extends AbstractDatatypeAwareComparator<Occurrence> { - - public int compare(Occurrence o1, Occurrence o2) { - if (o1 == o2) { - return 0; - } - int res = _compareValueDatatype(o1, o2); - if (res == 0) { - res = compareType(o1, o2); - if (res == 0) { - res = compareScope(o1, o2); - } - } - return res; - } - - } - - /** - * Canonical sort order: - * 1. [value] - * 2. [type] - * 3. [scope] - * 4. [parent] - */ - private final class NameComparator extends AbstractComparator<Name> { - - public int compare(Name o1, Name o2) { - if (o1 == o2) { - return 0; - } - int res = compareString(o1.getValue(), o2.getValue()); - if (res == 0) { - res = compareType(o1, o2); - if (res == 0) { - res = compareScope(o1, o2); - } - } - return res; - } - } - - /** - * Canonical sort order: - * 1. [value] - * 2. [datatype] - * 3. [scope] - * 4. [parent] - */ - private final class VariantComparator extends AbstractDatatypeAwareComparator<Variant> { - - public int compare(Variant o1, Variant o2) { - if (o1 == o2) { - return 0; - } - int res = _compareValueDatatype(o1, o2); - if (res == 0) { - res = compareScope(o1, o2); - } - return res; - } - } - - /** - * Comparator which compares the size of the provided set. - * - * Iff the size of the sets are equal, another comparison method is used - * to compare the content of the sets. - */ - private abstract class AbstractSetComparator<T> implements Comparator<Set<T>> { - - public int compare(Set<T> o1, Set<T> o2) { - int s1 = o1.size(); - int s2 = o2.size(); - int res = s1 - s2; - if (res == 0) { - res = compareContent(o1, o2, s1); - } - return res; - } - - /** - * Called iff the size of the sets is equal. - * - * This method is used to compare the content of the sets. - * - * @param o1 The first set. - * @param o2 The second set. - * @param size The size of the set(s). - * @return A negative integer, zero, or a positive integer as the - * first argument is less than, equal to, or greater than the - * second. - */ - abstract int compareContent(Set<T> o1, Set<T> o2, int size); - } - - /** - * Compares role sets. The parent of the roles is ignored! - */ - private final class RoleSetComparator extends AbstractSetComparator<Role> { - - private RoleIgnoreParentComparator _roleCmp; - - RoleSetComparator() { - _roleCmp = new RoleIgnoreParentComparator(); - } - - @Override - int compareContent(Set<Role> o1, Set<Role> o2, - int size) { - int res = 0; - Role[] roles1 = o1.toArray(new Role[size]); - Role[] roles2 = o2.toArray(new Role[size]); - Arrays.sort(roles1, _roleCmp); - Arrays.sort(roles2, _roleCmp); - for (int i=0; i < size && res == 0; i++) { - res = _roleCmp.compare(roles1[i], roles2[i]); - } - return res; - } - - } - - /** - * Compares the scope of two scoped Topic Maps constructs. - */ - private final class ScopeComparator extends AbstractSetComparator<Topic> { - - @Override - int compareContent(Set<Topic> o1, Set<Topic> o2, int size) { - int res = 0 ; - Topic[] topics1 = o1.toArray(new Topic[size]); - Topic[] topics2 = o2.toArray(new Topic[size]); - Arrays.sort(topics1, _topicComparator); - Arrays.sort(topics2, _topicComparator); - for (int i=0; i < size && res == 0; i++) { - res = _topicComparator.compare(topics1[i], topics2[i]); - } - return res; - } - - } - - /** - * Comparator for sets of {@link org.tmapi.core.Locator}s. - */ - private final class LocatorSetComparator extends AbstractSetComparator<Locator> { - - @Override - int compareContent(Set<Locator> o1, Set<Locator> o2, int size) { - int res = 0; - Locator[] locs1 = o1.toArray(new Locator[size]); - Locator[] locs2 = o2.toArray(new Locator[size]); - Arrays.sort(locs1, _locComparator); - Arrays.sort(locs2, _locComparator); - for (int i=0; i < size && res == 0; i++) { - res = _locComparator.compare(locs1[i], locs2[i]); - } - return res; - } - } - - /** - * Compares {@link org.tmapi.core.Locator}s. - */ - private final class LocatorComparator implements Comparator<Locator> { - - public int compare(Locator o1, Locator o2) { - if (o1 == o2) { - return 0; - } - return _normalizeLocator(o1).compareTo(_normalizeLocator(o2)); - } - - } - - - /* - * Helper classes to treat type-instance relationships, modelled as property - * of a topic, as associations. - */ - - private final class TypeInstanceTopic implements Topic { - - private final Set<Locator> _sids; - - TypeInstanceTopic(Locator sid) { - _sids = Collections.singleton(sid); - } - - public Set<Locator> getSubjectIdentifiers() { - return _sids; - } - - public void addItemIdentifier(Locator arg0) { } - public void addSubjectIdentifier(Locator arg0) {} - public void addSubjectLocator(Locator arg0) {} - public void addType(Topic arg0) {} - public Set<Occurrence> getOccurrences() { return Collections.emptySet(); } - public Reifiable getReified() { return null; } - public Set<Role> getRolesPlayed() { return Collections.emptySet(); } - public Set<Locator> getSubjectLocators() { return Collections.emptySet(); } - public Set<Name> getNames() { return Collections.emptySet(); } - public Set<Topic> getTypes() { return null; } - public void mergeIn(Topic arg0) { } - public void remove() throws TopicInUseException { } - public void removeSubjectIdentifier(Locator arg0) { } - public void removeSubjectLocator(Locator arg0) { } - public void removeType(Topic arg0) { } - public String getId() { return null; } - public Set<Locator> getItemIdentifiers() { return Collections.emptySet(); } - public TopicMap getTopicMap() { return null; } - public void removeItemIdentifier(Locator arg0) { } - public Name createName(String value, Collection<Topic> scope) { return null; } - public Name createName(String value, Topic... scope) {return null;} - public Name createName(Topic type, String value, Collection<Topic> scope) { return null; } - public Name createName(Topic type, String value, Topic... scope) { return null; } - public Occurrence createOccurrence(Topic type, Locator value, Collection<Topic> scope) { return null;} - public Occurrence createOccurrence(Topic type, Locator value, Topic... scope) {return null;} - public Occurrence createOccurrence(Topic type, String value, Collection<Topic> scope) { return null; } - public Occurrence createOccurrence(Topic type, String value, Locator datatype, Collection<Topic> scope) { return null; } - public Occurrence createOccurrence(Topic type, String value, Locator datatype, Topic... scope) { return null; } - public Occurrence createOccurrence(Topic type, String value, Topic... scope) { return null; } - public Set<Name> getNames(Topic type) { return null; } - public Set<Occurrence> getOccurrences(Topic type) { return null;} - public TopicMap getParent() { return null; } - public Set<Role> getRolesPlayed(Topic type, Topic assocType) { return null; } - public Set<Role> getRolesPlayed(Topic type) { return null; } - - } - - /** - * Used to represent type-instance relationships which are modelled as - * [type] property of topics. - */ - private final class TypeInstanceAssociation implements Association { - - final Set<Role> _roles; - - TypeInstanceAssociation(Topic type, Topic instance) { - Role typeRole = new TypeInstanceRole(this, _type, type); - Role instanceRole = new TypeInstanceRole(this, _instance, instance); - _roles = new TypeInstanceRoleSet(typeRole, instanceRole); - } - - public Set<Role> getRoles() { - return _roles; - } - - public Topic getType() { - return _typeInstance; - } - - public Set<Topic> getRoleTypes() { return null; } - public Set<Role> getRoles(Topic type) { return null; } - public void setReifier(Topic reifier) { } - public void addItemIdentifier(Locator itemIdentifier) { } - public Set<Locator> getItemIdentifiers() { return Collections.emptySet(); } - public TopicMap getParent() { return null; } - public void removeItemIdentifier(Locator itemIdentifier) { } - public Role createRole(Topic arg0, Topic arg1) { return null; } - public Topic getReifier() { return null; } - public void remove() {} - public void setType(Topic arg0) {} - public void addTheme(Topic arg0) {} - public Set<Topic> getScope() { return Collections.emptySet(); } - public void removeTheme(Topic arg0) {} - public String getId() { return null; } - public TopicMap getTopicMap() { return null; } - } - - /** - * Immutable association role. - */ - private class TypeInstanceRole implements Role { - private final Topic _type; - private final Topic _player; - private final Association _parent; - - TypeInstanceRole(Association parent, Topic type, Topic player) { - _type = type; - _player = player; - _parent = parent; - List<Role> roles = _topic2Roles.get(player); - if (roles == null) { - roles = CollectionFactory.createList(); - _topic2Roles.put(player, roles); - } - roles.add(this); - } - - public Topic getType() { - return _type; - } - - public Topic getPlayer() { - return _player; - } - - public void setReifier(Topic reifier) { } - public void addItemIdentifier(Locator itemIdentifier) { } - public Set<Locator> getItemIdentifiers() { return Collections.emptySet(); } - public Association getParent() { return _parent; } - public void removeItemIdentifier(Locator itemIdentifier) { } - public Association getAssociation() { return _parent; } - public Topic getReifier() { return null; } - public void remove() {} - public void setPlayer(Topic arg0) {} - public void setType(Topic arg0) {} - public String getId() { return null; } - public TopicMap getTopicMap() { return null; } - } - - /** - * Immutable 'set' of two roles. - */ - private static class TypeInstanceRoleSet extends AbstractSet<Role> { - - private final Role _role1; - private final Role _role2; - - TypeInstanceRoleSet(Role role1, Role role2) { - _role1 = role1; - _role2 = role2; - } - - @Override - public Iterator<Role> iterator() { - return new TypeInstanceRoleSetIterator(); - } - - @Override - public int size() { - return 2; - } - - private class TypeInstanceRoleSetIterator implements Iterator<Role> { - - private int _idx; - - public boolean hasNext() { - return _idx < 2; - } - - public Role next() { - if (_idx > 1) { - throw new NoSuchElementException(); - } - return 0 == _idx++ ? _role1 : _role2; - } - - public void remove() { - new UnsupportedOperationException(); - } - } - } - -} Deleted: tinytim-mio/trunk/src/main/java/org/tinytim/mio/XMLC14NWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/XMLC14NWriter.java 2009-11-04 16:58:30 UTC (rev 360) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/XMLC14NWriter.java 2009-11-04 18:29:23 UTC (rev 361) @@ -1,202 +0,0 @@ -/* - * Copyright 2008 Lars Heuer (heuer[at]semagia.com) - * - * 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.mio; - -import java.io.IOException; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.util.Arrays; - -import org.xml.sax.Attributes; -import org.xml.sax.helpers.AttributesImpl; - -/** - * Simple SAX-alike XML writer that respects canonical XML to some extend. - * <p> - * This class is not meant to be a generic XML-C14N writer, but it is good - * enough to support CXTM. - * </p> - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -final class XMLC14NWriter { - - public static final Attributes EMPTY_ATTRS = new AttributesImpl(); - - private static final char _NL = '\n'; - - private final OutputStreamWriter _out; - - public XMLC14NWriter(OutputStream out) throws IOException { - _out = new OutputStreamWriter(out, "UTF-8"); - } - - /** - * Indicates the start of the serialization process. - * - * @throws IOException If an error occurs. - */ - public void startDocument() throws IOException { - // noop - } - - /** - * Indicates the end of the serialization process. - * - * @throws IOException If an error occurs. - */ - public void endDocument() throws IOException { - _out.flush(); - } - - /** - * Indicates the start of an element with the specified local name. - * - * @see #startElement(String, Attributes). - * - * @param localName The element's name. - * @throws IOException If an error occurs. - */ - public void startElement(String localName) throws IOException { - startElement(localName, EMPTY_ATTRS); - } - - /** - * Indicates the start of an element with the provided local name. - * - * The attributes written in canonical XML. - * - * @param localName The name of the element. - * @param attrs The element's attributes. - * @throws IOException If an error occurs. - */ - public void startElement(String localName, Attributes attrs) throws IOException { - String[] names = new String[attrs.getLength()]; - for (int i=0; i < names.length; i++) { - names[i] = attrs.getLocalName(i); - } - Arrays.sort(names); - _out.write('<'); - _out.write(localName); - for (int i=0; i < names.length; i++) { - _out.write(' '); - _out.write(names[i]); - _out.write("=\""); - _writeEscapedAttributeValue(attrs.getValue("", names[i])); - _out.write('"'); - } - _out.write('>'); - } - - /** - * Indicates the end of an elemnt. - * - * @param localName The element's name. - * @throws IOException If an error occurs. - */ - public void endElement(String localName) throws IOException { - _out.write("</"); - _out.write(localName); - _out.write('>'); - } - - /** - * Writes a <tt>#x0A</tt> to the output. - * - * @throws IOException If an error occurs. - */ - public void newline() throws IOException { - _out.write(_NL); - } - - /** - * Writes the specified characters to the output. - * <p> - * The data is written according to the rules of canonicalized XML. - * </p> - * - * @param data The data to write. - * @throws IOException If an error occurs. - */ - public void characters(String data) throws IOException { - _writeEscapedTextContent(data); - } - - /** - * Escapes the data according to the canonical XML rules. - * - * @param value The value. - * @return The escaped value. - * @throws IOException - */ - private void _writeEscapedTextContent(String value) throws IOException { - char[] ch = value.toCharArray(); - for (int i=0; i < ch.length; i++) { - switch(ch[i]) { - case '\r': - _out.write("
"); - break; - case '&': - _out.write("&"); - break; - case '<': - _out.write("<"); - break; - case '>': - _out.write(">"); - break; - default: - _out.write(ch[i]); - } - } - } - - /** - * Escapes the attribute's value according to canonical XML. - * - * @param value The value to escape. - * @return The escaped value. - * @throws IOException - */ - private void _writeEscapedAttributeValue(String value) throws IOException { - char[] ch = value.toCharArray(); - for (int i=0; i<ch.length; i++) { - switch(ch[i]) { - case '\t': - _out.write("	"); - break; - case '\n': - _out.write("
"); - break; - case '\r': - _out.write("
"); - break; - case '\"': - _out.write("""); - break; - case '&': - _out.write("&"); - break; - case '<': - _out.write("<"); - break; - default: - _out.write(ch[i]); - } - } - } -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |