From: <lh...@us...> - 2008-08-14 11:58:31
|
Revision: 122 http://tinytim.svn.sourceforge.net/tinytim/?rev=122&view=rev Author: lheuer Date: 2008-08-14 11:58:37 +0000 (Thu, 14 Aug 2008) Log Message: ----------- - Adapted TMAPI 2.0 changes - Simplified argument checks Modified Paths: -------------- tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java tinytim/trunk/src/main/java/org/tinytim/core/DatatypeAwareConstruct.java tinytim/trunk/src/main/java/org/tinytim/core/IConstant.java tinytim/trunk/src/main/java/org/tinytim/core/MergeUtils.java tinytim/trunk/src/main/java/org/tinytim/core/NameImpl.java tinytim/trunk/src/main/java/org/tinytim/core/RoleImpl.java tinytim/trunk/src/main/java/org/tinytim/core/ScopedImpl.java tinytim/trunk/src/main/java/org/tinytim/core/TopicImpl.java tinytim/trunk/src/main/java/org/tinytim/core/TopicMapImpl.java tinytim/trunk/src/main/java/org/tinytim/core/TypedImpl.java tinytim/trunk/src/main/java/org/tinytim/core/VariantImpl.java tinytim/trunk/src/main/java/org/tinytim/internal/utils/DefaultIntObjectMap.java tinytim/trunk/src/test/java/org/tinytim/core/TestScope.java Added Paths: ----------- tinytim/trunk/src/main/java/org/tinytim/internal/utils/Check.java Modified: tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java 2008-08-12 12:01:10 UTC (rev 121) +++ tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java 2008-08-14 11:58:37 UTC (rev 122) @@ -23,9 +23,9 @@ import java.util.Collections; import java.util.Set; +import org.tinytim.internal.utils.Check; import org.tinytim.internal.utils.CollectionFactory; import org.tmapi.core.Association; -import org.tmapi.core.ModelConstraintException; import org.tmapi.core.Role; import org.tmapi.core.Topic; import org.tmapi.core.TopicMap; @@ -101,12 +101,8 @@ * @see org.tmapi.core.Association#createRole(org.tmapi.core.Topic, org.tmapi.core.Topic) */ public Role createRole(Topic type, Topic player) { - if (type == null) { - throw new ModelConstraintException(this, "The type must not be null"); - } - if (player == null) { - throw new ModelConstraintException(this, "The player must not be null"); - } + Check.typeNotNull(this, type); + Check.playerNotNull(this, player); RoleImpl role = new RoleImpl(_tm, type, player); addRole(role); return role; Modified: tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java 2008-08-12 12:01:10 UTC (rev 121) +++ tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java 2008-08-14 11:58:37 UTC (rev 122) @@ -26,6 +26,7 @@ import org.tinytim.internal.utils.CollectionFactory; import org.tmapi.core.Construct; import org.tmapi.core.Locator; +import org.tmapi.core.ModelConstraintException; import org.tmapi.core.TopicMap; /** @@ -79,7 +80,7 @@ */ public void addItemIdentifier(Locator itemIdentifier) { if (itemIdentifier == null) { - throw new IllegalArgumentException("The item identifier must not be null"); + throw new ModelConstraintException(this, "The item identifier must not be null"); } if (_iids != null && _iids.contains(itemIdentifier)) { return; Modified: tinytim/trunk/src/main/java/org/tinytim/core/DatatypeAwareConstruct.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/DatatypeAwareConstruct.java 2008-08-12 12:01:10 UTC (rev 121) +++ tinytim/trunk/src/main/java/org/tinytim/core/DatatypeAwareConstruct.java 2008-08-14 11:58:37 UTC (rev 122) @@ -23,6 +23,7 @@ import java.math.BigDecimal; import java.math.BigInteger; +import org.tinytim.internal.utils.Check; import org.tinytim.voc.XSD; import org.tmapi.core.DatatypeAware; import org.tmapi.core.Locator; @@ -82,6 +83,7 @@ * @see org.tmapi.core.DatatypeAware#setValue(java.lang.String) */ public void setValue(String value) { + Check.valueNotNull(this, value); setLiteral(Literal.create(value)); } @@ -89,6 +91,7 @@ * @see org.tmapi.core.DatatypeAware#setValue(java.math.BigDecimal) */ public void setValue(BigDecimal value) { + Check.valueNotNull(this, value); setLiteral(Literal.create(value)); } @@ -96,6 +99,7 @@ * @see org.tmapi.core.DatatypeAware#setValue(java.math.BigInteger) */ public void setValue(BigInteger value) { + Check.valueNotNull(this, value); setLiteral(Literal.create(value)); } @@ -117,6 +121,7 @@ * @see org.tmapi.core.DatatypeAware#setValue(org.tmapi.core.Locator) */ public void setValue(Locator value) { + Check.valueNotNull(this, value); setLiteral(Literal.create(value)); } @@ -131,6 +136,7 @@ * @see org.tmapi.core.DatatypeAware#setValue(java.lang.String, org.tmapi.core.Locator) */ public void setValue(String value, Locator datatype) { + Check.valueNotNull(this, value, datatype); setLiteral(Literal.create(value, datatype)); } Modified: tinytim/trunk/src/main/java/org/tinytim/core/IConstant.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IConstant.java 2008-08-12 12:01:10 UTC (rev 121) +++ tinytim/trunk/src/main/java/org/tinytim/core/IConstant.java 2008-08-14 11:58:37 UTC (rev 122) @@ -26,7 +26,7 @@ * This interface is not meant to be used outside of the tinyTiM package. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ interface IConstant { /** Modified: tinytim/trunk/src/main/java/org/tinytim/core/MergeUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/MergeUtils.java 2008-08-12 12:01:10 UTC (rev 121) +++ tinytim/trunk/src/main/java/org/tinytim/core/MergeUtils.java 2008-08-14 11:58:37 UTC (rev 122) @@ -20,7 +20,6 @@ */ package org.tinytim.core; -import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -107,12 +106,12 @@ if (sourceReifiable != null) { sourceReifiable.setReifier(target); } - List<Locator> locs = new ArrayList<Locator>(source.getSubjectIdentifiers()); + List<Locator> locs = CollectionFactory.createList(source.getSubjectIdentifiers()); for (Locator sid: locs) { source.removeSubjectIdentifier(sid); target.addSubjectIdentifier(sid); } - locs = new ArrayList<Locator>(source.getSubjectLocators()); + locs = CollectionFactory.createList(source.getSubjectLocators()); for (Locator slo: locs) { source.removeSubjectLocator(slo); target.addSubjectLocator(slo); @@ -126,7 +125,7 @@ sigs.put(SignatureGenerator.generateSignature(occ), occ); } Reifiable existing = null; - for (Occurrence occ: new ArrayList<Occurrence>(source.getOccurrences())) { + for (Occurrence occ: CollectionFactory.createList(source.getOccurrences())) { existing = sigs.get(SignatureGenerator.generateSignature(occ)); if (existing != null) { handleExistingConstruct(occ, existing); @@ -140,7 +139,7 @@ for (Name name: target.getNames()) { sigs.put(SignatureGenerator.generateSignature(name), name); } - for (Name name: new ArrayList<Name>(source.getNames())) { + for (Name name: CollectionFactory.createList(source.getNames())) { existing = sigs.get(SignatureGenerator.generateSignature(name)); if (existing != null) { handleExistingConstruct(name, existing); @@ -156,7 +155,7 @@ Association parent = role.getParent(); sigs.put(SignatureGenerator.generateSignature(parent), parent); } - for (Role role: new ArrayList<Role>(source.getRolesPlayed())) { + for (Role role: CollectionFactory.createList(source.getRolesPlayed())) { role.setPlayer(target); Association parent = role.getParent(); existing = sigs.get(SignatureGenerator.generateSignature(parent)); @@ -181,8 +180,7 @@ for (Role role: target.getRoles()) { sigs.put(SignatureGenerator.generateSignature(role), role); } - List<Role> roles = new ArrayList<Role>(source.getRoles()); - for (Role role: roles) { + for (Role role: CollectionFactory.createList(source.getRoles())) { handleExistingConstruct(role, sigs.get(SignatureGenerator.generateSignature(role))); role.remove(); } @@ -200,7 +198,7 @@ sigs.put(SignatureGenerator.generateSignature(var), var); } Variant existing = null; - for (Variant var: new ArrayList<Variant>(source.getVariants())) { + for (Variant var: CollectionFactory.createList(source.getVariants())) { existing = sigs.get(SignatureGenerator.generateSignature(var)); if (existing != null) { handleExistingConstruct(var, existing); @@ -311,7 +309,7 @@ * @param target The target which get the item identifiers. */ private static void _moveItemIdentifiers(Construct source, Construct target) { - List<Locator> iids = new ArrayList<Locator>(source.getItemIdentifiers()); + List<Locator> iids = CollectionFactory.createList(source.getItemIdentifiers()); for (Locator iid: iids) { source.removeItemIdentifier(iid); target.addItemIdentifier(iid); Modified: tinytim/trunk/src/main/java/org/tinytim/core/NameImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/NameImpl.java 2008-08-12 12:01:10 UTC (rev 121) +++ tinytim/trunk/src/main/java/org/tinytim/core/NameImpl.java 2008-08-14 11:58:37 UTC (rev 122) @@ -25,6 +25,7 @@ import java.util.Collections; import java.util.Set; +import org.tinytim.internal.utils.Check; import org.tinytim.internal.utils.CollectionFactory; import org.tmapi.core.Locator; import org.tmapi.core.ModelConstraintException; @@ -88,44 +89,49 @@ * @see org.tmapi.core.Name#setValue(java.lang.String) */ public void setValue(String value) { - if (value == null) { - throw new ModelConstraintException(this, "The value must not be null"); - } + Check.valueNotNull(this, value); setLiteral(Literal.create(value)); } /* (non-Javadoc) - * @see org.tmapi.core.TopicName#getVariants() + * @see org.tinytim.core.ScopedImpl#addTheme(org.tmapi.core.Topic) */ - public Set<Variant> getVariants() { - return _variants == null ? Collections.<Variant>emptySet() - : Collections.unmodifiableSet(_variants); - } - - private void _checkVariantValue(Object value) { - if (value == null) { - throw new ModelConstraintException(this, "The variant's value must not be null"); + @Override + public void addTheme(Topic theme) { + super.addTheme(theme); + if (_variants != null) { + for (Variant variant: _variants) { + variant.addTheme(theme); + } } } - private void _checkVariantValue(String value, Locator datatype) { - _checkVariantValue(value); - if (datatype == null) { - throw new ModelConstraintException(this, "The variant's datatype must not be null"); + /* (non-Javadoc) + * @see org.tinytim.core.ScopedImpl#removeTheme(org.tmapi.core.Topic) + */ + @Override + public void removeTheme(Topic theme) { + super.removeTheme(theme); + if (_variants != null) { + for (Variant variant: _variants) { + variant.removeTheme(theme); + } } } - private void _checkVariantScope(Topic[] scope) { - if (scope == null) { - throw new ModelConstraintException(this, "The variant's scope must not be null"); - } + /* (non-Javadoc) + * @see org.tmapi.core.TopicName#getVariants() + */ + public Set<Variant> getVariants() { + return _variants == null ? Collections.<Variant>emptySet() + : Collections.unmodifiableSet(_variants); } /* (non-Javadoc) * @see org.tmapi.core.Name#createVariant(org.tmapi.core.Locator, java.util.Collection) */ public Variant createVariant(Locator value, Collection<Topic> scope) { - _checkVariantValue(value); + Check.valueNotNull(this, value); return _createVariant(Literal.create(value), scope); } @@ -133,7 +139,7 @@ * @see org.tmapi.core.Name#createVariant(java.lang.String, java.util.Collection) */ public Variant createVariant(String value, Collection<Topic> scope) { - _checkVariantValue(value); + Check.valueNotNull(this, value); return _createVariant(Literal.create(value), scope); } @@ -141,7 +147,7 @@ * @see org.tmapi.core.Name#createVariant(org.tmapi.core.Locator, org.tmapi.core.Topic[]) */ public Variant createVariant(Locator value, Topic... scope) { - _checkVariantScope(scope); + Check.scopeNotNull(this, scope); return createVariant(value, Arrays.asList(scope)); } @@ -150,7 +156,7 @@ */ public Variant createVariant(String value, Locator datatype, Collection<Topic> scope) { - _checkVariantValue(value, datatype); + Check.valueNotNull(this, value, datatype); return _createVariant(value, datatype, scope); } @@ -158,7 +164,7 @@ * @see org.tmapi.core.Name#createVariant(java.lang.String, org.tmapi.core.Locator, org.tmapi.core.Topic[]) */ public Variant createVariant(String value, Locator datatype, Topic... scope) { - _checkVariantScope(scope); + Check.scopeNotNull(this, scope); return createVariant(value, datatype, Arrays.asList(scope)); } @@ -166,12 +172,12 @@ * @see org.tmapi.core.Name#createVariant(java.lang.String, org.tmapi.core.Topic[]) */ public Variant createVariant(String value, Topic... scope) { - _checkVariantScope(scope); + Check.scopeNotNull(this, scope); return createVariant(value, Arrays.asList(scope)); } private Variant _createVariant(String value, Locator datatype, Collection<Topic> scope) { - _checkVariantValue(value, datatype); + Check.valueNotNull(this, value, datatype); return _createVariant(Literal.create(value, datatype), scope); } @@ -179,12 +185,13 @@ if (scope.isEmpty()) { throw new ModelConstraintException(this, "The scope of the variant must not be unconstrained"); } - Set<Topic> scope_ = CollectionFactory.createIdentitySet(scope.size()); - scope_.addAll(scope); - scope_.removeAll(super.getScope()); - if (scope_.isEmpty()) { + Set<Topic> nameScope = super.getScope(); + if (nameScope.containsAll(scope)) { throw new ModelConstraintException(this, "The variant's scope is not a true superset of the parent's scope"); } + Set<Topic> scope_ = CollectionFactory.createIdentitySet(scope.size() + nameScope.size()); + scope_.addAll(scope); + scope_.addAll(nameScope); Variant variant = new VariantImpl(_tm, literal, Scope.create(scope_)); addVariant(variant); return variant; Modified: tinytim/trunk/src/main/java/org/tinytim/core/RoleImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/RoleImpl.java 2008-08-12 12:01:10 UTC (rev 121) +++ tinytim/trunk/src/main/java/org/tinytim/core/RoleImpl.java 2008-08-14 11:58:37 UTC (rev 122) @@ -20,8 +20,8 @@ */ package org.tinytim.core; +import org.tinytim.internal.utils.Check; import org.tmapi.core.Association; -import org.tmapi.core.ModelConstraintException; import org.tmapi.core.Role; import org.tmapi.core.Topic; @@ -62,9 +62,7 @@ * @see org.tmapi.core.Role#setPlayer(org.tmapi.core.Topic) */ public void setPlayer(Topic player) { - if (player == null) { - throw new ModelConstraintException(this, "The role player must not be null"); - } + Check.playerNotNull(this, player); if (_player == player) { return; } Modified: tinytim/trunk/src/main/java/org/tinytim/core/ScopedImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/ScopedImpl.java 2008-08-12 12:01:10 UTC (rev 121) +++ tinytim/trunk/src/main/java/org/tinytim/core/ScopedImpl.java 2008-08-14 11:58:37 UTC (rev 122) @@ -22,6 +22,7 @@ import java.util.Set; +import org.tmapi.core.ModelConstraintException; import org.tmapi.core.Topic; /** @@ -77,7 +78,7 @@ */ public void addTheme(Topic theme) { if (theme == null) { - throw new IllegalArgumentException("The theme must not be null"); + throw new ModelConstraintException(this, "The theme must not be null"); } setScopeObject(_scope.add(theme)); } Modified: tinytim/trunk/src/main/java/org/tinytim/core/TopicImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/TopicImpl.java 2008-08-12 12:01:10 UTC (rev 121) +++ tinytim/trunk/src/main/java/org/tinytim/core/TopicImpl.java 2008-08-14 11:58:37 UTC (rev 122) @@ -25,9 +25,11 @@ import java.util.Collections; import java.util.Set; +import org.tinytim.internal.utils.Check; import org.tinytim.internal.utils.CollectionFactory; import org.tinytim.utils.TopicUtils; import org.tmapi.core.Locator; +import org.tmapi.core.ModelConstraintException; import org.tmapi.core.Name; import org.tmapi.core.Occurrence; import org.tmapi.core.Reifiable; @@ -79,7 +81,7 @@ */ public void addSubjectIdentifier(Locator sid) { if (sid == null) { - throw new IllegalArgumentException("The subject identifier must not be null"); + throw new ModelConstraintException(this, "The subject identifier must not be null"); } if (_sids.contains(sid)) { return; @@ -112,7 +114,7 @@ */ public void addSubjectLocator(Locator slo) { if (slo == null) { - throw new IllegalArgumentException("The subject locator must not be null"); + throw new ModelConstraintException(this, "The subject locator must not be null"); } if (_slos != null && _sids.contains(slo)) { return; @@ -146,6 +148,7 @@ * @see org.tmapi.core.Topic#createOccurrence(org.tmapi.core.Topic, java.lang.String, java.util.Collection) */ public Occurrence createOccurrence(Topic type, String value, Collection<Topic> scope) { + Check.valueNotNull(this, value); return _createOccurrence(type, Literal.create(value), scope); } @@ -153,6 +156,7 @@ * @see org.tmapi.core.Topic#createOccurrence(org.tmapi.core.Locator, org.tmapi.core.Topic, java.util.Collection) */ public Occurrence createOccurrence(Topic type, Locator value, Collection<Topic> scope) { + Check.valueNotNull(this, value); return _createOccurrence(type, Literal.create(value), scope); } @@ -160,41 +164,37 @@ * @see org.tmapi.core.Topic#createOccurrence(org.tmapi.core.Topic, java.lang.String, org.tmapi.core.Locator, java.util.Collection) */ public Occurrence createOccurrence(Topic type, String value, Locator datatype, Collection<Topic> scope) { + Check.valueNotNull(this, value, datatype); return _createOccurrence(type, Literal.create(value, datatype), scope); } /* (non-Javadoc) * @see org.tmapi.core.Topic#createOccurrence(org.tmapi.core.Topic, java.lang.String, org.tmapi.core.Locator, org.tmapi.core.Topic[]) */ - public Occurrence createOccurrence(Topic type, String value, Locator datatype, Topic... themes) { - return _createOccurrence(type, Literal.create(value, datatype), Arrays.asList(themes)); + public Occurrence createOccurrence(Topic type, String value, Locator datatype, Topic... scope) { + Check.scopeNotNull(this, scope); + return createOccurrence(type, value, datatype, Arrays.asList(scope)); } /* (non-Javadoc) * @see org.tmapi.core.Topic#createOccurrence(org.tmapi.core.Topic, org.tmapi.core.Locator, org.tmapi.core.Topic[]) */ - public Occurrence createOccurrence(Topic type, Locator value, - Topic... scope) { - return _createOccurrence(type, Literal.create(value), Arrays.asList(scope)); + public Occurrence createOccurrence(Topic type, Locator value, Topic... scope) { + Check.scopeNotNull(this, scope); + return createOccurrence(type, value, Arrays.asList(scope)); } /* (non-Javadoc) * @see org.tmapi.core.Topic#createOccurrence(org.tmapi.core.Topic, java.lang.String, org.tmapi.core.Topic[]) */ public Occurrence createOccurrence(Topic type, String value, Topic... scope) { + Check.scopeNotNull(this, scope); return createOccurrence(type, value, Arrays.asList(scope)); } Occurrence _createOccurrence(Topic type, ILiteral literal, Collection<Topic> scope) { - if (type == null) { - throw new IllegalArgumentException("The type must not be null"); - } - if (literal == null) { - throw new IllegalArgumentException("The value must not be null"); - } - if (scope == null) { - throw new IllegalArgumentException("The scope must not be null"); - } + Check.typeNotNull(this, type); + Check.scopeNotNull(this, scope); Occurrence occ = new OccurrenceImpl(_tm, type, literal, Scope.create(scope)); addOccurrence(occ); return occ; @@ -265,6 +265,7 @@ * @see org.tmapi.core.Topic#createName(java.lang.String, org.tmapi.core.Topic[]) */ public Name createName(String value, Topic... scope) { + Check.scopeNotNull(this, scope); return createName(value, Arrays.asList(scope)); } @@ -272,6 +273,7 @@ * @see org.tmapi.core.Topic#createName(org.tmapi.core.Topic, java.lang.String, org.tmapi.core.Topic[]) */ public Name createName(Topic type, String value, Topic... scope) { + Check.scopeNotNull(this, scope); return createName(type, value, Arrays.asList(scope)); } @@ -302,19 +304,13 @@ * @see org.tmapi.core.Topic#createName(org.tmapi.core.Topic, java.lang.String, java.util.Collection) */ public Name createName(Topic type, String value, Collection<Topic> scope) { + Check.valueNotNull(this, value); return _createName(type, Literal.create(value), scope); } public Name _createName(Topic type, ILiteral literal, Collection<Topic> scope) { - if (type == null) { - throw new IllegalArgumentException("The type must not be null"); - } - if (literal == null) { - throw new IllegalArgumentException("The value must not be null"); - } - if (scope == null) { - throw new IllegalArgumentException("The scope must not be null"); - } + Check.typeNotNull(this, type); + Check.scopeNotNull(this, scope); NameImpl name = new NameImpl(_tm, type, literal, Scope.create(scope)); addName(name); return name; @@ -431,9 +427,7 @@ * @see org.tmapi.core.Topic#addType(org.tmapi.core.Topic) */ public void addType(Topic type) { - if (type == null) { - throw new IllegalArgumentException("The type must not be null"); - } + Check.typeNotNull(this, type); if (_types != null && _types.contains(type)) { return; } @@ -475,7 +469,7 @@ */ public void remove() throws TopicInUseException { if (!TopicUtils.isRemovable(this, true)) { - throw new TopicInUseException(this, "The topic is used as type, player, or theme"); + throw new TopicInUseException(this, "The topic is used as type, player, reifier, or theme"); } if (_reified != null) { _reified.setReifier(null); Modified: tinytim/trunk/src/main/java/org/tinytim/core/TopicMapImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/TopicMapImpl.java 2008-08-12 12:01:10 UTC (rev 121) +++ tinytim/trunk/src/main/java/org/tinytim/core/TopicMapImpl.java 2008-08-14 11:58:37 UTC (rev 122) @@ -20,7 +20,6 @@ */ package org.tinytim.core; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -30,10 +29,12 @@ import org.tinytim.index.IndexManager; import org.tinytim.index.IIndexManager; +import org.tinytim.internal.utils.Check; import org.tinytim.internal.utils.CollectionFactory; import org.tinytim.voc.TMDM; import org.tmapi.core.Association; import org.tmapi.core.IdentityConstraintException; +import org.tmapi.core.ModelConstraintException; import org.tmapi.core.Role; import org.tmapi.core.Locator; import org.tmapi.core.Occurrence; @@ -117,7 +118,7 @@ */ public Topic createTopicByItemIdentifier(Locator iid) { if (iid == null) { - throw new IllegalArgumentException("The item identifier must not be null"); + throw new ModelConstraintException(null, "The item identifier must not be null"); } Construct construct = getConstructByItemIdentifier(iid); if (construct != null) { @@ -148,7 +149,7 @@ */ public Topic createTopicBySubjectIdentifier(Locator sid) { if (sid == null) { - throw new IllegalArgumentException("The subject identifier must not be null"); + throw new ModelConstraintException(null, "The subject identifier must not be null"); } Topic topic = getTopicBySubjectIdentifier(sid); if (topic != null) { @@ -170,7 +171,7 @@ public Topic createTopicBySubjectLocator(Locator slo) { if (slo == null) { - throw new IllegalArgumentException("The subject locator must not be null"); + throw new ModelConstraintException(null, "The subject locator must not be null"); } Topic topic = getTopicBySubjectLocator(slo); if (topic != null) { @@ -223,16 +224,13 @@ } public Association createAssociation(Topic type, Topic... scope) { + Check.scopeNotNull(this, scope); return createAssociation(type, Arrays.asList(scope)); } public Association createAssociation(Topic type, Collection<Topic> scope) { - if (type == null) { - throw new IllegalArgumentException("The type must not be null"); - } - if (scope == null) { - throw new IllegalArgumentException("The scope must not be null"); - } + Check.typeNotNull(this, type); + Check.scopeNotNull(this, scope); AssociationImpl assoc = new AssociationImpl(this, type, Scope.create(scope)); addAssociation(assoc); return assoc; @@ -399,7 +397,7 @@ public void subscribe(Event event, IEventHandler handler) { List<IEventHandler> handlers = _evtHandlers.get(event); if (handlers == null) { - handlers = new ArrayList<IEventHandler>(); + handlers = CollectionFactory.createList(); _evtHandlers.put(event, handlers); } handlers.add(handler); Modified: tinytim/trunk/src/main/java/org/tinytim/core/TypedImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/TypedImpl.java 2008-08-12 12:01:10 UTC (rev 121) +++ tinytim/trunk/src/main/java/org/tinytim/core/TypedImpl.java 2008-08-14 11:58:37 UTC (rev 122) @@ -20,7 +20,7 @@ */ package org.tinytim.core; -import org.tmapi.core.ModelConstraintException; +import org.tinytim.internal.utils.Check; import org.tmapi.core.Reifiable; import org.tmapi.core.Topic; @@ -60,9 +60,7 @@ * @see org.tinytim.ITyped#setType(org.tmapi.core.Topic) */ public void setType(Topic type) { - if (type == null) { - throw new ModelConstraintException(this, "The type cannot be set to null"); - } + Check.typeNotNull(this, type); if (_type == type) { return; } Modified: tinytim/trunk/src/main/java/org/tinytim/core/VariantImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/VariantImpl.java 2008-08-12 12:01:10 UTC (rev 121) +++ tinytim/trunk/src/main/java/org/tinytim/core/VariantImpl.java 2008-08-14 11:58:37 UTC (rev 122) @@ -20,12 +20,7 @@ */ package org.tinytim.core; -import java.util.Set; - -import org.tinytim.internal.utils.CollectionFactory; import org.tmapi.core.Name; -import org.tmapi.core.Scoped; -import org.tmapi.core.Topic; import org.tmapi.core.Variant; /** @@ -53,20 +48,6 @@ } /* (non-Javadoc) - * @see org.tinytim.core.ScopedImpl#getScope() - */ - @Override - public Set<Topic> getScope() { - if (_tm == null || _parent == null) { - return super.getScope(); - } - Set<Topic> scope = CollectionFactory.createIdentitySet(4); - scope.addAll(super.getScope()); - scope.addAll(((Scoped) _parent).getScope()); - return scope; - } - - /* (non-Javadoc) * @see org.tinytim.IMovable#moveTo(java.lang.Object) */ public void moveTo(Name newParent) { Added: tinytim/trunk/src/main/java/org/tinytim/internal/utils/Check.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/internal/utils/Check.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/internal/utils/Check.java 2008-08-14 11:58:37 UTC (rev 122) @@ -0,0 +1,79 @@ +/* + * 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.internal.utils; + +import java.util.Collection; + +import org.tmapi.core.Construct; +import org.tmapi.core.Locator; +import org.tmapi.core.ModelConstraintException; +import org.tmapi.core.Topic; + +/** + * + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public class Check { + + private static void _reportError(Construct sender, String msg) { + throw new ModelConstraintException(sender, msg); + } + + public static void scopeNotNull(Construct sender, Topic[] scope) { + if (scope == null) { + _reportError(sender, "The scope must not be null"); + } + } + + public static void scopeNotNull(Construct sender, Collection<Topic> scope) { + if (scope == null) { + _reportError(sender, "The scope must not be null"); + } + } + + public static void typeNotNull(Construct sender, Topic type) { + if (type == null) { + _reportError(sender, "The type must not be null"); + } + } + + public static void valueNotNull(Construct sender, Object value) { + if (value == null) { + _reportError(sender, "The value must not be null"); + } + } + + public static void valueNotNull(Construct sender, Object value, Locator datatype) { + valueNotNull(sender, value); + if (datatype == null) { + _reportError(sender, "The datatype must not be null"); + } + } + + public static void playerNotNull(Construct sender, Topic player) { + if (player == null) { + _reportError(sender, "The role player must not be null"); + } + } + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/internal/utils/Check.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Modified: tinytim/trunk/src/main/java/org/tinytim/internal/utils/DefaultIntObjectMap.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/internal/utils/DefaultIntObjectMap.java 2008-08-12 12:01:10 UTC (rev 121) +++ tinytim/trunk/src/main/java/org/tinytim/internal/utils/DefaultIntObjectMap.java 2008-08-14 11:58:37 UTC (rev 122) @@ -26,7 +26,7 @@ * Default implementation of the {@link IIntObjectMap} which wraps a map. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ final class DefaultIntObjectMap<E> implements IIntObjectMap<E> { Modified: tinytim/trunk/src/test/java/org/tinytim/core/TestScope.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/core/TestScope.java 2008-08-12 12:01:10 UTC (rev 121) +++ tinytim/trunk/src/test/java/org/tinytim/core/TestScope.java 2008-08-14 11:58:37 UTC (rev 122) @@ -28,7 +28,7 @@ * * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public class TestScope extends TinyTimTestCase { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |