|
From: <lh...@us...> - 2008-08-19 12:01:52
|
Revision: 134
http://tinytim.svn.sourceforge.net/tinytim/?rev=134&view=rev
Author: lheuer
Date: 2008-08-19 12:02:01 +0000 (Tue, 19 Aug 2008)
Log Message:
-----------
- Updated Scope handling for Variants. The solution sucks but passes the TMAPI tests. Anyway, better solution needed
Modified Paths:
--------------
tinytim/trunk/src/main/java/org/tinytim/core/NameImpl.java
tinytim/trunk/src/main/java/org/tinytim/core/ScopedImpl.java
tinytim/trunk/src/main/java/org/tinytim/core/VariantImpl.java
Modified: tinytim/trunk/src/main/java/org/tinytim/core/NameImpl.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/core/NameImpl.java 2008-08-17 18:49:30 UTC (rev 133)
+++ tinytim/trunk/src/main/java/org/tinytim/core/NameImpl.java 2008-08-19 12:02:01 UTC (rev 134)
@@ -98,10 +98,13 @@
*/
@Override
public void addTheme(Topic theme) {
+ IScope scope = _scope;
super.addTheme(theme);
- if (_variants != null) {
- for (Variant variant: _variants) {
- variant.addTheme(theme);
+ if (scope != _scope) {
+ if (_variants != null) {
+ for (Variant variant: _variants) {
+ ((VariantImpl) variant)._addNameTheme(theme);
+ }
}
}
}
@@ -111,10 +114,13 @@
*/
@Override
public void removeTheme(Topic theme) {
+ IScope scope = _scope;
super.removeTheme(theme);
- if (_variants != null) {
- for (Variant variant: _variants) {
- variant.removeTheme(theme);
+ if (scope != _scope) {
+ if (_variants != null) {
+ for (Variant variant: _variants) {
+ ((VariantImpl) variant)._removeNameTheme(theme);
+ }
}
}
}
@@ -185,15 +191,14 @@
if (scope.isEmpty()) {
throw new ModelConstraintException(this, "The scope of the variant must not be unconstrained");
}
- Set<Topic> nameScope = super.getScope();
- if (nameScope.containsAll(scope)) {
+ if (_scope.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_));
+ VariantImpl variant = new VariantImpl(_tm, literal, Scope.create(scope));
addVariant(variant);
+ for (Topic theme: _scope) {
+ variant._addNameTheme(theme);
+ }
return variant;
}
Modified: tinytim/trunk/src/main/java/org/tinytim/core/ScopedImpl.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/core/ScopedImpl.java 2008-08-17 18:49:30 UTC (rev 133)
+++ tinytim/trunk/src/main/java/org/tinytim/core/ScopedImpl.java 2008-08-19 12:02:01 UTC (rev 134)
@@ -36,7 +36,7 @@
//NOTE: This class does NOT implement IScoped by intention!
- private IScope _scope;
+ protected IScope _scope;
ScopedImpl(TopicMapImpl tm) {
super(tm);
Modified: tinytim/trunk/src/main/java/org/tinytim/core/VariantImpl.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/core/VariantImpl.java 2008-08-17 18:49:30 UTC (rev 133)
+++ tinytim/trunk/src/main/java/org/tinytim/core/VariantImpl.java 2008-08-19 12:02:01 UTC (rev 134)
@@ -20,7 +20,11 @@
*/
package org.tinytim.core;
+import java.util.Set;
+
+import org.tinytim.internal.utils.CollectionFactory;
import org.tmapi.core.Name;
+import org.tmapi.core.Topic;
import org.tmapi.core.Variant;
/**
@@ -72,4 +76,25 @@
super.dispose();
}
+ /* (non-Javadoc)
+ * @see org.tinytim.core.ScopedImpl#getScope()
+ */
+ @Override
+ public Set<Topic> getScope() {
+ Set<Topic> scope = CollectionFactory.createIdentitySet(getParent().getScope());
+ scope.addAll(_scope.asSet());
+ return scope;
+ }
+
+ void _addNameTheme(Topic theme) {
+ if (!_scope.contains(theme)) {
+ _fireEvent(Event.SET_SCOPE, _scope, _scope.add(theme));
+ }
+ }
+
+ void _removeNameTheme(Topic theme) {
+ IScope scope = Scope.create(getScope());
+ _fireEvent(Event.SET_SCOPE, scope.add(theme), scope);
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|