diff options
Diffstat (limited to 'src/bindings/swig/java')
-rw-r--r-- | src/bindings/swig/java/CMakeLists.txt | 39 | ||||
-rw-r--r-- | src/bindings/swig/java/org/uscxml/InterpreterException.java | 9 | ||||
-rw-r--r-- | src/bindings/swig/java/uscxml.i | 166 |
3 files changed, 98 insertions, 116 deletions
diff --git a/src/bindings/swig/java/CMakeLists.txt b/src/bindings/swig/java/CMakeLists.txt index 51d67bb..3a7e9e0 100644 --- a/src/bindings/swig/java/CMakeLists.txt +++ b/src/bindings/swig/java/CMakeLists.txt @@ -33,3 +33,42 @@ set_target_properties(uscxmlNativeJava PROPERTIES COMPILE_FLAGS "-DSWIG") swig_link_libraries(uscxmlNativeJava uscxml) set(USCXML_LANGUAGE_BINDINGS ${USCXML_LANGUAGE_BINDINGS} PARENT_SCOPE) + +FIND_PROGRAM(ANT_EXECUTABLE ant PATHS $ENV{ANT_HOME}/bin ENV PATH ) +if (ANT_EXECUTABLE) + set(JAR_EXCLUDE_DEBUG OFF) + set(JAR_EXCLUDE_JNI OFF) + + # include all the JNI libraries prepared from DIST_PREPARE builds on the various desktop platforms + if (DIST_PREPARE) + if (CMAKE_CROSSCOMPILING) + if (ANDROID) + find_program(PROTOBUF_PROTOC_EXECUTABLE NAMES protoc protoc.exe) + set(JAR_EXCLUDE_JNI ON) # JNI inside jar not allowed with Android + SET(JAR_JNI_ROOT_PATH ${PROJECT_SOURCE_DIR}/package/cross-compiled/android) + else() + SET(JAR_JNI_ROOT_PATH ${PROJECT_SOURCE_DIR}/package/cross-compiled/${CMAKE_CROSSCOMPILING_TARGET_LC}) + endif() + else() + SET(JAR_JNI_ROOT_PATH ${PROJECT_SOURCE_DIR}/package) + endif() + else() + # when not preparing a distribution, just put the jar into the libs + SET(JAR_JNI_ROOT_PATH ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}) + endif() + + ADD_CUSTOM_TARGET(java + COMMAND ${ANT_EXECUTABLE} + -Dlib.dir=${JAR_JNI_ROOT_PATH} + -Dsrc.dir=${PROJECT_SOURCE_DIR} + -Dbuild.dir=${PROJECT_BINARY_DIR} + -Dbuild.type=${CMAKE_BUILD_TYPE} + -Dexclude.debug=${JAR_EXCLUDE_DEBUG} + -Dexclude.jni=${JAR_EXCLUDE_JNI} + -f build-java.xml + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/contrib/java + COMMENT "Creating the jar ...") + +else() + message(STATUS "Could not find ant binary - will not build jars") +endif()
\ No newline at end of file diff --git a/src/bindings/swig/java/org/uscxml/InterpreterException.java b/src/bindings/swig/java/org/uscxml/InterpreterException.java new file mode 100644 index 0000000..b089566 --- /dev/null +++ b/src/bindings/swig/java/org/uscxml/InterpreterException.java @@ -0,0 +1,9 @@ +package org.uscxml; + +public class InterpreterException extends Exception { + private static final long serialVersionUID = -3534919496547591015L; + + public InterpreterException(String msg) { + super(msg); + } +} diff --git a/src/bindings/swig/java/uscxml.i b/src/bindings/swig/java/uscxml.i index f72084e..b780f74 100644 --- a/src/bindings/swig/java/uscxml.i +++ b/src/bindings/swig/java/uscxml.i @@ -3,10 +3,6 @@ // provide a macro for the header files #define SWIGIMPORTED 1 -// import swig typemaps -//%include <arrays_java.i> -//%include <inttypes.i> - %include <stl.i> %include <std_map.i> %include <std_string.i> @@ -22,25 +18,20 @@ typedef uscxml::Event Event; typedef uscxml::InvokeRequest InvokeRequest; typedef uscxml::SendRequest SendRequest; +%feature("director") uscxml::WrappedInvoker; +%feature("director") uscxml::WrappedDataModel; +%feature("director") uscxml::WrappedIOProcessor; +%feature("director") uscxml::WrappedExecutableContent; + // disable warning related to unknown base class #pragma SWIG nowarn=401 -//%ignore boost::enable_shared_from_this; +// do not warn when we override symbols via extend +#pragma SWIG nowarn=302 %javaconst(1); -# %shared_ptr(uscxml::dom::Element); -# %shared_ptr(uscxml::dom::Executable); - %rename(equals) operator==; %rename(isValid) operator bool; -%ignore operator!=; -%ignore operator<; -%ignore operator=; -%ignore operator[]; -%ignore operator std::list<Data>; -%ignore operator std::string; -%ignore operator std::map<std::string,Data>; -%ignore operator<<; //************************************************** @@ -52,113 +43,54 @@ typedef uscxml::SendRequest SendRequest; #include "../../../uscxml/Message.h" #include "../../../uscxml/Factory.h" #include "../../../uscxml/Interpreter.h" - -//#include <DOM/Document.hpp> -//#include <DOM/Node.hpp> -//#include <DOM/Element.hpp> -//#include <DOM/Attr.hpp> -//#include <DOM/Text.hpp> +#include "../../../uscxml/concurrency/BlockingQueue.h" #include "../wrapped/WrappedInvoker.h" #include "../wrapped/WrappedDataModel.h" +#include "../wrapped/WrappedExecutableContent.h" +#include "../wrapped/WrappedIOProcessor.h" using namespace uscxml; using namespace Arabica::DOM; #include "../wrapped/WrappedInvoker.cpp" #include "../wrapped/WrappedDataModel.cpp" +#include "../wrapped/WrappedExecutableContent.cpp" +#include "../wrapped/WrappedIOProcessor.cpp" %} -%ignore uscxml::NumAttr; -%ignore uscxml::SCXMLParser; -%ignore uscxml::InterpreterImpl; - -%ignore create(); - -%ignore uscxml::Interpreter::getDelayQueue(); - -%ignore uscxml::WrappedInvoker::create(InterpreterImpl*); - -%ignore uscxml::WrappedDataModel::create(InterpreterImpl*); -%ignore uscxml::WrappedDataModel::init(const Arabica::DOM::Element<std::string>&, const Arabica::DOM::Document<std::string>&, const std::string&); -%ignore uscxml::WrappedDataModel::init(const std::string&, const Data&); -%ignore uscxml::WrappedDataModel::assign(const Arabica::DOM::Element<std::string>&, const Arabica::DOM::Document<std::string>&, const std::string&); -%ignore uscxml::WrappedDataModel::assign(const std::string&, const Data&); -%ignore uscxml::WrappedDataModel::eval(const Arabica::DOM::Element<std::string>&, const std::string&); - -%ignore uscxml::Event::Event(const Arabica::DOM::Node<std::string>&); -%ignore uscxml::Event::getStrippedDOM; -%ignore uscxml::Event::getFirstDOMElement; -%ignore uscxml::Event::getDOM(); -%ignore uscxml::Event::setDOM(const Arabica::DOM::Document<std::string>&); -%ignore uscxml::Event::toDocument(); - -%template(DataList) std::list<uscxml::Data>; -%template(DataMap) std::map<std::string, uscxml::Data>; -%template(StringSet) std::set<std::string>; -%template(StringVector) std::vector<std::string>; -%template(ParamPair) std::pair<std::string, uscxml::Data>; -%template(ParamPairVector) std::vector<std::pair<std::string, uscxml::Data> >; -%template(IOProcMap) std::map<std::string, uscxml::IOProcessor>; -%template(InvokerMap) std::map<std::string, uscxml::Invoker>; +%define WRAP_THROW_EXCEPTION( MATCH ) +%javaexception("org.uscxml.InterpreterException") MATCH { + try { + $action + } + catch ( uscxml::Event& e ) { + jclass eclass = jenv->FindClass("org/uscxml/InterpreterException"); + if ( eclass ) { + std::stringstream ss; + ss << std::endl << e; + jenv->ThrowNew( eclass, ss.str().c_str() ); + } + } +} +%enddef + +WRAP_THROW_EXCEPTION(uscxml::Interpreter::fromXML); +WRAP_THROW_EXCEPTION(uscxml::Interpreter::fromURI); +WRAP_THROW_EXCEPTION(uscxml::Interpreter::step); +WRAP_THROW_EXCEPTION(uscxml::Interpreter::interpret); + + +%include "../uscxml_ignores.i" %rename Data DataNative; -%feature("director") uscxml::WrappedInvoker; -%feature("director") uscxml::WrappedDataModel; - // translate param multimap to Map<String, List<Data> > %rename(getParamsNative) uscxml::Event::getParams(); %javamethodmodifiers uscxml::Event::getParams() "private"; -%extend uscxml::Event { - std::vector<std::pair<std::string, Data> > getParamPairs() { - std::vector<std::pair<std::string, Data> > pairs; - std::multimap<std::string, Data>::iterator paramPairIter = self->getParams().begin(); - while(paramPairIter != self->getParams().end()) { - pairs.push_back(*paramPairIter); - paramPairIter++; - } - return pairs; - } -}; - -%extend uscxml::Interpreter { - std::vector<std::string> getIOProcessorKeys() { - std::vector<std::string> keys; - std::map<std::string, IOProcessor>::const_iterator iter = self->getIOProcessors().begin(); - while(iter != self->getIOProcessors().end()) { - keys.push_back(iter->first); - iter++; - } - return keys; - } - - std::vector<std::string> getInvokerKeys() { - std::vector<std::string> keys; - std::map<std::string, Invoker>::const_iterator iter = self->getInvokers().begin(); - while(iter != self->getInvokers().end()) { - keys.push_back(iter->first); - iter++; - } - return keys; - } - -}; - -%extend uscxml::Data { - std::vector<std::string> getCompundKeys() { - std::vector<std::string> keys; - std::map<std::string, Data>::const_iterator iter = self->compound.begin(); - while(iter != self->compound.end()) { - keys.push_back(iter->first); - iter++; - } - return keys; - } -}; - +%include "../uscxml_beautify.i" //*********************************************** @@ -169,19 +101,21 @@ using namespace Arabica::DOM; %include "../../../uscxml/Factory.h" %include "../../../uscxml/Message.h" %include "../../../uscxml/Interpreter.h" -#include "../../../uscxml/DOMUtils.h" - -# %include <DOM/Document.hpp> -# %include <DOM/Node.hpp> -# %include <DOM/Element.hpp> -# %include <DOM/Attr.hpp> -# %include <DOM/Text.hpp> +%include "../../../uscxml/concurrency/BlockingQueue.h" %include "../wrapped/WrappedInvoker.h" %include "../wrapped/WrappedDataModel.h" +%include "../wrapped/WrappedExecutableContent.h" +%include "../wrapped/WrappedIOProcessor.h" + -# %template(XMLDocument) Arabica::DOM::Document<std::string>; -# %template(XMLNode) Arabica::DOM::Node<std::string>; -# %template(XMLElement) Arabica::DOM::Element<std::string>; -# %template(XMLAttr) Arabica::DOM::Attr<std::string>; -# %template(XMLText) Arabica::DOM::Text<std::string>; +%template(DataList) std::list<uscxml::Data>; +%template(DataMap) std::map<std::string, uscxml::Data>; +%template(StringSet) std::set<std::string>; +%template(StringVector) std::vector<std::string>; +%template(StringList) std::list<std::string>; +%template(ParamPair) std::pair<std::string, uscxml::Data>; +%template(ParamPairVector) std::vector<std::pair<std::string, uscxml::Data> >; +%template(IOProcMap) std::map<std::string, uscxml::IOProcessor>; +%template(InvokerMap) std::map<std::string, uscxml::Invoker>; +%template(ParentQueue) uscxml::concurrency::BlockingQueue<uscxml::SendRequest>; |