From b98de5fa08f69ca3ad71a592c62e5752cdef582b Mon Sep 17 00:00:00 2001 From: ishmal Date: Sat, 8 Mar 2008 22:50:44 +0000 Subject: [PATCH] First commit for java binding --- src/bind/dobinding.cpp | 166 +++++ .../java/org/inkscape/cmn/BaseObject.java | 41 ++ .../java/org/inkscape/cmn/ScriptRunner.java | 105 +++ src/bind/java/org/inkscape/dom/DOMBase.java | 70 ++ .../inkscape/dom/DOMImplementationImpl.java | 84 +++ .../java/org/inkscape/dom/DOMLocatorImpl.java | 103 +++ .../inkscape/dom/DocumentFragmentImpl.java | 47 ++ .../java/org/inkscape/dom/DocumentImpl.java | 300 ++++++++ .../org/inkscape/dom/DocumentTypeImpl.java | 93 +++ .../java/org/inkscape/dom/ElementImpl.java | 209 ++++++ .../org/inkscape/dom/NamedNodeMapImpl.java | 109 +++ src/bind/java/org/inkscape/dom/NodeImpl.java | 350 +++++++++ .../java/org/inkscape/dom/NodeListImpl.java | 60 ++ .../java/org/inkscape/dom/TypeInfoImpl.java | 77 ++ .../org/inkscape/dom/UserDataHandlerImpl.java | 53 ++ src/bind/javabind-private.h | 118 ++++ src/bind/javabind.cpp | 665 ++++++++++++++++++ src/bind/javabind.h | 283 ++++++++ 18 files changed, 2933 insertions(+) create mode 100644 src/bind/dobinding.cpp create mode 100644 src/bind/java/org/inkscape/cmn/BaseObject.java create mode 100644 src/bind/java/org/inkscape/cmn/ScriptRunner.java create mode 100644 src/bind/java/org/inkscape/dom/DOMBase.java create mode 100644 src/bind/java/org/inkscape/dom/DOMImplementationImpl.java create mode 100644 src/bind/java/org/inkscape/dom/DOMLocatorImpl.java create mode 100644 src/bind/java/org/inkscape/dom/DocumentFragmentImpl.java create mode 100644 src/bind/java/org/inkscape/dom/DocumentImpl.java create mode 100644 src/bind/java/org/inkscape/dom/DocumentTypeImpl.java create mode 100644 src/bind/java/org/inkscape/dom/ElementImpl.java create mode 100644 src/bind/java/org/inkscape/dom/NamedNodeMapImpl.java create mode 100644 src/bind/java/org/inkscape/dom/NodeImpl.java create mode 100644 src/bind/java/org/inkscape/dom/NodeListImpl.java create mode 100644 src/bind/java/org/inkscape/dom/TypeInfoImpl.java create mode 100644 src/bind/java/org/inkscape/dom/UserDataHandlerImpl.java create mode 100644 src/bind/javabind-private.h create mode 100644 src/bind/javabind.cpp create mode 100644 src/bind/javabind.h diff --git a/src/bind/dobinding.cpp b/src/bind/dobinding.cpp new file mode 100644 index 000000000..29da3c0a4 --- /dev/null +++ b/src/bind/dobinding.cpp @@ -0,0 +1,166 @@ +/** + * This is a simple mechanism to bind Inkscape to Java, and thence + * to all of the nice things that can be layered upon that. + * + * Authors: + * Bob Jamison + * + * Copyright (C) 2007 Bob Jamison + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +#include +#include +#include +#include +#include + +#ifdef __WIN32__ +#include +#else +#include +#include +#endif + +#include "javabind.h" +#include "javabind-private.h" + +#include +#include + +namespace Inkscape +{ +namespace Bind +{ + +using namespace org::w3c::dom; + +/** + * This file has the actual C++ --> Java bindings + * This file can get quite large! + */ + + +//######################################################################## +//# BASE OBJECT +//######################################################################## + +static jlong getPointer(JNIEnv *env, jobject obj) +{ + jfieldID id = env->GetFieldID(env->GetObjectClass(obj), "_pointer", "J"); + jlong val = env->GetLongField(obj, id); + return val; +} + +static void setPointer(JNIEnv *env, jobject obj, jlong val) +{ + jfieldID id = env->GetFieldID(env->GetObjectClass(obj), "_pointer", "J"); + env->SetLongField(obj, id, val); +} + +static void JNICALL DOMBase_construct + (JNIEnv *env, jobject obj) +{ + setPointer(env, obj, 0L); +} + +static void JNICALL DOMBase_destruct + (JNIEnv *env, jobject obj) +{ + NodePtr *ptr = (NodePtr *)getPointer(env, obj); + if (ptr) + { + delete ptr; + } + setPointer(env, obj, 0L); +} + + +static JNINativeMethod DOMBaseMethods[] = +{ +{ (char *)"construct", (char *)"()V", (void *)DOMBase_construct }, +{ (char *)"destruct", (char *)"()V", (void *)DOMBase_destruct }, +{ NULL, NULL, NULL } +}; + +//######################################################################## +//# DOMImplementation +//######################################################################## + + +void JNICALL DOMImplementation_nCreateDocument + (JNIEnv *env, jobject obj) +{ + DOMImplementationImpl domImpl; + DocumentTypePtr docType = domImpl.createDocumentType("", "", ""); + DocumentPtr doc = domImpl.createDocument("", "", docType); + DocumentPtr *ptr = new DocumentPtr(doc); + setPointer(env, obj, (jlong)ptr); +} + + + +static JNINativeMethod DOMImplementationMethods[] = +{ +{ (char *)"construct", (char *)"()V", (void *)DOMImplementation_nCreateDocument }, +{ NULL, NULL, NULL } +}; + + + +//######################################################################## +//# MAIN +//######################################################################## +typedef struct +{ + const char *className; + JNINativeMethod *methods; +} NativeEntry; + + +static NativeEntry nativeEntries[] = +{ + { "org/inkscape/dom/DOMBase", DOMBaseMethods }, + { "org/inkscape/dom/DOMImplementation", DOMImplementationMethods }, + { NULL, NULL } +}; + + + +bool JavaBinderyImpl::doBinding() +{ + for (NativeEntry *ne = nativeEntries ; ne->className ; ne++) + { + bool ret = registerNatives(ne->className, ne->methods); + if (!ret) + { + err("Could not bind native methods"); + return false; + } + } + return true; +} + + + + +} // namespace Bind +} // namespace Inkscape + +//######################################################################## +//# E N D O F F I L E +//######################################################################## diff --git a/src/bind/java/org/inkscape/cmn/BaseObject.java b/src/bind/java/org/inkscape/cmn/BaseObject.java new file mode 100644 index 000000000..5e496b67d --- /dev/null +++ b/src/bind/java/org/inkscape/cmn/BaseObject.java @@ -0,0 +1,41 @@ +/** + * This is a simple mechanism to bind Inkscape to Java, and thence + * to all of the nice things that can be layered upon that. + * + * Authors: + * Bob Jamison + * + * Copyright (C) 2007-2008 Bob Jamison + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package org.inkscape.cmn; + +public class BaseObject +{ + +private long _pointer; + +protected native void construct(); + +protected native void destruct(); + +public BaseObject() +{ + construct(); +} + +} diff --git a/src/bind/java/org/inkscape/cmn/ScriptRunner.java b/src/bind/java/org/inkscape/cmn/ScriptRunner.java new file mode 100644 index 000000000..1addfc72e --- /dev/null +++ b/src/bind/java/org/inkscape/cmn/ScriptRunner.java @@ -0,0 +1,105 @@ +/** + * This is a simple mechanism to bind Inkscape to Java, and thence + * to all of the nice things that can be layered upon that. + * + * Authors: + * Bob Jamison + * + * Copyright (C) 2007 Bob Jamison + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package org.inkscape.cmn; + +import javax.script.*; +import java.io.FileReader; +import java.io.IOException; +import javax.swing.JOptionPane; + + + + +public class ScriptRunner +{ + + + +static void err(String message) +{ + JOptionPane.showMessageDialog(null, message, + "Script Error", JOptionPane.ERROR_MESSAGE); +} + + + +public static boolean run(String lang, String str) +{ + ScriptEngineManager factory = new ScriptEngineManager(); + // create JavaScript engine + ScriptEngine engine = factory.getEngineByName(lang); + // evaluate JavaScript code from given file - specified by first argument + try + { + engine.eval(str); + } + catch (javax.script.ScriptException e) + { + err("Executing script: " + e); + } + return true; +} + +public static boolean runFile(String lang, String fname) +{ + ScriptEngineManager factory = new ScriptEngineManager(); + // create JavaScript engine + ScriptEngine engine = factory.getEngineByName(lang); + // evaluate JavaScript code from given file - specified by first argument + FileReader in = null; + boolean ret = true; + try + { + in = new FileReader(fname); + } + catch (java.io.IOException e) + { + err("Executing file: " + e); + return false; + } + try + { + engine.eval(in); + } + catch (javax.script.ScriptException e) + { + err("Executing file: " + e); + ret = false; + } + try + { + in.close(); + } + catch (java.io.IOException e) + { + err("Executing file: " + e); + return false; + } + return ret; +} + + + +} diff --git a/src/bind/java/org/inkscape/dom/DOMBase.java b/src/bind/java/org/inkscape/dom/DOMBase.java new file mode 100644 index 000000000..88a3e7de1 --- /dev/null +++ b/src/bind/java/org/inkscape/dom/DOMBase.java @@ -0,0 +1,70 @@ +/** + * This is a simple mechanism to bind Inkscape to Java, and thence + * to all of the nice things that can be layered upon that. + * + * Authors: + * Bob Jamison + * + * Copyright (C) 2007 Bob Jamison + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package org.inkscape.dom; + + + +/** + * This is the base Java class upon which + * all of the DOM classes are rooted + */ +public class DOMBase +{ + +protected long _pointer; + +/** + * @see dobinding.cpp: DOMBase_construct() + */ +protected native void construct(); + +/** + * @see dobinding.cpp: DOMBase_destruct() + */ +protected native void destruct(); + + + +/** + * Overload Object.finalize() so that we + * can perform proper cleanup. + */ +protected void finalize() +{ + destruct(); +} + + +public DOMBase() +{ + construct(); + _pointer = 0; +} + +} +//######################################################################## +//# E N D O F F I L E +//######################################################################## + diff --git a/src/bind/java/org/inkscape/dom/DOMImplementationImpl.java b/src/bind/java/org/inkscape/dom/DOMImplementationImpl.java new file mode 100644 index 000000000..553d613c4 --- /dev/null +++ b/src/bind/java/org/inkscape/dom/DOMImplementationImpl.java @@ -0,0 +1,84 @@ +/** + * This is a simple mechanism to bind Inkscape to Java, and thence + * to all of the nice things that can be layered upon that. + * + * Authors: + * Bob Jamison + * + * Copyright (C) 2007 Bob Jamison + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package org.inkscape.dom; + +import org.w3c.dom.*; + + +public class DOMImplementationImpl + extends DOMBase + implements org.w3c.dom.DOMImplementation +{ + +/** + * Creates a DOM Document object of the specified type + * with its document element. + */ +public Document createDocument(String namespaceURI, + String qualifiedName, + DocumentType doctype) +{ + return null; +} + +/** + * Creates an empty DocumentType node. + */ +public DocumentType createDocumentType(String qualifiedName, + String publicId, + String systemId) +{ + return null; +} + +/** + * This method returns a specialized object which implements the + * specialized APIs of the specified feature and version, as specified + * in DOM Features. + */ +public Object getFeature(String feature, String version) +{ + return null; +} + +/** + * Test if the DOM implementation implements a specific + * feature and version, as specified in DOM Features. + */ +public boolean hasFeature(String feature, String version) +{ + return false; +} + + +/** + * + */ +public DOMImplementationImpl() +{ + super(); +} + +} diff --git a/src/bind/java/org/inkscape/dom/DOMLocatorImpl.java b/src/bind/java/org/inkscape/dom/DOMLocatorImpl.java new file mode 100644 index 000000000..813d8c6ba --- /dev/null +++ b/src/bind/java/org/inkscape/dom/DOMLocatorImpl.java @@ -0,0 +1,103 @@ +/** + * This is a simple mechanism to bind Inkscape to Java, and thence + * to all of the nice things that can be layered upon that. + * + * Authors: + * Bob Jamison + * + * Copyright (C) 2007 Bob Jamison + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package org.inkscape.dom; + +import org.w3c.dom.*; + + + +public class DOMLocatorImpl + extends DOMBase + implements org.w3c.dom.DOMLocator +{ + + +/** + * The byte offset into the input source this locator is pointing to + * or -1 if there is no byte offset available. + */ +public int getByteOffset() +{ + return 0; +} + + +/** + * The column number this locator is pointing to, + * or -1 if there is no column number available. + */ +public int getColumnNumber() +{ + return 0; +} + + +/** + * The line number this locator is pointing to, or -1 if + * there is no column number available. + */ +public int getLineNumber() +{ + return 0; +} + + +/** + * The node this locator is pointing to, or null if no node is available. + */ +public Node getRelatedNode() +{ + return null; +} + + +/** + * The URI this locator is pointing to, or null if no URI is available. + */ +public String getUri() +{ + return ""; +} + + +/** + * The UTF-16, as defined in [Unicode] and + * Amendment 1 of [ISO/IEC 10646], offset into the input source + * this locator is pointing to or -1 if there is no UTF-16 + * offset available. + */ +public int getUtf16Offset() +{ + return 0; +} + + + +public DOMLocatorImpl() +{ + super(); +} + +} diff --git a/src/bind/java/org/inkscape/dom/DocumentFragmentImpl.java b/src/bind/java/org/inkscape/dom/DocumentFragmentImpl.java new file mode 100644 index 000000000..3c10d8f97 --- /dev/null +++ b/src/bind/java/org/inkscape/dom/DocumentFragmentImpl.java @@ -0,0 +1,47 @@ +/** + * This is a simple mechanism to bind Inkscape to Java, and thence + * to all of the nice things that can be layered upon that. + * + * Authors: + * Bob Jamison + * + * Copyright (C) 2007 Bob Jamison + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package org.inkscape.dom; + +import org.w3c.dom.*; + + +/** + * No methods are defined for this class + */ +public class DocumentFragmentImpl extends NodeImpl + implements org.w3c.dom.DocumentFragment +{ + + + + + + +public DocumentFragmentImpl() +{ + super(); +} + +} diff --git a/src/bind/java/org/inkscape/dom/DocumentImpl.java b/src/bind/java/org/inkscape/dom/DocumentImpl.java new file mode 100644 index 000000000..d0c63d98a --- /dev/null +++ b/src/bind/java/org/inkscape/dom/DocumentImpl.java @@ -0,0 +1,300 @@ +/** + * This is a simple mechanism to bind Inkscape to Java, and thence + * to all of the nice things that can be layered upon that. + * + * Authors: + * Bob Jamison + * + * Copyright (C) 2007 Bob Jamison + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package org.inkscape.dom; + +import org.w3c.dom.*; + +public class DocumentImpl extends NodeImpl + implements org.w3c.dom.Document +{ + +/** + * Attempts to adopt a node from another document to this document. + */ +public Node adoptNode(Node source) +{ + return null; +} + +/** + * Creates an Attr of the given name. + */ +public Attr createAttribute(String name) +{ + return null; +} + +/** + * Creates an attribute of the given qualified name and namespace URI. + */ +public Attr createAttributeNS(String namespaceURI, String qualifiedName) +{ + return null; +} + +/** + * Creates a CDATASection node whose value is the specified string. + */ +public CDATASection createCDATASection(String data) +{ + return null; +} + +/** + * Creates a Comment node given the specified string. + */ +public Comment createComment(String data) +{ + return null; +} + +/** + * Creates an empty DocumentFragment object. + */ +public DocumentFragment createDocumentFragment() +{ + return null; +} + +/** + * Creates an element of the type specified. + */ +public Element createElement(String tagName) +{ + return null; +} + +/** + * Creates an element of the given qualified name and namespace URI. + */ +public Element createElementNS(String namespaceURI, String qualifiedName) +{ + return null; +} + +/** + * Creates an EntityReference object. + */ +public EntityReference createEntityReference(String name) +{ + return null; +} + +/** + * Creates a ProcessingInstruction node given the specified name + * and data strings. + */ +public ProcessingInstruction createProcessingInstruction(String target, String data) +{ + return null; +} + +/** + * Creates a Text node given the specified string. + */ +public Text createTextNode(String data) +{ + return null; +} + +/** + * The Document Type Declaration (see DocumentType) associated + * with this document. + */ +public DocumentType getDoctype() +{ + return null; +} + +/** + * This is a convenience attribute that allows direct access to the + * child node that is the document element of the document. + */ +public Element getDocumentElement() +{ + return null; +} + +/** + * The location of the document or null if undefined or if the Document + * was created using DOMImplementation.createDocument. + */ +public String getDocumentURI() +{ + return ""; +} + +/** + * The configuration used when Document.normalizeDocument() is invoked. + */ +public DOMConfiguration getDomConfig() +{ + return null; +} + +/** + * Returns the Element that has an ID attribute with the given value. + */ +public Element getElementById(String elementId) +{ + return null; +} + +/** + * Returns a NodeList of all the Elements in document order with a + * given tag name and are contained in the document. + */ +public NodeList getElementsByTagName(String tagname) +{ + return null; +} + +/** + * Returns a NodeList of all the Elements with a given local name + * and namespace URI in document order. + */ +public NodeList getElementsByTagNameNS(String namespaceURI, String localName) +{ + return null; +} + +/** + * The DOMImplementation object that handles this document. + */ +public DOMImplementation getImplementation() +{ + return null; +} + +/** + * An attribute specifying the encoding used for this document at + * the time of the parsing. + */ +public String getInputEncoding() +{ + return ""; +} + +/** + * An attribute specifying whether error checking is enforced or not. + */ +public boolean getStrictErrorChecking() +{ + return false; +} + +/** + * An attribute specifying, as part of the XML declaration, + * the encoding of this document. + */ +public String getXmlEncoding() +{ + return ""; +} + +/** + * An attribute specifying, as part of the XML declaration, + * whether this document is standalone. + */ +public boolean getXmlStandalone() +{ + return false; +} + +/** + * An attribute specifying, as part of the XML declaration, + * the version number of this document. + */ +public String getXmlVersion() +{ + return ""; +} + +/** + * Imports a node from another document to this document, + * without altering or removing the source node from the + * original document; this method creates a + * new copy of the source node. + */ +public Node importNode(Node importedNode, boolean deep) +{ + return null; +} + +/** + * This method acts as if the document was going through + * a save and load cycle, putting the document in a "normal" form. + */ +public void normalizeDocument() +{ +} + +/** + * Rename an existing node of type ELEMENT_NODE or ATTRIBUTE_NODE. + */ +public Node renameNode(Node n, String namespaceURI, String qualifiedName) +{ + return null; +} + +/** + * The location of the document or null if undefined or if + * the Document was created using DOMImplementation.createDocument. + */ +public void setDocumentURI(String documentURI) +{ +} + +/** + * An attribute specifying whether error checking is enforced or not. + */ +public void setStrictErrorChecking(boolean strictErrorChecking) +{ +} + +/** + * An attribute specifying, as part of the XML declaration, + * whether this document is standalone. + */ +public void setXmlStandalone(boolean xmlStandalone) +{ +} + +/** + * An attribute specifying, as part of the XML declaration, + * the version number of this document. + */ +public void setXmlVersion(String xmlVersion) +{ +} + + +public DocumentImpl() +{ + super(); +} + +} + diff --git a/src/bind/java/org/inkscape/dom/DocumentTypeImpl.java b/src/bind/java/org/inkscape/dom/DocumentTypeImpl.java new file mode 100644 index 000000000..641565c7e --- /dev/null +++ b/src/bind/java/org/inkscape/dom/DocumentTypeImpl.java @@ -0,0 +1,93 @@ +/** + * This is a simple mechanism to bind Inkscape to Java, and thence + * to all of the nice things that can be layered upon that. + * + * Authors: + * Bob Jamison + * + * Copyright (C) 2007 Bob Jamison + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package org.inkscape.dom; + +import org.w3c.dom.*; + + + +public class DocumentTypeImpl extends NodeImpl + implements org.w3c.dom.DocumentType +{ + + +/** + * A NamedNodeMap containing the general entities, both + * external and internal, declared in the DTD. + */ +public NamedNodeMap getEntities() +{ + return null; +} + +/** + * The internal subset as a string, or null if there is none. + */ +public String getInternalSubset() +{ + return ""; +} + +/** + * The name of DTD; i.e., the name immediately following the + * DOCTYPE keyword. + */ +public String getName() +{ + return ""; +} + +/** + * A NamedNodeMap containing the notations declared in the DTD. + */ +public NamedNodeMap getNotations() +{ + return null; +} + +/** + * The public identifier of the external subset. + */ +public String getPublicId() +{ + return null; +} + +/** + * The system identifier of the external subset. + */ +public String getSystemId() +{ + return ""; +} + + + +public DocumentTypeImpl() +{ + super(); +} + +} diff --git a/src/bind/java/org/inkscape/dom/ElementImpl.java b/src/bind/java/org/inkscape/dom/ElementImpl.java new file mode 100644 index 000000000..24aa46404 --- /dev/null +++ b/src/bind/java/org/inkscape/dom/ElementImpl.java @@ -0,0 +1,209 @@ +/** + * This is a simple mechanism to bind Inkscape to Java, and thence + * to all of the nice things that can be layered upon that. + * + * Authors: + * Bob Jamison + * + * Copyright (C) 2007 Bob Jamison + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package org.inkscape.dom; + +import org.w3c.dom.*; + + + +public class ElementImpl extends NodeImpl + implements org.w3c.dom.Element +{ + + +/** + * Retrieves an attribute value by name. + */ +public String getAttribute(String name) +{ + return ""; +} + +/** + * Retrieves an attribute node by name. + */ +public Attr getAttributeNode(String name) +{ + return null; +} + +/** + * Retrieves an Attr node by local name and namespace URI. + */ +public Attr getAttributeNodeNS(String namespaceURI, String localName) +{ + return null; +} + +/** + * Retrieves an attribute value by local name and namespace URI. + */ +public String getAttributeNS(String namespaceURI, String localName) +{ + return ""; +} + +/** + * Returns a NodeList of all descendant Elements with a given + * tag name, in document order. + */ +public NodeList getElementsByTagName(String name) +{ + return null; +} + +/** + * Returns a NodeList of all the descendant Elements with a given + * local name and namespace URI in document order. + */ +public NodeList getElementsByTagNameNS(String namespaceURI, + String localName) +{ + return null; +} + +/** + * The type information associated with this element. + */ +public TypeInfo getSchemaTypeInfo() +{ + return null; +} + +/** + * The name of the element. + */ +public String getTagName() +{ + return ""; +} + +/** + * Returns true when an attribute with a given name is + * specified on this element or has a default value, false otherwise. + */ +public boolean hasAttribute(String name) +{ + return false; +} + +/** + * Returns true when an attribute with a given local name and + * namespace URI is specified on this element or has a default value, + * false otherwise. + */ +public boolean hasAttributeNS(String namespaceURI, String localName) +{ + return false; +} + +/** + * Removes an attribute by name. + */ +public void removeAttribute(String name) +{ +} + +/** + * Removes the specified attribute node. + */ +public Attr removeAttributeNode(Attr oldAttr) +{ + return null; +} + +/** + * Removes an attribute by local name and namespace URI. + */ +public void removeAttributeNS(String namespaceURI, String localName) +{ +} + +/** + * Adds a new attribute. + */ +public void setAttribute(String name, String value) +{ +} + +/** + * Adds a new attribute node. + */ +public Attr setAttributeNode(Attr newAttr) +{ + return null; +} + +/** + * Adds a new attribute. + */ +public Attr setAttributeNodeNS(Attr newAttr) +{ + return null; +} + +/** + * Adds a new attribute. + */ +public void setAttributeNS(String namespaceURI, + String qualifiedName, String value) +{ +} + +/** + * If the parameter isId is true, this method declares the + * specified attribute to be a user-determined ID attribute . + */ +public void setIdAttribute(String name, boolean isId) +{ +} + +/** + * If the parameter isId is true, this method declares the + * specified attribute to be a user-determined ID attribute . + */ +public void setIdAttributeNode(Attr idAttr, boolean isId) +{ +} + +/** + * If the parameter isId is true, this method declares the specified + * attribute to be a user-determined ID attribute . + */ +public void setIdAttributeNS(String namespaceURI, + String localName, boolean isId) +{ +} + + + +public ElementImpl() +{ + super(); +} + + + +} diff --git a/src/bind/java/org/inkscape/dom/NamedNodeMapImpl.java b/src/bind/java/org/inkscape/dom/NamedNodeMapImpl.java new file mode 100644 index 000000000..703efe699 --- /dev/null +++ b/src/bind/java/org/inkscape/dom/NamedNodeMapImpl.java @@ -0,0 +1,109 @@ +/** + * This is a simple mechanism to bind Inkscape to Java, and thence + * to all of the nice things that can be layered upon that. + * + * Authors: + * Bob Jamison + * + * Copyright (C) 2007 Bob Jamison + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package org.inkscape.dom; + +import org.w3c.dom.*; + + + +public class NamedNodeMapImpl + extends DOMBase + implements org.w3c.dom.NamedNodeMap +{ + + + +/** + * The number of nodes in this map. + */ +public int getLength() +{ + return 0; +} + +/** + * Retrieves a node specified by name. + */ +public Node getNamedItem(String name) +{ + return null; +} + +/** + * Retrieves a node specified by local name and namespace URI. + */ +public Node getNamedItemNS(String namespaceURI, String localName) +{ + return null; +} + +/** + * Returns the indexth item in the map. + */ +public Node item(int index) +{ + return null; +} + +/** + * Removes a node specified by name. + */ +public Node removeNamedItem(String name) +{ + return null; +} + +/** + * Removes a node specified by local name and namespace URI. + */ +public Node removeNamedItemNS(String namespaceURI, String localName) +{ + return null; +} + +/** + * Adds a node using its nodeName attribute. + */ +public Node setNamedItem(Node arg) +{ + return null; +} + +/** + * Adds a node using its namespaceURI and localName. + */ +public Node setNamedItemNS(Node arg) +{ + return null; +} + + + +public NamedNodeMapImpl() +{ + super(); +} + +} diff --git a/src/bind/java/org/inkscape/dom/NodeImpl.java b/src/bind/java/org/inkscape/dom/NodeImpl.java new file mode 100644 index 000000000..225d123c6 --- /dev/null +++ b/src/bind/java/org/inkscape/dom/NodeImpl.java @@ -0,0 +1,350 @@ +/** + * This is a simple mechanism to bind Inkscape to Java, and thence + * to all of the nice things that can be layered upon that. + * + * Authors: + * Bob Jamison + * + * Copyright (C) 2007 Bob Jamison + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package org.inkscape.dom; + +import org.w3c.dom.*; + + + +public class NodeImpl extends DOMBase + implements org.w3c.dom.Node +{ + +/** + * Adds the node newChild to the end of the list of children of this node. + */ +public Node appendChild(Node newChild) +{ + return null; +} + + +/** + * Returns a duplicate of this node, i.e., serves as a generic copy + * constructor for nodes. + */ +public Node cloneNode(boolean deep) +{ + return null; +} + +/** + * Compares the reference node, i.e. + */ +public short compareDocumentPosition(Node other) +{ + return 0; +} + +/** + * A NamedNodeMap containing the attributes of this node (if it is + * an Element) or null otherwise. + */ +public NamedNodeMap getAttributes() +{ + return null; +} + +/** + * The absolute base URI of this node or null if the + * implementation wasn't able to obtain an absolute URI. + */ +public String getBaseURI() +{ + return ""; +} + +/** + * A NodeList that contains all children of this node. + */ +public NodeList getChildNodes() +{ + return null; +} + +/** + * This method returns a specialized object which implements the + * specialized APIs of the specified feature and version, as specified in . + */ +public Object getFeature(String feature, String version) +{ + return null; +} + +/** + * The first child of this node. + */ +public Node getFirstChild() +{ + return null; +} + +/** + * The last child of this node. + */ +public Node getLastChild() +{ + return null; +} + +/** + * Returns the local part of the qualified name of this node. + */ +public String getLocalName() +{ + return ""; +} + +/** + * The namespace URI of this node, or null if it is unspecified (see ). + */ +public String getNamespaceURI() +{ + return ""; +} + +/** + * The node immediately following this node. + */ +public Node getNextSibling() +{ + return null; +} + +/** + * The name of this node, depending on its type; see the table above. + */ +public String getNodeName() +{ + return ""; +} + +/** + * A code representing the type of the underlying object, + * as defined above. + */ +public short getNodeType() +{ + return 0; +} + +/** + * The value of this node, depending on its type; see the table above. + */ +public String getNodeValue() +{ + return ""; +} + +/** + * The Document object associated with this node. + */ +public Document getOwnerDocument() +{ + return null; +} + +/** + * The parent of this node. + */ +public Node getParentNode() +{ + return null; +} + +/** + * The namespace prefix of this node, or null if it is unspecified. + */ +public String getPrefix() +{ + return ""; +} + +/** + * The node immediately preceding this node. + */ +public Node getPreviousSibling() +{ + return null; +} + +/** + * This attribute returns the text content of this node + * and its descendants. + */ +public String getTextContent() +{ + return ""; +} + +/** + * Retrieves the object associated to a key on a this node. + */ +public Object getUserData(String key) +{ + return null; +} + +/** + * Returns whether this node (if it is an element) has any attributes. + */ +public boolean hasAttributes() +{ + return false; +} + +/** + * Returns whether this node has any children. + */ +public boolean hasChildNodes() +{ + return false; +} + +/** + * Inserts the node newChild before the existing child node refChild. + */ +public Node insertBefore(Node newChild, Node refChild) +{ + return null; +} + +/** + * This method checks if the specified namespaceURI is the + * default namespace or not. + */ +public boolean isDefaultNamespace(String namespaceURI) +{ + return false; +} + +/** + * Tests whether two nodes are equal. + */ +public boolean isEqualNode(Node arg) +{ + return false; +} + +/** + * Returns whether this node is the same node as the given one. + */ +public boolean isSameNode(Node other) +{ + return false; +} + +/** + * Tests whether the DOM implementation implements a specific feature + * and that feature is supported by this node, as specified in . + */ +public boolean isSupported(String feature, String version) +{ + return false; +} + +/** + * Look up the namespace URI associated to the given prefix, + * starting from this node. + */ +public String lookupNamespaceURI(String prefix) +{ + return ""; +} + +/** + * Look up the prefix associated to the given namespace URI, starting + * from this node. + */ +public String lookupPrefix(String namespaceURI) +{ + return ""; +} + +/** + * Puts all Text nodes in the full depth of the sub-tree underneath + * this Node, including attribute nodes, into a "normal" form where only structure (e.g., elements, comments, processing instructions, CDATA sections, and entity references) separates Text nodes, i.e., there are neither adjacent Text nodes nor empty Text nodes. + */ +public void normalize() +{ +} + +/** + * Removes the child node indicated by oldChild from the list of + * children, and returns it. + */ +public Node removeChild(Node oldChild) +{ + return null; +} + +/** + * Replaces the child node oldChild with newChild in the list of + * children, and returns the oldChild node. + */ +public Node replaceChild(Node newChild, Node oldChild) +{ + return null; +} + +/** + * The value of this node, depending on its type; see the table above. + */ +public void setNodeValue(String nodeValue) +{ +} + +/** + * The namespace prefix of this node, or null if it is unspecified. + */ +public void setPrefix(String prefix) +{ +} + +/** + * This attribute returns the text content of this node and + * its descendants. + */ +public void setTextContent(String textContent) +{ +} + +/** + * Associate an object to a key on this node. + */ +public Object setUserData(String key, Object data, UserDataHandler handler) +{ + return null; +} + + +public NodeImpl() +{ + super(); +} + + + +} diff --git a/src/bind/java/org/inkscape/dom/NodeListImpl.java b/src/bind/java/org/inkscape/dom/NodeListImpl.java new file mode 100644 index 000000000..338b1d982 --- /dev/null +++ b/src/bind/java/org/inkscape/dom/NodeListImpl.java @@ -0,0 +1,60 @@ +/** + * This is a simple mechanism to bind Inkscape to Java, and thence + * to all of the nice things that can be layered upon that. + * + * Authors: + * Bob Jamison + * + * Copyright (C) 2007 Bob Jamison + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package org.inkscape.dom; + +import org.w3c.dom.Node; + + +public class NodeListImpl extends DOMBase + implements org.w3c.dom.NodeList +{ + +/** + * Returns the indexth item in the collection. + */ +public Node item(int index) +{ + return null; +} + + +/** + * The number of nodes in the list. + */ +public int getLength() +{ + return 0; +} + + +/** + * + */ +public NodeListImpl() +{ + super(); +} + +} diff --git a/src/bind/java/org/inkscape/dom/TypeInfoImpl.java b/src/bind/java/org/inkscape/dom/TypeInfoImpl.java new file mode 100644 index 000000000..c01ffd152 --- /dev/null +++ b/src/bind/java/org/inkscape/dom/TypeInfoImpl.java @@ -0,0 +1,77 @@ +/** + * This is a simple mechanism to bind Inkscape to Java, and thence + * to all of the nice things that can be layered upon that. + * + * Authors: + * Bob Jamison + * + * Copyright (C) 2007 Bob Jamison + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package org.inkscape.dom; + +import org.w3c.dom.*; + + + +public class TypeInfoImpl + extends DOMBase + implements org.w3c.dom.TypeInfo +{ + + +/** + * The name of a type declared for the associated element + * or attribute, or null if unknown. + */ +public String getTypeName() +{ + return ""; +} + + +/** + * The namespace of the type declared for the associated + * element or attribute or null if the element does not have + * declaration or if no namespace information is available. + */ +public String getTypeNamespace() +{ + return ""; +} + + + +/** + * This method returns if there is a derivation between + * the reference type definition, i.e. + */ +public boolean isDerivedFrom(String typeNamespaceArg, + String typeNameArg, + int derivationMethod) +{ + return false; +} + + + +public TypeInfoImpl() +{ + super(); +} + +} diff --git a/src/bind/java/org/inkscape/dom/UserDataHandlerImpl.java b/src/bind/java/org/inkscape/dom/UserDataHandlerImpl.java new file mode 100644 index 000000000..329f471bb --- /dev/null +++ b/src/bind/java/org/inkscape/dom/UserDataHandlerImpl.java @@ -0,0 +1,53 @@ +/** + * This is a simple mechanism to bind Inkscape to Java, and thence + * to all of the nice things that can be layered upon that. + * + * Authors: + * Bob Jamison + * + * Copyright (C) 2007 Bob Jamison + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package org.inkscape.dom; + +import org.w3c.dom.*; + + + +public class UserDataHandlerImpl + extends DOMBase + implements org.w3c.dom.UserDataHandler +{ + + +/** + * This method is called whenever the node for which this + * is registered is imported or cloned. + */ +public void handle(short operation, String key, + Object data, Node src, Node dst) +{ +} + + + +public UserDataHandlerImpl() +{ + super(); +} + +} diff --git a/src/bind/javabind-private.h b/src/bind/javabind-private.h new file mode 100644 index 000000000..18b041471 --- /dev/null +++ b/src/bind/javabind-private.h @@ -0,0 +1,118 @@ +#ifndef __JAVABIND_PRIVATE_H__ +#define __JAVABIND_PRIVATE_H__ +/** + * This is a simple mechanism to bind Inkscape to Java, and thence + * to all of the nice things that can be layered upon that. + * + * Authors: + * Bob Jamison + * + * Copyright (C) 2007 Bob Jamison + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include + +#include "javabind.h" + + + +namespace Inkscape +{ + +namespace Bind +{ + + +class JavaBinderyImpl : public JavaBindery +{ +public: + + JavaBinderyImpl(); + + virtual ~JavaBinderyImpl(); + + virtual bool loadJVM(); + + virtual bool callStatic(int type, + const String &className, + const String &methodName, + const String &signature, + const std::vector ¶ms, + Value &retval); + + virtual bool callMain(const String &className); + + virtual bool isLoaded(); + + virtual bool registerNatives(const String &className, + const JNINativeMethod *methods); + + virtual bool doBinding(); + + static JavaBinderyImpl *getInstance(); + + +private: + + JavaVM *jvm; + JNIEnv *env; + +}; + + +//######################################################################## +//# MESSAGES +//######################################################################## + +void err(const char *fmt, ...); + +void msg(const char *fmt, ...); + +//######################################################################## +//# UTILITY +//######################################################################## + +jint getInt(JNIEnv *env, jobject obj, const char *name); + +void setInt(JNIEnv *env, jobject obj, const char *name, jint val); + +jlong getLong(JNIEnv *env, jobject obj, const char *name); + +void setLong(JNIEnv *env, jobject obj, const char *name, jlong val); + +jfloat getFloat(JNIEnv *env, jobject obj, const char *name); + +void setFloat(JNIEnv *env, jobject obj, const char *name, jfloat val); + +jdouble getDouble(JNIEnv *env, jobject obj, const char *name); + +void setDouble(JNIEnv *env, jobject obj, const char *name, jdouble val); + +String getString(JNIEnv *env, jobject obj, const char *name); + +void setString(JNIEnv *env, jobject obj, const char *name, const String &val); + + + +} // namespace Bind +} // namespace Inkscape + +#endif /* __JAVABIND_PRIVATE_H__ */ +//######################################################################## +//# E N D O F F I L E +//######################################################################## + diff --git a/src/bind/javabind.cpp b/src/bind/javabind.cpp new file mode 100644 index 000000000..36facee88 --- /dev/null +++ b/src/bind/javabind.cpp @@ -0,0 +1,665 @@ +/** + * This is a simple mechanism to bind Inkscape to Java, and thence + * to all of the nice things that can be layered upon that. + * + * Authors: + * Bob Jamison + * + * Copyright (C) 2007 Bob Jamison + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +#include +#include +#include +#include +#include + +#include +#include + + +#ifdef __WIN32__ +#include +#else +#include +#include +#endif + +#include "javabind.h" +#include "javabind-private.h" +#include +#include + + + + + +namespace Inkscape +{ + +namespace Bind +{ + + +//######################################################################## +//# DEFINITIONS +//######################################################################## + +typedef jint (*CreateVMFunc)(JavaVM **, JNIEnv **, void *); + + + +//######################################################################## +//# UTILITY +//######################################################################## + +jint getInt(JNIEnv *env, jobject obj, const char *name) +{ + jfieldID fid = env->GetFieldID(env->GetObjectClass(obj), name, "I"); + return env->GetIntField(obj, fid); +} + +void setInt(JNIEnv *env, jobject obj, const char *name, jint val) +{ + jfieldID fid = env->GetFieldID(env->GetObjectClass(obj), name, "I"); + env->SetIntField(obj, fid, val); +} + +jlong getLong(JNIEnv *env, jobject obj, const char *name) +{ + jfieldID fid = env->GetFieldID(env->GetObjectClass(obj), name, "J"); + return env->GetLongField(obj, fid); +} + +void setLong(JNIEnv *env, jobject obj, const char *name, jlong val) +{ + jfieldID fid = env->GetFieldID(env->GetObjectClass(obj), name, "J"); + env->SetLongField(obj, fid, val); +} + +jfloat getFloat(JNIEnv *env, jobject obj, const char *name) +{ + jfieldID fid = env->GetFieldID(env->GetObjectClass(obj), name, "F"); + return env->GetFloatField(obj, fid); +} + +void setFloat(JNIEnv *env, jobject obj, const char *name, jfloat val) +{ + jfieldID fid = env->GetFieldID(env->GetObjectClass(obj), name, "F"); + env->SetFloatField(obj, fid, val); +} + +jdouble getDouble(JNIEnv *env, jobject obj, const char *name) +{ + jfieldID fid = env->GetFieldID(env->GetObjectClass(obj), name, "D"); + return env->GetDoubleField(obj, fid); +} + +void setDouble(JNIEnv *env, jobject obj, const char *name, jdouble val) +{ + jfieldID fid = env->GetFieldID(env->GetObjectClass(obj), name, "D"); + env->SetDoubleField(obj, fid, val); +} + +String getString(JNIEnv *env, jobject obj, const char *name) +{ + jfieldID fid = env->GetFieldID(env->GetObjectClass(obj), name, "Ljava/lang/String;"); + jstring jstr = (jstring)env->GetObjectField(obj, fid); + const char *chars = env->GetStringUTFChars(jstr, JNI_FALSE); + String str = chars; + env->ReleaseStringUTFChars(jstr, chars); + return str; +} + +void setString(JNIEnv *env, jobject obj, const char *name, const String &val) +{ + jstring jstr = env->NewStringUTF(val.c_str()); + jfieldID fid = env->GetFieldID(env->GetObjectClass(obj), name, "Ljava/lang/String;"); + env->SetObjectField(obj, fid, jstr); +} + + + + +//######################################################################## +//# CONSTRUCTOR/DESTRUCTOR +//######################################################################## + +static JavaBinderyImpl *_instance = NULL; + +JavaBindery *JavaBindery::getInstance() +{ + return JavaBinderyImpl::getInstance(); +} + +JavaBinderyImpl *JavaBinderyImpl::getInstance() +{ + if (!_instance) + { + _instance = new JavaBinderyImpl(); + } + return _instance; +} + +JavaBinderyImpl::JavaBinderyImpl() +{ + jvm = NULL; + env = NULL; +} + +JavaBinderyImpl::~JavaBinderyImpl() +{ +} + +void err(const char *fmt, ...) +{ +#if 0 + va_list args; + fprintf(stderr, "JavaBinderyImpl err:"); + va_start(args, fmt); + vfprintf(stderr, fmt, args); + va_end(args); + fprintf(stderr, "\n"); +#else + va_list args; + g_warning("JavaBinderyImpl err:"); + va_start(args, fmt); + g_logv(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, fmt, args); + va_end(args); + g_warning("\n"); +#endif +} + +void msg(const char *fmt, ...) +{ +#if 0 + va_list args; + fprintf(stdout, "JavaBinderyImpl:"); + va_start(args, fmt); + vfprintf(stdout, fmt, args); + va_end(args); + fprintf(stdout, "\n"); +#else + va_list args; + g_message("JavaBinderyImpl:"); + va_start(args, fmt); + g_logv(G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, fmt, args); + va_end(args); + g_message("\n"); +#endif +} + +bool JavaBinderyImpl::isLoaded() +{ + return (jvm != (void *)0); +} + + + +#ifdef __WIN32__ + + +//######################################################################## +//# W I N 3 2 S T Y L E +//######################################################################## + + +#define DIR_SEPARATOR "\\" +#define PATH_SEPARATOR ";" + + + +static bool getRegistryString(HKEY root, const char *keyName, + const char *valName, char *buf, int buflen) +{ + HKEY key; + DWORD bufsiz = buflen; + RegOpenKeyEx(HKEY_LOCAL_MACHINE, keyName, 0, KEY_READ, &key); + int ret = RegQueryValueEx(key, TEXT(valName), + NULL, NULL, (BYTE *)buf, &bufsiz); + if (ret != ERROR_SUCCESS) + { + err("Key '%s\\%s not found\n", keyName, valName); + return false; + } + RegCloseKey(key); + return true; +} + + +static CreateVMFunc getCreateVMFunc() +{ + char verbuf[16]; + char regpath[80]; + strcpy(regpath, "SOFTWARE\\JavaSoft\\Java Runtime Environment"); + bool ret = getRegistryString(HKEY_LOCAL_MACHINE, + regpath, "CurrentVersion", verbuf, 15); + if (!ret) + { + err("JVM CurrentVersion not found in registry\n"); + return NULL; + } + strcat(regpath, "\\"); + strcat(regpath, verbuf); + //msg("reg path: %s\n", regpath); + char libname[80]; + ret = getRegistryString(HKEY_LOCAL_MACHINE, + regpath, "RuntimeLib", libname, 79); + if (!ret) + { + err("Current JVM RuntimeLib not found in registry\n"); + return NULL; + } + //msg("jvm path: %s\n", libname); + HMODULE lib = LoadLibrary(libname); + if (!lib) + { + err("Java VM not found at '%s'", libname); + return NULL; + } + CreateVMFunc createVM = (CreateVMFunc)GetProcAddress(lib, "JNI_CreateJavaVM"); + if (!createVM) + { + err("Could not find 'JNI_CreateJavaVM' in shared library"); + return NULL; + } + return createVM; +} + +static void getJavaRoot(String &javaroot) +{ + char exeName[80]; + GetModuleFileName(NULL, exeName, 80); + char *slashPos = strrchr(exeName, '\\'); + if (slashPos) + *slashPos = '\0'; + javaroot = exeName; + javaroot.append("\\share\\java"); +} + + +#else + + +//######################################################################## +//# U N I X S T Y L E +//######################################################################## + + +#define DIR_SEPARATOR "/" +#define PATH_SEPARATOR ":" + + +/** + * Recursively descend into a directory looking for libjvm.so + */ +static bool findJVMRecursive(const String &dirpath, + std::vector &results) +{ + DIR *dir = opendir(dirpath.c_str()); + if (!dir) + return false; + bool ret = false; + while (true) + { + struct dirent *de = readdir(dir); + if (!de) + break; + String fname = de->d_name; + if (fname == "." || fname == "..") + continue; + String path = dirpath; + path.push_back('/'); + path.append(fname); + if (fname == "libjvm.so") + { + ret = true; + results.push_back(path); + continue; + } + struct stat finfo; + if (lstat(path.c_str(), &finfo)<0) + { + break; + } + if (finfo.st_mode & S_IFDIR) + { + ret |= findJVMRecursive(path, results); + } + } + closedir(dir); + return ret; +} + + +static const char *commonJavaPaths[] = +{ + "/usr/java", + "/usr/local/java", + "/usr/lib/jvm", + "/usr/local/lib/jvm", + NULL +}; + +/** + * Look for a Java VM (libjvm.so) in several Unix places + */ +static bool findJVM(String &result) +{ + std::vector results; + int found = false; + + /* Is there one specified by the user? */ + const char *javaHome = getenv("JAVA_HOME"); + if (javaHome && findJVMRecursive(javaHome, results)) + found = true; + else for (const char **path = commonJavaPaths ; *path ; path++) + { + if (findJVMRecursive(*path, results)) + { + found = true; + break; + } + } + if (!found) + { + return false; + } + if (results.size() == 0) + return false; + //Look first for a Client VM + for (unsigned int i=0 ; id_name; + if (fname == "." || fname == "..") + continue; + if (fname.size()<5) //x.jar + continue; + if (fname.compare(fname.size()-4, 4, ".jar") != 0) + continue; + + String path = libdir; + path.append(DIR_SEPARATOR); + path.append(fname); + + cp.append(PATH_SEPARATOR); + cp.append(path); + } + closedir(dir); + + result = cp; + + return; +} + + + +bool JavaBinderyImpl::loadJVM() +{ + if (jvm) + return true; + + CreateVMFunc createVM = getCreateVMFunc(); + if (!createVM) + { + err("Could not find 'JNI_CreateJavaVM' in shared library"); + return false; + } + + String javaroot; + getJavaRoot(javaroot); + String cp; + populateClassPath(javaroot, cp); + String classpath = "-Djava.class.path="; + classpath.append(cp); + msg("Class path is: '%s'", classpath.c_str()); + + String libpath = "-Djava.library.path="; + libpath.append(javaroot); + libpath.append(DIR_SEPARATOR); + libpath.append("libm"); + msg("Lib path is: '%s'", libpath.c_str()); + + JavaVMInitArgs vm_args; + JavaVMOption options[4]; + options[0].optionString = (char *)classpath.c_str(); + options[1].optionString = (char *)libpath.c_str(); + vm_args.version = JNI_VERSION_1_2; + vm_args.options = options; + vm_args.nOptions = 2; + vm_args.ignoreUnrecognized = true; + + if (createVM(&jvm, &env, &vm_args) < 0) + { + err("JNI_GetDefaultJavaVMInitArgs() failed"); + return false; + } + + return true; +} + + + + +bool JavaBinderyImpl::callStatic(int type, + const String &className, + const String &methodName, + const String &signature, + const std::vector ¶ms, + Value &retval) +{ + jclass cls = env->FindClass(className.c_str()); + if (!cls) + { + err("Could not find class '%s'", className.c_str()); + return false; + } + jmethodID mid = env->GetStaticMethodID(cls, + methodName.c_str(), signature.c_str()); + if (!mid) + { + err("Could not find method '%s:%s/%s'", className.c_str(), + methodName.c_str(), signature.c_str()); + return false; + } + jvalue *jvals = new jvalue[params.size()]; + for (unsigned int i=0 ; iNewStringUTF(v.getString().c_str()); + break; + } + default: + { + err("Unknown value type: %d", v.getType()); + return false; + } + } + } + switch (type) + { + case Value::BIND_VOID: + { + env->CallStaticVoidMethodA(cls, mid, jvals); + break; + } + case Value::BIND_BOOLEAN: + { + env->CallStaticBooleanMethodA(cls, mid, jvals); + break; + } + case Value::BIND_INT: + { + env->CallStaticIntMethodA(cls, mid, jvals); + break; + } + case Value::BIND_DOUBLE: + { + env->CallStaticDoubleMethodA(cls, mid, jvals); + break; + } + case Value::BIND_STRING: + { + env->CallStaticObjectMethodA(cls, mid, jvals); + break; + } + default: + { + err("Unknown return type: %d", type); + return false; + } + } + delete jvals; + return true; +} + + + + +bool JavaBinderyImpl::callMain(const String &className) +{ + std::vector parms; + Value retval; + return callStatic(Value::BIND_VOID, className, "main", + "([Ljava/lang/String;)V", parms, retval); +} + + + +bool JavaBinderyImpl::registerNatives(const String &className, + const JNINativeMethod *methods) +{ + jclass cls = env->FindClass(className.c_str()); + if (!cls) + { + err("Could not find class '%s'", className.c_str()); + return false; + } + int nrMethods = 0; + for (const JNINativeMethod *m = methods ; m->name ; m++) + nrMethods++; + if (env->RegisterNatives(cls, (const JNINativeMethod *)methods, nrMethods) < 0) + { + err("Could not register natives"); + return false; + } + return true; +} + + + + +} // namespace Bind +} // namespace Inkscape + +//######################################################################## +//# E N D O F F I L E +//######################################################################## diff --git a/src/bind/javabind.h b/src/bind/javabind.h new file mode 100644 index 000000000..24db22e20 --- /dev/null +++ b/src/bind/javabind.h @@ -0,0 +1,283 @@ +#ifndef __JAVABIND_H__ +#define __JAVABIND_H__ +/** + * This is a simple mechanism to bind Inkscape to Java, and thence + * to all of the nice things that can be layered upon that. + * + * Authors: + * Bob Jamison + * + * Copyright (C) 2007-2008 Bob Jamison + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include + + +namespace Inkscape +{ + +namespace Bind +{ + + +/** + * Select which String implementation we want to use + */ +typedef Glib::ustring String; + + + +/** + * + */ +class Value +{ +public: + + /** + * Types for this value + */ + typedef enum + { + BIND_VOID, + BIND_INT, + BIND_BOOLEAN, + BIND_DOUBLE, + BIND_STRING + } ValueType; + + /** + * + */ + Value() + { + init(); + } + + /** + * + */ + Value(const Value &other) + { + assign(other); + } + + /** + * + */ + Value &operator=(const Value &other) + { + assign(other); + return *this; + } + + /** + * + */ + virtual ~Value() + { + } + + /** + * + */ + int getType() + { return type; } + + /** + * + */ + void setBoolean(bool val) + { type = BIND_BOOLEAN; ival = (int)val; } + + /** + * + */ + bool getBoolean() + { + if (type == BIND_BOOLEAN) + return (bool)ival; + else + return false; + } + + /** + * + */ + void setInt(int val) + { type = BIND_INT; ival = val; } + + /** + * + */ + bool getInt() + { + if (type == BIND_INT) + return ival; + else + return 0; + } + + /** + * + */ + void setDouble(double val) + { type = BIND_DOUBLE; dval = val; } + + /** + * + */ + double getDouble() + { + if (type == BIND_DOUBLE) + return dval; + else + return 0.0; + } + + /** + * + */ + void setString(const String &val) + { type = BIND_STRING; sval = val; } + + /** + * + */ + String getString() + { + if (type == BIND_STRING) + return sval; + else + return ""; + } + + +private: + + void init() + { + type = BIND_INT; + ival = 0; + dval = 0.0; + sval = ""; + } + + void assign(const Value &other) + { + type = other.type; + ival = other.ival; + dval = other.dval; + sval = other.sval; + } + + int type; + long ival; + double dval; + String sval; + +}; + + + + + +/** + * + */ +class JavaBindery +{ +public: + + /** + * + */ + JavaBindery() + {} + + /** + * + */ + virtual ~JavaBindery() + {} + + /** + * + */ + virtual bool loadJVM() + { + return false; + } + + /** + * + */ + virtual bool callStatic(int /*type*/, + const String &/*className*/, + const String &/*methodName*/, + const String &/*signature*/, + const std::vector &/*params*/, + Value &/*retval*/) + { + return false; + } + + /** + * + */ + virtual bool callMain(const String &/*className*/) + { + return false; + } + + /** + * + */ + virtual bool isLoaded() + { + return false; + } + + /** + * + */ + virtual bool doBinding() + { + return false; + } + + + /** + * Return a singleton instance of this bindery + */ + static JavaBindery *getInstance(); + +}; + + + + + +} // namespace Bind +} // namespace Inkscape + +#endif /* __JAVABIND_H__ */ +//######################################################################## +//# E N D O F F I L E +//######################################################################## + -- 2.30.2