|
From: <lh...@us...> - 2008-08-11 13:42:48
|
Revision: 117
http://tinytim.svn.sourceforge.net/tinytim/?rev=117&view=rev
Author: lheuer
Date: 2008-08-11 13:42:49 +0000 (Mon, 11 Aug 2008)
Log Message:
-----------
- Aligned C14N to tinyTiM 2
Modified Paths:
--------------
tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/Canonicalizer.java
Added Paths:
-----------
tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/LiteralCanonicalizer.java
Modified: tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/Canonicalizer.java
===================================================================
--- tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/Canonicalizer.java 2008-08-11 13:01:22 UTC (rev 116)
+++ tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/Canonicalizer.java 2008-08-11 13:42:49 UTC (rev 117)
@@ -28,9 +28,6 @@
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -38,29 +35,27 @@
import java.util.Set;
import java.util.logging.Logger;
-import org.tinytim.DuplicateRemovalUtils;
-import org.tinytim.IConstruct;
-import org.tinytim.IDatatypeAwareConstruct;
-import org.tinytim.IReifiable;
-import org.tinytim.ITyped;
-import org.tinytim.TopicMapImpl;
-import org.tinytim.index.ITypeInstanceIndex;
+import org.tinytim.core.DuplicateRemovalUtils;
+import org.tinytim.core.ILiteralAware;
+import org.tinytim.core.TopicMapImpl;
+import org.tinytim.utils.CollectionFactory;
import org.tinytim.voc.TMDM;
+import org.tinytim.voc.XSD;
import org.tmapi.core.Association;
-import org.tmapi.core.AssociationRole;
-import org.tmapi.core.DuplicateSourceLocatorException;
+import org.tmapi.core.Construct;
+import org.tmapi.core.DatatypeAware;
import org.tmapi.core.Locator;
-import org.tmapi.core.MergeException;
-import org.tmapi.core.ModelConstraintException;
+import org.tmapi.core.Name;
import org.tmapi.core.Occurrence;
-import org.tmapi.core.ScopedObject;
-import org.tmapi.core.TMAPIException;
+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.TopicMapObject;
-import org.tmapi.core.TopicName;
+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;
@@ -84,10 +79,7 @@
* </p>
* <p>
* The canonicalizer IS NOT a generic TMAPI-compatible implementation. It
- * requires tinyTiM. The canonicalizer requires that the property
- * {@link org.tinytim.Property#XTM10_REIFICATION} is set to <tt>false</tt> and
- * that the property {@link org.tinytim.Property#INHERIT_NAME_SCOPE} is enabled
- * (set to <tt>true</tt>).
+ * requires tinyTiM.
* </p>
* @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
* @version $Rev$ - $Date$
@@ -96,31 +88,29 @@
private static final Logger LOG = Logger.getLogger(Canonicalizer.class.getName());
- private static final String _XSD_ANY_URI = "http://www.w3.org/2001/XMLSchema#anyURI";
+ private static final Role[] _EMPTY_ROLES = new Role[0];
- private static final AssociationRole[] _EMPTY_ROLES = new AssociationRole[0];
-
private Topic _type;
private Topic _instance;
private Topic _typeInstance;
private CXTMWriter _out;
private final String _normBase;
- private Map<TopicMapObject, Integer> _construct2Id;
- private Map<Topic, List<AssociationRole>> _topic2Roles;
- private Map<String, String> _locator2Norm;
+ private Map<Construct, Integer> _construct2Id;
+ private Map<Topic, List<Role>> _topic2Roles;
+ private Map<Locator, String> _locator2Norm;
private Comparator<Topic> _topicComparator;
private Comparator<Association> _assocComparator;
- private Comparator<AssociationRole> _roleComparator;
+ private Comparator<Role> _roleComparator;
private Comparator<Occurrence> _occComparator;
- private Comparator<TopicName> _nameComparator;
+ private Comparator<Name> _nameComparator;
private Comparator<Variant> _variantComparator;
private Comparator<Set<Locator>> _locSetComparator;
private Comparator<Locator> _locComparator;
private Comparator<Set<Topic>> _scopeComparator;
- private Map<Association, AssociationRole[]> _assoc2Roles;
+ private Map<Association, Role[]> _assoc2Roles;
/**
* Creates a canonicalizer.
@@ -162,11 +152,11 @@
*/
public void write(TopicMap topicMap) throws IOException {
DuplicateRemovalUtils.removeDuplicates(topicMap);
- _construct2Id = new IdentityHashMap<TopicMapObject, Integer>();
- _locator2Norm = new HashMap<String, String>();
- _assoc2Roles = new IdentityHashMap<Association, AssociationRole[]>();
- _topic2Roles = new IdentityHashMap<Topic, List<AssociationRole>>();
- ITypeInstanceIndex typeInstanceIndex = ((TopicMapImpl) topicMap).getIndexManager().getTypeInstanceIndex();
+ _construct2Id = CollectionFactory.createIdentityMap();
+ _locator2Norm = CollectionFactory.createIdentityMap();
+ _assoc2Roles = CollectionFactory.createIdentityMap();
+ _topic2Roles = CollectionFactory.createIdentityMap();
+ TypeInstanceIndex typeInstanceIndex = ((TopicMapImpl) topicMap).getIndexManager().getTypeInstanceIndex();
if (!typeInstanceIndex.isAutoUpdated()) {
typeInstanceIndex.reindex();
}
@@ -176,7 +166,7 @@
_createIndex(topics, assocs);
_out.startDocument();
AttributesImpl attrs = new AttributesImpl();
- _addReifier(attrs, (IReifiable)topicMap);
+ _addReifier(attrs, topicMap);
_out.startElement("topicMap", attrs);
_out.newline();
_writeItemIdentifiers(topicMap);
@@ -208,8 +198,7 @@
* @param idx A (upto date) type instance index.
* @return All topics which must be included into the output.
*/
- @SuppressWarnings("unchecked")
- private Topic[] _fetchTopics(TopicMap topicMap, ITypeInstanceIndex idx) {
+ private Topic[] _fetchTopics(TopicMap topicMap, TypeInstanceIndex idx) {
Collection<Topic> types = idx.getTopicTypes();
if (types.isEmpty()) {
Set<Topic> topics = topicMap.getTopics();
@@ -255,8 +244,7 @@
* @param idx A (upto date) type instance index.
* @return An unsorted array of associations which must be included into the output.
*/
- @SuppressWarnings("unchecked")
- private Association[] _fetchAssociations(TopicMap tm, ITypeInstanceIndex idx) {
+ private Association[] _fetchAssociations(TopicMap tm, TypeInstanceIndex idx) {
Collection<Topic> types = idx.getTopicTypes();
if (types.isEmpty()) {
Set<Association> assocs = tm.getAssociations();
@@ -281,7 +269,6 @@
* @param topics An array of topics.
* @param assocs An array of associations.
*/
- @SuppressWarnings("unchecked")
private void _createIndex(Topic[] topics, Association[] assocs) {
Arrays.sort(topics, _topicComparator);
Topic topic = null;
@@ -294,8 +281,8 @@
for (int i=0; i < assocs.length; i++) {
assoc = assocs[i];
_construct2Id.put(assoc, Integer.valueOf(i+1));
- Set<AssociationRole> roles_ = assoc.getAssociationRoles();
- AssociationRole[] roles = roles_.toArray(new AssociationRole[roles_.size()]);
+ 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++) {
@@ -310,8 +297,8 @@
* @param assoc The association to retrieve the roles from.
* @return A (maybe empty) sorted array of roles.
*/
- private AssociationRole[] _getRoles(Association assoc) {
- AssociationRole[] roles = _assoc2Roles.get(assoc);
+ private Role[] _getRoles(Association assoc) {
+ Role[] roles = _assoc2Roles.get(assoc);
return roles != null ? roles : _EMPTY_ROLES;
}
@@ -321,10 +308,9 @@
* @param topic The topic to retrieve the names from.
* @return A (maybe empty) sorted array of names.
*/
- @SuppressWarnings("unchecked")
- private TopicName[] _getNames(Topic topic) {
- Set<TopicName> names_ = topic.getTopicNames();
- TopicName[] names = names_.toArray(new TopicName[names_.size()]);
+ private Name[] _getNames(Topic topic) {
+ Set<Name> names_ = topic.getNames();
+ Name[] names = names_.toArray(new Name[names_.size()]);
Arrays.sort(names, _nameComparator);
return names;
}
@@ -335,8 +321,7 @@
* @param name The name to retrieve the variants from.
* @return A (maybe empty) sorted array of variants.
*/
- @SuppressWarnings("unchecked")
- private Variant[] _getVariants(TopicName name) {
+ private Variant[] _getVariants(Name name) {
Set<Variant> variants_ = name.getVariants();
Variant[] variants = variants_.toArray(new Variant[variants_.size()]);
Arrays.sort(variants, _variantComparator);
@@ -349,7 +334,6 @@
* @param topic The topic to retrieve the occurrences from.
* @return A (maybe emtpy) sorted array of occurrences.
*/
- @SuppressWarnings("unchecked")
private Occurrence[] _getOccurrences(Topic topic) {
Set<Occurrence> occs_ = topic.getOccurrences();
Occurrence[] occs = occs_.toArray(new Occurrence[occs_.size()]);
@@ -367,7 +351,7 @@
* @param tmo The Topic Maps construct to return the index of.
* @return The index of the Topic Maps construct.
*/
- private int _indexOf(TopicMapObject tmo) {
+ private int _indexOf(Construct tmo) {
return _construct2Id.get(tmo).intValue();
}
@@ -377,7 +361,6 @@
* @param topic The topic to serialize.
* @throws IOException If an error occurs.
*/
- @SuppressWarnings("unchecked")
private void _writeTopic(Topic topic) throws IOException {
AttributesImpl attrs = new AttributesImpl();
attrs.addAttribute("", "number", null, null, "" +_indexOf(topic));
@@ -386,7 +369,7 @@
_writeLocatorSet("subjectIdentifiers", topic.getSubjectIdentifiers());
_writeLocatorSet("subjectLocators", topic.getSubjectLocators());
_writeItemIdentifiers(topic);
- TopicName[] names = _getNames(topic);
+ Name[] names = _getNames(topic);
for (int i=0; i < names.length; i++) {
_writeName(names[i], i+1);
}
@@ -394,18 +377,18 @@
for (int i=0; i < occs.length; i++) {
_writeOccurrence(occs[i], i+1);
}
- Set<AssociationRole> roles_ = new HashSet<AssociationRole>(topic.getRolesPlayed());
- List<AssociationRole> alienRoles = _topic2Roles.get(topic);
+ List<Role> roles_ = new ArrayList<Role>(topic.getRolesPlayed());
+ List<Role> alienRoles = _topic2Roles.get(topic);
if (alienRoles != null) {
roles_.addAll(alienRoles);
}
- AssociationRole[] roles = roles_.toArray(new AssociationRole[roles_.size()]);
+ Role[] roles = roles_.toArray(new Role[roles_.size()]);
Arrays.sort(roles, _roleComparator);
AttributesImpl roleAttrs = new AttributesImpl();
StringBuilder sb = new StringBuilder();
for (int i=0; i < roles.length; i++) {
sb.append("association.")
- .append(_indexOf(roles[i].getAssociation()))
+ .append(_indexOf(roles[i].getParent()))
.append(".role.")
.append(_indexOf(roles[i]));
roleAttrs.addAttribute("", "ref", null, null, sb.toString());
@@ -425,18 +408,17 @@
* @param assoc The association to serialize.
* @throws IOException If an error occurs.
*/
- @SuppressWarnings("unchecked")
private void _writeAssociation(Association assoc) throws IOException {
_out.startElement("association", _attributes(assoc, _indexOf(assoc)));
_out.newline();
- _writeType((ITyped) assoc);
- for (AssociationRole role: _getRoles(assoc)) {
+ _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((ITyped) role);
+ _writeType(role);
_writeItemIdentifiers(role);
_out.endElement("role");
_out.newline();
@@ -456,8 +438,8 @@
private void _writeOccurrence(Occurrence occ, int pos) throws IOException {
_out.startElement("occurrence", _attributes(occ, pos));
_out.newline();
- _writeDatatyped((IDatatypeAwareConstruct) occ);
- _writeType((ITyped) occ);
+ _writeDatatyped(occ);
+ _writeType(occ);
_writeScope(occ);
_writeItemIdentifiers(occ);
_out.endElement("occurrence");
@@ -470,19 +452,15 @@
* @param obj The construct to serialize.
* @throws IOException If an error occurs.
*/
- private void _writeDatatyped(IDatatypeAwareConstruct obj) throws IOException {
- String value = obj.getValue2();
- String datatype = obj.getDatatype().getReference();
- //TODO: Handle xsd:decimal, xsd:integer, xsd:date, xsd:dateTime xsd:anyType(?!?)
- if (_XSD_ANY_URI.equals(datatype)) {
- value = _normalizeLocator(value);
- }
+ private void _writeDatatyped(DatatypeAware obj) throws IOException {
+ String value = XSD.ANY_URI.equals(obj.getDatatype()) ? _normalizeLocator(obj.locatorValue())
+ : LiteralCanonicalizer.canonicalize((ILiteralAware) obj);
_out.startElement("value");
_out.characters(value);
_out.endElement("value");
_out.newline();
_out.startElement("datatype");
- _out.characters(_normalizeLocator(datatype));
+ _out.characters(_normalizeLocator(obj.getDatatype()));
_out.endElement("datatype");
_out.newline();
}
@@ -493,14 +471,14 @@
* @param name The name to serialize.
* @throws IOException If an error occurs.
*/
- private void _writeName(TopicName name, int pos) throws IOException {
+ private void _writeName(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((ITyped) name);
+ _writeType(name);
_writeScope(name);
Variant[] variants = _getVariants(name);
Variant variant = null;
@@ -508,7 +486,7 @@
variant = variants[i];
_out.startElement("variant", _attributes(variant, i+1));
_out.newline();
- _writeDatatyped((IDatatypeAwareConstruct) variant);
+ _writeDatatyped(variant);
_writeScope(variant);
_writeItemIdentifiers(variant);
_out.endElement("variant");
@@ -526,7 +504,7 @@
* serialized.
* @throws IOException If an error occurs.
*/
- private void _writeType(ITyped typed) throws IOException {
+ private void _writeType(Typed typed) throws IOException {
Topic type = typed.getType();
if (type == null) {
_reportInvalid("The type of " + typed + " is null");
@@ -544,8 +522,7 @@
* @param scoped The scoped Topic Maps construct.
* @throws IOException If an error occurs.
*/
- @SuppressWarnings("unchecked")
- private void _writeScope(ScopedObject scoped) throws IOException {
+ private void _writeScope(Scoped scoped) throws IOException {
Set<Topic> scope = scoped.getScope();
if (scope.isEmpty()) {
return;
@@ -573,7 +550,7 @@
*/
private void _writeLocator(Locator loc) throws IOException {
_out.startElement("locator");
- _out.characters(_normalizeLocator(loc.getReference()));
+ _out.characters(_normalizeLocator(loc));
_out.endElement("locator");
_out.newline();
}
@@ -584,9 +561,8 @@
* @param tmo The Topic Maps construct to take the item identifiers from.
* @throws IOException If an error occurs.
*/
- @SuppressWarnings("unchecked")
- private void _writeItemIdentifiers(TopicMapObject tmo) throws IOException {
- _writeLocatorSet("itemIdentifiers", tmo.getSourceLocators());
+ private void _writeItemIdentifiers(Construct tmo) throws IOException {
+ _writeLocatorSet("itemIdentifiers", tmo.getItemIdentifiers());
}
/**
@@ -638,9 +614,9 @@
* @return Attributes which contain a reference to the reifier (if any) and
* the number of the provided Topic Maps construct.
*/
- private Attributes _attributes(TopicMapObject reifiable, int i) {
+ private Attributes _attributes(Reifiable reifiable, int i) {
AttributesImpl attrs = new AttributesImpl();
- _addReifier(attrs, (IReifiable)reifiable);
+ _addReifier(attrs, reifiable);
attrs.addAttribute("", "number", null, null, "" + i);
return attrs;
}
@@ -653,7 +629,7 @@
* @param attrs The attributes.
* @param reifiable The reifiable Topic Maps construct.
*/
- private void _addReifier(AttributesImpl attrs, IReifiable reifiable) {
+ private void _addReifier(AttributesImpl attrs, Reifiable reifiable) {
Topic reifier = reifiable.getReifier();
if (reifier != null) {
attrs.addAttribute("", "reifier", null, null, "" + _indexOf(reifier));
@@ -666,28 +642,29 @@
* @param locator The locator to normalize.
* @return A normalized representation of the locator.
*/
- private String _normalizeLocator(String locator) {
+ private String _normalizeLocator(final Locator locator) {
String normLoc = _locator2Norm.get(locator);
if (normLoc != null) {
return normLoc;
}
- normLoc = locator;
- if (locator.startsWith(_normBase)) {
- normLoc = locator.substring(_normBase.length());
+ final String ref = locator.getReference();
+ normLoc = ref;
+ if (ref.startsWith(_normBase)) {
+ normLoc = ref.substring(_normBase.length());
}
else {
int i = 0;
int slashPos = -1;
- final int max = _normBase.length() < locator.length() ? _normBase.length()
- : locator.length();
- while(i < max && _normBase.charAt(i) == locator.charAt(i)) {
+ final int max = _normBase.length() < ref.length() ? _normBase.length()
+ : ref.length();
+ while(i < max && _normBase.charAt(i) == ref.charAt(i)) {
if (_normBase.charAt(i) == '/') {
slashPos = i;
}
i++;
}
if (slashPos > -1) {
- normLoc = locator.substring(slashPos);
+ normLoc = ref.substring(slashPos);
}
}
if (normLoc.startsWith("/")) {
@@ -741,7 +718,6 @@
private final class TopicComparator implements Comparator<Topic> {
- @SuppressWarnings("unchecked")
public int compare(Topic o1, Topic o2) {
if (o1 == o2) {
return 0;
@@ -758,7 +734,7 @@
if (res == 0) {
res = _locSetComparator.compare(o1.getSubjectLocators(), o2.getSubjectLocators());
if (res == 0) {
- res = _locSetComparator.compare(o1.getSourceLocators(), o2.getSourceLocators());
+ res = _locSetComparator.compare(o1.getItemIdentifiers(), o2.getItemIdentifiers());
}
}
return res;
@@ -791,7 +767,7 @@
* first argument is less than, equal to, or greater than the
* second.
*/
- int compareType(ITyped o1, ITyped o2) {
+ int compareType(Typed o1, Typed o2) {
return _topicComparator.compare(o1.getType(), o2.getType());
}
/**
@@ -804,8 +780,7 @@
* first argument is less than, equal to, or greater than the
* second.
*/
- @SuppressWarnings("unchecked")
- int compareScope(ScopedObject o1, ScopedObject o2) {
+ int compareScope(Scoped o1, Scoped o2) {
return _scopeComparator.compare(o1.getScope(), o2.getScope());
}
}
@@ -824,8 +799,8 @@
* first argument is less than, equal to, or greater than the
* second.
*/
- int _compareValueDatatype(IDatatypeAwareConstruct o1, IDatatypeAwareConstruct o2) {
- int res = compareString(o1.getValue2(), o2.getValue2());
+ int _compareValueDatatype(DatatypeAware o1, DatatypeAware o2) {
+ int res = compareString(o1.getValue(), o2.getValue());
if (res == 0) {
res = compareString(o1.getDatatype().getReference(), o2.getDatatype().getReference());
}
@@ -842,20 +817,19 @@
*/
private final class AssociationComparator extends AbstractComparator<Association> {
- private Comparator<Set<AssociationRole>> _roleSetComparator;
+ private Comparator<Set<Role>> _roleSetComparator;
AssociationComparator() {
_roleSetComparator = new RoleSetComparator();
}
- @SuppressWarnings("unchecked")
public int compare(Association o1, Association o2) {
if (o1 == o2) {
return 0;
}
- int res = compareType((ITyped) o1, (ITyped) o2);
+ int res = compareType(o1, o2);
if (res == 0) {
- res = _roleSetComparator.compare(o1.getAssociationRoles(), o2.getAssociationRoles());
+ res = _roleSetComparator.compare(o1.getRoles(), o2.getRoles());
if (res == 0) {
res = compareScope(o1, o2);
}
@@ -869,15 +843,15 @@
* is meant to be used for roles where the parent is known to be equal or
* unequal.
*/
- private class RoleIgnoreParentComparator extends AbstractComparator<AssociationRole> {
+ private class RoleIgnoreParentComparator extends AbstractComparator<Role> {
- public int compare(AssociationRole o1, AssociationRole o2) {
+ 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((ITyped) o1, (ITyped) o2);
+ res = compareType(o1, o2);
}
return res;
}
@@ -891,13 +865,13 @@
*/
private final class RoleComparator extends RoleIgnoreParentComparator {
- public int compare(AssociationRole o1, AssociationRole o2) {
+ 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.getAssociation(), o2.getAssociation());
+ res = _assocComparator.compare(o1.getParent(), o2.getParent());
}
return res;
}
@@ -917,9 +891,9 @@
if (o1 == o2) {
return 0;
}
- int res = _compareValueDatatype((IDatatypeAwareConstruct) o1, (IDatatypeAwareConstruct) o2);
+ int res = _compareValueDatatype(o1, o2);
if (res == 0) {
- res = compareType((ITyped) o1, (ITyped) o2);
+ res = compareType(o1, o2);
if (res == 0) {
res = compareScope(o1, o2);
}
@@ -936,15 +910,15 @@
* 3. [scope]
* 4. [parent]
*/
- private final class NameComparator extends AbstractComparator<TopicName> {
+ private final class NameComparator extends AbstractComparator<Name> {
- public int compare(TopicName o1, TopicName o2) {
+ public int compare(Name o1, Name o2) {
if (o1 == o2) {
return 0;
}
int res = compareString(o1.getValue(), o2.getValue());
if (res == 0) {
- res = compareType((ITyped) o1, (ITyped) o2);
+ res = compareType(o1, o2);
if (res == 0) {
res = compareScope(o1, o2);
}
@@ -966,7 +940,7 @@
if (o1 == o2) {
return 0;
}
- int res = _compareValueDatatype((IDatatypeAwareConstruct) o1, (IDatatypeAwareConstruct) o2);
+ int res = _compareValueDatatype(o1, o2);
if (res == 0) {
res = compareScope(o1, o2);
}
@@ -1010,7 +984,7 @@
/**
* Compares role sets. The parent of the roles is ignored!
*/
- private final class RoleSetComparator extends AbstractSetComparator<AssociationRole> {
+ private final class RoleSetComparator extends AbstractSetComparator<Role> {
private RoleIgnoreParentComparator _roleCmp;
@@ -1019,11 +993,11 @@
}
@Override
- int compareContent(Set<AssociationRole> o1, Set<AssociationRole> o2,
+ int compareContent(Set<Role> o1, Set<Role> o2,
int size) {
int res = 0;
- AssociationRole[] roles1 = o1.toArray(new AssociationRole[size]);
- AssociationRole[] roles2 = o2.toArray(new AssociationRole[size]);
+ 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++) {
@@ -1082,7 +1056,7 @@
if (o1 == o2) {
return 0;
}
- return _normalizeLocator(o1.getReference()).compareTo(_normalizeLocator(o2.getReference()));
+ return _normalizeLocator(o1).compareTo(_normalizeLocator(o2));
}
}
@@ -1093,7 +1067,6 @@
* of a topic, as associations.
*/
- @SuppressWarnings("unchecked")
private final class TypeInstanceTopic implements Topic {
private final Set<Locator> _sids;
@@ -1106,47 +1079,58 @@
return _sids;
}
- public void addSourceLocator(Locator arg0) throws DuplicateSourceLocatorException, MergeException { }
- public void addSubjectIdentifier(Locator arg0) throws MergeException {}
- public void addSubjectLocator(Locator arg0) throws MergeException, ModelConstraintException {}
+ public void addItemIdentifier(Locator arg0) { }
+ public void addSubjectIdentifier(Locator arg0) {}
+ public void addSubjectLocator(Locator arg0) {}
public void addType(Topic arg0) {}
- public Occurrence createOccurrence(String arg0, Topic arg1, Collection arg2) { return null; }
- public Occurrence createOccurrence(Locator arg0, Topic arg1, Collection arg2) { return null; }
- public TopicName createTopicName(String arg0, Collection arg1) throws MergeException { return null; }
- public TopicName createTopicName(String arg0, Topic arg1, Collection arg2) throws UnsupportedOperationException, MergeException { return null; }
- public Set getOccurrences() { return Collections.emptySet(); }
- public Set getReified() { return null; }
- public Set getRolesPlayed() { return Collections.emptySet(); }
- public Set getSubjectLocators() { return Collections.emptySet(); }
- public Set getTopicNames() { return Collections.emptySet(); }
- public Set getTypes() { return null; }
- public void mergeIn(Topic arg0) throws MergeException { }
+ 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 getObjectId() { return null; }
- public Set getSourceLocators() { return Collections.emptySet(); }
+ public String getId() { return null; }
+ public Set<Locator> getItemIdentifiers() { return Collections.emptySet(); }
public TopicMap getTopicMap() { return null; }
- public void removeSourceLocator(Locator arg0) { }
+ 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.
*/
- @SuppressWarnings("unchecked")
- private final class TypeInstanceAssociation implements Association, IReifiable, ITyped {
+ private final class TypeInstanceAssociation implements Association {
- final Set<AssociationRole> _roles;
+ final Set<Role> _roles;
TypeInstanceAssociation(Topic type, Topic instance) {
- AssociationRole typeRole = new TypeInstanceRole(this, _type, type);
- AssociationRole instanceRole = new TypeInstanceRole(this, _instance, instance);
+ Role typeRole = new TypeInstanceRole(this, _type, type);
+ Role instanceRole = new TypeInstanceRole(this, _instance, instance);
_roles = new TypeInstanceRoleSet(typeRole, instanceRole);
}
- public Set<AssociationRole> getAssociationRoles() {
+ public Set<Role> getRoles() {
return _roles;
}
@@ -1154,30 +1138,28 @@
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 IConstruct getParent() { return null; }
+ public TopicMap getParent() { return null; }
public void removeItemIdentifier(Locator itemIdentifier) { }
- public AssociationRole createAssociationRole(Topic arg0, Topic arg1) { return null; }
+ public Role createRole(Topic arg0, Topic arg1) { return null; }
public Topic getReifier() { return null; }
- public void remove() throws TMAPIException {}
+ public void remove() {}
public void setType(Topic arg0) {}
- public void addScopingTopic(Topic arg0) {}
- public Set getScope() { return Collections.emptySet(); }
- public void removeScopingTopic(Topic arg0) {}
- public void addSourceLocator(Locator arg0) throws DuplicateSourceLocatorException {}
- public String getObjectId() { return null; }
- public Set getSourceLocators() { return Collections.emptySet(); }
+ 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; }
- public void removeSourceLocator(Locator arg0) {}
}
/**
* Immutable association role.
*/
- @SuppressWarnings("unchecked")
- private class TypeInstanceRole implements AssociationRole , IReifiable, ITyped {
+ private class TypeInstanceRole implements Role {
private final Topic _type;
private final Topic _player;
private final Association _parent;
@@ -1186,9 +1168,9 @@
_type = type;
_player = player;
_parent = parent;
- List<AssociationRole> roles = _topic2Roles.get(player);
+ List<Role> roles = _topic2Roles.get(player);
if (roles == null) {
- roles = new ArrayList<AssociationRole>();
+ roles = new ArrayList<Role>();
_topic2Roles.put(player, roles);
}
roles.add(this);
@@ -1205,35 +1187,32 @@
public void setReifier(Topic reifier) { }
public void addItemIdentifier(Locator itemIdentifier) { }
public Set<Locator> getItemIdentifiers() { return Collections.emptySet(); }
- public IConstruct getParent() { return (IConstruct) _parent; }
+ public Association getParent() { return _parent; }
public void removeItemIdentifier(Locator itemIdentifier) { }
public Association getAssociation() { return _parent; }
public Topic getReifier() { return null; }
- public void remove() throws TMAPIException {}
+ public void remove() {}
public void setPlayer(Topic arg0) {}
public void setType(Topic arg0) {}
- public void addSourceLocator(Locator arg0) throws DuplicateSourceLocatorException {}
- public String getObjectId() { return null; }
- public Set getSourceLocators() { return Collections.emptySet(); }
+ public String getId() { return null; }
public TopicMap getTopicMap() { return null; }
- public void removeSourceLocator(Locator arg0) {}
}
/**
* Immutable 'set' of two roles.
*/
- private static class TypeInstanceRoleSet extends AbstractSet<AssociationRole> {
+ private static class TypeInstanceRoleSet extends AbstractSet<Role> {
- private final AssociationRole _role1;
- private final AssociationRole _role2;
+ private final Role _role1;
+ private final Role _role2;
- TypeInstanceRoleSet(AssociationRole role1, AssociationRole role2) {
+ TypeInstanceRoleSet(Role role1, Role role2) {
_role1 = role1;
_role2 = role2;
}
@Override
- public Iterator<AssociationRole> iterator() {
+ public Iterator<Role> iterator() {
return new TypeInstanceRoleSetIterator();
}
@@ -1242,7 +1221,7 @@
return 2;
}
- private class TypeInstanceRoleSetIterator implements Iterator<AssociationRole> {
+ private class TypeInstanceRoleSetIterator implements Iterator<Role> {
private int _idx;
@@ -1250,7 +1229,7 @@
return _idx < 2;
}
- public AssociationRole next() {
+ public Role next() {
if (_idx > 1) {
throw new NoSuchElementException();
}
Added: tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/LiteralCanonicalizer.java
===================================================================
--- tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/LiteralCanonicalizer.java (rev 0)
+++ tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/LiteralCanonicalizer.java 2008-08-11 13:42:49 UTC (rev 117)
@@ -0,0 +1,57 @@
+/*
+ * This is tinyTiM, a tiny Topic Maps engine.
+ *
+ * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+package org.tinytim.cxtm;
+
+import org.tinytim.core.ILiteral;
+import org.tinytim.core.ILiteralAware;
+import org.tinytim.voc.XSD;
+import org.tmapi.core.Locator;
+
+/**
+ *
+ *
+ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
+ * @version $Rev:$ - $Date:$
+ */
+final class LiteralCanonicalizer {
+
+ private LiteralCanonicalizer () {
+ // noop.
+ }
+
+ public static String canonicalize(final ILiteralAware obj) {
+ final ILiteral lit = obj.getLiteral();
+ final String value = lit.getValue();
+ final Locator datatype = lit.getDatatype();
+ if (datatype == XSD.ANY_URI || datatype == XSD.STRING) {
+ return lit.getValue();
+ }
+ else if (datatype == XSD.DECIMAL || datatype == XSD.INT || datatype == XSD.INTEGER) {
+ if (value.charAt(0) == '+') {
+ return value.substring(1);
+ }
+ return value;
+ }
+ return lit.getValue();
+ }
+
+
+}
Property changes on: tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/LiteralCanonicalizer.java
___________________________________________________________________
Added: svn:keywords
+ Rev Date Id
Added: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|