|
From: <lh...@us...> - 2008-05-24 15:25:13
|
Revision: 67
http://tinytim.svn.sourceforge.net/tinytim/?rev=67&view=rev
Author: lheuer
Date: 2008-05-24 08:24:58 -0700 (Sat, 24 May 2008)
Log Message:
-----------
- Replaced the fixed stateStack with a dynamic one to allow more states
Modified Paths:
--------------
tinytim-io/trunk/src/main/java/org/tinytim/io/MapInputHandler.java
tinytim-io/trunk/src/test/java/org/tinytim/io/TestMapInputHandler.java
Modified: tinytim-io/trunk/src/main/java/org/tinytim/io/MapInputHandler.java
===================================================================
--- tinytim-io/trunk/src/main/java/org/tinytim/io/MapInputHandler.java 2008-05-24 08:13:04 UTC (rev 66)
+++ tinytim-io/trunk/src/main/java/org/tinytim/io/MapInputHandler.java 2008-05-24 15:24:58 UTC (rev 67)
@@ -44,6 +44,7 @@
import com.semagia.mio.IMapHandler;
import com.semagia.mio.IRef;
import com.semagia.mio.MIOException;
+import com.semagia.mio.voc.XSD;
/**
* {@link com.semagia.mio.IMapHandler} implementation.
@@ -58,14 +59,10 @@
SCOPE, THEME, REIFIER, PLAYER, ISA, TYPE;
}
- private static final String _XSD_STRING = "http://www.w3.org/2001/XMLSchema#string";
- private static final String _XSD_ANY_URI = "http://www.w3.org/2001/XMLSchema#anyURI";
-
private static final Logger LOG = Logger.getLogger(MapInputHandler.class.getName());
private TopicMapImpl _tm;
- private State[] _stateStack;
- private int _stackPointer;
+ private List<State> _stateStack;
private List<TopicMapObject> _constructStack;
public MapInputHandler() {
@@ -93,8 +90,7 @@
*/
public void startTopicMap() throws MIOException {
_constructStack = new ArrayList<TopicMapObject>();
- _stateStack = new State[15];
- _stackPointer = -1;
+ _stateStack = new ArrayList<State>();
_enterState(State.INITIAL, _tm);
}
@@ -374,8 +370,8 @@
* @see com.semagia.mio.IMapHandler#value(java.lang.String, java.lang.String)
*/
public void value(String value, String datatype) throws MIOException {
- boolean isLocator = _XSD_ANY_URI.equals(datatype);
- if (!isLocator && !_XSD_STRING.equals(datatype)) {
+ boolean isLocator = XSD.ANY_URI.equals(datatype);
+ if (!isLocator && !XSD.STRING.equals(datatype)) {
LOG.warning("The datatype '" + datatype + "' was converted into xsd:string");
}
if (_state() == State.OCCURRENCE) {
@@ -405,7 +401,7 @@
* @param state The state to push ontop of the state stack.
*/
private void _enterState(State state) {
- _stateStack[++_stackPointer] = state;
+ _stateStack.add(state);
}
/**
@@ -427,10 +423,10 @@
* @throws MIOException If the state is not equals to the current state.
*/
private void _leaveState(State state) throws MIOException {
- if (!(state == _stateStack[_stackPointer])) {
- _reportError("Unexpected state: " + _stateStack[_stackPointer] + ", expected: " + state);
+ State current = _stateStack.remove(_stateStack.size()-1);
+ if (state != current) {
+ _reportError("Unexpected state: " + current + ", expected: " + state);
}
- --_stackPointer;
}
/**
@@ -469,7 +465,7 @@
* @return The current state.
*/
private State _state() {
- return _stateStack[_stackPointer];
+ return _stateStack.get(_stateStack.size()-1);
}
/**
Modified: tinytim-io/trunk/src/test/java/org/tinytim/io/TestMapInputHandler.java
===================================================================
--- tinytim-io/trunk/src/test/java/org/tinytim/io/TestMapInputHandler.java 2008-05-24 08:13:04 UTC (rev 66)
+++ tinytim-io/trunk/src/test/java/org/tinytim/io/TestMapInputHandler.java 2008-05-24 15:24:58 UTC (rev 67)
@@ -75,6 +75,27 @@
}
/**
+ * Tests reifying a topic map.
+ */
+ public void testTMReifier() throws Exception {
+ String itemIdent = "http://sf.net/projects/tinytim/test#1";
+ assertEquals(0, _tm.getTopics().size());
+ assertEquals(0, _tm.getAssociations().size());
+ _handler.startTopicMap();
+ _handler.startReifier();
+ _handler.startTopic(Ref.createItemIdentifier(itemIdent));
+ _handler.endTopic();
+ _handler.endReifier();
+ _handler.endTopicMap();
+ assertEquals(1, _tm.getTopics().size());
+ assertEquals(0, _tm.getAssociations().size());
+ Topic topic = (Topic) _tm.getObjectByItemIdentifier(_tm.createLocator(itemIdent));
+ assertNotNull(topic);
+ assertNotNull(_tm.getReifier());
+ assertEquals(topic, _tm.getReifier());
+ }
+
+ /**
* Tests topic creation with an item identifier.
*/
public void testTopicIdentityItemIdentifier() throws Exception {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|