You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by bu...@apache.org on 2006/05/09 19:33:39 UTC
DO NOT REPLY [Bug 39534] New: - External Digester does not addCustomActions
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=39534>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=39534
Summary: External Digester does not addCustomActions
Product: Commons
Version: 1.0 Alpha
Platform: Other
OS/Version: other
Status: NEW
Severity: normal
Priority: P2
Component: SCXML
AssignedTo: commons-dev@jakarta.apache.org
ReportedBy: fasihullah.askiri@gmail.com
I was not sure where to put my test-case. So attaching it here.
/*
* Copyright 2006 The Apache Software Foundation.
*
* Licensed 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.
*/
package org.apache.commons.scxml.model;
import java.net.URL;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.apache.commons.digester.Digester;
import org.apache.commons.scxml.Context;
import org.apache.commons.scxml.Evaluator;
import org.apache.commons.scxml.SCXMLExecutor;
import org.apache.commons.scxml.SCXMLTestHelper;
import org.apache.commons.scxml.env.jexl.JexlContext;
import org.apache.commons.scxml.env.jexl.JexlEvaluator;
import org.apache.commons.scxml.io.SCXMLDigester;
import org.apache.commons.scxml.model.SCXML;
import org.apache.commons.scxml.model.State;
public class ExternalCustomActionTest extends TestCase {
public ExternalCustomActionTest(String testName) {
super(testName);
}
public static Test suite() {
return new TestSuite(ExternalCustomActionTest.class);
}
public static void main(String args[]) {
String[] testCaseName = { ExternalCustomActionTest.class.getName()};
junit.textui.TestRunner.main(testCaseName);
}
private URL externalhello01, custom01;
private Digester digester;
private SCXMLExecutor exec;
/**
* Set up instance variables required by this test case.
*/
public void setUp() {
externalhello01 = this.getClass().getClassLoader().
getResource("org/apache/commons/scxml/external-hello-world.xml");
custom01 = this.getClass().getClassLoader().
getResource("org/apache/commons/scxml/custom-hello-world.xml");
}
/**
* Tear down instance variables required by this test case.
*/
public void tearDown() {
externalhello01 = custom01 = null;
digester = null;
exec = null;
}
// Hello World example using the SCXML <log> action
public void testHelloWorld() {
// (1) Get Digester with "default" rules for parsing SCXML documents
digester = SCXMLDigester.newInstance(null, null);
// (2) Register the "custom" action(s)
SCXMLDigester.addCustomAction(digester,
"http://my.custom-actions.domain/CUSTOM", "hello", Hello.class);
// (3) Parse the SCXML document containing the custom action(s)
SCXML scxml = null;
try {
scxml = (SCXML) digester.parse(externalhello01.toString());
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
// (4) Wire up the object model for the SCXMLExecutor
SCXMLDigester.updateSCXML(scxml);
// (5) Get a SCXMLExecutor
Context context = new JexlContext();
Evaluator evaluator = new JexlEvaluator();
exec = SCXMLTestHelper.getExecutor(scxml, context, evaluator);
// (6) Single, final state
assertEquals("external-hello", ((State) exec.getCurrentStatus().getStates().
iterator().next()).getId());
assertEquals ("external world", context.get("custom"));
}
// Hello World example using a custom <hello> action
public void testCustomActionHelloWorld() {
// (1) Get Digester with "default" rules for parsing SCXML documents
digester = SCXMLDigester.newInstance(null, null);
// (2) Register the "custom" action(s)
SCXMLDigester.addCustomAction(digester,
"http://my.custom-actions.domain/CUSTOM", "hello", Hello.class);
// (3) Parse the SCXML document containing the custom action(s)
SCXML scxml = null;
try {
scxml = (SCXML) digester.parse(custom01.toString());
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
// (4) Wire up the object model for the SCXMLExecutor
SCXMLDigester.updateSCXML(scxml);
// (5) Get a SCXMLExecutor
Context context = new JexlContext();
Evaluator evaluator = new JexlEvaluator();
exec = SCXMLTestHelper.getExecutor(scxml, context, evaluator);
// (6) Fire events, proceed as usual
assertEquals("external-hello", ((State) exec.getCurrentStatus().getStates().
iterator().next()).getId());
assertEquals ("external world", context.get("custom"));
}
}
<?xml version="1.0"?>
<scxml xmlns="http://www.w3.org/2005/07/SCXML"
xmlns:my="http://my.custom-actions.domain/CUSTOM"
version="1.0"
initialstate="external-hello">
<state id="external-hello">
<onentry>
<my:hello name="external world"/>
</onentry>
</state>
</scxml>
<?xml version="1.0"?>
<scxml xmlns="http://www.w3.org/2005/07/SCXML"
xmlns:my="http://my.custom-actions.domain/CUSTOM"
version="1.0"
initialstate="custom">
<datamodel/>
<state id="custom" final="true"
src="test/org/apache/commons/scxml/external-hello-world.xml"/>
</scxml>
--
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
DO NOT REPLY [Bug 39534] - [scxml] External Digester does not addCustomActions
Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=39534>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=39534
rahul@apache.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
Summary|External Digester does not |[scxml] External Digester
|addCustomActions |does not addCustomActions
------- Additional Comments From rahul@apache.org 2006-05-09 21:53 -------
Indeed, the approach to adding custom actions after calling newInstance() on
the digester does not address the case where the external documents pulled in
contain custom actions. It seems best to take this opportunity to refactor a
couple of related bits in the SCXMLDigester related to custom action parsing.
Thanks for reporting this, I'll take a look later tonight.
--
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
DO NOT REPLY [Bug 39534] - [scxml] External Digester does not addCustomActions
Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=39534>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=39534
------- Additional Comments From rahul@apache.org 2006-05-10 20:04 -------
That will definitely be a larger change for the users, but also conceptually,
since the custom actions are meant to be in other XML namespaces, the approach
used is similar to how Mozilla does XTF for its plugins (you define a backing
bean for each element in the namespace). If we take the POJO approach, then it
does imply higher reflection overheads (at runtime, reflection is our bread-n-
butter at parsing time) and is probably strange as an XML namespace. After
all, the actions are called custom actions since their utility and
implementation preferences are subjective.
As a library, Commons SCXML provides opportunities to customize most of its
internals, be it parsing, custom actions or engine semantics. Together, these
should allow users to build atop with their ideas (and the useful ones can
hopefully come back in to Commons SCXML). There is only so much that will come
out of the box, especially for the first release. I have some cleanup done
that fixes this issue about not parsing custom actions in "src'ed in"
documents, but the repository seems down ATM.
--
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
DO NOT REPLY [Bug 39534] - [scxml] External Digester does not addCustomActions
Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=39534>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=39534
------- Additional Comments From fasihullah.askiri@gmail.com 2006-05-09 22:50 -------
I think that this approach is "weird" if nothing else ;)
I guess a cleaner approach would be to go the Xalan way, either have an entity
resolver to find out the mapping or support java: namespace,
the second would be a lot more easier/intuitive to use.
in my example I would have used
xmlns:hello="java://com.mycompany.customactions.Hello"
instead of the
xmlns:hello="http://some.bakar.com/HELLO"
Which does not serve any purpose at all!!
hello:sayhi would call Hello.sayhi
However, doing this would mean a lot of change, also, it will mean that the old
code where ppl implemented SayHi.class to say a hi will be deprecated (Though
not broken, they should still be able to do what they do, only the java:
namespace can have this semantic)
Anyways, this was just my thought.
(In reply to comment #1)
> Indeed, the approach to adding custom actions after calling newInstance() on
> the digester does not address the case where the external documents pulled in
> contain custom actions. It seems best to take this opportunity to refactor a
> couple of related bits in the SCXMLDigester related to custom action parsing.
>
> Thanks for reporting this, I'll take a look later tonight.
>
>
--
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org