You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ra...@apache.org on 2008/11/15 00:03:28 UTC
svn commit: r714183 - in /commons/proper/scxml/branches/J6/src:
main/java/org/apache/commons/scxml/io/
main/java/org/apache/commons/scxml/model/
test/java/org/apache/commons/scxml/io/
Author: rahul
Date: Fri Nov 14 15:03:28 2008
New Revision: 714183
URL: http://svn.apache.org/viewvc?rev=714183&view=rev
Log:
Porting r714181 from trunk.
SCXMLParser should throw an exception for parsing failures on bad URIs in <state>'s "src" attribute.
Added couple of test cases with bad URIs (unfortunately these will produce traces on console when the tests run).
SCXML-80
Added:
commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/io/src-test-4.xml (with props)
commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/io/src-test-5.xml (with props)
Modified:
commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/io/SCXMLParser.java
commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/model/Data.java
commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/io/StateSrcTest.java
Modified: commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/io/SCXMLParser.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/io/SCXMLParser.java?rev=714183&r1=714182&r2=714183&view=diff
==============================================================================
--- commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/io/SCXMLParser.java (original)
+++ commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/io/SCXMLParser.java Fri Nov 14 15:03:28 2008
@@ -677,6 +677,29 @@
private static final String ERR_CUSTOM_ACTION_TYPE = "Custom actions list"
+ " contained unknown object (not a Commons SCXML Action subtype)";
+ /**
+ * Error message when the URI in a <state>'s "src"
+ * attribute does not point to a valid SCXML document, and thus cannot be
+ * parsed.
+ */
+ private static final String ERR_STATE_SRC =
+ "Source attribute in <state src=\"{0}\"> cannot be parsed";
+
+ /**
+ * Error message when the target of the URI fragment in a <state>'s
+ * "src" attribute is not defined in the referenced document.
+ */
+ private static final String ERR_STATE_SRC_FRAGMENT = "URI Fragment in "
+ + "<state src=\"{0}\"> is an unknown state in referenced document";
+
+ /**
+ * Error message when the target of the URI fragment in a <state>'s
+ * "src" attribute is not a <state> or <final> in
+ * the referenced document.
+ */
+ private static final String ERR_STATE_SRC_FRAGMENT_TARGET = "URI Fragment"
+ + " in <state src=\"{0}\"> does not point to a <state> or <final>";
+
// String constants
/** Slash. */
private static final String STR_SLASH = "/";
@@ -1440,7 +1463,7 @@
* @see Rule#begin(String, String, Attributes)
*/
public final void begin(final String namespace, final String name,
- final Attributes attributes) {
+ final Attributes attributes) throws ModelException {
String src = attributes.getValue("src");
if (SCXMLHelper.isStringEmpty(src)) {
return;
@@ -1480,9 +1503,12 @@
try {
externalSCXML = (SCXML) externalSrcDigester.parse(location);
} catch (Exception e) {
- org.apache.commons.logging.Log log = LogFactory.
- getLog(SCXMLParser.class);
- log.error(e.getMessage(), e);
+ MessageFormat msgFormat =
+ new MessageFormat(ERR_STATE_SRC);
+ String errMsg = msgFormat.format(new Object[] {
+ path
+ });
+ throw new ModelException(errMsg + " : " + e.getMessage(), e);
}
// 2) Adopt the children and datamodel
@@ -1507,11 +1533,12 @@
// Need to pull in descendent targets
Object source = externalSCXML.getTargets().get(fragment);
if (source == null) {
- org.apache.commons.logging.Log log = LogFactory.
- getLog(SCXMLParser.class);
- log.error("Unknown fragment in <state src=\"" + path +
- "\">");
- return;
+ MessageFormat msgFormat =
+ new MessageFormat(ERR_STATE_SRC_FRAGMENT);
+ String errMsg = msgFormat.format(new Object[] {
+ path
+ });
+ throw new ModelException(errMsg);
}
if (source instanceof State) {
State include = (State) source;
@@ -1540,10 +1567,12 @@
s.addTransition(t);
}
} else {
- org.apache.commons.logging.Log log = LogFactory.
- getLog(SCXMLParser.class);
- log.error("Fragment in <state src=\"" + path +
- "\"> is not a <state> or <final>");
+ MessageFormat msgFormat =
+ new MessageFormat(ERR_STATE_SRC_FRAGMENT_TARGET);
+ String errMsg = msgFormat.format(new Object[] {
+ path
+ });
+ throw new ModelException(errMsg);
}
}
}
Modified: commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/model/Data.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/model/Data.java?rev=714183&r1=714182&r2=714183&view=diff
==============================================================================
--- commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/model/Data.java (original)
+++ commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/model/Data.java Fri Nov 14 15:03:28 2008
@@ -89,7 +89,6 @@
* @deprecated Use {@link #setId(String)} instead.
*/
public final void setName(final String name) {
- System.err.println("\n\n" + name + "\n\n");
this.id = name;
}
Modified: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/io/StateSrcTest.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/io/StateSrcTest.java?rev=714183&r1=714182&r2=714183&view=diff
==============================================================================
--- commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/io/StateSrcTest.java (original)
+++ commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/io/StateSrcTest.java Fri Nov 14 15:03:28 2008
@@ -26,8 +26,10 @@
import org.apache.commons.scxml.SCXMLExecutor;
import org.apache.commons.scxml.SCXMLTestHelper;
+import org.apache.commons.scxml.env.SimpleErrorHandler;
import org.apache.commons.scxml.model.SCXML;
import org.apache.commons.scxml.model.TransitionTarget;
+import org.xml.sax.SAXException;
/**
* Unit tests {@link org.apache.commons.scxml.SCXMLDigester}
* Test white box nature of <state> element "src" attribute.
@@ -48,7 +50,7 @@
}
// Test data
- private URL src01;
+ private URL src01, src04, src05;
private SCXML scxml;
private SCXMLExecutor exec;
@@ -58,13 +60,17 @@
public void setUp() {
src01 = this.getClass().getClassLoader().
getResource("org/apache/commons/scxml/io/src-test-1.xml");
+ src04 = this.getClass().getClassLoader().
+ getResource("org/apache/commons/scxml/io/src-test-4.xml");
+ src05 = this.getClass().getClassLoader().
+ getResource("org/apache/commons/scxml/io/src-test-5.xml");
}
/**
* Tear down instance variables required by this test case.
*/
public void tearDown() {
- src01 = null;
+ src01 = src04 = src05 = null;
scxml = null;
exec = null;
}
@@ -86,7 +92,33 @@
assertTrue(exec.getCurrentStatus().isFinal());
}
- public static void main(String args[]) {
+ public void testBadSrcInclude() {
+ try {
+ scxml = SCXMLParser.parse(src04, new SimpleErrorHandler());
+ fail("Document with bad <state> src attribute shouldn't be parsed!");
+ } catch (SAXException me) {
+ assertTrue("Unexpected error message for bad <state> 'src' URI",
+ me.getMessage() != null && me.getMessage().contains("Source attribute in <state src="));
+ } catch (Exception e) {
+ fail("Unexpected exception [" + e.getClass().getName() + ":" +
+ e.getMessage());
+ }
+ }
+
+ public void testBadSrcFragmentInclude() {
+ try {
+ scxml = SCXMLParser.parse(src05, new SimpleErrorHandler());
+ fail("Document with bad <state> src attribute shouldn't be parsed!");
+ } catch (SAXException me) {
+ assertTrue("Unexpected error message for bad <state> 'src' URI fragment",
+ me.getMessage() != null && me.getMessage().contains("URI Fragment in <state src="));
+ } catch (Exception e) {
+ fail("Unexpected exception [" + e.getClass().getName() + ":" +
+ e.getMessage());
+ }
+ }
+
+ public static void main(String args[]) {
TestRunner.run(suite());
}
}
Added: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/io/src-test-4.xml
URL: http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/io/src-test-4.xml?rev=714183&view=auto
==============================================================================
--- commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/io/src-test-4.xml (added)
+++ commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/io/src-test-4.xml Fri Nov 14 15:03:28 2008
@@ -0,0 +1,30 @@
+<?xml version="1.0"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+-->
+<!-- Used for SrcTest.java in io package -->
+<scxml xmlns="http://www.w3.org/2005/07/scxml"
+ version="1.0"
+ initialstate="srctest1">
+
+ <state id="srctest1" src="bad-document-404.xml">
+ <transition event="srctest1.done" target="srctest1end"/>
+ </state>
+
+ <state id="srctest1end" final="true"/>
+
+</scxml>
+
Propchange: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/io/src-test-4.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/io/src-test-4.xml
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/io/src-test-5.xml
URL: http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/io/src-test-5.xml?rev=714183&view=auto
==============================================================================
--- commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/io/src-test-5.xml (added)
+++ commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/io/src-test-5.xml Fri Nov 14 15:03:28 2008
@@ -0,0 +1,30 @@
+<?xml version="1.0"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+-->
+<!-- Used for SrcTest.java in io package -->
+<scxml xmlns="http://www.w3.org/2005/07/scxml"
+ version="1.0"
+ initialstate="srctest1">
+
+ <state id="srctest1" src="src-test-3.xml#badstateid404">
+ <transition event="srctest1.done" target="srctest1end"/>
+ </state>
+
+ <state id="srctest1end" final="true"/>
+
+</scxml>
+
Propchange: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/io/src-test-5.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/io/src-test-5.xml
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL