python-jpype-0.5.4.2/0000775000175000017500000000000011620747357013636 5ustar takakitakakipython-jpype-0.5.4.2/PKG-INFO0000666000175000017500000000037511614231506014725 0ustar takakitakakiMetadata-Version: 1.0 Name: JPype Version: 0.5.4.2 Summary: Python-Java bridge Home-page: http://jpype.sourceforge.net/ Author: Steve Menard Author-email: devilwolf@users.sourceforge.net License: UNKNOWN Description: UNKNOWN Platform: UNKNOWN python-jpype-0.5.4.2/README-LINUX.TXT0000666000175000017500000000116411614007722016061 0ustar takakitakakiThis release include preliminary support for linux. In order to compile the source, distribution, you need to make the 2 following changes : 1) in setup.py, change the line 19 to reflect the path to YOUR JDK installation Also, even if you do install from binary, you have to make the following change after installing. in the file jpype/_copy.py, at line 33, change to reflect the path to YOUR JDK installation These two steps are temporary, and should disappear before the 0.3 final. There is one additional problem with jpype and linux. You can more about it and a solution in the examples/linux directory. python-jpype-0.5.4.2/test/0000775000175000017500000000000011620747357014615 5ustar takakitakakipython-jpype-0.5.4.2/test/build.xml0000666000175000017500000000055211614007722016426 0ustar takakitakaki python-jpype-0.5.4.2/test/sample/0000775000175000017500000000000011620747357016076 5ustar takakitakakipython-jpype-0.5.4.2/test/sample/big.xml0000666000175000017500000050527611614007722017366 0ustar takakitakaki animate-elem-02-t Test 'additive' and 'accumulate' attributes. anim.5 anim.6 anim.7 anim.8 $Revision: 1.1 $ animate-elem-02-t Test 'additive' and 'accumulate' attributes. anim.5 anim.6 anim.7 anim.8 $Revision: 1.1 $ animate-elem-02-t Test 'additive' and 'accumulate' attributes. anim.5 anim.6 anim.7 anim.8 $Revision: 1.1 $ animate-elem-02-t Test 'additive' and 'accumulate' attributes. anim.5 anim.6 anim.7 anim.8 $Revision: 1.1 $ animate-elem-02-t Test 'additive' and 'accumulate' attributes. anim.5 anim.6 anim.7 anim.8 $Revision: 1.1 $ animate-elem-02-t Test 'additive' and 'accumulate' attributes. anim.5 anim.6 anim.7 anim.8 $Revision: 1.1 $ animate-elem-02-t Test 'additive' and 'accumulate' attributes. anim.5 anim.6 anim.7 anim.8 $Revision: 1.1 $ animate-elem-02-t Test 'additive' and 'accumulate' attributes. anim.5 anim.6 anim.7 anim.8 $Revision: 1.1 $ animate-elem-02-t Test 'additive' and 'accumulate' attributes. anim.5 anim.6 anim.7 anim.8 $Revision: 1.1 $ animate-elem-02-t Test 'additive' and 'accumulate' attributes. anim.5 anim.6 anim.7 anim.8 $Revision: 1.1 $ animate-elem-02-t Test 'additive' and 'accumulate' attributes. anim.5 anim.6 anim.7 anim.8 $Revision: 1.1 $ animate-elem-02-t Test 'additive' and 'accumulate' attributes. anim.5 anim.6 anim.7 anim.8 $Revision: 1.1 $ animate-elem-02-t Test 'additive' and 'accumulate' attributes. anim.5 anim.6 anim.7 anim.8 $Revision: 1.1 $ animate-elem-02-t Test 'additive' and 'accumulate' attributes. anim.5 anim.6 anim.7 anim.8 $Revision: 1.1 $ animate-elem-02-t Test 'additive' and 'accumulate' attributes. anim.5 anim.6 anim.7 anim.8 $Revision: 1.1 $ animate-elem-02-t Test 'additive' and 'accumulate' attributes. anim.5 anim.6 anim.7 anim.8 $Revision: 1.1 $ animate-elem-02-t Test 'additive' and 'accumulate' attributes. anim.5 anim.6 anim.7 anim.8 $Revision: 1.1 $ animate-elem-02-t Test 'additive' and 'accumulate' attributes. anim.5 anim.6 anim.7 anim.8 $Revision: 1.1 $ animate-elem-02-t Test 'additive' and 'accumulate' attributes. anim.5 anim.6 anim.7 anim.8 $Revision: 1.1 $ animate-elem-02-t Test 'additive' and 'accumulate' attributes. anim.5 anim.6 anim.7 anim.8 $Revision: 1.1 $ animate-elem-02-t Test 'additive' and 'accumulate' attributes. anim.5 anim.6 anim.7 anim.8 $Revision: 1.1 $ animate-elem-02-t Test 'additive' and 'accumulate' attributes. anim.5 anim.6 anim.7 anim.8 $Revision: 1.1 $ animate-elem-02-t Test 'additive' and 'accumulate' attributes. anim.5 anim.6 anim.7 anim.8 $Revision: 1.1 $ animate-elem-02-t Test 'additive' and 'accumulate' attributes. anim.5 anim.6 anim.7 anim.8 $Revision: 1.1 $ animate-elem-02-t Test 'additive' and 'accumulate' attributes. anim.5 anim.6 anim.7 anim.8 $Revision: 1.1 $ animate-elem-02-t Test 'additive' and 'accumulate' attributes. anim.5 anim.6 anim.7 anim.8 $Revision: 1.1 $ animate-elem-02-t Test 'additive' and 'accumulate' attributes. anim.5 anim.6 anim.7 anim.8 $Revision: 1.1 $ animate-elem-02-t Test 'additive' and 'accumulate' attributes. anim.5 anim.6 anim.7 anim.8 $Revision: 1.1 $ animate-elem-02-t Test 'additive' and 'accumulate' attributes. anim.5 anim.6 anim.7 anim.8 $Revision: 1.1 $ animate-elem-02-t Test 'additive' and 'accumulate' attributes. anim.5 anim.6 anim.7 anim.8 $Revision: 1.1 $ animate-elem-02-t Test 'additive' and 'accumulate' attributes. anim.5 anim.6 anim.7 anim.8 $Revision: 1.1 $ animate-elem-02-t Test 'additive' and 'accumulate' attributes. anim.5 anim.6 anim.7 anim.8 $Revision: 1.1 $ animate-elem-02-t Test 'additive' and 'accumulate' attributes. anim.5 anim.6 anim.7 anim.8 $Revision: 1.1 $ animate-elem-02-t Test 'additive' and 'accumulate' attributes. anim.5 anim.6 anim.7 anim.8 $Revision: 1.1 $ animate-elem-02-t Test 'additive' and 'accumulate' attributes. anim.5 anim.6 anim.7 anim.8 $Revision: 1.1 $ animate-elem-02-t Test 'additive' and 'accumulate' attributes. anim.5 anim.6 anim.7 anim.8 $Revision: 1.1 $ animate-elem-02-t Test 'additive' and 'accumulate' attributes. anim.5 anim.6 anim.7 anim.8 $Revision: 1.1 $ animate-elem-02-t Test 'additive' and 'accumulate' attributes. anim.5 anim.6 anim.7 anim.8 $Revision: 1.1 $ animate-elem-02-t Test 'additive' and 'accumulate' attributes. anim.5 anim.6 anim.7 anim.8 $Revision: 1.1 $ animate-elem-02-t Test 'additive' and 'accumulate' attributes. anim.5 anim.6 anim.7 anim.8 $Revision: 1.1 $ animate-elem-02-t Test 'additive' and 'accumulate' attributes. anim.5 anim.6 anim.7 anim.8 $Revision: 1.1 $ animate-elem-02-t Test 'additive' and 'accumulate' attributes. anim.5 anim.6 anim.7 anim.8 $Revision: 1.1 $ animate-elem-02-t Test 'additive' and 'accumulate' attributes. anim.5 anim.6 anim.7 anim.8 $Revision: 1.1 $ python-jpype-0.5.4.2/test/java_dom.py0000666000175000017500000000333111614007722016735 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # 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. # #***************************************************************************** import time from jpype import * startJVM(getDefaultJVMPath(), "-ea") # XML test Element = JPackage("org").w3c.dom.Element def output(el, prefix="") : if not Element.__isinstance__(el) : return #print prefix, "<", el.getTagName(), atts = el.getAttributes() for i in range(atts.getLength()) : a = atts.item(i); #print a.getNodeName(), '="%s"' % a.getNodeValue(), #print '>' nl = el.getChildNodes() for i in range(nl.getLength()) : output(nl.item(i), prefix+" ") #print prefix, "" t = time.time() count = 30 for i in range(count) : build = javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder() doc = build.parse("d:/darkwolf/jpype/test/sample/big.xml") el = doc.getDocumentElement() output(el) t2 = time.time() print count, "iterations in", t2-t, "seconds" shutdownJVM() python-jpype-0.5.4.2/test/testlucene.py0000666000175000017500000000204011614007722017324 0ustar takakitakakifrom jpype import * startJVM(getDefaultJVMPath(),'-Djava.class.path=c:/tools/lucene-1.4.3/lucene-1.4.3.jar') QueryParser = JClass("org.apache.lucene.queryParser.QueryParser") IndexSearcher = JClass("org.apache.lucene.search.IndexSearcher") IndexReader = JClass("org.apache.lucene.index.IndexReader") StandardAnalyzer = JClass("org.apache.lucene.analysis.standard.StandardAnalyzer") FSDirectory = JClass("org.apache.lucene.store.FSDirectory") IndexWriter = JClass("org.apache.lucene.index.IndexWriter") SimpleAnalyzer = JClass("org.apache.lucene.analysis.SimpleAnalyzer") IndexWriter('c:/temp/lucene', SimpleAnalyzer(), True).close() directory = FSDirectory.getDirectory("c:/temp/lucene",False) reader = IndexReader.open(directory) searcher = IndexSearcher(reader) queryparser = QueryParser.parse("wenger","contents",StandardAnalyzer()) print queryparser.rewrite print queryparser.rewrite.matchReport(reader) qp = queryparser.rewrite(reader) print qp print searcher.search.matchReport(qp) hits = searcher.search(qp) python-jpype-0.5.4.2/test/harness/0000775000175000017500000000000011620747357016260 5ustar takakitakakipython-jpype-0.5.4.2/test/harness/jpype/0000775000175000017500000000000011620747357017407 5ustar takakitakakipython-jpype-0.5.4.2/test/harness/jpype/exc/0000775000175000017500000000000011620747357020166 5ustar takakitakakipython-jpype-0.5.4.2/test/harness/jpype/exc/ExceptionTest.java0000666000175000017500000000242611614007722023621 0ustar takakitakaki// ***************************************************************************** //Copyright 2004-2008 Steve Menard // //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 jpype.exc; class ExceptionTest { public static void throwRuntime() { throw new RuntimeException("Foo"); } public static void throwIOException() throws java.io.IOException { throw new java.io.IOException("Bar"); } public static boolean delegateThrow(ExceptionThrower th) { try { th.throwIOException(); } catch (java.io.IOException ex) { return true; } catch (Throwable ex) { ex.printStackTrace(); } return false; } }python-jpype-0.5.4.2/test/harness/jpype/exc/ExceptionThrower.java0000666000175000017500000000154311614007722024333 0ustar takakitakaki//***************************************************************************** //Copyright 2004-2008 Steve Menard // //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 jpype.exc; interface ExceptionThrower { void throwIOException() throws java.io.IOException; }python-jpype-0.5.4.2/test/harness/jpype/xml/0000775000175000017500000000000011620747357020207 5ustar takakitakakipython-jpype-0.5.4.2/test/harness/jpype/xml/DelegateHandler.java0000666000175000017500000000635711614007722024063 0ustar takakitakaki//***************************************************************************** //Copyright 2004-2008 Steve Menard // //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 jpype.xml; import org.xml.sax.helpers.*; import org.xml.sax.*; public class DelegateHandler extends DefaultHandler { private EntityResolver er; private DTDHandler dh; private ContentHandler ch; private ErrorHandler eh; public DelegateHandler(EntityResolver er, DTDHandler dh, ContentHandler ch, ErrorHandler eh) { this.er = er; this.dh = dh; this.ch = ch; this.eh = eh; } public void characters(char[] ch, int start, int length) throws SAXException { if (ch != null) { this.ch.characters(ch, start, length); } } public void endDocument() throws SAXException { if (ch != null) { ch.endDocument(); } } public void endElement(String namespaceURI, String localName, String qName) throws SAXException { if (ch != null) { ch.endElement(namespaceURI, localName, qName); } } public void endPrefixMapping(String prefix) throws SAXException { if (ch != null) { ch.endPrefixMapping(prefix); } } public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException { if (ch != null) { this.ch.ignorableWhitespace(ch, start, length); } } public void processingInstruction(String target, String data) throws SAXException { if (ch != null) { ch.processingInstruction(target, data); } } public void setDocumentLocator(Locator locator) { if (ch != null) { ch.setDocumentLocator(locator); } } public void skippedEntity(String name) throws SAXException { if (ch != null) { ch.skippedEntity(name); } } public void startDocument() throws SAXException { if (ch != null) { ch.startDocument(); } } public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException { if (ch != null) { ch.startElement(namespaceURI, localName, qName, atts); } } public void startPrefixMapping(String prefix, String uri) throws SAXException { if (ch != null) { ch.startPrefixMapping(prefix, uri); } } }python-jpype-0.5.4.2/test/harness/jpype/mro/0000775000175000017500000000000011620747357020204 5ustar takakitakakipython-jpype-0.5.4.2/test/harness/jpype/mro/F.java0000666000175000017500000000143611614007722021226 0ustar takakitakaki//***************************************************************************** //Copyright 2004-2008 Steve Menard // //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 jpype.mro; interface F { }python-jpype-0.5.4.2/test/harness/jpype/mro/B.java0000666000175000017500000000145311614007722021221 0ustar takakitakaki//***************************************************************************** //Copyright 2004-2008 Steve Menard // //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 jpype.mro; interface B extends D, A { }python-jpype-0.5.4.2/test/harness/jpype/mro/D.java0000666000175000017500000000143611614007722021224 0ustar takakitakaki//***************************************************************************** //Copyright 2004-2008 Steve Menard // //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 jpype.mro; interface D { }python-jpype-0.5.4.2/test/harness/jpype/mro/E.java0000666000175000017500000000143611614007722021225 0ustar takakitakaki//***************************************************************************** //Copyright 2004-2008 Steve Menard // //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 jpype.mro; interface E { }python-jpype-0.5.4.2/test/harness/jpype/mro/C.java0000666000175000017500000000150311614007722021216 0ustar takakitakaki//***************************************************************************** //Copyright 2004-2008 Steve Menard // //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 jpype.mro; class C implements A, B { public void foo() {} }python-jpype-0.5.4.2/test/harness/jpype/mro/A.java0000666000175000017500000000147111614007722021220 0ustar takakitakaki//***************************************************************************** //Copyright 2004-2008 Steve Menard // //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 jpype.mro; interface A extends E, F { void foo(); }python-jpype-0.5.4.2/test/harness/jpype/rmi/0000775000175000017500000000000011620747357020176 5ustar takakitakakipython-jpype-0.5.4.2/test/harness/jpype/rmi/IServer.java0000666000175000017500000000157011614007722022411 0ustar takakitakaki//***************************************************************************** //Copyright 2004-2008 Steve Menard // //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 jpype.rmi; import java.rmi.*; interface IServer extends Remote { void callRemote() throws RemoteException; }python-jpype-0.5.4.2/test/harness/jpype/rmi/ServerImpl.java0000666000175000017500000000343211614007722023121 0ustar takakitakaki//***************************************************************************** //Copyright 2004-2008 Steve Menard // //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 jpype.rmi; import java.rmi.*; import java.rmi.server.*; import java.rmi.registry.*; class ServerImpl extends UnicastRemoteObject implements IServer { public ServerImpl() throws RemoteException { super(); } public void callRemote() throws RemoteException { System.out.println("Method has been called!!!!"); } public static void main(String args[]) { // Create and install a security manager // if (System.getSecurityManager() == null) { // System.setSecurityManager(new RMISecurityManager()); // } try { Registry reg = LocateRegistry.createRegistry(2004); ServerImpl obj = new ServerImpl(); // Bind this object instance to the name "HelloServer" Naming.rebind("//192.168.100.60:2004/server", obj); System.out.println("HelloServer bound in registry"); } catch (Exception e) { System.out.println("HelloImpl err: " + e.getMessage()); e.printStackTrace(); } } } python-jpype-0.5.4.2/test/harness/jpype/ref/0000775000175000017500000000000011620747357020163 5ustar takakitakakipython-jpype-0.5.4.2/test/harness/jpype/ref/TestReferenceQeue.java0000666000175000017500000000206211614007722024372 0ustar takakitakakipackage jpype.ref; public class TestReferenceQeue { public static void main(String[] args) { // final JPypeReferenceQueue queue = new JPypeReferenceQueue(); // // new Thread(new Runnable() { // // public void run() // { // queue.startManaging(); // } // // }).start(); // // Object dummy = new Object(); // long dummyAddress = 123456; // // JPypeReference ref = new JPypeReference(dummy, queue); // // queue.registerRef(ref, dummyAddress); // // System.out.println("ref is enqueued? "+ref.isEnqueued()); // // long start = System.currentTimeMillis(); // dummy = null; // while (System.currentTimeMillis()-start < 30000 && ! (ref.isEnqueued())) // { // System.gc(); // System.out.print("."); // try // { // Thread.sleep(250); // } // catch(InterruptedException ex) {} // } // // System.out.println(); // System.out.println("ref is enqueued? "+ref.isEnqueued()); // queue.stop(); } } python-jpype-0.5.4.2/test/harness/jpype/objectwrapper/0000775000175000017500000000000011620747357022256 5ustar takakitakakipython-jpype-0.5.4.2/test/harness/jpype/objectwrapper/Test1.java0000666000175000017500000000211311614007722024104 0ustar takakitakaki//***************************************************************************** // Copyright 2004-2008 Steve Menard // // 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 jpype.objectwrapper; public class Test1 { public Test1() { } public int Method1(Number n) { return 1; } public int Method1(Integer n) { return 2; } public int Method1(Object n) { return 3; } public int Method1(String n) { return 4; } }python-jpype-0.5.4.2/test/harness/jpype/proxy/0000775000175000017500000000000011620747357020570 5ustar takakitakakipython-jpype-0.5.4.2/test/harness/jpype/proxy/ITestInterface3.java0000666000175000017500000000155011614007722024356 0ustar takakitakaki//***************************************************************************** //Copyright 2004-2008 Steve Menard // //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 jpype.proxy; public interface ITestInterface3 extends ITestInterface2 { String testMethod2(); }python-jpype-0.5.4.2/test/harness/jpype/proxy/Test3.java0000666000175000017500000000351111614007722022423 0ustar takakitakaki//***************************************************************************** //Copyright 2004-2008 Steve Menard // //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 jpype.proxy; public class Test3 { public static void testProxy(ITestInterface2 itf) { System.out.println("Test Method = "+itf.testMethod()); if (itf instanceof ITestInterface3) { System.out.println("Test Method2 = "+((ITestInterface3)itf).testMethod2()); } } public void testProxyWithThread(final ITestInterface2 itf) { Thread t = new Thread(new Runnable() { public void run() { for (int i = 0; i < 10; i++) { itf.testMethod(); } } }); t.start(); try { System.out.println("Waiting for thread to finish"); t.join(); System.out.println("Thread has finished"); } catch(InterruptedException ex) { } } public void testCallbackWithParameters(ITestInterface2 itf) { byte[] vals = { 1, 2, 3, 4}; itf.write(vals , 12, 13); } }python-jpype-0.5.4.2/test/harness/jpype/proxy/ITestInterface2.java0000666000175000017500000000160311614007722024354 0ustar takakitakaki//***************************************************************************** //Copyright 2004-2008 Steve Menard // //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 jpype.proxy; public interface ITestInterface2 { int testMethod(); void write(byte[] bytes, int pos, int length); }python-jpype-0.5.4.2/test/harness/jpype/attr/0000775000175000017500000000000011620747357020361 5ustar takakitakakipython-jpype-0.5.4.2/test/harness/jpype/attr/Holder.java0000666000175000017500000000147711614007722022440 0ustar takakitakaki//***************************************************************************** //Copyright 2004-2008 Steve Menard // //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 jpype.attr; public class Holder { public String f; }python-jpype-0.5.4.2/test/harness/jpype/attr/Test2.java0000666000175000017500000000215611614007722022217 0ustar takakitakaki//***************************************************************************** // Copyright 2004-2008 Steve Menard // // 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 jpype.attr; public class Test2 extends Test1 { public Test2() { super(); } public void test2Method() { } public String toString(String foo) { return foo; } public Test2 delete(String arg1, String arg2) { System.out.println("Overloaded test 2 called"); return null; } }python-jpype-0.5.4.2/test/harness/jpype/attr/SubHolder.java0000666000175000017500000000153111614007722023101 0ustar takakitakaki//***************************************************************************** //Copyright 2004-2008 Steve Menard // //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 jpype.attr; public class SubHolder extends Holder implements java.io.Serializable { }python-jpype-0.5.4.2/test/harness/jpype/attr/ClassWithBuffer.java0000666000175000017500000000031511614007722024244 0ustar takakitakakipackage jpype.attr; import java.awt.image.BufferStrategy; public class ClassWithBuffer { public BufferStrategy bufferStrategy; public void foo() { System.out.println("foo"); } } python-jpype-0.5.4.2/test/harness/jpype/attr/Test1.java0000666000175000017500000000437111614007722022217 0ustar takakitakaki//***************************************************************************** // Copyright 2004-2008 Steve Menard // // 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 jpype.attr; public class Test1 { private String mBigString; public Test1() { StringBuffer sb = new StringBuffer(4001); for (int i = 0; i < 4000; i++) { sb.append("A"); } mBigString = sb.toString(); } public String getBigString() { return mBigString; } public String toString() { return "aaa"; } public static String[] testStaticString(String s1, String s2) { return new String[] { s1, s2}; } public static String testStaticHolder(Holder h) { return h.f; } public String[] testString(String s1, String s2) { return new String[] { s1, s2}; } public String[] testStringArray(String[] vals) { return vals; } public String stringValue = "Foo"; public char charValue = 'a'; public static Object objectValue= new Integer(234); public static void reset() { objectValue= new Integer(234); } public Object getSubClass() { return new SubHolder(); } public void callWithClass(Class c) { } public void test1Method() { } public void setByte(byte b) { } public void setShort(short b) { } public void setInt(int b) { } public String callWithSomething(Object obj) { return "Object"; } public String callWithSomething(Class obj) { return "Class"; } public Test1 delete(String arg1, String arg2) { System.out.println("Overloaded test 1 called"); return null; } }python-jpype-0.5.4.2/test/harness/jpype/numeric/0000775000175000017500000000000011620747357021051 5ustar takakitakakipython-jpype-0.5.4.2/test/harness/jpype/numeric/NumericTest.java0000666000175000017500000000161711614007722024151 0ustar takakitakaki//***************************************************************************** //Copyright 2004-2008 Steve Menard // //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 jpype.numeric; class NumericTest { public static boolean doubleIsTwiceMaxFloat(double d) { return d == (Float.MAX_VALUE*2.0); } }python-jpype-0.5.4.2/test/harness/jpype/nio/0000775000175000017500000000000011620747357020174 5ustar takakitakakipython-jpype-0.5.4.2/test/harness/jpype/nio/NioReceive.java0000666000175000017500000000233311614007722023056 0ustar takakitakaki//***************************************************************************** //Copyright 2004-2008 Steve Menard // //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 jpype.nio; import java.nio.*; class NioReceive { public static void receiveBuffer(ByteBuffer buffer) { System.out.println("Received a buffer of "+buffer.toString()); } public static void allocSomeMemory() { byte[] b = new byte[10000]; } public static void receiveBufferWithException(ByteBuffer buffer) { System.out.println("Received a buffer of "+buffer.toString()); throw new RuntimeException("hello!"); } }python-jpype-0.5.4.2/test/harness/jpype/array/0000775000175000017500000000000011620747357020525 5ustar takakitakakipython-jpype-0.5.4.2/test/harness/jpype/array/Test2.java0000666000175000017500000000026211614007722022357 0ustar takakitakakipackage jpype.array; public class Test2 { public Object[] getValue() { return new Object[0]; } public Object test(Object o) { return null; } }python-jpype-0.5.4.2/test/harness/jpype/array/TestArray.java0000666000175000017500000000255011614007722023276 0ustar takakitakaki// ***************************************************************************** //Copyright 2004-2008 Steve Menard // //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 jpype.array; public class TestArray { public TestArray() { } public int[] i = {12234,1234,234,1324,424,234,234,142,5,251,242,35,235,62,1235,46,245132,51, 2, 3, 4}; public Object[] getSubClassArray() { return new String[] { "aaa", "bbb" }; } public Object getArrayAsObject() { return new String[] { "aaa", "bbb" }; } public char[] getCharArray() { return new char[] { 'a', 'v', 'c', 'd' }; } public byte[] getByteArray() { String s = "avcd"; return s.getBytes(); } }python-jpype-0.5.4.2/test/harness/jpype/serial/0000775000175000017500000000000011620747357020666 5ustar takakitakakipython-jpype-0.5.4.2/test/harness/jpype/serial/SerializationTest.java0000666000175000017500000000140611614007722025175 0ustar takakitakaki//Copyright 2004-2008 Steve Menard // //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 jpype.serial; public class SerializationTest implements java.io.Serializable { }python-jpype-0.5.4.2/test/lists_and_maps.py0000666000175000017500000000122511614007722020155 0ustar takakitakakifrom jpype import * import time startJVM(getDefaultJVMPath()) #startJVM("c:/tools/jdk1.4.2/jre/bin/server/jvm.dll") arr = java.util.ArrayList() # no matching overloads found for this line: arr.addAll([str(x) for x in xrange(50)]) print arr hmap = java.util.HashMap() # no matching overloads found for this line: hmap.putAll({5:6, 7:8, 'hello':'there'}) print hmap #for x in xrange(5): # # this works: # hmap.put(str(x), str(x)) # # but this doesn't: # hmap.put(str(x), x) # # ## this throws: AttributeError: 'java.util.HashMap' object has no attribute 'iterator' #for x in hmap: # print x, hmap[x] python-jpype-0.5.4.2/test/buf_leak_test3.py0000666000175000017500000000272511614007722020055 0ustar takakitakakifrom jpype import * import time remote_pack="c:/tools/netbeean-remote-pack" profiler_options = [ "-agentpath:%s/lib/deployed/jdk15/windows/profilerinterface.dll=%s/lib,5140" % (remote_pack, remote_pack) ] options = [ #'-verbose:gc', '-Xmx64m', '-Djava.class.path=classes' ] #+ profiler_options cnt = 0 #setUsePythonThreadForDeamon(True) startJVM(getDefaultJVMPath(), *options) #startJVM("c:/tools/jdk1.4.2/jre/bin/server/jvm.dll", *options) class MyStr(str): def __init__ (self, val): str.__init__(self, val) global cnt cnt += 1 print 'created string', cnt def __del__(self): global cnt cnt -= 1 print 'deleted string', cnt receive = JClass("jpype.nio.NioReceive") while True: # everything runs great with this line uncommented #p = JString('5' * 1024 * 1024) # with this line uncommented, the python strings aren't GC'd p = java.lang.StringBuffer(MyStr('5' * 1024 * 1024)) # with this line uncommented, the JVM throws an OutOfMemoryError (not GC'ing the proxied java objects?), # but the python strings are being GC'd #p = java.lang.StringBuffer(JString(MyStr('5' * 1024 * 1024))) # # forget the direct buffer for now.... # buf = nio.convertToDirectBuffer(MyStr('5' * 1024 * 1024 * 5)) try : receive.receiveBufferWithException(buf) except : pass python-jpype-0.5.4.2/test/stub.py0000666000175000017500000000162611614007722016137 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # 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. # #***************************************************************************** import jpype jpype.startJVM(jpype.getDefaultJVMPath(), "-ea") s = jpype.java.lang.String t = jpype.java.awt.Color print s print t python-jpype-0.5.4.2/test/findjvm.py0000666000175000017500000000157111614007722016616 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # 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. # #***************************************************************************** import jpype, os.path jvmlib = jpype.getDefaultJVMPath() print os.path.dirname(os.path.dirname(jvmlib)) python-jpype-0.5.4.2/test/jpypetest/0000775000175000017500000000000011620747357016644 5ustar takakitakakipython-jpype-0.5.4.2/test/jpypetest/numeric.py0000666000175000017500000000351211614007722020647 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # 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. # #***************************************************************************** from jpype import JPackage, java, JFloat import unittest, common, sys def suite() : return unittest.makeSuite(NumericTestCase) class NumericTestCase(common.JPypeTestCase) : def testMathAbs(self) : assert java.lang.Math.abs(-10) == 10 def testDoubleConversion(self) : f = java.lang.Float.MAX_VALUE * 2 jpype = JPackage("jpype") assert jpype.numeric.NumericTest.doubleIsTwiceMaxFloat(f) def testDoubleIsProperlyConverted(self) : if sys.platform.find("linux") != -1 : # double comparison on linux is broken ... Nan == 0.0!!! print java.lang.Double.NaN, " != ", 0.0, " -> ", bool(java.lang.Double.NaN != 0.0), " == -> ", bool(java.lang.Double.NaN == 0.0) else : assert java.lang.Double.NEGATIVE_INFINITY != 0.0 assert java.lang.Double.MAX_VALUE != 0.0 assert java.lang.Double.NaN != 0.0 assert java.lang.Double.POSITIVE_INFINITY != 0.0 def testNegativeJFloatWrapper(self): f = JFloat(-1) python-jpype-0.5.4.2/test/jpypetest/mro.py0000666000175000017500000000175511614007722020011 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # 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. # #***************************************************************************** from jpype import JPackage, java import unittest, common, sys def suite() : return unittest.makeSuite(MroTestCase) class MroTestCase(common.JPypeTestCase) : def testMro(self) : C = JPackage('jpype.mro').Cpython-jpype-0.5.4.2/test/jpypetest/array.py0000666000175000017500000000706111614007722020326 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # 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. # #***************************************************************************** import jpype from jpype import JPackage, JArray, JByte, java import unittest, common VALUES = (12234,1234,234,1324,424,234,234,142,5,251,242,35,235,62,1235,46,245132,51, 2, 3, 4) def suite() : return unittest.makeSuite(ArrayTestCase) class ArrayTestCase(common.JPypeTestCase) : def __arrayEquals(self, a1, a2) : assert len(a1) == len(a2) for i in range(len(a1)) : assert a1[i] == a2[i] def testReadArray(self) : t = JPackage("jpype").array.TestArray() assert not isinstance(t, JPackage) self.__arrayEquals(VALUES, t.i) assert t.i[0] == VALUES[0] self.__arrayEquals(VALUES[1:-2], t.i[1:-2]) def testStangeBehavior(self) : ''' Test for stange crash reported in bug #1089302''' Test2 = jpype.JPackage('jpype.array').Test2 test = Test2() test.test(test.getValue()) def testWriteArray(self) : t = JPackage("jpype").array.TestArray() assert not isinstance(t, JPackage) t.i[0] = 32 assert t.i[0] == 32 t.i[1:3] = (33, 34) assert t.i[1] == 33 assert t.i[2] == 34 self.__arrayEquals(t.i[:5], (32, 33, 34 ,1324, 424) ) def testObjectArraySimple(self) : a = JArray(java.lang.String, 1)(2) a[1] = "Foo" assert "Foo" == a[1] def testByteArraySimple(self) : a = JArray(JByte)(2) a[1] = 2 assert a[1] == 2 def testIterateArray(self): t = JPackage("jpype").array.TestArray() assert not isinstance(t, JPackage) for i in t.i : assert i != 0 def testGetSubclass(self) : t = JPackage("jpype").array.TestArray() v = t.getSubClassArray() assert isinstance(v[0], unicode) def testGetArrayAsObject(self) : t = JPackage("jpype").array.TestArray() v = t.getArrayAsObject() def testCharArrayAsString(self) : t = JPackage("jpype").array.TestArray() v = t.charArray assert str(v) == 'avcd' assert unicode(v) == u'avcd' def testByteArrayAsString(self) : t = JPackage("jpype").array.TestArray() v = t.byteArray assert str(v) == 'avcd' def testByteArrayIntoVector(self): ba = jpype.JArray(jpype.JByte)('123') v = jpype.java.util.Vector(1) v.add(ba) assert len(v) == 1 assert v[0] is not None if __name__ == '__main__' : import os.path root = os.path.abspath(os.path.dirname(__file__)) common.CLASSPATH= "%s/../../build/test/java" % root runner = unittest.TextTestRunner() runner.run(suite()) python-jpype-0.5.4.2/test/jpypetest/proxy.py0000666000175000017500000000522111614007722020365 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # 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. # #***************************************************************************** from jpype import * import unittest, common def suite() : return unittest.makeSuite(ProxyTestCase) def _testMethod() : return 32 def _testMethod2() : return "Fooo!" class C : def testMethod(self) : return 42 def testMethod2(self) : return "Bar" def write(self, bytes, start, length) : print 'aaaaa' print bytes.__class__, bytes[0] print start print length class ProxyTestCase(common.JPypeTestCase) : def testProxyWithDict(self) : d = { 'testMethod' : _testMethod, 'testMethod2' : _testMethod2, } itf2 = JPackage("jpype.proxy").ITestInterface3 Test3 = JPackage("jpype.proxy").Test3 proxy = JProxy(itf2, dict=d) Test3.testProxy(proxy) def testProxyWithInst(self) : itf2 = JPackage("jpype.proxy").ITestInterface3 Test3 = JPackage("jpype.proxy").Test3 c = C() proxy = JProxy(itf2, inst=c) Test3.testProxy(proxy) def testProxyWithThread(self) : itf2 = JPackage("jpype.proxy").ITestInterface3 Test3 = JPackage("jpype.proxy").Test3 c = C() proxy = JProxy(itf2, inst=c) t3 = Test3() t3.testProxyWithThread(proxy) def testProxyWithArguments(self) : itf2 = JPackage("jpype.proxy").ITestInterface2 Test3 = JPackage("jpype.proxy").Test3 c = C() proxy = JProxy(itf2, inst=c) Test3().testCallbackWithParameters(proxy) def testProxyWithMultipleInterface(self) : itf2 = JPackage("jpype.proxy").ITestInterface2 itf3 = JPackage("jpype.proxy").ITestInterface3 Test3 = JPackage("jpype.proxy").Test3 c = C() proxy = JProxy([itf2,itf3], inst=c) Test3().testCallbackWithParameters(proxy) python-jpype-0.5.4.2/test/jpypetest/__init__.py0000666000175000017500000000156011614007722020745 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # 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. # #***************************************************************************** __all__ = ['common', 'array', 'attr', 'objectwrapper', 'proxy', 'numeric', 'exc', 'serial', 'mro']python-jpype-0.5.4.2/test/jpypetest/attr.py0000666000175000017500000001211511614007722020156 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # 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. # #***************************************************************************** import jpype from jpype import JString, java, JArray import unittest import common import time def suite() : return unittest.makeSuite(AttributeTestCase) class AttributeTestCase(common.JPypeTestCase) : def setUp(self) : common.JPypeTestCase.setUp(self) self.__jp = self.jpype.attr def testWithBufferStrategy(self): j = jpype.JPackage("jpype").attr.ClassWithBuffer print j def testCallOverloadedMethodWithCovariance(self): # This is a JDk5-specific problem. h = jpype.java.lang.StringBuffer() h.delete(0, 0) def testCallStaticString(self) : h = self.__jp.Test1() v = h.testString(JString("abcd"), JString("abcde")) assert v[0] == 'abcd' assert v[1] == 'abcde' def testCallStaticUnicodeString(self) : h = self.__jp.Test1() v = h.testString(JString(u"abcd"), JString(u"abcde")) assert v[0] == 'abcd' assert v[1] == 'abcde' def testCallString(self) : v = self.__jp.Test1.testStaticString("a", "b") assert v[0] == 'a' assert v[1] == 'b' def testCallUnicodeString(self) : v = self.__jp.Test1.testStaticString(u"a", u"b") assert v[0] == 'a' assert v[1] == 'b' def testCallStringWithNone(self) : v = self.__jp.Test1.testStaticString("a", None) assert v[0] == 'a' assert v[1] == None def testWithHolder(self) : print 'testWithHolder' holder = self.__jp.Holder() holder.f = "ffff" assert holder.f == "ffff" self.__jp.Test1.testStaticHolder(holder) def testWithSubHolder(self) : h2 = self.__jp.SubHolder() h2.f = "subholder" self.__jp.Test1.testStaticHolder(h2) def testCallWithArray(self) : h2 = self.__jp.Test1() StringArray = JArray(JString) v = StringArray(["Foo", "bar"]) t = self.__jp.Test1() t.testStringArray(v) def testGetStaticValue(self) : assert str(self.__jp.Test1.objectValue) == "234" def testGetStaticByInstance(self) : h = self.__jp.Test1() assert str(h.objectValue) == "234" def testGetNonStatic(self) : h = self.__jp.Test1() assert h.stringValue == "Foo" def testSetStaticValue(self) : self.__jp.Test1.objectValue = java.lang.Integer(43) assert str(self.__jp.Test1.objectValue) == "43" self.__jp.Test1.reset() def testSetNonStaticValue(self) : h = self.__jp.Test1() h.stringValue="bar" assert h.stringValue == "bar" def testReturnSubClass(self) : h = self.__jp.Test1() v = h.getSubClass() assert isinstance(v, self.__jp.SubHolder) def testCallWithClass(self) : h = self.__jp.Test1() h.callWithClass(java.lang.Comparable) def testCallSuperclassMethod(self) : h = self.__jp.Test2() h.test2Method() h.test1Method() def testCallWithLong(self) : h = self.__jp.Test1() l = long(123) h.setByte(l) h.setShort(l) h.setInt(l) def testCharAttribute(self) : h = self.__jp.Test1() h.charValue = u'b' print h.charValue print repr(h.charValue) assert h.charValue == u'b' def testGetPrimitiveType(self) : Integer = jpype.JClass("java.lang.Integer") intType = Integer.TYPE def testDifferentiateClassAndObject(self) : h = self.__jp.Test1() assert h.callWithSomething(self.__jp.Test1) == u"Class" assert h.callWithSomething(jpype.JObject(self.__jp.Test1, jpype.java.lang.Object)) == u"Object" def testToString(self): h = self.__jp.Test1() assert str(h) == 'aaa' def testSuperToString(self): h = self.__jp.Test2() print h assert str(h) == 'aaa' del h # def testStringToConversion(self): # try : # jpype.ConversionConfig.string = False # for i in range(1) : # h = self.__jp.Test1() # # start = time.time(); # for j in range(10): # ts = h.getBigString() # stop = time.time() # print ts.__class__, (stop-start), 'ms' # # # for comparison ... convert a string to JStrng and back # s = "".join([" "]*1024*1024*5) # start = time.time() # js = JString(s) # stop = time.time() # print "converted to JString in", (stop-start), 'ms', len(s) # # start = time.time() # cs = str(JString(s)) # print cs # print "converted to String in", (stop-start), 'ms', len(cs), cs # finally : # jpype.ConversionConfig.string = True python-jpype-0.5.4.2/test/jpypetest/serial.py0000666000175000017500000000321611614007722020465 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # 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. # #***************************************************************************** from jpype import JException, java, JavaException, JProxy, JClass import unittest, common import traceback def suite() : return unittest.makeSuite(SerializationTestCase) class SerializationTestCase(common.JPypeTestCase) : def testSerialize(self) : o = JClass("jpype.serial.SerializationTest")() fos = java.io.FileOutputStream("testSerial.dat") oos = java.io.ObjectOutputStream(fos) oos.writeObject(o) oos.flush() oos.close() fos.close() # The following cannto work because JPype has no way to simulate the "caller's ClassLoader" # def testDeSerialize(self) : # # fis = java.io.FileInputStream("testSerial.dat") # ois = java.io.ObjectInputStream(fis) # # o = ois.readObject() # ois.close() # fis.close() python-jpype-0.5.4.2/test/jpypetest/exc.py0000666000175000017500000000463611614007722017774 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # 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. # #***************************************************************************** from jpype import JException, java, JavaException, JProxy, JPackage import unittest, common import traceback def throwIOException() : raise java.io.IOException.PYEXC("Test throw") def throwByJavaException() : JPackage('jpype').exc.ExceptionTest.throwIOException() def suite() : return unittest.makeSuite(ExceptionTestCase) class ExceptionTestCase(common.JPypeTestCase) : def testExceptionThrown(self) : try : self.jpype.exc.ExceptionTest.throwRuntime() assert False except JavaException, ex : print 'Caught a Java exception ...' if ex.javaClass() is java.lang.RuntimeException : print "Caught the exception", ex.message() print ex.stacktrace() else: assert False except Exception, ex: print ex.__class__, isinstance(ex, JavaException) print ex.__class__.__bases__[0].__bases__[0].__bases__ print JavaException assert False print 'if here, everything is fine' def testExceptionByJavaClass(self) : try : self.jpype.exc.ExceptionTest.throwRuntime() assert False except JException(java.lang.RuntimeException), ex : print "Caught the exception", ex.message(), "->", ex.javaClass() print ex.stacktrace() except Exception, ex: print ex assert False # def testThrowException(self) : # d = {"throwIOException" : throwIOException, } # p = JProxy(self.jpype.exc.ExceptionThrower, dict=d) # # assert self.jpype.exc.ExceptionTest.delegateThrow(p) def testThrowException3(self) : d = {"throwIOException" : throwByJavaException, } p = JProxy(self.jpype.exc.ExceptionThrower, dict=d) assert self.jpype.exc.ExceptionTest.delegateThrow(p) python-jpype-0.5.4.2/test/jpypetest/objectwrapper.py0000666000175000017500000000247311614007722022061 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # 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. # #***************************************************************************** from jpype import * import unittest, common def suite() : return unittest.makeSuite(ObjectWrapperTestCase) class ObjectWrapperTestCase(common.JPypeTestCase) : def testCallOverloads(self) : # build the harness h = JPackage("jpype.objectwrapper").Test1() o = java.lang.Integer(1) assert h.Method1(JObject(o, java.lang.Number)) == 1 assert h.Method1(o) == 2 assert h.Method1(JObject(java.lang.Integer(1), java.lang.Object)) == 3 assert h.Method1(JString("")) == 4 python-jpype-0.5.4.2/test/jpypetest/common.py0000666000175000017500000000176711614007722020507 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # 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. # #***************************************************************************** from jpype import * import unittest CLASSPATH = None class JPypeTestCase(unittest.TestCase) : def setUp(self) : self.jpype = JPackage('jpype') def tearDown(self) : pass python-jpype-0.5.4.2/test/convtest.py0000666000175000017500000000653011614007722017026 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # 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. # #***************************************************************************** import jpype import array import time import os def generateStringData(aSize): return ''.join(['a']*aSize) DATA_SIZE = 5*1024*1024 # 5 MB def runBaseline(data): print 'Running baseline test : converting a python string->array.array->JArray(JByte). size = ', len(data)/1024.0, 'kb' print ' Start time (no optimize) on my machine is 3.56 seconds.' start = time.time() #darr = array.array('b', DATA) arr_cls = jpype.JArray(jpype.JByte) java_arr = arr_cls(DATA) end = time.time() print ' test run in', (end-start), 'seconds.' def runStringToByteBuffer(data): print 'Running String conversion to byte buffer. size = ', len(data)/1024.0, 'kb' start = time.time() bb = jpype.nio.convertToDirectBuffer(data) end = time.time() print ' test run in', (end-start), 'seconds.' jpype.JPackage("jpype").nio.NioReceive.receiveBuffer(bb) def runStringToByteArray(data): print 'Running String conversion to byte array. size = ', len(data)/1024.0, 'kb' start = time.time() arr_cls = jpype.JArray(jpype.JByte) java_arr = arr_cls(data) end = time.time() print ' test run in', (end-start), 'seconds.' root = os.path.abspath(os.path.dirname(__file__)) jpype.startJVM(jpype.getDefaultJVMPath(), "-ea", "-Xmx5M", "-verbose:gc", "-Djava.class.path=./classes%s%s%sclasses" % (os.pathsep, root, os.sep)) DELETED = False class MyStr(str): def __del__(self): global DELETED print 'string got deleted' DELETED = True def testStringMemory(): print 'with keeping the data' data = MyStr('5' * 1024) print data buf = jpype.nio.convertToDirectBuffer(data) # print buf.get() # print buf.get() # print buf.get() print 'now deleting the data' del data # print buf.get() # print buf.get() # print buf.get() # print buf.get() print 'now deleting the buffer itself' del buf print 'now waiting for the string to get deleted' while not DELETED: time.sleep(1) print '.', jpype.JPackage("jpype").nio.NioReceive.allocSomeMemory() testStringMemory() #for i in range(1,5) : # DATA = generateStringData(DATA_SIZE*i) # runBaseline(DATA) # runStringToByteBuffer(DATA) # runStringToByteArray(DATA) # expressly delete data to test the GC ... #del DATA #for i in range(3) : # print 'GC', i # jpype.JClass("java.lang.System").gc(); # time.sleep(15) jpype.shutdownJVM()python-jpype-0.5.4.2/test/testsuite.py0000666000175000017500000000302711614007722017210 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # 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. # #***************************************************************************** import unittest, os, sys, new from jpypetest import * import jpype import os.path def suite() : return unittest.TestSuite( ( numeric.suite(), attr.suite(), array.suite(), objectwrapper.suite(), proxy.suite(), exc.suite(), serial.suite(), mro.suite(), )) import jpype def runTest() : root = os.path.abspath(os.path.dirname(__file__)) print "Running testsuite using JVM", jpype.getDefaultJVMPath() jpype.startJVM(jpype.getDefaultJVMPath(), "-ea", "-Xmx256M", "-Xms64M", "-Djava.class.path=./classes%s%s%sclasses" % (os.pathsep, root, os.sep)) runner = unittest.TextTestRunner() runner.run(suite()) s = slice(2, 4) print s, dir(s) jpype.shutdownJVM() if __name__ == '__main__' : runTest() python-jpype-0.5.4.2/test/buf_leak_test.py0000666000175000017500000000116111614007722017763 0ustar takakitakakifrom jpype import * import time remote_pack="c:/tools/netbeean-remote-pack" profiler_options = [ "-agentpath:%s/lib/deployed/jdk15/windows/profilerinterface.dll=%s/lib,5140" % (remote_pack, remote_pack) ] options = [ '-verbose:gc', '-Xmx16m', ] #+ profiler_options #startJVM(getDefaultJVMPath(), *options) startJVM("c:/tools/jdk1.4.2/jre/bin/server/jvm.dll", *options) class MyStr(str): def __del__(self): print 'string got deleted' while True: buf = java.lang.String('5' * 1024 * 1024 * 5) buf = nio.convertToDirectBuffer(MyStr('5' * 1024 * 1024)) # time.sleep(1) python-jpype-0.5.4.2/test/test_awt.py0000666000175000017500000000044411614007722017011 0ustar takakitakakifrom jpype import * import time def run(): print 'Thread started' try: print repr(java.awt.Frame) javax.swing.JFrame("Test Frame").setVisible(True) shutdownGuiEnvironment() except JException, ex : print ex startJVM(getDefaultJVMPath()) setupGuiEnvironment(run) python-jpype-0.5.4.2/test/java_sax.py0000666000175000017500000000423311614007722016753 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # 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. # #***************************************************************************** import time from jpype import * import os.path root = os.path.abspath(os.path.dirname(__file__)) startJVM(getDefaultJVMPath(), "-ea", "-Djava.class.path=%s/classes" % root) # XML test Element = JPackage("org").w3c.dom.Element class ContentHandler(object) : def characters(self, ch, start, length) : pass def endDocument(self) : pass def endElement(self, namespaceURI, localName, qName) : pass def endPrefixMapping(self, prefix) : pass def ignorableWhitespace(self, ch, start, length) : pass def processingInstruction(self, target, data) : pass def setDocumentLocator(self, locator) : pass def skippedEntity(self, name) : pass def startDocument(self, ) : pass def startElement(self, namespaceURI, localName, qName, atts) : pass def startPrefixMapping(self, prefix, uri) : pass t = time.time() count = 30 for i in range(count) : DelegateHandler = JPackage("jpype.xml").DelegateHandler dh = DelegateHandler(None, None, JProxy("org.xml.sax.ContentHandler", inst=ContentHandler()), None) build = javax.xml.parsers.SAXParserFactory.newInstance().newSAXParser() build.parse("d:/darkwolf/jpype/test/sample/big.xml", dh) t2 = time.time() print count, "iterations in", t2-t, "seconds" shutdownJVM() python-jpype-0.5.4.2/test/python_dom.py0000666000175000017500000000275511614007722017346 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # 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. # #***************************************************************************** import time from xml.dom import minidom def output(el, prefix="") : if el.nodeType != el.ELEMENT_NODE : return #print prefix, "<", el.tagName, atts = el.attributes for i in range(atts.length) : a = atts.item(i); #print a.nodeName, '="%s"' % a.nodeValue, #print '>' nl = el.childNodes for i in range(nl.length) : output(nl.item(i), prefix+" ") #print prefix, "" t = time.time() count = 30 for i in range(count) : doc = minidom.parse("d:/darkwolf/jpype/test/sample/big.xml") el = doc.documentElement output(el) t2 = time.time() print count, "iterations in", t2-t, "seconds" python-jpype-0.5.4.2/src/0000775000175000017500000000000011620747357014425 5ustar takakitakakipython-jpype-0.5.4.2/src/native/0000775000175000017500000000000011620747357015713 5ustar takakitakakipython-jpype-0.5.4.2/src/native/python/0000775000175000017500000000000011620747357017234 5ustar takakitakakipython-jpype-0.5.4.2/src/native/python/py_method.cpp0000666000175000017500000002510411614007722021720 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve M�nard 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. *****************************************************************************/ #include static PyMethodDef methodMethods[] = { {"getName", &PyJPMethod::getName, METH_VARARGS, ""}, {"isBeanAccessor", &PyJPMethod::isBeanAccessor, METH_VARARGS, ""}, {"isBeanMutator", &PyJPMethod::isBeanMutator, METH_VARARGS, ""}, {"matchReport", &PyJPMethod::matchReport, METH_VARARGS, ""}, {NULL}, }; static PyTypeObject methodClassType = { PyObject_HEAD_INIT(&PyType_Type) 0, /*ob_size*/ "JavaMethod", /*tp_name*/ sizeof(PyJPMethod), /*tp_basicsize*/ 0, /*tp_itemsize*/ PyJPMethod::__dealloc__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ 0, /*tp_compare*/ 0, /*tp_repr*/ 0, /*tp_as_number*/ 0, /*tp_as_sequence*/ 0, /*tp_as_mapping*/ 0, /*tp_hash */ PyJPMethod::__call__, /*tp_call*/ PyJPMethod::__str__, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT, /*tp_flags*/ "Java Method", /*tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ 0, /* tp_iter */ 0, /* tp_iternext */ methodMethods, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ 0, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ 0, /* tp_init */ 0, /* tp_alloc */ PyType_GenericNew /* tp_new */ }; // Static methods void PyJPMethod::initType(PyObject* module) { PyType_Ready(&methodClassType); PyModule_AddObject(module, "_JavaMethod", (PyObject*)&methodClassType); } PyJPMethod* PyJPMethod::alloc(JPMethod* m) { PyJPMethod* res = PyObject_New(PyJPMethod, &methodClassType); res->m_Method = m; return res; } PyObject* PyJPMethod::__call__(PyObject* o, PyObject* args, PyObject* kwargs) { TRACE_IN("PyJPMethod::__call__"); try { PyJPMethod* self = (PyJPMethod*)o; TRACE1(self->m_Method->getName()); JPCleaner cleaner; //JPyHelper::dumpSequenceRefs(args, "start"); vector vargs; Py_ssize_t len = JPyObject::length(args); for (Py_ssize_t i = 0; i < len; i++) { PyObject* obj = JPySequence::getItem(args, i); // return a new ref HostRef* ref = new HostRef((void*)obj); cleaner.add(ref); vargs.push_back(ref); Py_DECREF(obj); // delete the new ref returned by getItem } //JPyHelper::dumpSequenceRefs(args, "middle"); HostRef* res = self->m_Method->invoke(vargs); //JPyHelper::dumpSequenceRefs(args, "end"); return detachRef(res); } PY_STANDARD_CATCH return NULL; TRACE_OUT; } void PyJPMethod::__dealloc__(PyObject* o) { PyJPMethod* self = (PyJPMethod*)o; self->ob_type->tp_free(o); } PyObject* PyJPMethod::__str__(PyObject* o) { PyJPMethod* self = (PyJPMethod*)o; stringstream sout; sout << "m_Method->getClassName() << "." << self->m_Method->getName() << ">"; return JPyString::fromString(sout.str().c_str()); } PyObject* PyJPMethod::isBeanAccessor(PyObject* o, PyObject* arg) { try { PyJPMethod* self = (PyJPMethod*)o; bool res = self->m_Method->isBeanAccessor(); if (res) { return JPyBoolean::getTrue(); } return JPyBoolean::getFalse(); } PY_STANDARD_CATCH return NULL; } PyObject* PyJPMethod::isBeanMutator(PyObject* o, PyObject* arg) { try { PyJPMethod* self = (PyJPMethod*)o; bool res = self->m_Method->isBeanMutator(); if (res) { return JPyBoolean::getTrue(); } return JPyBoolean::getFalse(); } PY_STANDARD_CATCH return NULL; } PyObject* PyJPMethod::getName(PyObject* o, PyObject* arg) { try { PyJPMethod* self = (PyJPMethod*)o; string name = self->m_Method->getName(); PyObject* res = JPyString::fromString(name.c_str()); return res; } PY_STANDARD_CATCH return NULL; } PyObject* PyJPMethod::matchReport(PyObject* o, PyObject* args) { try { PyJPMethod* self = (PyJPMethod*)o; JPCleaner cleaner; vector vargs; Py_ssize_t len = JPyObject::length(args); for (Py_ssize_t i = 0; i < len; i++) { PyObject* obj = JPySequence::getItem(args, i); HostRef* ref = new HostRef((void*)obj); cleaner.add(ref); vargs.push_back(ref); Py_DECREF(obj); } string report = self->m_Method->matchReport(vargs); PyObject* res = JPyString::fromString(report.c_str()); return res; } PY_STANDARD_CATCH return NULL; } static PyMethodDef boundMethodMethods[] = { {"matchReport", &PyJPBoundMethod::matchReport, METH_VARARGS, ""}, {NULL}, }; static PyTypeObject boundMethodClassType = { PyObject_HEAD_INIT(&PyType_Type) 0, /*ob_size*/ "JavaBoundMethod", /*tp_name*/ sizeof(PyJPBoundMethod), /*tp_basicsize*/ 0, /*tp_itemsize*/ PyJPBoundMethod::__dealloc__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ 0, /*tp_compare*/ 0, /*tp_repr*/ 0, /*tp_as_number*/ 0, /*tp_as_sequence*/ 0, /*tp_as_mapping*/ 0, /*tp_hash */ PyJPBoundMethod::__call__, /*tp_call*/ PyJPBoundMethod::__str__, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT, /*tp_flags*/ "Java Bound Method", /*tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ 0, /* tp_iter */ 0, /* tp_iternext */ boundMethodMethods, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ 0, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ PyJPBoundMethod::__init__, /* tp_init */ 0, /* tp_alloc */ PyType_GenericNew /* tp_new */ }; // Static methods void PyJPBoundMethod::initType(PyObject* module) { PyType_Ready(&boundMethodClassType); PyModule_AddObject(module, "_JavaBoundMethod", (PyObject*)&boundMethodClassType); } int PyJPBoundMethod::__init__(PyObject* o, PyObject* args, PyObject* kwargs) { try { PyJPBoundMethod* self = (PyJPBoundMethod*)o; PyObject* javaMethod; PyObject* inst; JPyArg::parseTuple(args, "OO", &javaMethod, &inst); Py_INCREF(inst); Py_INCREF(javaMethod); self->m_Instance = inst; self->m_Method = (PyJPMethod*)javaMethod; return 0; } PY_STANDARD_CATCH return 1; } PyObject* PyJPBoundMethod::__call__(PyObject* o, PyObject* args, PyObject* kwargs) { TRACE_IN("PyJPBoundMethod::__call__"); try { PyObject* result=NULL; { PyJPBoundMethod* self = (PyJPBoundMethod*)o; JPCleaner cleaner; TRACE1(self->m_Method->m_Method->getName()); vector vargs; Py_ssize_t len = JPyObject::length(args); HostRef* ref = new HostRef((void*)self->m_Instance); cleaner.add(ref); vargs.push_back(ref); for (Py_ssize_t i = 0; i < len; i++) { PyObject* obj = JPySequence::getItem(args, i); // returns a new ref ref = new HostRef((void*)obj); cleaner.add(ref); vargs.push_back(ref); Py_DECREF(obj); // remove ref returned by getItem } HostRef* res = self->m_Method->m_Method->invoke(vargs); TRACE2("Call finished, result = ", res); result = detachRef(res); TRACE1("Cleaning up"); } return result; } PY_STANDARD_CATCH return NULL; TRACE_OUT; } void PyJPBoundMethod::__dealloc__(PyObject* o) { TRACE_IN("PyJPBoundMethod::__dealloc__"); PyJPBoundMethod* self = (PyJPBoundMethod*)o; Py_DECREF(self->m_Instance); Py_DECREF(self->m_Method); self->ob_type->tp_free(o); TRACE1("Method freed"); TRACE_OUT; } PyObject* PyJPBoundMethod::__str__(PyObject* o) { PyJPBoundMethod* self = (PyJPBoundMethod*)o; stringstream sout; sout << "m_Method->m_Method->getClassName() << "." << self->m_Method->m_Method->getName() << ">"; return JPyString::fromString(sout.str().c_str()); } PyObject* PyJPBoundMethod::matchReport(PyObject* o, PyObject* args) { try { PyJPBoundMethod* self = (PyJPBoundMethod*)o; cout << "Match report for " << self->m_Method->m_Method->getName() << endl; vector vargs; Py_ssize_t len = JPyObject::length(args); for (Py_ssize_t i = 0; i < len; i++) { PyObject* obj = JPySequence::getItem(args, i); vargs.push_back(new HostRef((void*)obj)); Py_DECREF(obj); } string report = self->m_Method->m_Method->matchReport(vargs); PyObject* res = JPyString::fromString(report.c_str()); return res; } PY_STANDARD_CATCH return NULL; } python-jpype-0.5.4.2/src/native/python/py_field.cpp0000666000175000017500000001371611614007722021531 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard 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. *****************************************************************************/ #include static PyMethodDef fieldMethods[] = { {"getName", &PyJPField::getName, METH_VARARGS, ""}, {"isFinal", &PyJPField::isFinal, METH_VARARGS, ""}, {"isStatic", &PyJPField::isStatic, METH_VARARGS, ""}, {"getStaticAttribute", &PyJPField::getStaticAttribute, METH_VARARGS, ""}, {"setStaticAttribute", &PyJPField::setStaticAttribute, METH_VARARGS, ""}, {"getInstanceAttribute", &PyJPField::getInstanceAttribute, METH_VARARGS, ""}, {"setInstanceAttribute", &PyJPField::setInstanceAttribute, METH_VARARGS, ""}, {NULL}, }; static PyTypeObject fieldClassType = { PyObject_HEAD_INIT(&PyType_Type) 0, /*ob_size*/ "JavaField", /*tp_name*/ sizeof(PyJPField), /*tp_basicsize*/ 0, /*tp_itemsize*/ PyJPField::__dealloc__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ 0, /*tp_compare*/ 0, /*tp_repr*/ 0, /*tp_as_number*/ 0, /*tp_as_sequence*/ 0, /*tp_as_mapping*/ 0, /*tp_hash */ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT, /*tp_flags*/ "Java Field", /*tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ 0, /* tp_iter */ 0, /* tp_iternext */ fieldMethods, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ 0, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ 0, /* tp_init */ 0, /* tp_alloc */ PyType_GenericNew /* tp_new */ }; // Static methods void PyJPField::initType(PyObject* module) { PyType_Ready(&fieldClassType); PyModule_AddObject(module, "_JavaField", (PyObject*)&fieldClassType); } PyJPField* PyJPField::alloc(JPField* m) { PyJPField* res = PyObject_New(PyJPField, &fieldClassType); res->m_Field = m; return res; } void PyJPField::__dealloc__(PyObject* o) { PyJPField* self = (PyJPField*)o; self->ob_type->tp_free(o); } PyObject* PyJPField::getName(PyObject* o, PyObject* arg) { try { PyJPField* self = (PyJPField*)o; string name = self->m_Field->getName(); PyObject* res = JPyString::fromString(name.c_str()); return res; } PY_STANDARD_CATCH return NULL; } PyObject* PyJPField::getStaticAttribute(PyObject* o, PyObject* arg) { try { PyJPField* self = (PyJPField*)o; HostRef* res = self->m_Field->getStaticAttribute(); PyObject* result = detachRef(res); return result; } PY_STANDARD_CATCH return NULL; } PyObject* PyJPField::setStaticAttribute(PyObject* o, PyObject* arg) { try { PyJPField* self = (PyJPField*)o; PyObject* value; JPyArg::parseTuple(arg, "O", &value); HostRef v(value); self->m_Field->setStaticAttribute(&v); Py_INCREF(Py_None); return Py_None; } PY_STANDARD_CATCH return NULL; } PyObject* PyJPField::setInstanceAttribute(PyObject* o, PyObject* arg) { JPCleaner cleaner; try { PyJPField* self = (PyJPField*)o; PyObject* jo; PyObject* value; JPyArg::parseTuple(arg, "O!O", &PyCObject_Type, &jo, &value); JPObject* obj = (JPObject*)JPyCObject::asVoidPtr(jo); HostRef* ref = new HostRef(value); cleaner.add(ref); jobject jobj = obj->getObject(); cleaner.addLocal(jobj); self->m_Field->setAttribute(jobj, ref); Py_INCREF(Py_None); return Py_None; } PY_STANDARD_CATCH return NULL; } PyObject* PyJPField::getInstanceAttribute(PyObject* o, PyObject* arg) { TRACE_IN("getInstanceAttribute"); JPCleaner cleaner; try { PyJPField* self = (PyJPField*)o; PyObject* jo; JPyArg::parseTuple(arg, "O!", &PyCObject_Type, &jo); JPObject* obj = (JPObject*)JPyCObject::asVoidPtr(jo); jobject jobj = obj->getObject(); cleaner.addLocal(jobj); HostRef* res = self->m_Field->getAttribute(jobj); return detachRef(res); } PY_STANDARD_CATCH return NULL; TRACE_OUT; } PyObject* PyJPField::isStatic(PyObject* o, PyObject* arg) { JPCleaner cleaner; try { PyJPField* self = (PyJPField*)o; if (self->m_Field->isStatic()) { return JPyBoolean::getTrue(); } return JPyBoolean::getFalse(); } PY_STANDARD_CATCH return NULL; } PyObject* PyJPField::isFinal(PyObject* o, PyObject* arg) { JPCleaner cleaner; try { PyJPField* self = (PyJPField*)o; if (self->m_Field->isFinal()) { return JPyBoolean::getTrue(); } return JPyBoolean::getFalse(); } PY_STANDARD_CATCH return NULL; } python-jpype-0.5.4.2/src/native/python/py_hostenv.cpp0000666000175000017500000003755711614007722022145 0ustar takakitakaki/***************************************************************************** Copyright 2004-2008 Steve Menard 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. *****************************************************************************/ #include #define UNWRAP(ref) ((PyObject*)ref->data()) #define GETDESC(ref) string((char*)JPyCObject::getDesc(UNWRAP(ref))) #define WRAP(ref, t) new HostRef( JPyCObject::fromVoidAndDesc(ref, (void*)t, NULL) ) #define IS_REF(ref, t) JPyCObject::check((PyObject*)ref) && GETDESC(ref) == t void* PythonHostEnvironment::acquireRef(void* d) { Py_XINCREF((PyObject*)d); return d; } void PythonHostEnvironment::releaseRef(void* d) { Py_XDECREF((PyObject*)d); } bool PythonHostEnvironment::isRefNull(void* d) { return d == NULL; } string PythonHostEnvironment::describeRef(HostRef* ref) { stringstream out; return out.str(); } void* PythonHostEnvironment::gotoExternal() { PyThreadState *_save; _save = PyEval_SaveThread(); return (void*)_save; } void PythonHostEnvironment::returnExternal(void* state) { PyThreadState *_save = (PyThreadState *)state; PyEval_RestoreThread(_save); } void PythonHostEnvironment::setRuntimeException(const char* msg) { JPyErr::setString(PyExc_RuntimeError, msg); } void PythonHostEnvironment::setAttributeError(const char* msg) { JPyErr::setString(PyExc_AttributeError, msg); } void PythonHostEnvironment::setTypeError(const char* msg) { JPyErr::setString(PyExc_TypeError, msg); } void PythonHostEnvironment::raise(const char* msg) { RAISE(JPypeException, msg); } HostRef* PythonHostEnvironment::getNone() { return new HostRef(Py_None); } bool PythonHostEnvironment::isNone(HostRef* ref) { return UNWRAP(ref) == Py_None; } bool PythonHostEnvironment::isBoolean(HostRef* ref) { return JPyBoolean::isTrue(UNWRAP(ref)) || JPyBoolean::isFalse(UNWRAP(ref)); } jboolean PythonHostEnvironment::booleanAsBoolean(HostRef* ref) { if (JPyBoolean::isTrue(UNWRAP(ref))) { return true; } return false; } HostRef* PythonHostEnvironment::getTrue() { return new HostRef(JPyBoolean::getTrue(), false); } HostRef* PythonHostEnvironment::getFalse() { return new HostRef(JPyBoolean::getFalse(), false); } bool PythonHostEnvironment::isSequence(HostRef* ref) { return JPySequence::check(UNWRAP(ref)) && ! JPyString::check(UNWRAP(ref)); } HostRef* PythonHostEnvironment::newMutableSequence(jsize sz) { return new HostRef(JPySequence::newList(sz), false); } HostRef* PythonHostEnvironment::newImmutableSequence(jsize sz) { return new HostRef(JPySequence::newTuple(sz), false); } jsize PythonHostEnvironment::getSequenceLength(HostRef* ref) { return (jsize)JPyObject::length(UNWRAP(ref)); } HostRef* PythonHostEnvironment::getSequenceItem(HostRef* ref, jsize pos) { return new HostRef(JPySequence::getItem(UNWRAP(ref), pos), false); } void PythonHostEnvironment::setSequenceItem(HostRef* seq, jsize pos, HostRef* val) { JPySequence::setItem(UNWRAP(seq), pos, UNWRAP(val)); } bool PythonHostEnvironment::isInt(HostRef* res) { return JPyInt::check(UNWRAP(res)); } HostRef* PythonHostEnvironment::newInt(jint v) { return new HostRef(JPyInt::fromLong(v), false); } jint PythonHostEnvironment::intAsInt(HostRef* res) { return JPyInt::asLong(UNWRAP(res)); } bool PythonHostEnvironment::isLong(HostRef* ref) { return JPyLong::check(UNWRAP(ref)); } HostRef* PythonHostEnvironment::newLong(jlong v) { TRACE_IN("PythonHostEnvironment::newLong"); return new HostRef(JPyLong::fromLongLong(v), false); TRACE_OUT; } jlong PythonHostEnvironment::longAsLong(HostRef* ref) { return JPyLong::asLongLong(UNWRAP(ref)); } bool PythonHostEnvironment::isFloat(HostRef* ref) { return JPyFloat::check(UNWRAP(ref)); } HostRef* PythonHostEnvironment::newFloat(jdouble v) { return new HostRef(JPyFloat::fromDouble(v), false); } jdouble PythonHostEnvironment::floatAsDouble(HostRef* ref) { return JPyFloat::asDouble(UNWRAP(ref)); } bool PythonHostEnvironment::isMethod(HostRef* ref) { return IS_REF(ref, "JPMethod"); } HostRef* PythonHostEnvironment::newMethod(JPMethod* m) { return WRAP(m, "JPMethod"); } JPMethod* PythonHostEnvironment::asMethod(HostRef* ref) { return (JPMethod*)JPyCObject::asVoidPtr(UNWRAP(ref)); } bool PythonHostEnvironment::isObject(HostRef* ref) { PyObject* obj = UNWRAP(ref); if (JPyObject::isInstance(obj, m_JavaLangObject)) { return true; } return false; } JPObject* PythonHostEnvironment::asObject(HostRef* m) { PyObject* obj = (PyObject*)m->data(); if (JPyCObject::check(obj)) { return (JPObject*)JPyCObject::asVoidPtr(obj); } PyObject* javaObject = JPyObject::getAttrString(obj, "__javaobject__"); JPObject* res = (JPObject*)JPyCObject::asVoidPtr(javaObject); Py_DECREF(javaObject); return res; } HostRef* PythonHostEnvironment::newObject(JPObject* obj) { TRACE_IN("PythonHostEnvironment::newObject"); TRACE2("classname", obj->getClass()->getName().getSimpleName()); JPClass* jc = obj->getClass(); JPTypeName name = jc->getName(); PyObject* pyClass = getJavaShadowClass(jc); PyObject* args = JPySequence::newTuple(2); PyObject* arg2 = JPySequence::newTuple(1); JPySequence::setItem(arg2, 0, args); Py_DECREF(args); PyObject* joHolder = JPyCObject::fromVoidAndDesc((void*)obj, (void*)"JPObject", &deleteJPObjectDestructor); JPySequence::setItem(args, 0, m_SpecialConstructorKey); JPySequence::setItem(args, 1, joHolder); Py_DECREF(joHolder); PyObject* res = JPyObject::call(pyClass, arg2, NULL); Py_DECREF(arg2); return new HostRef(res, false); TRACE_OUT; } bool PythonHostEnvironment::isClass(HostRef* ref) { PyObject* self = UNWRAP(ref); if (! JPyType::check(self)) { // If its not a type ... it can;t be a java type return false; } return JPyType::isSubclass(self, m_JavaLangObject); } HostRef* PythonHostEnvironment::newClass(JPClass* m) { PyJPClass* co = PyJPClass::alloc(m); PyObject* args = JPySequence::newTuple(1); JPySequence::setItem(args, 0, (PyObject*)co); Py_DECREF(co); PyObject* pyClass = JPyObject::call(m_GetClassMethod, args, NULL); return new HostRef(pyClass, false); } JPClass* PythonHostEnvironment::asClass(HostRef* ref) { PyObject* self = UNWRAP(ref); PyObject* claz = JPyObject::getAttrString(self, "__javaclass__"); PyJPClass* res = (PyJPClass*)claz; Py_DECREF(claz); return res->m_Class; } bool PythonHostEnvironment::isArrayClass(HostRef* ref) { PyObject* self = UNWRAP(ref); if (! JPyType::check(self)) { // If its not a type ... it can;t be a java type return false; } return JPyType::isSubclass(self, m_JavaArrayClass); } HostRef* PythonHostEnvironment::newArrayClass(JPArrayClass* m) { PyObject* args = JPySequence::newTuple(1); PyObject* cname = JPyString::fromString(m->getName().getSimpleName().c_str()); JPySequence::setItem(args, 0, cname); Py_DECREF(cname); PyObject* pyClass = JPyObject::call(m_GetArrayClassMethod, args, NULL); return new HostRef(pyClass, false); } JPArrayClass* PythonHostEnvironment::asArrayClass(HostRef* ref) { PyObject* self = UNWRAP(ref); PyObject* claz = JPyObject::getAttrString(self, "__javaclass__"); JPArrayClass* res = (JPArrayClass*)JPyCObject::asVoidPtr(claz); Py_DECREF(claz); return res; } bool PythonHostEnvironment::isArray(HostRef* ref) { PyObject* obj = UNWRAP(ref); if (JPyObject::isInstance(obj, m_JavaArrayClass)) { return true; } return false; } HostRef* PythonHostEnvironment::newArray(JPArray* m) { JPArrayClass* jc = m->getClass(); JPTypeName name = jc->getName(); PyObject* args = JPySequence::newTuple(1); PyObject* cname = JPyString::fromString(name.getSimpleName().c_str()); JPySequence::setItem(args, 0, cname); Py_DECREF(cname); PyObject* pyClass = JPyObject::call(m_GetArrayClassMethod, args, NULL); Py_DECREF(args); PyObject* joHolder = JPyCObject::fromVoidAndDesc((void*)m, (void*)"JPArray", &deleteJPArrayDestructor); args = JPySequence::newTuple(2); JPySequence::setItem(args, 0, m_SpecialConstructorKey); JPySequence::setItem(args, 1, joHolder); Py_DECREF(joHolder); PyObject* res = JPyObject::call(pyClass, args, NULL); Py_DECREF(args); return new HostRef(res, false); } JPArray* PythonHostEnvironment::asArray(HostRef* ref) { PyObject* obj = UNWRAP(ref); PyObject* javaObject = JPyObject::getAttrString(obj, "__javaobject__"); JPArray* res = (JPArray*)JPyCObject::asVoidPtr(javaObject); Py_DECREF(javaObject); return res; } bool PythonHostEnvironment::isWrapper(HostRef* ref) { return JPyObject::isInstance(UNWRAP(ref), m_WrapperClass); } bool PythonHostEnvironment::isProxy(HostRef* ref) { return JPyObject::isInstance(UNWRAP(ref), m_ProxyClass); } JPProxy* PythonHostEnvironment::asProxy(HostRef* ref) { JPCleaner cleaner; PyObject* proxy = UNWRAP(ref); PyObject* jproxy = JPyObject::getAttrString(proxy, "_proxy"); cleaner.add(new HostRef(jproxy, false)); JPProxy* res = (JPProxy*)JPyCObject::asVoidPtr(jproxy); return res; } HostRef* PythonHostEnvironment::getCallableFrom(HostRef* ref, string& name) { JPCleaner cleaner; PyObject* pname = JPyString::fromString(name.c_str()); cleaner.add(new HostRef(pname, false)); PyObject* mname = JPyString::fromString("getCallable"); cleaner.add(new HostRef(mname, false)); PyObject* call = PyObject_CallMethodObjArgs(UNWRAP(ref), mname, pname, NULL); JPyErr::check(); return new HostRef(call, false); } bool PythonHostEnvironment::isString(HostRef* ref) { return JPyString::check(UNWRAP(ref)); } jsize PythonHostEnvironment::getStringLength(HostRef* ref) { return (jsize)JPyObject::length(UNWRAP(ref)); } string PythonHostEnvironment::stringAsString(HostRef* ref) { return JPyString::asString(UNWRAP(ref)); } JCharString PythonHostEnvironment::stringAsJCharString(HostRef* ref) { return JPyString::asJCharString(UNWRAP(ref)); } HostRef* PythonHostEnvironment::newStringFromUnicode(const jchar* v, unsigned int l) { TRACE_IN("PythonHostEnvironment::newStringFromUnicode"); return new HostRef(JPyString::fromUnicode(v, l), false); TRACE_OUT; } HostRef* PythonHostEnvironment::newStringFromASCII(const char* v, unsigned int l) { return new HostRef(JPyString::fromString(v), false); } void* PythonHostEnvironment::prepareCallbackBegin() { PyGILState_STATE state = PyGILState_Ensure();; return (void*)new PyGILState_STATE(state); } void PythonHostEnvironment::prepareCallbackFinish(void* state) { PyGILState_STATE* state2 = (PyGILState_STATE*)state; PyGILState_Release(*state2); delete state2; } HostRef* PythonHostEnvironment::callObject(HostRef* c, vector& args) { JPCleaner cleaner; PyObject* pargs = JPySequence::newTuple((int)args.size()); cleaner.add(new HostRef(pargs, false)); for (unsigned int i = 0; i < args.size(); i++) { JPySequence::setItem(pargs, i, UNWRAP(args[i])); } PyObject* res = JPyObject::call(UNWRAP(c), pargs, NULL); return new HostRef(res, false); } void PythonHostEnvironment::printError() { PyErr_Print(); PyErr_Clear(); } bool PythonHostEnvironment::mapContains(HostRef* mapping, HostRef* key) { return JPyDict::contains(UNWRAP(mapping), UNWRAP(key)); } HostRef* PythonHostEnvironment::getMapItem(HostRef* mapping, HostRef* key) { return new HostRef(JPyDict::getItem(UNWRAP(mapping), UNWRAP(key)), false); } bool PythonHostEnvironment::objectHasAttribute(HostRef* obj, HostRef* key) { return JPyObject::hasAttr(UNWRAP(obj), UNWRAP(key)); } HostRef* PythonHostEnvironment::getObjectAttribute(HostRef* obj, HostRef* key) { return new HostRef(JPyObject::getAttr(UNWRAP(obj), UNWRAP(key)), false); } bool PythonHostEnvironment::isJavaException(HostException* ex) { PythonException* pe = (PythonException*)ex; return JPyObject::isSubclass(pe->m_ExceptionClass, m_JavaExceptionClass); } HostRef* PythonHostEnvironment::getJavaException(HostException* ex) { PythonException* pe = (PythonException*)ex; PyObject* obj = pe->getJavaException(); PyObject* javaObject = JPyObject::getAttrString(obj, "__javaobject__"); return new HostRef(javaObject, false); } void PythonHostEnvironment::clearError() { PyErr_Clear(); } bool PythonHostEnvironment::isWrapper(PyObject* obj) { return JPyObject::isInstance(obj, m_WrapperClass); } JPTypeName PythonHostEnvironment::getWrapperTypeName(PyObject* obj) { PyObject* pyTName = JPyObject::getAttrString(obj, "typeName"); string tname = JPyString::asString(pyTName); Py_DECREF(pyTName); return JPTypeName::fromSimple(tname.c_str()); } jvalue PythonHostEnvironment::getWrapperValue(PyObject* obj) { JPTypeName name = getWrapperTypeName(obj); PyObject* value = JPyObject::getAttrString(obj, "_value"); jvalue* v = (jvalue*)JPyCObject::asVoidPtr(value); Py_DECREF(value); if (name.isObjectType()) { jvalue res; res.l = JPEnv::getJava()->NewGlobalRef(v->l); return res; } return *v; } JPTypeName PythonHostEnvironment::getWrapperTypeName(HostRef* obj) { return getWrapperTypeName(UNWRAP(obj)); } jvalue PythonHostEnvironment::getWrapperValue(HostRef* obj) { return getWrapperValue(UNWRAP(obj)); } PyObject* PythonHostEnvironment::getJavaShadowClass(JPClass* jc) { PyJPClass* cls = PyJPClass::alloc(jc); PyObject* args = JPySequence::newTuple(1); JPySequence::setItem(args, 0, (PyObject*)cls); Py_DECREF(cls); PyObject* res = JPyObject::call(m_GetClassMethod, args, NULL); Py_DECREF(args); return res; } bool PythonHostEnvironment::isByteString(HostRef* ref) { PyObject* obj = UNWRAP(ref); return JPyString::checkStrict(obj); } bool PythonHostEnvironment::isUnicodeString(HostRef* ref) { return JPyString::checkUnicode(UNWRAP(ref)); } void PythonHostEnvironment::getRawByteString(HostRef* obj, char** outBuffer, long& outSize) { PyObject* objRef = UNWRAP(obj); Py_ssize_t tempSize = 0; JPyString::AsStringAndSize(objRef, outBuffer, &tempSize); outSize = (long)tempSize; } void PythonHostEnvironment::getRawUnicodeString(HostRef* obj, jchar** outBuffer, long& outSize) { PyObject* objRef = UNWRAP(obj); outSize = (long)JPyObject::length(objRef); *outBuffer = (jchar*)JPyString::AsUnicode(objRef); } size_t PythonHostEnvironment::getUnicodeSize() { return sizeof(Py_UNICODE); } HostRef* PythonHostEnvironment::newStringWrapper(jstring jstr) { TRACE_IN("PythonHostEnvironment::newStringWrapper"); jvalue* v = new jvalue; v->l = jstr; PyObject* value = JPyCObject::fromVoidAndDesc((void*)v, (void*)"object jvalue", deleteObjectJValueDestructor); PyObject* args = JPySequence::newTuple(1); JPySequence::setItem(args, 0, Py_None); PyObject* res = JPyObject::call(m_StringWrapperClass, args, Py_None); Py_DECREF(args); JPyObject::setAttrString(res, "_value", value); Py_DECREF(value); HostRef* resRef = new HostRef(res); Py_DECREF(res); return resRef; TRACE_OUT; } void PythonHostEnvironment::printReferenceInfo(HostRef* obj) { PyObject* pobj = UNWRAP(obj); cout << "Object info report" << endl; cout << " obj type " << pobj->ob_type->tp_name << endl; cout << " Ref count " << (long)pobj->ob_refcnt << endl; } void PythonHostEnvironment::deleteJPObjectDestructor(void* data, void* desc) { delete (JPObject*)data; } python-jpype-0.5.4.2/src/native/python/jpype_module.cpp0000666000175000017500000001704411614007722022430 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve M�nard 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. *****************************************************************************/ #include PyObject* JPypeModule::startup(PyObject* obj, PyObject* args) { TRACE_IN("startup"); try { PyObject* vmOpt; PyObject* vmPath; char ignoreUnrecognized = true; JPyArg::parseTuple(args, "OO!b|", &vmPath, &PyTuple_Type, &vmOpt, &ignoreUnrecognized); if (! (JPyString::check(vmPath))) { RAISE(JPypeException, "First paramter must be a string or unicode"); } string cVmPath = JPyString::asString(vmPath); StringVector args; for (int i = 0; i < JPyObject::length(vmOpt); i++) { PyObject* obj = JPySequence::getItem(vmOpt, i); if (JPyString::check(obj)) { // TODO support unicode string v = JPyString::asString(obj); args.push_back(v); } else if (JPySequence::check(obj)) { //String name = arg[0]; //Callable value = arg[1]; // TODO complete this for the hooks .... } else { RAISE(JPypeException, "VM Arguments must be string or tuple"); } } JPEnv::loadJVM(cVmPath, ignoreUnrecognized, args); Py_INCREF(Py_None); return Py_None; } PY_STANDARD_CATCH return NULL; TRACE_OUT; } PyObject* JPypeModule::attach(PyObject* obj, PyObject* args) { TRACE_IN("attach"); try { PyObject* vmPath; JPyArg::parseTuple(args, "O", &vmPath); if (! (JPyString::check(vmPath))) { RAISE(JPypeException, "First paramter must be a string or unicode"); } string cVmPath = JPyString::asString(vmPath); JPEnv::attachJVM(cVmPath); Py_INCREF(Py_None); return Py_None; } PY_STANDARD_CATCH return NULL; TRACE_OUT; } PyObject* JPypeModule::dumpJVMStats(PyObject* obj) { cerr << "JVM activity report :" << endl; //cerr << "\tmethod calls : " << methodCalls << endl; //cerr << "\tstatic method calls : " << staticMethodCalls << endl; //cerr << "\tconstructor calls : " << constructorCalls << endl; //cerr << "\tproxy callbacks : " << JProxy::getCallbackCount() << endl; //cerr << "\tfield gets : " << fieldGets << endl; //cerr << "\tfield sets : " << fieldSets << endl; cerr << "\tclasses loaded : " << JPTypeManager::getLoadedClasses() << endl; Py_INCREF(Py_None); return Py_None; } PyObject* JPypeModule::shutdown(PyObject* obj) { TRACE_IN("shutdown"); try { dumpJVMStats(obj); JPEnv::getJava()->checkInitialized(); JPTypeManager::flushCache(); if (JPEnv::getJava()->DestroyJavaVM() ) { RAISE(JPypeException, "Unable to destroy JVM"); } JPEnv::getJava()->shutdown(); cerr << "JVM has been shutdown" << endl; Py_INCREF(Py_None); return Py_None; } PY_STANDARD_CATCH; return NULL; TRACE_OUT; } PyObject* JPypeModule::synchronized(PyObject* obj, PyObject* args) { JPCleaner cleaner; TRACE_IN("synchronized"); try { PyObject* o; JPyArg::parseTuple(args, "O!", &PyCObject_Type, &o); string desc = (char*)JPyCObject::getDesc(o); jobject obj; if (desc == "JPObject") { JPObject* jpo = (JPObject*)JPyCObject::asVoidPtr(o); obj = jpo->getObject(); cleaner.addLocal(obj); } else if (desc == "JPClass") { JPClass* jpo = (JPClass*)JPyCObject::asVoidPtr(o); obj = jpo->getClass(); cleaner.addLocal(obj); } else if (desc == "JPArray") { JPArray* jpo = (JPArray*)JPyCObject::asVoidPtr(o); obj = jpo->getObject(); cleaner.addLocal(obj); } else if (desc == "JPArrayClass") { JPArrayClass* jpo = (JPArrayClass*)JPyCObject::asVoidPtr(o); obj = jpo->getClass(); cleaner.addLocal(obj); } else if (hostEnv->isWrapper(o) && hostEnv->getWrapperTypeName(o).isObjectType()) { obj = hostEnv->getWrapperValue(o).l; cleaner.addLocal(obj); } // TODO proxy else { RAISE(JPypeException, "method only accepts object values."); } PyJPMonitor* c = PyJPMonitor::alloc(new JPMonitor(obj)); return (PyObject*)c; } PY_STANDARD_CATCH; PyErr_Clear(); Py_INCREF(Py_None); return Py_None; TRACE_OUT; } PyObject* JPypeModule::isStarted(PyObject* obj) { if (JPEnv::isInitialized()) { return JPyBoolean::getTrue(); } return JPyBoolean::getFalse(); } PyObject* JPypeModule::attachThread(PyObject* obj) { try { JPEnv::attachCurrentThread(); Py_INCREF(Py_None); return Py_None; } PY_STANDARD_CATCH; return NULL; } PyObject* JPypeModule::detachThread(PyObject* obj) { try { JPEnv::getJava()->DetachCurrentThread(); Py_INCREF(Py_None); return Py_None; } PY_STANDARD_CATCH; return NULL; } PyObject* JPypeModule::isThreadAttached(PyObject* obj) { try { if (JPEnv::isThreadAttached()) { return JPyBoolean::getTrue(); } return JPyBoolean::getFalse(); } PY_STANDARD_CATCH; return NULL; } PyObject* JPypeModule::raiseJava(PyObject* , PyObject* args) { try { //PyObject* arg; //JPyArg::parseTuple(args, "O", &arg); //JPObject* obj; //JPCleaner cleaner; // //if (JPyCObject::check(arg) && string((char*)JPyCObject::getDesc(arg)) == "JPObject") //{ // obj = (JPObject*)JPyCObject::asVoidPtr(arg); //} //else //{ // JPyErr::setString(PyExc_TypeError, "You can only throw a subclass of java.lang.Throwable"); // return NULL; //} // //// check if claz is an instance of Throwable //JPClass* claz = obj->getClass(); //jclass jc = claz->getClass(); //cleaner.add(jc); //if (! JPJni::isThrowable(jc)) //{ // JPyErr::setString(PyExc_TypeError, "You can only throw a subclass of java.lang.Throwable"); // return NULL; //} // //jobject jobj = obj->getObject(); //cleaner.add(jobj); //JPEnv::getJava()->Throw((jthrowable)jobj); //PyJavaException::errorOccurred(); } PY_STANDARD_CATCH; return NULL; } PyObject* JPypeModule::attachThreadAsDaemon(PyObject* obj) { try { JPEnv::attachCurrentThreadAsDaemon(); Py_INCREF(Py_None); return Py_None; } PY_STANDARD_CATCH; return NULL; } PyObject* JPypeModule::startReferenceQueue(PyObject* obj, PyObject* args) { try { int i; JPyArg::parseTuple(args, "i", &i); JPJni::startJPypeReferenceQueue(i == 1); Py_INCREF(Py_None); return Py_None; } PY_STANDARD_CATCH; return NULL; } PyObject* JPypeModule::stopReferenceQueue(PyObject* obj) { try { JPJni::stopJPypeReferenceQueue(); Py_INCREF(Py_None); return Py_None; } PY_STANDARD_CATCH; return NULL; } PyObject* JPypeModule::setConvertStringObjects(PyObject* obj, PyObject* args) { try { PyObject* flag; JPyArg::parseTuple(args, "O", &flag); if (JPyBoolean::isTrue(flag)) { JPEnv::getJava()->setConvertStringObjects(true); } else { JPEnv::getJava()->setConvertStringObjects(false); } Py_INCREF(Py_None); return Py_None; } PY_STANDARD_CATCH; return NULL; } python-jpype-0.5.4.2/src/native/python/jpype_python.cpp0000666000175000017500000001722611614007722022466 0ustar takakitakaki/***************************************************************************** Copyright 2004-2008 Steve Menard 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. *****************************************************************************/ #include PythonHostEnvironment* hostEnv; PyObject* JPypeJavaWrapper::setWrapperClass(PyObject* self, PyObject* arg) { try { PyObject* t; JPyArg::parseTuple(arg, "O", &t); hostEnv->setWrapperClass(t); Py_INCREF(Py_None); return Py_None; } PY_STANDARD_CATCH return NULL; } PyObject* JPypeJavaWrapper::setStringWrapperClass(PyObject* self, PyObject* arg) { try { PyObject* t; JPyArg::parseTuple(arg, "O", &t); hostEnv->setStringWrapperClass(t); Py_INCREF(Py_None); return Py_None; } PY_STANDARD_CATCH return NULL; } PyObject* JPypeJavaProxy::setProxyClass(PyObject* self, PyObject* arg) { try { PyObject* t; JPyArg::parseTuple(arg, "O", &t); hostEnv->setProxyClass(t); Py_INCREF(Py_None); return Py_None; } PY_STANDARD_CATCH return NULL; } PyObject* convertToJValue(PyObject* self, PyObject* arg) { try { char* tname; PyObject* value; JPyArg::parseTuple(arg, "sO", &tname, &value); JPTypeName name = JPTypeName::fromSimple(tname); JPType* type = JPTypeManager::getType(name); HostRef ref(value); jvalue v = type->convertToJava(&ref); jvalue* pv = new jvalue(); *pv = v; PyObject* res; if (type->isObjectType()) { res = JPyCObject::fromVoidAndDesc((void*)pv, (void*)"object jvalue", PythonHostEnvironment::deleteObjectJValueDestructor); } else { res = JPyCObject::fromVoidAndDesc((void*)pv, (void*)"jvalue", PythonHostEnvironment::deleteJValueDestructor); } return res; } PY_STANDARD_CATCH return NULL; } PyObject* JPypeJavaProxy::createProxy(PyObject*, PyObject* arg) { try { JPCleaner cleaner; PyObject* self; PyObject* intf; JPyArg::parseTuple(arg, "OO", &self, &intf); std::vector interfaces; Py_ssize_t len = JPyObject::length(intf); for (Py_ssize_t i = 0; i < len; i++) { PyObject* subObj = JPySequence::getItem(intf, i); cleaner.add(new HostRef(subObj, false)); PyObject* claz = JPyObject::getAttrString(subObj, "__javaclass__"); PyJPClass* c = (PyJPClass*)claz; jclass jc = c->m_Class->getClass(); cleaner.addLocal(jc); interfaces.push_back(jc); } HostRef ref = HostRef(self); JPProxy* proxy = new JPProxy(&ref, interfaces); PyObject* res = JPyCObject::fromVoidAndDesc(proxy, (void*)"jproxy", PythonHostEnvironment::deleteJPProxyDestructor); return res; } PY_STANDARD_CATCH return NULL; } static PyObject* setJavaExceptionClass(PyObject* self, PyObject* arg) { try { PyObject* t; JPyArg::parseTuple(arg, "O", &t); hostEnv->setJavaExceptionClass(t); Py_INCREF(Py_None); return Py_None; } PY_STANDARD_CATCH return NULL; } static PyMethodDef jpype_methods[] = { {"isStarted", (PyCFunction)&JPypeModule::isStarted, METH_NOARGS, ""}, {"startup", &JPypeModule::startup, METH_VARARGS, ""}, {"attach", &JPypeModule::attach, METH_VARARGS, ""}, {"shutdown", (PyCFunction)&JPypeModule::shutdown, METH_NOARGS, ""}, {"findClass", &JPypeJavaClass::findClass, METH_VARARGS, ""}, {"synchronized", &JPypeModule::synchronized, METH_VARARGS, ""}, {"isThreadAttachedToJVM", (PyCFunction)&JPypeModule::isThreadAttached, METH_NOARGS, ""}, {"attachThreadToJVM", (PyCFunction)&JPypeModule::attachThread, METH_NOARGS, ""}, {"detachThreadFromJVM", (PyCFunction)&JPypeModule::detachThread, METH_NOARGS, ""}, {"dumpJVMStats", (PyCFunction)&JPypeModule::dumpJVMStats, METH_NOARGS, ""}, {"attachThreadAsDaemon", (PyCFunction)&JPypeModule::attachThreadAsDaemon, METH_NOARGS, ""}, {"startReferenceQueue", &JPypeModule::startReferenceQueue, METH_VARARGS, ""}, {"stopReferenceQueue", (PyCFunction)&JPypeModule::stopReferenceQueue, METH_NOARGS, ""}, {"setJavaLangObjectClass", &JPypeJavaClass::setJavaLangObjectClass, METH_VARARGS, ""}, {"setGetClassMethod", &JPypeJavaClass::setGetClassMethod, METH_VARARGS, ""}, {"setSpecialConstructorKey", &JPypeJavaClass::setSpecialConstructorKey, METH_VARARGS, ""}, {"setJavaArrayClass", &JPypeJavaArray::setJavaArrayClass, METH_VARARGS, ""}, {"setGetJavaArrayClassMethod", &JPypeJavaArray::setGetJavaArrayClassMethod, METH_VARARGS, ""}, {"setWrapperClass", &JPypeJavaWrapper::setWrapperClass, METH_VARARGS, ""}, {"setProxyClass", &JPypeJavaProxy::setProxyClass, METH_VARARGS, ""}, {"createProxy", &JPypeJavaProxy::createProxy, METH_VARARGS, ""}, {"setStringWrapperClass", &JPypeJavaWrapper::setStringWrapperClass, METH_VARARGS, ""}, {"convertToJValue", &convertToJValue, METH_VARARGS, ""}, {"findArrayClass", &JPypeJavaArray::findArrayClass, METH_VARARGS, ""}, {"getArrayLength", &JPypeJavaArray::getArrayLength, METH_VARARGS, ""}, {"getArrayItem", &JPypeJavaArray::getArrayItem, METH_VARARGS, ""}, {"setArrayItem", &JPypeJavaArray::setArrayItem, METH_VARARGS, ""}, {"getArraySlice", &JPypeJavaArray::getArraySlice, METH_VARARGS, ""}, {"setArraySlice", &JPypeJavaArray::setArraySlice, METH_VARARGS, ""}, {"setArrayValues", &JPypeJavaArray::setArrayValues, METH_VARARGS, ""}, {"newArray", &JPypeJavaArray::newArray, METH_VARARGS, ""}, {"setJavaExceptionClass", &setJavaExceptionClass, METH_VARARGS, ""}, {"convertToDirectBuffer", &JPypeJavaNio::convertToDirectBuffer, METH_VARARGS, ""}, {"setConvertStringObjects", &JPypeModule::setConvertStringObjects, METH_VARARGS, ""}, // sentinel {NULL} }; PyMODINIT_FUNC init_jpype() { Py_Initialize(); PyEval_InitThreads(); PyObject* module = Py_InitModule("_jpype", jpype_methods); Py_INCREF(module); hostEnv = new PythonHostEnvironment(); JPEnv::init(hostEnv); PyJPMonitor::initType(module); PyJPMethod::initType(module); PyJPBoundMethod::initType(module); PyJPClass::initType(module); PyJPField::initType(module); } PyObject* detachRef(HostRef* ref) { PyObject* data = (PyObject*)ref->data(); Py_XINCREF(data); ref->release(); return data; } void JPypeJavaException::errorOccurred() { TRACE_IN("PyJavaException::errorOccurred"); JPCleaner cleaner; jthrowable th = JPEnv::getJava()->ExceptionOccurred(); cleaner.addLocal(th); JPEnv::getJava()->ExceptionClear(); jclass ec = JPJni::getClass(th); JPTypeName tn = JPJni::getName(ec); JPClass* jpclass = JPTypeManager::findClass(tn); cleaner.addLocal(ec); PyObject* jexclass = hostEnv->getJavaShadowClass(jpclass); HostRef* pyth = hostEnv->newObject(new JPObject(tn, th)); cleaner.add(pyth); PyObject* args = JPySequence::newTuple(2); PyObject* arg2 = JPySequence::newTuple(1); JPySequence::setItem(arg2, 0, args); Py_DECREF(args); JPySequence::setItem(args, 0, hostEnv->m_SpecialConstructorKey); JPySequence::setItem(args, 1, (PyObject*)pyth->data()); PyObject* pyexclass = JPyObject::getAttrString(jexclass, "PYEXC"); Py_DECREF(jexclass); JPyErr::setObject(pyexclass, arg2); Py_DECREF(arg2); Py_DECREF(pyexclass); TRACE_OUT; } python-jpype-0.5.4.2/src/native/python/include/0000775000175000017500000000000011620747357020657 5ustar takakitakakipython-jpype-0.5.4.2/src/native/python/include/py_monitor.h0000666000175000017500000000217011614007722023215 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard 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. *****************************************************************************/ #ifndef _PYMONITOR_H_ #define _PYMONITOR_H_ #include "object.h" struct PyJPMonitor { PyObject_HEAD // Python-visible methods static void initType(PyObject* module); static PyJPMonitor* alloc(JPMonitor*); static void __dealloc__(PyObject* o); static PyObject* __str__(PyObject* o); JPMonitor* state; }; #endif // _PYMONITOR_H_ python-jpype-0.5.4.2/src/native/python/include/jp_runloopstopper.h0000666000175000017500000000060311614007722024621 0ustar takakitakaki#import @interface JPRunLoopStopper : NSObject { BOOL shouldStop; } + currentRunLoopStopper; - init; - (BOOL) shouldRun; + (void) addRunLoopStopper:(JPRunLoopStopper *) runLoopStopper toRunLoop:(NSRunLoop *) runLoop; + (void) removeRunLoopStopperFromRunLoop:(NSRunLoop *) runLoop; - (void) stop; - (void) performStop:(id) sender; @end python-jpype-0.5.4.2/src/native/python/include/py_class.h0000666000175000017500000000440111614007722022632 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard 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. *****************************************************************************/ #ifndef _PYCLASS_H_ #define _PYCLASS_H_ struct PyJPClass { //AT's comments on porting: // 1) Some Unix compilers do not tolerate the semicolumn after PyObject_HEAD //PyObject_HEAD; PyObject_HEAD // Python-visible methods static void initType(PyObject* module); static PyJPClass* alloc(JPClass* cls); static bool check(PyObject* o); static void __dealloc__(PyObject* o); static PyObject* getName(PyObject* self, PyObject* arg); static PyObject* getBaseClass(PyObject* self, PyObject* arg); static PyObject* getBaseInterfaces(PyObject* self, PyObject* arg); static PyObject* getClassMethods(PyObject* self, PyObject* arg); static PyObject* getClassFields(PyObject* self, PyObject* arg); static PyObject* newClassInstance(PyObject* self, PyObject* arg); static PyObject* isInterface(PyObject* self, PyObject* arg); static PyObject* isPrimitive(PyObject* self, PyObject* arg); static PyObject* isSubclass(PyObject* self, PyObject* arg); static PyObject* isException(PyObject* self, PyObject* arg); static PyObject* isArray(PyObject* self, PyObject* arg); static PyObject* getConstructors(PyObject* self); static PyObject* getDeclaredConstructors(PyObject* self); static PyObject* getDeclaredFields(PyObject* self); static PyObject* getDeclaredMethods(PyObject* self); static PyObject* getFields(PyObject* self); static PyObject* getMethods(PyObject* self); static PyObject* getModifiers(PyObject* self); JPClass* m_Class; }; #endif // _PYCLASS_H_ python-jpype-0.5.4.2/src/native/python/include/pythonenv.h0000666000175000017500000001641611614007722023060 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve M�nard 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. *****************************************************************************/ #ifndef _PYTHON_ENV_H_ #define _PYTHON_ENV_H_ #define PY_CHECK(op) op; { \ PyObject* __ex = PyErr_Occurred(); \ if (__ex) { \ throw new PythonException(); \ }\ }; /** * Exception wrapper for python-generated exceptions */ class PythonException : public HostException { public : PythonException(); PythonException(PythonException& ex); virtual ~PythonException(); bool isJavaException(); PyObject* getJavaException(); public : PyObject* m_ExceptionClass; PyObject* m_ExceptionValue; }; /** * JPythonEnvHelper */ class JPythonEnvHelper { }; /** * JPyErr */ class JPyErr : public JPythonEnvHelper { public : static void setString(PyObject*exClass, const char* str); static void setObject(PyObject*exClass, PyObject* obj); static void check() { PY_CHECK(;); } }; /** * JPyArg */ class JPyArg : public JPythonEnvHelper { public : template static void parseTuple(PyObject* arg, char* pattern, T1 a1) { PY_CHECK( PyArg_ParseTuple(arg, pattern, a1) ); } template static void parseTuple(PyObject* arg, char* pattern, T1 a1, T2 a2) { PY_CHECK( PyArg_ParseTuple(arg, pattern, a1, a2) ); } template static void parseTuple(PyObject* arg, char* pattern, T1 a1, T2 a2, T3 a3) { PY_CHECK( PyArg_ParseTuple(arg, pattern, a1, a2, a3) ); } template static void parseTuple(PyObject* arg, char* pattern, T1 a1, T2 a2, T3 a3, T4 a4) { PY_CHECK( PyArg_ParseTuple(arg, pattern, a1, a2, a3, a4)) ; } template static void parseTuple(PyObject* arg, char* pattern, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) { PY_CHECK( PyArg_ParseTuple(arg, pattern, a1, a2, a3, a4, a5)) ; } private : static void check_exception(); }; /** * JPyString */ class JPyString : public JPythonEnvHelper { public : static bool check(PyObject* obj); static bool checkStrict(PyObject*); static bool checkUnicode(PyObject*); static string asString(PyObject* obj); static JCharString asJCharString(PyObject* obj); static Py_ssize_t AsStringAndSize(PyObject *obj, char **buffer, Py_ssize_t *); static Py_UNICODE* AsUnicode(PyObject *obj); static PyObject* fromUnicode(const jchar*, int); static PyObject* fromString(const char*); }; /** * JPyTuple */ class JPySequence : public JPythonEnvHelper { public : static bool check(PyObject* obj); static PyObject* newTuple(Py_ssize_t ndx); static PyObject* newList(Py_ssize_t ndx); static PyObject* getItem(PyObject* tuple, Py_ssize_t ndx); static void setItem(PyObject* tuple, Py_ssize_t ndx, PyObject* val); }; /** * JPyObject */ class JPyObject : public JPythonEnvHelper { public : static Py_ssize_t length(PyObject* obj); static bool hasAttr(PyObject*, PyObject*); static PyObject* getAttr(PyObject*, PyObject*); static PyObject* call(PyObject*, PyObject*, PyObject*); static PyObject* getAttrString(PyObject*, const char*); static void setAttrString(PyObject*, const char*, PyObject *); static bool isInstance(PyObject* obj, PyObject* t); static bool isSubclass(PyObject* obj, PyObject* t); }; class JPyInt : public JPythonEnvHelper { public : static PyObject* fromLong(long l); static bool check(PyObject*); static long asLong(PyObject*); }; class JPyLong : public JPythonEnvHelper { public : static PyObject* fromLongLong(PY_LONG_LONG l); static bool check(PyObject*); static PY_LONG_LONG asLongLong(PyObject*); }; class JPyBoolean : public JPythonEnvHelper { public : static bool isTrue(PyObject* o) { return o == Py_True; } static bool isFalse(PyObject* o) { return o == Py_False; } static PyObject* getTrue(); static PyObject* getFalse(); }; class JPyFloat : public JPythonEnvHelper { public : static PyObject* fromDouble(double l); static bool check(PyObject*); static double asDouble(PyObject*); }; class JPyDict : public JPythonEnvHelper { public : static bool check(PyObject* obj); static bool contains(PyObject*, PyObject*); static PyObject* getItem(PyObject*, PyObject*); static PyObject* getKeys(PyObject*); static PyObject* copy(PyObject*); static PyObject* newInstance(); static void setItemString(PyObject*, PyObject*, const char*); }; class JPyCObject : public JPythonEnvHelper { public : static bool check(PyObject* obj); static PyObject* fromVoid(void* data, void (*destr)(void *)); static PyObject* fromVoidAndDesc(void* data, void* desc, void (*destr)(void *, void*)); static void* asVoidPtr(PyObject*); static void* getDesc(PyObject*); }; class JPyType : public JPythonEnvHelper { public : static bool check(PyObject* obj); static bool isSubclass(PyObject*, PyObject*); }; class JPyHelper : public JPythonEnvHelper { public : static void dumpSequenceRefs(PyObject* seq, const char* comment); }; #undef PY_CHECK #define PY_STANDARD_CATCH \ catch(JavaException* ex) \ { \ try { \ JPypeJavaException::errorOccurred(); \ } \ catch(...) \ { \ JPEnv::getHost()->setRuntimeException("An unknown error occured while handling a Java Exception"); \ }\ delete ex; \ }\ catch(JPypeException* ex)\ {\ try { \ JPEnv::getHost()->setRuntimeException(ex->getMsg()); \ } \ catch(...) \ { \ JPEnv::getHost()->setRuntimeException("An unknown error occured while handling a JPype Exception"); \ }\ delete ex; \ }\ catch(PythonException* ex) \ { \ delete ex; \ } \ catch(...) \ {\ JPEnv::getHost()->setRuntimeException("Unknown Exception"); \ } \ #define PY_LOGGING_CATCH \ catch(JavaException* ex) \ { \ try { \ cout << "Java error occured : " << ex->message << endl; \ JPypeJavaException::errorOccurred(); \ } \ catch(...) \ { \ JPEnv::getHost()->setRuntimeException("An unknown error occured while handling a Java Exception"); \ }\ delete ex; \ }\ catch(JPypeException* ex)\ {\ try { \ cout << "JPype error occured" << endl; \ JPEnv::getHost()->setRuntimeException(ex->getMsg()); \ } \ catch(...) \ { \ JPEnv::getHost()->setRuntimeException("An unknown error occured while handling a JPype Exception"); \ }\ delete ex; \ }\ catch(PythonException* ex) \ { \ cout << "Pyhton error occured" << endl; \ delete ex; \ } \ catch(...) \ {\ cout << "Unknown error occured" << endl; \ JPEnv::getHost()->setRuntimeException("Unknown Exception"); \ } \ #endif // _PYTHON_ENV_H_ python-jpype-0.5.4.2/src/native/python/include/py_hostenv.h0000666000175000017500000001446011614007722023221 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve M�nard 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. *****************************************************************************/ #ifndef _PYHOSTENV_H_ #define _PYHOSTENV_H_ class PythonHostEnvironment : public HostEnvironment { public : PythonHostEnvironment() { } virtual ~PythonHostEnvironment() { } public : void setJavaLangObjectClass(PyObject* obj) { m_JavaLangObject = obj; } PyObject* getJavaLangObjectClass() { return m_JavaLangObject; } void setJavaArrayClass(PyObject* obj) { m_JavaArrayClass = obj; } void setWrapperClass(PyObject* obj) { m_WrapperClass = obj; } void setStringWrapperClass(PyObject* obj) { m_StringWrapperClass = obj; } void setProxyClass(PyObject* obj) { m_ProxyClass = obj; } void setGetJavaClassMethod(PyObject* obj) { m_GetClassMethod = obj; Py_INCREF(obj); } void setGetJavaArrayClassMethod(PyObject* obj) { m_GetArrayClassMethod = obj; Py_INCREF(obj); } void setSpecialConstructorKey(PyObject* obj) { m_SpecialConstructorKey = obj; Py_INCREF(obj); } PyObject* getSpecialConstructorKey() { return m_SpecialConstructorKey; } void setJavaExceptionClass(PyObject* obj) { m_JavaExceptionClass = obj; } static void deleteJPObjectDestructor(void* data, void* desc); static void deleteJPArrayDestructor(void* data, void* desc) { delete (JPArray*)data; } static void deleteObjectJValueDestructor(void* data, void* desc) { jvalue* pv = (jvalue*)data; JPEnv::getJava()->DeleteGlobalRef(pv->l); delete pv; } static void deleteJValueDestructor(void* data, void* desc) { jvalue* pv = (jvalue*)data; delete pv; } static void deleteJPProxyDestructor(void* data, void* desc) { JPProxy* pv = (JPProxy*)data; delete pv; } PyObject* getJavaShadowClass(JPClass* jc); private : PyObject* m_JavaLangObject; PyObject* m_JavaArrayClass; PyObject* m_WrapperClass; PyObject* m_StringWrapperClass; PyObject* m_ProxyClass; map m_ClassMap; PyObject* m_GetClassMethod; PyObject* m_GetArrayClassMethod; public : PyObject* m_SpecialConstructorKey; PyObject* m_JavaExceptionClass; public : virtual void* acquireRef(void*); virtual void releaseRef(void*); virtual bool isRefNull(void*); virtual string describeRef(HostRef*); virtual void* gotoExternal(); virtual void returnExternal(void* state); virtual void setRuntimeException(const char* msg); virtual void setAttributeError(const char* msg); virtual void setTypeError(const char* msg); virtual void raise(const char* msg); virtual HostRef* getNone(); virtual bool isNone(HostRef*); virtual bool isBoolean(HostRef*); virtual jboolean booleanAsBoolean(HostRef*); virtual HostRef* getTrue(); virtual HostRef* getFalse(); virtual bool isSequence(HostRef*); virtual HostRef* newMutableSequence(jsize); virtual HostRef* newImmutableSequence(jsize); virtual jsize getSequenceLength(HostRef*); virtual HostRef* getSequenceItem(HostRef*, jsize); virtual void setSequenceItem(HostRef*, jsize, HostRef*); virtual bool isInt(HostRef*); virtual HostRef* newInt(jint); virtual jint intAsInt(HostRef*); virtual bool isLong(HostRef*); virtual HostRef* newLong(jlong); virtual jlong longAsLong(HostRef*); virtual bool isFloat(HostRef*); virtual HostRef* newFloat(jdouble); virtual jdouble floatAsDouble(HostRef*); virtual bool isMethod(HostRef*); virtual HostRef* newMethod(JPMethod*); virtual JPMethod* asMethod(HostRef*); virtual bool isObject(HostRef*); virtual HostRef* newObject(JPObject*); virtual JPObject* asObject(HostRef*); virtual bool isClass(HostRef*); virtual HostRef* newClass(JPClass*); virtual JPClass* asClass(HostRef*); virtual bool isArrayClass(HostRef*); virtual HostRef* newArrayClass(JPArrayClass*); virtual JPArrayClass* asArrayClass(HostRef*); virtual bool isArray(HostRef*); virtual HostRef* newArray(JPArray*); virtual JPArray* asArray(HostRef*); virtual bool isProxy(HostRef*); virtual JPProxy* asProxy(HostRef*); virtual HostRef* getCallableFrom(HostRef*, string&); virtual bool isWrapper(PyObject*) ; virtual JPTypeName getWrapperTypeName(PyObject*); virtual jvalue getWrapperValue(PyObject*); virtual bool isWrapper(HostRef*); virtual JPTypeName getWrapperTypeName(HostRef*); virtual jvalue getWrapperValue(HostRef*); virtual HostRef* newStringWrapper(jstring); virtual bool isString(HostRef*); virtual jsize getStringLength(HostRef*); virtual string stringAsString(HostRef*); virtual JCharString stringAsJCharString(HostRef*); virtual HostRef* newStringFromUnicode(const jchar*, unsigned int); virtual HostRef* newStringFromASCII(const char*, unsigned int); virtual bool isByteString(HostRef*); virtual bool isUnicodeString(HostRef* ref); virtual void getRawByteString(HostRef*, char**, long&); virtual void getRawUnicodeString(HostRef*, jchar**, long&); virtual size_t getUnicodeSize(); virtual void* prepareCallbackBegin(); virtual void prepareCallbackFinish(void* state); virtual HostRef* callObject(HostRef* callable, vector& args); virtual void printError(); virtual bool mapContains(HostRef* map, HostRef* key); virtual HostRef* getMapItem(HostRef* map, HostRef* key); virtual bool objectHasAttribute(HostRef* obj, HostRef* key); virtual HostRef* getObjectAttribute(HostRef* obj, HostRef* key); virtual bool isJavaException(HostException*); virtual HostRef* getJavaException(HostException*); virtual void clearError(); virtual void printReferenceInfo(HostRef* obj); }; #endif // _PYHOSTENV_H_ python-jpype-0.5.4.2/src/native/python/include/py_method.h0000666000175000017500000000365211614007722023014 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard 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. *****************************************************************************/ #ifndef _PYMETHOD_H_ #define _PYMETHOD_H_ struct PyJPMethod { PyObject_HEAD // Python-visible methods static void initType(PyObject* module); static PyJPMethod* alloc(JPMethod* mth); static void __dealloc__(PyObject* o); static PyObject* __str__(PyObject* o); static PyObject* __call__(PyObject* self, PyObject* args, PyObject* kwargs); static PyObject* isBeanMutator(PyObject* self, PyObject* arg); static PyObject* isBeanAccessor(PyObject* self, PyObject* arg); static PyObject* getName(PyObject* self, PyObject* arg); static PyObject* matchReport(PyObject* self, PyObject* arg); JPMethod* m_Method; }; struct PyJPBoundMethod { PyObject_HEAD // Python-visible methods static void initType(PyObject* module); static int __init__(PyObject* self, PyObject* args, PyObject* kwargs); static void __dealloc__(PyObject* o); static PyObject* __str__(PyObject* o); static PyObject* __call__(PyObject* self, PyObject* args, PyObject* kwargs); static PyObject* matchReport(PyObject* self, PyObject* arg); PyObject* m_Instance; PyJPMethod* m_Method; }; #endif // _PYMETHOD_H_ python-jpype-0.5.4.2/src/native/python/include/jpype_python.h0000666000175000017500000000754211614007722023556 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve M�nard 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. *****************************************************************************/ #ifndef _JPYPE_PYTHON_H_ #define _JPYPE_PYTHON_H_ // This file defines the _jpype module's interface and initializes it #include #include // TODO figure a better way to do this .. Python dependencies should not be in common code #include #if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN) typedef int Py_ssize_t; #define PY_SSIZE_T_MAX INT_MAX #define PY_SSIZE_T_MIN INT_MIN #endif #include "pythonenv.h" class JPypeModule { public : static PyObject* startup(PyObject* obj, PyObject* args); static PyObject* attach(PyObject* obj, PyObject* args); static PyObject* dumpJVMStats(PyObject* obj); static PyObject* shutdown(PyObject* obj); static PyObject* synchronized(PyObject* obj, PyObject* args); static PyObject* isStarted(PyObject* obj); static PyObject* attachThread(PyObject* obj); static PyObject* detachThread(PyObject* obj); static PyObject* isThreadAttached(PyObject* obj); static PyObject* getJException(PyObject* obj, PyObject* args); static PyObject* raiseJava(PyObject* obj, PyObject* args); static PyObject* attachThreadAsDaemon(PyObject* obj); static PyObject* startReferenceQueue(PyObject* obj, PyObject* args); static PyObject* stopReferenceQueue(PyObject* obj); static PyObject* setConvertStringObjects(PyObject* obj, PyObject* args); }; class JPypeJavaClass { public: static PyObject* findClass(PyObject* obj, PyObject* args); static PyObject* setJavaLangObjectClass(PyObject* self, PyObject* arg); static PyObject* setGetClassMethod(PyObject* self, PyObject* arg); static PyObject* setSpecialConstructorKey(PyObject* self, PyObject* arg); }; class JPypeJavaProxy { public: static PyObject* setProxyClass(PyObject* self, PyObject* arg); static PyObject* createProxy(PyObject*, PyObject* arg); }; class JPypeJavaArray { public: static PyObject* findArrayClass(PyObject* obj, PyObject* args); static PyObject* getArrayLength(PyObject* self, PyObject* arg); static PyObject* getArrayItem(PyObject* self, PyObject* arg); static PyObject* getArraySlice(PyObject* self, PyObject* arg); static PyObject* setArraySlice(PyObject* self, PyObject* arg); static PyObject* newArray(PyObject* self, PyObject* arg); static PyObject* setArrayItem(PyObject* self, PyObject* arg); static PyObject* setGetJavaArrayClassMethod(PyObject* self, PyObject* arg); static PyObject* setJavaArrayClass(PyObject* self, PyObject* arg); static PyObject* setArrayValues(PyObject* self, PyObject* arg); }; class JPypeJavaNio { public: static PyObject* convertToDirectBuffer(PyObject* self, PyObject* arg); }; class JPypeJavaWrapper { public: static PyObject* setWrapperClass(PyObject* self, PyObject* arg); static PyObject* setStringWrapperClass(PyObject* self, PyObject* arg); }; class JPypeJavaException { public: static void errorOccurred(); }; #include "py_monitor.h" #include "py_method.h" #include "py_class.h" #include "py_field.h" #include "py_hostenv.h" extern PythonHostEnvironment* hostEnv; // Utility method PyObject* detachRef(HostRef* ref); #endif // _JPYPE_PYTHON_H_ python-jpype-0.5.4.2/src/native/python/include/jp_cocoatools.h0000666000175000017500000000004111614007722023647 0ustar takakitakaki void JPRunConsoleEventLoop(); python-jpype-0.5.4.2/src/native/python/include/py_field.h0000666000175000017500000000300111614007722022603 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard 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. *****************************************************************************/ #ifndef _PYFIELD_H_ #define _PYFIELD_H_ struct PyJPField { PyObject_HEAD // Python-visible methods static void initType(PyObject* module); static PyJPField* alloc(JPField* mth); static void __dealloc__(PyObject* o); static PyObject* getName(PyObject* self, PyObject* arg); static PyObject* getStaticAttribute(PyObject* self, PyObject* arg); static PyObject* setStaticAttribute(PyObject* self, PyObject* arg); static PyObject* setInstanceAttribute(PyObject* self, PyObject* arg); static PyObject* getInstanceAttribute(PyObject* self, PyObject* arg); static PyObject* isStatic(PyObject* self, PyObject* arg); static PyObject* isFinal(PyObject* self, PyObject* arg); JPField* m_Field; }; #endif // _PYFIELD_H_ python-jpype-0.5.4.2/src/native/python/py_class.cpp0000666000175000017500000003405311614007722021550 0ustar takakitakaki/***************************************************************************** Copyright 2004-2008 Steve Menard 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. *****************************************************************************/ #include static PyMethodDef classMethods[] = { {"getName", &PyJPClass::getName, METH_VARARGS, ""}, {"getBaseClass", &PyJPClass::getBaseClass, METH_VARARGS, ""}, {"getClassFields", &PyJPClass::getClassFields, METH_VARARGS, ""}, {"getClassMethods", &PyJPClass::getClassMethods, METH_VARARGS, ""}, {"newClassInstance", &PyJPClass::newClassInstance, METH_VARARGS, ""}, {"isInterface", &PyJPClass::isInterface, METH_VARARGS, ""}, {"getBaseInterfaces", &PyJPClass::getBaseInterfaces, METH_VARARGS, ""}, {"isSubclass", &PyJPClass::isSubclass, METH_VARARGS, ""}, {"isPrimitive", &PyJPClass::isPrimitive, METH_VARARGS, ""}, {"isException", &PyJPClass::isException, METH_VARARGS, ""}, {"isArray", &PyJPClass::isArray, METH_VARARGS, ""}, {"getSuperclass",&PyJPClass::getBaseClass, METH_NOARGS, ""}, {"getConstructors", (PyCFunction)&PyJPClass::getConstructors, METH_NOARGS, ""}, {"getDeclaredConstructors", (PyCFunction)&PyJPClass::getDeclaredConstructors, METH_NOARGS, ""}, {"getDeclaredFields", (PyCFunction)&PyJPClass::getDeclaredFields, METH_NOARGS, ""}, {"getDeclaredMethods", (PyCFunction)&PyJPClass::getDeclaredMethods, METH_NOARGS, ""}, {"getFields", (PyCFunction)&PyJPClass::getFields, METH_NOARGS, ""}, {"getMethods", (PyCFunction)&PyJPClass::getMethods, METH_NOARGS, ""}, {"getModifiers", (PyCFunction)&PyJPClass::getModifiers, METH_NOARGS, ""}, {NULL}, }; static PyTypeObject classClassType = { PyObject_HEAD_INIT(&PyType_Type) 0, /*ob_size*/ "JavaClass", /*tp_name*/ sizeof(PyJPClass), /*tp_basicsize*/ 0, /*tp_itemsize*/ PyJPClass::__dealloc__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ 0, /*tp_compare*/ 0, /*tp_repr*/ 0, /*tp_as_number*/ 0, /*tp_as_sequence*/ 0, /*tp_as_mapping*/ 0, /*tp_hash */ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT, /*tp_flags*/ "Java Class", /*tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ 0, /* tp_iter */ 0, /* tp_iternext */ classMethods, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ 0, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ 0, /* tp_init */ 0, /* tp_alloc */ PyType_GenericNew /* tp_new */ }; // Static methods void PyJPClass::initType(PyObject* module) { PyType_Ready(&classClassType); PyModule_AddObject(module, "_JavaClass", (PyObject*)&classClassType); } PyJPClass* PyJPClass::alloc(JPClass* cls) { PyJPClass* res = PyObject_New(PyJPClass, &classClassType); res->m_Class = cls; return res; } void PyJPClass::__dealloc__(PyObject* o) { TRACE_IN("PyJPClass::__dealloc__"); PyJPClass* self = (PyJPClass*)o; self->ob_type->tp_free(o); TRACE_OUT; } PyObject* PyJPClass::getName(PyObject* o, PyObject* arg) { try { PyJPClass* self = (PyJPClass*)o; JPTypeName name = self->m_Class->getName(); PyObject* res = JPyString::fromString(name.getSimpleName().c_str()); return res; } PY_STANDARD_CATCH return NULL; } PyObject* PyJPClass::getBaseClass(PyObject* o, PyObject* arg) { try { PyJPClass* self = (PyJPClass*)o; JPClass* base = self->m_Class->getSuperClass(); if (base == NULL) { Py_INCREF(Py_None); return Py_None; } PyObject* res = (PyObject*)PyJPClass::alloc(base); return res; } PY_STANDARD_CATCH return NULL; } PyObject* PyJPClass::getBaseInterfaces(PyObject* o, PyObject* arg) { try { PyJPClass* self = (PyJPClass*)o; vector baseItf = self->m_Class->getInterfaces(); PyObject* result = JPySequence::newTuple((int)baseItf.size()); for (unsigned int i = 0; i < baseItf.size(); i++) { JPClass* base = baseItf[i]; PyObject* obj = (PyObject*)PyJPClass::alloc(base); JPySequence::setItem(result, i, obj); } return result; } PY_STANDARD_CATCH return NULL; } PyObject* PyJPClass::getClassFields(PyObject* o, PyObject* arg) { try { PyJPClass* self = (PyJPClass*)o; map staticFields = self->m_Class->getStaticFields(); map instFields = self->m_Class->getInstanceFields(); PyObject* res = JPySequence::newTuple((int)(staticFields.size()+instFields.size())); int i = 0; for (map::iterator curStatic = staticFields.begin(); curStatic != staticFields.end(); curStatic ++) { PyObject* f = (PyObject*)PyJPField::alloc(curStatic->second); JPySequence::setItem(res, i, f); i++; Py_DECREF(f); } for (map::iterator curInst = instFields.begin(); curInst != instFields.end(); curInst ++) { PyObject* f = (PyObject*)PyJPField::alloc(curInst->second); JPySequence::setItem(res, i, f); i++; Py_DECREF(f); } return res; } PY_STANDARD_CATCH return NULL; } PyObject* PyJPClass::getClassMethods(PyObject* o, PyObject* arg) { try { PyJPClass* self = (PyJPClass*)o; vector methods = self->m_Class->getMethods(); PyObject* res = JPySequence::newTuple((int)methods.size()); int i = 0; for (vector::iterator curMethod = methods.begin(); curMethod != methods.end(); curMethod ++) { JPMethod* mth= *curMethod; PyJPMethod* methObj = PyJPMethod::alloc(mth); JPySequence::setItem(res, i, (PyObject*)methObj); i++; Py_DECREF(methObj); } return res; } PY_STANDARD_CATCH return NULL; } PyObject* PyJPClass::newClassInstance(PyObject* o, PyObject* arg) { try { PyJPClass* self = (PyJPClass*)o; JPCleaner cleaner; //cout << "Creating a new " << self->m_Class->getName().getSimpleName() << endl; //JPyHelper::dumpSequenceRefs(arg, "Start"); vector args; Py_ssize_t len = JPyObject::length(arg); for (Py_ssize_t i = 0; i < len; i++) { PyObject* obj = JPySequence::getItem(arg, i); HostRef* ref = new HostRef((void*)obj); cleaner.add(ref); args.push_back(ref); Py_DECREF(obj); } JPObject* resObject = self->m_Class->newInstance(args); PyObject* res = JPyCObject::fromVoidAndDesc((void*)resObject, (void*)"JPObject", &PythonHostEnvironment::deleteJPObjectDestructor); //JPyHelper::dumpSequenceRefs(arg, "End"); return res; } PY_STANDARD_CATCH return NULL; } PyObject* PyJPClass::isInterface(PyObject* o, PyObject* arg) { try { PyJPClass* self = (PyJPClass*)o; if (self->m_Class->isInterface()) { return JPyBoolean::getTrue(); } return JPyBoolean::getFalse(); } PY_STANDARD_CATCH return NULL; } PyObject* PyJPClass::isSubclass(PyObject* o, PyObject* arg) { try { PyJPClass* self = (PyJPClass*)o; char* other; JPyArg::parseTuple(arg, "s", &other); JPTypeName name = JPTypeName::fromSimple(other); JPClass* otherClass = JPTypeManager::findClass(name); if (self->m_Class->isSubclass(otherClass)) { return JPyBoolean::getTrue(); } return JPyBoolean::getFalse(); } PY_STANDARD_CATCH return NULL; } PyObject* PyJPClass::isException(PyObject* o, PyObject* args) { try { JPCleaner cleaner; PyJPClass* self = (PyJPClass*)o; bool res = JPJni::isThrowable(self->m_Class->getClass()); if (res) { return JPyBoolean::getTrue(); } return JPyBoolean::getFalse(); } PY_STANDARD_CATCH; return NULL; } bool PyJPClass::check(PyObject* o) { return o->ob_type == &classClassType; } PyObject* PyJPClass::getDeclaredMethods(PyObject* o) { try { JPCleaner cleaner; PyJPClass* self = (PyJPClass*)o; vector mth = JPJni::getDeclaredMethods(self->m_Class->getClass()); PyObject* res = JPySequence::newTuple((int)mth.size()); JPTypeName methodClassName = JPTypeName::fromSimple("java.lang.reflect.Method"); JPClass* methodClass = JPTypeManager::findClass(methodClassName); for (unsigned int i = 0; i < mth.size(); i++) { jvalue v; v.l = mth[i]; HostRef* ref = methodClass->asHostObject(v); cleaner.add(ref); JPySequence::setItem(res, i, (PyObject*)ref->data()); } return res; } PY_STANDARD_CATCH; return NULL; } PyObject* PyJPClass::getConstructors(PyObject* o) { try { JPCleaner cleaner; PyJPClass* self = (PyJPClass*)o; vector mth = JPJni::getConstructors(self->m_Class->getClass()); PyObject* res = JPySequence::newTuple((int)mth.size()); JPTypeName methodClassName = JPTypeName::fromSimple("java.lang.reflect.Method"); JPClass* methodClass = JPTypeManager::findClass(methodClassName); for (unsigned int i = 0; i < mth.size(); i++) { jvalue v; v.l = mth[i]; HostRef* ref = methodClass->asHostObject(v); cleaner.add(ref); JPySequence::setItem(res, i, (PyObject*)ref->data()); } return res; } PY_STANDARD_CATCH; return NULL; } PyObject* PyJPClass::getDeclaredConstructors(PyObject* o) { try { JPCleaner cleaner; PyJPClass* self = (PyJPClass*)o; vector mth = JPJni::getDeclaredConstructors(self->m_Class->getClass()); PyObject* res = JPySequence::newTuple((int)mth.size()); JPTypeName methodClassName = JPTypeName::fromSimple("java.lang.reflect.Method"); JPClass* methodClass = JPTypeManager::findClass(methodClassName); for (unsigned int i = 0; i < mth.size(); i++) { jvalue v; v.l = mth[i]; HostRef* ref = methodClass->asHostObject(v); cleaner.add(ref); JPySequence::setItem(res, i, (PyObject*)ref->data()); } return res; } PY_STANDARD_CATCH; return NULL; } PyObject* PyJPClass::getDeclaredFields(PyObject* o) { try { JPCleaner cleaner; PyJPClass* self = (PyJPClass*)o; vector mth = JPJni::getDeclaredFields(self->m_Class->getClass()); PyObject* res = JPySequence::newTuple((int)mth.size()); JPTypeName fieldClassName = JPTypeName::fromSimple("java.lang.reflect.Field"); JPClass* fieldClass = JPTypeManager::findClass(fieldClassName); for (unsigned int i = 0; i < mth.size(); i++) { jvalue v; v.l = mth[i]; HostRef* ref = fieldClass->asHostObject(v); cleaner.add(ref); JPySequence::setItem(res, i, (PyObject*)ref->data()); } return res; } PY_STANDARD_CATCH; return NULL; } PyObject* PyJPClass::getFields(PyObject* o) { try { JPCleaner cleaner; PyJPClass* self = (PyJPClass*)o; vector mth = JPJni::getFields(self->m_Class->getClass()); PyObject* res = JPySequence::newTuple((int)mth.size()); JPTypeName fieldClassName = JPTypeName::fromSimple("java.lang.reflect.Field"); JPClass* fieldClass = JPTypeManager::findClass(fieldClassName); for (unsigned int i = 0; i < mth.size(); i++) { jvalue v; v.l = mth[i]; HostRef* ref = fieldClass->asHostObject(v); cleaner.add(ref); JPySequence::setItem(res, i, (PyObject*)ref->data()); } return res; } PY_STANDARD_CATCH; return NULL; } PyObject* PyJPClass::getModifiers(PyObject* o) { try { JPCleaner cleaner; PyJPClass* self = (PyJPClass*)o; long mod = JPJni::getClassModifiers(self->m_Class->getClass()); PyObject* res = JPyLong::fromLongLong(mod); return res; } PY_STANDARD_CATCH; return NULL; } PyObject* PyJPClass::getMethods(PyObject* o) { try { JPCleaner cleaner; PyJPClass* self = (PyJPClass*)o; vector mth = JPJni::getMethods(self->m_Class->getClass()); PyObject* res = JPySequence::newTuple((int)mth.size()); JPTypeName methodClassName = JPTypeName::fromSimple("java.lang.reflect.Method"); JPClass* methodClass = JPTypeManager::findClass(methodClassName); for (unsigned int i = 0; i < mth.size(); i++) { jvalue v; v.l = mth[i]; HostRef* ref = methodClass->asHostObject(v); cleaner.add(ref); JPySequence::setItem(res, i, (PyObject*)ref->data()); } return res; } PY_STANDARD_CATCH; return NULL; } PyObject* PyJPClass::isPrimitive(PyObject* o, PyObject* args) { try { JPCleaner cleaner; PyJPClass* self = (PyJPClass*)o; JPTypeName name = self->m_Class->getName(); if (name.isObjectType()) { return JPyBoolean::getFalse(); } return JPyBoolean::getTrue(); } PY_STANDARD_CATCH; return NULL; } PyObject* PyJPClass::isArray(PyObject* o, PyObject* args) { try { JPCleaner cleaner; PyJPClass* self = (PyJPClass*)o; JPTypeName name = self->m_Class->getName(); char c = name.getNativeName()[0]; if (c == '[') { return JPyBoolean::getTrue(); } return JPyBoolean::getFalse(); } PY_STANDARD_CATCH; return NULL; } python-jpype-0.5.4.2/src/native/python/py_monitor.cpp0000666000175000017500000000616311614007722022133 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard 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. *****************************************************************************/ #include static PyMethodDef methods[] = { {NULL}, }; static PyTypeObject monitorClassType = { PyObject_HEAD_INIT(&PyType_Type) 0, /*ob_size*/ "JavaMonitor", /*tp_name*/ sizeof(PyJPMonitor), /*tp_basicsize*/ 0, /*tp_itemsize*/ PyJPMonitor::__dealloc__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ 0, /*tp_compare*/ 0, /*tp_repr*/ 0, /*tp_as_number*/ 0, /*tp_as_sequence*/ 0, /*tp_as_mapping*/ 0, /*tp_hash */ 0, /*tp_call*/ PyJPMonitor::__str__, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT, /*tp_flags*/ "Java Monitor", /*tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ 0, /* tp_iter */ 0, /* tp_iternext */ methods, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ 0, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ 0, /* tp_init */ 0, /* tp_alloc */ PyType_GenericNew /* tp_new */ }; // Static methods void PyJPMonitor::initType(PyObject* module) { PyType_Ready(&monitorClassType); } PyJPMonitor* PyJPMonitor::alloc(JPMonitor* o) { PyJPMonitor* res = PyObject_New(PyJPMonitor, &monitorClassType); res->state = o; return res; } void PyJPMonitor::__dealloc__(PyObject* o) { PyJPMonitor* self = (PyJPMonitor*)o; delete self->state; self->ob_type->tp_free(o); } PyObject* PyJPMonitor::__str__(PyObject* o) { // TODO JPyErr::setString(PyExc_RuntimeError, "__str__ Not implemented"); return NULL; } python-jpype-0.5.4.2/src/native/python/jpype_javanio.cpp0000666000175000017500000000312511614007722022565 0ustar takakitakaki/***************************************************************************** Copyright 2004-2008 Steve M�nard 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. *****************************************************************************/ #include PyObject* JPypeJavaNio::convertToDirectBuffer(PyObject* self, PyObject* args) { TRACE_IN("convertStringToBuffer"); // Use special method defined on the TypeConverter interface ... PyObject* src; JPyArg::parseTuple(args, "O", &src); PyObject* res = NULL; if (JPyString::checkStrict(src)) { // converts to byte buffer ... JPTypeName tname = JPTypeName::fromType(JPTypeName::_byte); JPType* type = JPTypeManager::getType(tname); HostRef srcRef(src); TRACE1("Converting"); HostRef* ref = type->convertToDirectBuffer(&srcRef); JPEnv::registerRef(ref, &srcRef); TRACE1("detaching result"); res = detachRef(ref); } if (res != NULL) { return res; } RAISE(JPypeException, "Do not know how to convert to Direct Buffer"); return NULL; TRACE_OUT; } python-jpype-0.5.4.2/src/native/python/pythonenv.cpp0000666000175000017500000002303011614007722021756 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve M�nard 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. *****************************************************************************/ #include #define PY_CHECK(op) op; { PyObject* __ex = PyErr_Occurred(); if (__ex) { throw new PythonException(); }}; bool JPyString::check(PyObject* obj) { return PyString_Check(obj) || PyUnicode_Check(obj); } bool JPyString::checkStrict(PyObject* obj) { return PyString_Check(obj); } bool JPyString::checkUnicode(PyObject* obj) { return PyUnicode_Check(obj); } Py_UNICODE* JPyString::AsUnicode(PyObject* obj) { return PyUnicode_AsUnicode(obj); } string JPyString::asString(PyObject* obj) { TRACE_IN("JPyString::asString"); PY_CHECK( string res = string(PyString_AsString(obj)) ); return res; TRACE_OUT; } JCharString JPyString::asJCharString(PyObject* obj) { PyObject* torelease = NULL; TRACE_IN("JPyString::asJCharString"); if (PyString_Check(obj)) { PY_CHECK( obj = PyUnicode_FromObject(obj) ); torelease = obj; } Py_UNICODE* val = PyUnicode_AS_UNICODE(obj); Py_ssize_t length = JPyObject::length(obj); JCharString res(length); for (int i = 0; val[i] != 0; i++) { res[i] = (jchar)val[i]; } if (torelease != NULL) { Py_DECREF(torelease); } return res; TRACE_OUT; } PyObject* JPyString::fromUnicode(const jchar* str, int len) { Py_UNICODE* value = new Py_UNICODE[len+1]; value[len] = 0; for (int i = 0; i < len; i++) { value[i] = (Py_UNICODE)str[i]; } PY_CHECK( PyObject* obj = PyUnicode_FromUnicode(value, len) ); delete value; return obj; } PyObject* JPyString::fromString(const char* str) { PY_CHECK( PyObject* obj = PyString_FromString(str) ); return obj; } Py_ssize_t JPyString::AsStringAndSize(PyObject *obj, char **buffer, Py_ssize_t *length) { PY_CHECK( Py_ssize_t res = PyString_AsStringAndSize(obj, buffer, length) ); return res; } PyObject* JPySequence::newTuple(Py_ssize_t sz) { PY_CHECK( PyObject* res = PyTuple_New(sz);); return res; } PyObject* JPySequence::newList(Py_ssize_t sz) { PY_CHECK( PyObject* res = PyList_New(sz);); return res; } void JPySequence::setItem(PyObject* lst, Py_ssize_t ndx, PyObject* val) { if (PyList_Check(lst)) { Py_XINCREF(val); PY_CHECK( PyList_SetItem(lst, ndx, val) ); } else if (PyTuple_Check(lst)) { Py_XINCREF(val); PY_CHECK( PyTuple_SetItem(lst, ndx, val) ); } else { Py_XINCREF(val); PY_CHECK( PySequence_SetItem(lst, ndx, val) ); } } bool JPySequence::check(PyObject* obj) { if (PySequence_Check(obj) || PyList_Check(obj) || PyTuple_Check(obj)) { return true; } return false; } PyObject* JPySequence::getItem(PyObject* tuple, Py_ssize_t ndx) { PY_CHECK( PyObject* res = PySequence_GetItem(tuple, ndx) ); return res; } Py_ssize_t JPyObject::length(PyObject* obj) { PY_CHECK( Py_ssize_t res = PyObject_Length(obj) ); return res; } bool JPyObject::hasAttr(PyObject* m, PyObject* k) { PY_CHECK( int res = PyObject_HasAttr(m, k) ); if (res) return true; return false; } PyObject* JPyObject::getAttr(PyObject* m, PyObject* k) { PY_CHECK( PyObject* res = PyObject_GetAttr(m, k) ); return res; } PyObject* JPyObject::getAttrString(PyObject* m, const char* k) { PY_CHECK( PyObject* res = PyObject_GetAttrString(m, (char*)k) ); return res; } void JPyObject::setAttrString(PyObject* m, const char* k, PyObject *v) { PY_CHECK( PyObject_SetAttrString(m, (char*)k, v ) ); } PyObject* JPyObject::call(PyObject* c, PyObject* a, PyObject* w) { PY_CHECK( PyObject* res = PyObject_Call(c, a, w) ); return res; } bool JPyObject::isInstance(PyObject* obj, PyObject* t) { PY_CHECK( int res = PyObject_IsInstance(obj, t) ); if (res) { return true; } return false; } bool JPyObject::isSubclass(PyObject* obj, PyObject* t) { int res = PyObject_IsSubclass(obj, t); if (res) { return true; } return false; } void JPyErr::setString(PyObject* exClass, const char* str) { PyErr_SetString(exClass, str); } void JPyErr::setObject(PyObject* exClass, PyObject* str) { PyErr_SetObject(exClass, str); } PyObject* JPyInt::fromLong(long l) { TRACE_IN("JPyInt::fromLong"); PY_CHECK( PyObject* res = PyInt_FromLong(l) ); return res; TRACE_OUT; } bool JPyInt::check(PyObject* obj) { return PyInt_Check(obj); } long JPyInt::asLong(PyObject* obj) { return PyInt_AsLong(obj); } PyObject* JPyLong::fromLongLong(PY_LONG_LONG l) { TRACE_IN("JPyLong::fromLongLong"); PY_CHECK( PyObject* res = PyLong_FromLongLong(l) ); return res; TRACE_OUT; } bool JPyLong::check(PyObject* obj) { return PyLong_Check(obj); } PY_LONG_LONG JPyLong::asLongLong(PyObject* obj) { return PyLong_AsLongLong(obj); } PyObject* JPyFloat::fromDouble(double l) { PY_CHECK( PyObject* res = PyFloat_FromDouble(l) ); return res; } bool JPyFloat::check(PyObject* obj) { return PyFloat_Check(obj); } double JPyFloat::asDouble(PyObject* obj) { return PyFloat_AsDouble(obj); } PyObject* JPyBoolean::getTrue() { return PyInt_FromLong(1); } PyObject* JPyBoolean::getFalse() { return PyInt_FromLong(0); } bool JPyDict::contains(PyObject* m, PyObject* k) { PY_CHECK( int res = PyMapping_HasKey(m, k) ); if (res) return true; return false; } PyObject* JPyDict::getItem(PyObject* m, PyObject* k) { PY_CHECK( PyObject* res = PyDict_GetItem(m, k) ); Py_XINCREF(res); return res; } bool JPyDict::check(PyObject* obj) { return PyDict_Check(obj); } PyObject* JPyDict::getKeys(PyObject* m) { PY_CHECK( PyObject* res = PyDict_Keys(m) ); return res; } PyObject* JPyDict::copy(PyObject* m) { PY_CHECK( PyObject* res = PyDict_Copy(m) ); return res; } PyObject* JPyDict::newInstance() { PY_CHECK( PyObject* res = PyDict_New() ); return res; } void JPyDict::setItemString(PyObject* d, PyObject* o, const char* n) { PY_CHECK( PyDict_SetItemString(d, n, o) ); } PythonException::PythonException() { TRACE_IN("PythonException::PythonException"); PyObject* traceback; PyErr_Fetch(&m_ExceptionClass, &m_ExceptionValue, &traceback); Py_INCREF(m_ExceptionClass); Py_INCREF(m_ExceptionValue); PyObject* name = JPyObject::getAttrString(m_ExceptionClass, "__name__"); string ascname = JPyString::asString(name); TRACE1(ascname); Py_DECREF(name); TRACE1(m_ExceptionValue->ob_type->tp_name); if (JPySequence::check(m_ExceptionValue)) { } PyErr_Restore(m_ExceptionClass, m_ExceptionValue, traceback); TRACE_OUT; } PythonException::PythonException(PythonException& ex) { m_ExceptionClass = ex.m_ExceptionClass; Py_INCREF(m_ExceptionClass); m_ExceptionValue = ex.m_ExceptionValue; Py_INCREF(m_ExceptionValue); } PythonException::~PythonException() { Py_XDECREF(m_ExceptionClass); Py_XDECREF(m_ExceptionValue); } PyObject* PythonException::getJavaException() { PyObject* retVal = NULL; // If the exception was caught further down ... if (JPySequence::check(m_ExceptionValue) && JPyObject::length(m_ExceptionValue) == 1) { PyObject* v0 = JPySequence::getItem(m_ExceptionValue, 0); if (JPySequence::check(v0) && JPyObject::length(v0) == 2) { PyObject* v00 = JPySequence::getItem(v0, 0); PyObject* v01 = JPySequence::getItem(v0, 1); if (v00 == hostEnv->getSpecialConstructorKey()) { retVal = v01; } else { Py_DECREF(v01); } Py_DECREF(v00); } else { Py_DECREF(v0); } } else { Py_XINCREF(m_ExceptionValue); retVal = m_ExceptionValue; } return retVal; } PyObject* JPyCObject::fromVoid(void* data, void (*destr)(void *)) { PY_CHECK( PyObject* res = PyCObject_FromVoidPtr(data, destr) ); return res; } PyObject* JPyCObject::fromVoidAndDesc(void* data, void* desc, void (*destr)(void *, void*)) { PY_CHECK( PyObject* res = PyCObject_FromVoidPtrAndDesc(data, desc, destr) ); return res; } void* JPyCObject::asVoidPtr(PyObject* obj) { PY_CHECK( void* res = PyCObject_AsVoidPtr(obj) ); return res; } void* JPyCObject::getDesc(PyObject* obj) { PY_CHECK( void* res = PyCObject_GetDesc(obj) ); return res; } bool JPyCObject::check(PyObject* obj) { return PyCObject_Check(obj); } bool JPyType::check(PyObject* obj) { return PyType_Check(obj); } bool JPyType::isSubclass(PyObject* o1, PyObject* o2) { if (PyType_IsSubtype((PyTypeObject*)o1, (PyTypeObject*)o2)) { return true; } return false; } void JPyHelper::dumpSequenceRefs(PyObject* seq, const char* comment) { cerr << "Dumping sequence state at " << comment << endl; cerr << " sequence has " << (long)seq->ob_refcnt << " reference(s)" << endl; Py_ssize_t dx = PySequence_Length(seq); for (Py_ssize_t i = 0; i < dx; i++) { PyObject* el = PySequence_GetItem(seq, i); Py_XDECREF(el); // PySequence_GetItem return a new ref cerr << " item[" << (long)i << "] has " << (long)el->ob_refcnt << " references" << endl; } } python-jpype-0.5.4.2/src/native/python/jpype_javaarray.cpp0000666000175000017500000001241711614007722023122 0ustar takakitakaki/***************************************************************************** Copyright 2004-2008 Steve Menard 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. *****************************************************************************/ #include PyObject* JPypeJavaArray::findArrayClass(PyObject* obj, PyObject* args) { try { char* cname; JPyArg::parseTuple(args, "s", &cname); JPTypeName name = JPTypeName::fromSimple(cname); JPArrayClass* claz = JPTypeManager::findArrayClass(name); if (claz == NULL) { Py_INCREF(Py_None); return Py_None; } PyObject* res = JPyCObject::fromVoidAndDesc((void*)claz, (void*)"jclass", NULL); return res; } PY_STANDARD_CATCH; PyErr_Clear(); Py_INCREF(Py_None); return Py_None; } PyObject* JPypeJavaArray::setJavaArrayClass(PyObject* self, PyObject* arg) { try { PyObject* t; JPyArg::parseTuple(arg, "O", &t); hostEnv->setJavaArrayClass(t); Py_INCREF(Py_None); return Py_None; } PY_STANDARD_CATCH return NULL; } PyObject* JPypeJavaArray::setGetJavaArrayClassMethod(PyObject* self, PyObject* arg) { try { PyObject* t; JPyArg::parseTuple(arg, "O", &t); hostEnv->setGetJavaArrayClassMethod(t); Py_INCREF(Py_None); return Py_None; } PY_STANDARD_CATCH return NULL; } PyObject* JPypeJavaArray::getArrayLength(PyObject* self, PyObject* arg) { try { PyObject* arrayObject; JPyArg::parseTuple(arg, "O!", &PyCObject_Type, &arrayObject); JPArray* a = (JPArray*)JPyCObject::asVoidPtr(arrayObject); int res = a->getLength(); return JPyInt::fromLong(res); } PY_STANDARD_CATCH return NULL; } PyObject* JPypeJavaArray::getArrayItem(PyObject* self, PyObject* arg) { try { PyObject* arrayObject; int ndx; JPyArg::parseTuple(arg, "O!i", &PyCObject_Type, &arrayObject, &ndx); JPArray* a = (JPArray*)JPyCObject::asVoidPtr(arrayObject); HostRef* res = a->getItem(ndx); return detachRef(res); } PY_STANDARD_CATCH return NULL; } PyObject* JPypeJavaArray::getArraySlice(PyObject* self, PyObject* arg) { try { PyObject* arrayObject; int ndx; int ndx2; JPyArg::parseTuple(arg, "O!ii", &PyCObject_Type, &arrayObject, &ndx, &ndx2); JPArray* a = (JPArray*)JPyCObject::asVoidPtr(arrayObject); vector values = a->getRange(ndx, ndx2); JPCleaner cleaner; PyObject* res = JPySequence::newList((int)values.size()); for (unsigned int i = 0; i < values.size(); i++) { JPySequence::setItem(res, i, (PyObject*)values[i]->data()); cleaner.add(values[i]); } return res; } PY_STANDARD_CATCH return NULL; } PyObject* JPypeJavaArray::setArraySlice(PyObject* self, PyObject* arg) { try { PyObject* arrayObject; int ndx = -1; int ndx2 = -1; PyObject* val; JPyArg::parseTuple(arg, "O!iiO", &PyCObject_Type, &arrayObject, &ndx, &ndx2, &val); JPArray* a = (JPArray*)JPyCObject::asVoidPtr(arrayObject); Py_ssize_t len = JPyObject::length(val); vector values; JPCleaner cleaner; for (Py_ssize_t i = 0; i < len; i++) { HostRef* v = new HostRef(JPySequence::getItem(val, i), false); values.push_back(v); cleaner.add(v); } a->setRange(ndx, ndx2, values); Py_INCREF(Py_None); return Py_None; } PY_STANDARD_CATCH return NULL; } PyObject* JPypeJavaArray::setArrayItem(PyObject* self, PyObject* arg) { try { PyObject* arrayObject; int ndx; PyObject* value; JPyArg::parseTuple(arg, "O!iO", &PyCObject_Type, &arrayObject, &ndx, &value); JPArray* a = (JPArray*)JPyCObject::asVoidPtr(arrayObject); JPCleaner cleaner; HostRef* v = new HostRef(value); cleaner.add(v); a->setItem(ndx, v); Py_INCREF(Py_None); return Py_None; } PY_STANDARD_CATCH return NULL; } PyObject* JPypeJavaArray::newArray(PyObject* self, PyObject* arg) { try { PyObject* arrayObject; int sz; JPyArg::parseTuple(arg, "O!i", &PyCObject_Type, &arrayObject, &sz); JPArrayClass* a = (JPArrayClass*)JPyCObject::asVoidPtr(arrayObject); JPArray* v = a->newInstance(sz); PyObject* res = JPyCObject::fromVoidAndDesc(v, (void*)"JPArray", PythonHostEnvironment::deleteJPArrayDestructor); return res; } PY_STANDARD_CATCH return NULL; } PyObject* JPypeJavaArray::setArrayValues(PyObject* self, PyObject* arg) { try { PyObject* arrayObject; PyObject* values; JPyArg::parseTuple(arg, "O!O", &PyCObject_Type, &arrayObject, &values); JPArray* a = (JPArray*)JPyCObject::asVoidPtr(arrayObject); JPArrayClass* arrayClass = a->getClass(); HostRef valuesRef(values); arrayClass->getComponentType()->setArrayValues((jarray)a->getObject(), &valuesRef); Py_INCREF(Py_None); return Py_None; } PY_STANDARD_CATCH return NULL; } python-jpype-0.5.4.2/src/native/python/jpype_javaclass.cpp0000666000175000017500000000421411614007722023105 0ustar takakitakaki/***************************************************************************** Copyright 2004-2008 Steve Menard 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. *****************************************************************************/ #include PyObject* JPypeJavaClass::setJavaLangObjectClass(PyObject* self, PyObject* arg) { try { PyObject* t; JPyArg::parseTuple(arg, "O", &t); hostEnv->setJavaLangObjectClass(t); Py_INCREF(Py_None); return Py_None; } PY_STANDARD_CATCH return NULL; } PyObject* JPypeJavaClass::setGetClassMethod(PyObject* self, PyObject* arg) { try { PyObject* t; JPyArg::parseTuple(arg, "O", &t); hostEnv->setGetJavaClassMethod(t); Py_INCREF(Py_None); return Py_None; } PY_STANDARD_CATCH return NULL; } PyObject* JPypeJavaClass::setSpecialConstructorKey(PyObject* self, PyObject* arg) { try { PyObject* t; JPyArg::parseTuple(arg, "O", &t); hostEnv->setSpecialConstructorKey(t); Py_INCREF(Py_None); return Py_None; } PY_STANDARD_CATCH return NULL; } PyObject* JPypeJavaClass::findClass(PyObject* obj, PyObject* args) { TRACE_IN("JPypeModule::findClass"); try { char* cname; JPyArg::parseTuple(args, "s", &cname); TRACE1(cname); JPTypeName name = JPTypeName::fromSimple(cname); JPClass* claz = JPTypeManager::findClass(name); if (claz == NULL) { Py_INCREF(Py_None); return Py_None; } PyObject* res = (PyObject*)PyJPClass::alloc(claz); return res; } PY_STANDARD_CATCH; PyErr_Clear(); Py_INCREF(Py_None); return Py_None; TRACE_OUT; } python-jpype-0.5.4.2/src/native/common/0000775000175000017500000000000011620747357017203 5ustar takakitakakipython-jpype-0.5.4.2/src/native/common/jp_platform_win32.cpp0000666000175000017500000000155711614007722023244 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard 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. *****************************************************************************/ #ifdef JPYPE_WIN32 void longToHexString(long value, char* outStr) { ltoa(value, outStr, 16); } #endif python-jpype-0.5.4.2/src/native/common/jp_arrayclass.cpp0000666000175000017500000001101311614007722022526 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve M�nard 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. *****************************************************************************/ #include JPArrayClass::JPArrayClass(const JPTypeName& tname, jclass c) : JPClassBase(tname, c) { JPTypeName compname = m_Name.getComponentName(); m_ComponentType = JPTypeManager::getType(compname); } JPArrayClass::~JPArrayClass() { } EMatchType JPArrayClass::canConvertToJava(HostRef* o) { JPCleaner cleaner; if (JPEnv::getHost()->isNone(o)) { return _implicit; } if (JPEnv::getHost()->isArray(o)) { JPArray* a = JPEnv::getHost()->asArray(o); JPArrayClass* ca = a->getClass(); if (ca == this) { return _exact; } if (JPEnv::getJava()->IsAssignableFrom(ca->m_Class, m_Class)) { return _implicit; } } else if (JPEnv::getHost()->isUnicodeString(o) && m_ComponentType->getName().getType() ==JPTypeName::_char) { // Strings are also char[] return _implicit; } else if (JPEnv::getHost()->isByteString(o) && m_ComponentType->getName().getType() ==JPTypeName::_byte) { // Strings are also char[] return _implicit; } else if (JPEnv::getHost()->isSequence(o)) { EMatchType match = _implicit; int length = JPEnv::getHost()->getSequenceLength(o); for (int i = 0; i < length && match > _none; i++) { HostRef* obj = JPEnv::getHost()->getSequenceItem(o, i); cleaner.add(obj); EMatchType newMatch = m_ComponentType->canConvertToJava(obj); if (newMatch < match) { match = newMatch; } } return match; } return _none; } HostRef* JPArrayClass::asHostObject(jvalue val) { if (val.l == NULL) { return JPEnv::getHost()->getNone(); } return JPEnv::getHost()->newArray(new JPArray(m_Name, (jarray)val.l)); } jvalue JPArrayClass::convertToJava(HostRef* obj) { JPCleaner cleaner; jvalue res; res.l = NULL; if (JPEnv::getHost()->isArray(obj)) { JPArray* a = JPEnv::getHost()->asArray(obj); res = a->getValue(); } else if (JPEnv::getHost()->isByteString(obj) && m_ComponentType->getName().getType() == JPTypeName::_byte && sizeof(char) == sizeof(jbyte)) { char* rawData; long size; JPEnv::getHost()->getRawByteString(obj, &rawData, size); jbyteArray array = JPEnv::getJava()->NewByteArray(size); cleaner.addLocal(array); res.l = array; jboolean isCopy; jbyte* contents = JPEnv::getJava()->GetByteArrayElements(array, &isCopy); memcpy(contents, rawData, size*sizeof(jbyte)); JPEnv::getJava()->ReleaseByteArrayElements(array, contents, 0); cleaner.removeLocal(array); } else if (JPEnv::getHost()->isUnicodeString(obj) && m_ComponentType->getName().getType() == JPTypeName::_char && JPEnv::getHost()->getUnicodeSize() == sizeof(jchar)) { jchar* rawData; long size; JPEnv::getHost()->getRawUnicodeString(obj, &rawData, size); jcharArray array = JPEnv::getJava()->NewCharArray(size); cleaner.addLocal(array); res.l = array; jboolean isCopy; jchar* contents = JPEnv::getJava()->GetCharArrayElements(array, &isCopy); memcpy(contents, rawData, size*sizeof(jchar)); JPEnv::getJava()->ReleaseCharArrayElements(array, contents, 0); cleaner.removeLocal(array); } else if (JPEnv::getHost()->isSequence(obj)) { int length = JPEnv::getHost()->getSequenceLength(obj); jarray array = m_ComponentType->newArrayInstance(length); cleaner.addLocal(array); res.l = array; for (int i = 0; i < length ; i++) { HostRef* obj2 = JPEnv::getHost()->getSequenceItem(obj, i); cleaner.add(obj2); m_ComponentType->setArrayItem(array, i, obj2); } cleaner.removeLocal(array); } return res; } JPArray* JPArrayClass::newInstance(int length) { JPCleaner cleaner; jarray array = m_ComponentType->newArrayInstance(length); cleaner.addLocal(array); JPArray* res = new JPArray(getName(), array); return res; } python-jpype-0.5.4.2/src/native/common/jp_classbase.cpp0000666000175000017500000000210111614007722022320 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard 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. *****************************************************************************/ #include JPClassBase::JPClassBase(const JPTypeName& tname, jclass c) : JPObjectType(JPTypeName::_unknown, JPTypeName::fromType(JPTypeName::_void)), m_Name(tname) { m_Class = (jclass)JPEnv::getJava()->NewGlobalRef(c); } JPClassBase::~JPClassBase() { JPEnv::getJava()->DeleteGlobalRef(m_Class); } python-jpype-0.5.4.2/src/native/common/jp_proxy.cpp0000666000175000017500000001723411614007722021556 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve M�nard 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. *****************************************************************************/ #include JNIEXPORT jobject JNICALL Java_jpype_JPypeInvocationHandler_hostInvoke( JNIEnv *env, jclass clazz, jstring name, jlong hostObj, jobjectArray args, jobjectArray types, jclass returnType) { TRACE_IN("Java_jpype_JPypeInvocationHandler_hostInvoke"); void* callbackState = JPEnv::getHost()->prepareCallbackBegin(); JPCleaner cleaner; try { string cname = JPJni::asciiFromJava(name); HostRef* hostObjRef = (HostRef*)hostObj; HostRef* callable = JPEnv::getHost()->getCallableFrom(hostObjRef, cname); cleaner.add(callable); if (callable == NULL || callable->isNull() || JPEnv::getHost()->isNone(callable)) { JPEnv::getJava()->ThrowNew(JPJni::s_NoSuchMethodErrorClass, cname.c_str()); JPEnv::getHost()->prepareCallbackFinish(callbackState); return NULL; } // convert the arguments into a python list jsize argLen = JPEnv::getJava()->GetArrayLength(types); vector hostArgs; std::vector argTypes; for (jsize j = 0; j < argLen; j++) { jclass c = (jclass)JPEnv::getJava()->GetObjectArrayElement(types, j); cleaner.addLocal(c); JPTypeName tn = JPJni::getName(c); argTypes.push_back(tn); } for (int i = 0; i < argLen; i++) { jobject obj = JPEnv::getJava()->GetObjectArrayElement(args, i); cleaner.addLocal(obj); JPTypeName t = argTypes[i]; jvalue v; v.l = obj; HostRef* o = JPTypeManager::getType(t)->asHostObjectFromObject(v); cleaner.add(o); hostArgs.push_back(o); } HostRef* returnValue = JPEnv::getHost()->callObject(callable, hostArgs); cleaner.add(returnValue); JPTypeName returnT = JPJni::getName(returnType); if (returnValue == NULL || returnValue->isNull() || JPEnv::getHost()->isNone(returnValue)) { if (returnT.getType() != JPTypeName::_void && returnT.getType() < JPTypeName::_object) { JPEnv::getJava()->ThrowNew(JPJni::s_RuntimeExceptionClass, "Return value is None when it cannot be"); JPEnv::getHost()->prepareCallbackFinish(callbackState); return NULL; } } if (returnT.getType() == JPTypeName::_void) { JPEnv::getHost()->prepareCallbackFinish(callbackState); return NULL; } JPType* rt = JPTypeManager::getType(returnT); if (rt->canConvertToJava(returnValue) == _none) { JPEnv::getJava()->ThrowNew(JPJni::s_RuntimeExceptionClass, "Return value is not compatible with required type."); JPEnv::getHost()->prepareCallbackFinish(callbackState); return NULL; } jobject returnObj = rt->convertToJavaObject(returnValue); JPEnv::getHost()->prepareCallbackFinish(callbackState); return returnObj; } catch(HostException* ex) { JPEnv::getHost()->clearError(); if (JPEnv::getHost()->isJavaException(ex)) { JPCleaner cleaner; HostRef* javaExcRef = JPEnv::getHost()->getJavaException(ex); JPObject* javaExc = JPEnv::getHost()->asObject(javaExcRef); cleaner.add(javaExcRef); jobject obj = javaExc->getObject(); cleaner.addLocal(obj); JPEnv::getJava()->Throw((jthrowable)obj); } else { JPEnv::getJava()->ThrowNew(JPJni::s_RuntimeExceptionClass, "Python exception thrown"); } } catch(JavaException*) { cerr << "Java exception at " << __FILE__ << ":" << __LINE__ << endl; } catch(JPypeException* ex) { JPEnv::getJava()->ThrowNew(JPJni::s_RuntimeExceptionClass, ex->getMsg()); } JPEnv::getHost()->prepareCallbackFinish(callbackState); return NULL; TRACE_OUT; } JNIEXPORT jobject JNICALL Java_jpype_ref_JPypeReferenceQueue_removeHostReference( JNIEnv *env, jclass clazz, jlong hostObj) { TRACE_IN("Java_jpype_ref_JPypeReferenceQueue_removeHostReference"); void* callbackState = JPEnv::getHost()->prepareCallbackBegin(); if (hostObj >0) { HostRef* hostObjRef = (HostRef*)hostObj; //JPEnv::getHost()->printReferenceInfo(hostObjRef); delete hostObjRef; } JPEnv::getHost()->prepareCallbackFinish(callbackState); return NULL; TRACE_OUT; } static jclass handlerClass; static jclass referenceClass; static jclass referenceQueueClass; static jmethodID invocationHandlerConstructorID; static jfieldID hostObjectID; void JPProxy::init() { TRACE_IN("JPProxy::init"); // build the proxy class ... jobject cl = JPJni::getSystemClassLoader(); JPCleaner cleaner; jclass handler = JPEnv::getJava()->DefineClass("jpype/JPypeInvocationHandler", cl, JPypeInvocationHandler, getJPypeInvocationHandlerLength()); handlerClass = (jclass)JPEnv::getJava()->NewGlobalRef(handler); cleaner.addLocal(handler); JNINativeMethod method[1]; method[0].name = "hostInvoke"; method[0].signature = "(Ljava/lang/String;J[Ljava/lang/Object;[Ljava/lang/Class;Ljava/lang/Class;)Ljava/lang/Object;"; method[0].fnPtr = (void*)&Java_jpype_JPypeInvocationHandler_hostInvoke; hostObjectID = JPEnv::getJava()->GetFieldID(handler, "hostObject", "J"); invocationHandlerConstructorID = JPEnv::getJava()->GetMethodID(handler, "", "()V"); JPEnv::getJava()->RegisterNatives(handlerClass, method, 1); // Not quite the right area ... but I;m doing similar here already so let's register the other classes too jclass reference = JPEnv::getJava()->DefineClass("jpype/ref/JPypeReference", cl, JPypeReference, getJPypeReferenceLength()); jclass referenceQueue = JPEnv::getJava()->DefineClass("jpype/ref/JPypeReferenceQueue", cl, JPypeReferenceQueue, getJPypeReferenceQueueLength()); referenceClass = (jclass)JPEnv::getJava()->NewGlobalRef(reference); referenceQueueClass = (jclass)JPEnv::getJava()->NewGlobalRef(referenceQueue); cleaner.addLocal(reference); cleaner.addLocal(referenceQueue); JNINativeMethod method2[1]; method2[0].name = "removeHostReference"; method2[0].signature = "(J)V"; method2[0].fnPtr = (void*)&Java_jpype_ref_JPypeReferenceQueue_removeHostReference; JPEnv::getJava()->RegisterNatives(referenceQueueClass, method2, 1); TRACE_OUT; } JPProxy::JPProxy(HostRef* inst, vector& intf) { m_Instance = inst->copy(); jobjectArray ar = JPEnv::getJava()->NewObjectArray((int)intf.size(), JPJni::s_ClassClass, NULL); m_Interfaces = (jobjectArray)JPEnv::getJava()->NewGlobalRef(ar); JPEnv::getJava()->DeleteLocalRef(ar); for (unsigned int i = 0; i < intf.size(); i++) { m_InterfaceClasses.push_back((jclass)JPEnv::getJava()->NewGlobalRef(intf[i])); JPEnv::getJava()->SetObjectArrayElement(m_Interfaces, i, m_InterfaceClasses[i]); } m_Handler = JPEnv::getJava()->NewObject(handlerClass, invocationHandlerConstructorID); JPEnv::getJava()->SetLongField(m_Handler, hostObjectID, (jlong)inst->copy()); } jobject JPProxy::getProxy() { JPCleaner cleaner; jobject cl = JPJni::getSystemClassLoader(); cleaner.addLocal(cl); jvalue v[3]; v[0].l = cl; v[1].l = m_Interfaces; v[2].l = m_Handler; jobject res = JPEnv::getJava()->CallStaticObjectMethodA(JPJni::s_ProxyClass, JPJni::s_NewProxyInstanceID, v); return res; } python-jpype-0.5.4.2/src/native/common/jp_monitor.cpp0000666000175000017500000000201311614007722022051 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard 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. *****************************************************************************/ #include JPMonitor::JPMonitor(jobject o) { JPEnv::getJava()->MonitorEnter(o); m_Object = JPEnv::getJava()->NewGlobalRef(o); } JPMonitor::~JPMonitor() { JPEnv::getJava()->MonitorExit(m_Object); JPEnv::getJava()->DeleteGlobalRef(m_Object); } python-jpype-0.5.4.2/src/native/common/jp_array.cpp0000666000175000017500000000545111614007722021511 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard 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. *****************************************************************************/ #include JPArray::JPArray(JPTypeName name, jarray inst) { m_Class = JPTypeManager::findArrayClass(name); m_Object = (jarray)JPEnv::getJava()->NewGlobalRef(inst); } JPArray::~JPArray() { JPEnv::getJava()->DeleteGlobalRef(m_Object); } int JPArray::getLength() { return JPEnv::getJava()->GetArrayLength(m_Object); } vector JPArray::getRange(int start, int stop) { TRACE_IN("JPArray::getRange"); JPType* compType = m_Class->getComponentType(); TRACE2("Compoennt type", compType->getName().getSimpleName()); vector res = compType->getArrayRange(m_Object, start, stop-start); return res; TRACE_OUT; } void JPArray::setRange(int start, int stop, vector& val) { JPCleaner cleaner; JPType* compType = m_Class->getComponentType(); int len = stop-start; size_t plength = val.size(); if (len != plength) { std::stringstream out; out << "Slice assignment must be of equal lengths : " << len << " != " << plength; RAISE(JPypeException, out.str()); } for (size_t i = 0; i < plength; i++) { HostRef* v = val[i]; if ( compType->canConvertToJava(v)<= _explicit) { RAISE(JPypeException, "Unable to convert."); } } compType->setArrayRange(m_Object, start, stop-start, val); } void JPArray::setItem(int ndx, HostRef* val) { JPType* compType = m_Class->getComponentType(); if (compType->canConvertToJava(val) <= _explicit) { RAISE(JPypeException, "Unable to convert."); } compType->setArrayItem(m_Object, ndx, val); } HostRef* JPArray::getItem(int ndx) { JPType* compType = m_Class->getComponentType(); return compType->getArrayItem(m_Object, ndx); } JPType* JPArray::getType() { return m_Class; } jvalue JPArray::getValue() { jvalue val; val.l = JPEnv::getJava()->NewLocalRef(m_Object); return val; } JCharString JPArray::toString() { static const char* value = "Array wrapper"; jchar res[14]; res[13] = 0; for (int i = 0; value[i] != 0; i++) { res[i] = value[i]; } return res; } python-jpype-0.5.4.2/src/native/common/jp_methodoverload.cpp0000666000175000017500000001604011614007722023403 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve M�nard 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. *****************************************************************************/ #include JPMethodOverload::JPMethodOverload() { m_Method = NULL; } JPMethodOverload::JPMethodOverload(const JPMethodOverload& o) : m_Class(o.m_Class), m_MethodID(o.m_MethodID), m_ReturnType(o.m_ReturnType), m_Arguments(o.m_Arguments), m_IsStatic(o.m_IsStatic), m_IsFinal(o.m_IsFinal), m_IsConstructor(o.m_IsConstructor) { m_Method = JPEnv::getJava()->NewGlobalRef(o.m_Method); } JPMethodOverload::JPMethodOverload(JPClass* claz, jobject mth) { m_Class = claz; m_Method = JPEnv::getJava()->NewGlobalRef(mth); // static m_IsStatic = JPJni::isMemberStatic(mth); m_IsFinal = JPJni::isMemberStatic(m_Method); // Method ID m_MethodID = JPEnv::getJava()->FromReflectedMethod(mth); m_IsConstructor = JPJni::isConstructor(m_Method); // return type if (! m_IsConstructor) { m_ReturnType = JPJni::getReturnType(mth); } // arguments m_Arguments = JPJni::getParameterTypes(mth, m_IsConstructor); // Add the implicit "this" argument if (! m_IsStatic && ! m_IsConstructor) { m_Arguments.insert(m_Arguments.begin(), 1, claz->getName()); } } JPMethodOverload::~JPMethodOverload() { JPEnv::getJava()->DeleteGlobalRef(m_Method); } string JPMethodOverload::getSignature() { stringstream res; res << "("; for (vector::iterator it = m_Arguments.begin(); it != m_Arguments.end(); it++) { res << it->getNativeName(); } res << ")" ; return res.str(); } string JPMethodOverload::getArgumentString() { stringstream res; res << "("; bool first = true; for (vector::iterator it = m_Arguments.begin(); it != m_Arguments.end(); it++) { if (! first) { res << ", "; } else { first = false; } res << it->getSimpleName(); } res << ")"; return res.str(); } bool JPMethodOverload::isSameOverload(JPMethodOverload& o) { if (isStatic() != o.isStatic()) { return false; } if (m_Arguments.size() != o.m_Arguments.size()) { return false; } TRACE_IN("JPMethodOverload::isSameOverload"); TRACE2("My sig", getSignature()); TRACE2("It's sig", o.getSignature()); int start = 0; if (! isStatic()) { start = 1; } for (unsigned int i = start; i < m_Arguments.size() && i < o.m_Arguments.size(); i++) { JPTypeName mine = m_Arguments[i]; JPTypeName his = o.m_Arguments[i]; string mineSimple = mine.getSimpleName(); string hisSimple = his.getSimpleName(); if (mineSimple != hisSimple) { return false; } } return true; TRACE_OUT; } EMatchType JPMethodOverload::matches(bool ignoreFirst, vector& arg) { TRACE_IN("JPMethodOverload::matches"); size_t len = arg.size(); if (len != m_Arguments.size()) { return _none; } EMatchType lastMatch = _exact; for (unsigned int i = 0; i < len; i++) { if (i == 0 && ignoreFirst) { continue; } HostRef* obj = arg[i]; JPType* type = JPTypeManager::getType(m_Arguments[i]); EMatchType match = type->canConvertToJava(obj); if (match < _implicit) { return _none; } if (match < lastMatch) { lastMatch = match; } } return lastMatch; TRACE_OUT; } HostRef* JPMethodOverload::invokeStatic(vector& arg) { TRACE_IN("JPMethodOverload::invokeStatic"); JPCleaner cleaner; size_t len = arg.size(); JPMallocCleaner v(len); JPMallocCleaner types(len); for (unsigned int i = 0; i < len; i++) { HostRef* obj = arg[i]; types[i] = JPTypeManager::getType(m_Arguments[i]); v[i] = types[i]->convertToJava(obj); if (types[i]->isObjectType()) { cleaner.addLocal(v[i].l); } } jclass claz = m_Class->getClass(); cleaner.addLocal(claz); JPType* retType = JPTypeManager::getType(m_ReturnType); return retType->invokeStatic(claz, m_MethodID, v.borrow()); TRACE_OUT; } HostRef* JPMethodOverload::invokeInstance(vector& args) { TRACE_IN("JPMethodOverload::invokeInstance"); HostRef* res; { JPCleaner cleaner; // Arg 0 is "this" HostRef* self = args[0]; JPObject* selfObj = JPEnv::getHost()->asObject(self); size_t len = args.size(); JPMallocCleaner v(len-1); for (unsigned int i = 1; i < len; i++) { HostRef* obj = args[i]; JPType* type = JPTypeManager::getType(m_Arguments[i]); v[i-1] = type->convertToJava(obj); if (type->isObjectType()) { cleaner.addLocal(v[i-1].l); } } JPType* retType = JPTypeManager::getType(m_ReturnType); jobject c = selfObj->getObject(); cleaner.addLocal(c); jclass clazz = m_Class->getClass(); cleaner.addLocal(clazz); res = retType->invoke(c, clazz, m_MethodID, v.borrow()); TRACE1("Call finished"); } TRACE1("Call successfull"); return res; TRACE_OUT; } JPObject* JPMethodOverload::invokeConstructor(jclass claz, vector& arg) { TRACE_IN("JPMethodOverload::invokeConstructor"); size_t len = arg.size(); JPCleaner cleaner; JPMallocCleaner v(len); for (unsigned int i = 0; i < len; i++) { HostRef* obj = arg[i]; // TODO the following can easily be optimized ... or at least cached JPType* t = JPTypeManager::getType(m_Arguments[i]); v[i] = t->convertToJava(obj); if (t->isObjectType()) { cleaner.addLocal(v[i].l); } } jvalue val; val.l = JPEnv::getJava()->NewObjectA(claz, m_MethodID, v.borrow()); cleaner.addLocal(val.l); TRACE1("Object created"); JPTypeName name = JPJni::getName(claz); return new JPObject(name, val.l); TRACE_OUT; } string JPMethodOverload::matchReport(vector& args) { stringstream res; res << m_ReturnType.getNativeName() << " ("; bool isFirst = true; for (vector::iterator it = m_Arguments.begin(); it != m_Arguments.end(); it++) { if (isFirst && ! isStatic()) { isFirst = false; continue; } isFirst = false; res << it->getNativeName(); } res << ") ==> "; EMatchType match = matches(! isStatic(), args); switch(match) { case _none : res << "NONE"; break; case _explicit : res << "EXPLICIT"; break; case _implicit : res << "IMPLICIT"; break; case _exact : res << "EXACT"; break; default : res << "UNKNOWN"; break; } res << endl; return res.str(); } python-jpype-0.5.4.2/src/native/common/jp_objecttypes.cpp0000666000175000017500000002312611614007722022725 0ustar takakitakaki/***************************************************************************** Copyright 2004-2008 Steve Menard 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. *****************************************************************************/ #include HostRef* JPObjectType::getStaticValue(jclass c, jfieldID fid, JPTypeName& tgtType) { TRACE_IN("JPObjectType::getStaticValue"); JPCleaner cleaner; jobject r = JPEnv::getJava()->GetStaticObjectField(c, fid); cleaner.addLocal(r); jvalue v; v.l = r; JPTypeName name = JPJni::getClassName(v.l); JPType* type = JPTypeManager::getType(name); return type->asHostObject(v); TRACE_OUT; } HostRef* JPObjectType::getInstanceValue(jobject c, jfieldID fid, JPTypeName& tgtType) { TRACE_IN("JPObjectType::getInstanceValue"); JPCleaner cleaner; jobject r = JPEnv::getJava()->GetObjectField(c, fid); cleaner.addLocal(r); jvalue v; v.l = r; JPTypeName name = JPJni::getClassName(v.l); JPType* type = JPTypeManager::getType(name); return type->asHostObject(v); TRACE_OUT; } HostRef* JPObjectType::invokeStatic(jclass claz, jmethodID mth, jvalue* val) { TRACE_IN("JPObjectType::invokeStatic"); JPCleaner cleaner; jobject res = JPEnv::getJava()->CallStaticObjectMethodA(claz, mth, val); cleaner.addLocal(res); jvalue v; v.l = res; JPTypeName name = JPJni::getClassName(v.l); JPType* type = JPTypeManager::getType(name); return type->asHostObject(v); TRACE_OUT; } HostRef* JPObjectType::invoke(jobject claz, jclass clazz, jmethodID mth, jvalue* val) { TRACE_IN("JPObjectType::invoke"); JPCleaner cleaner; jobject res = JPEnv::getJava()->CallNonvirtualObjectMethodA(claz, clazz, mth, val); cleaner.addLocal(res); jvalue v; v.l = res; JPTypeName name = JPJni::getClassName(v.l); JPType* type = JPTypeManager::getType(name); HostRef* ref = type->asHostObject(v); TRACE1("Successfulyl converted to host reference"); return ref; TRACE_OUT; } void JPObjectType::setStaticValue(jclass c, jfieldID fid, HostRef* obj) { TRACE_IN("JPObjectType::setStaticValue"); JPCleaner cleaner; jobject val = convertToJava(obj).l; cleaner.addLocal(val); JPEnv::getJava()->SetStaticObjectField(c, fid, val); TRACE_OUT; } void JPObjectType::setInstanceValue(jobject c, jfieldID fid, HostRef* obj) { TRACE_IN("JPObjectType::setInstanceValue"); JPCleaner cleaner; jobject val = convertToJava(obj).l; cleaner.addLocal(val); JPEnv::getJava()->SetObjectField(c, fid, val); TRACE_OUT; } jarray JPObjectType::newArrayInstance(int sz) { JPCleaner cleaner; jclass c = getClass(); cleaner.addLocal(c); return JPEnv::getJava()->NewObjectArray(sz, c, NULL); } vector JPObjectType::getArrayRange(jarray a, int start, int length) { jobjectArray array = (jobjectArray)a; JPCleaner cleaner; vector res; jvalue v; for (int i = 0; i < length; i++) { v.l = JPEnv::getJava()->GetObjectArrayElement(array, i+start); cleaner.addLocal(v.l); JPTypeName name = JPJni::getClassName(v.l); JPType* t = JPTypeManager::getType(name); HostRef* pv = t->asHostObject(v); res.push_back(pv); } return res; } void JPObjectType::setArrayRange(jarray a, int start, int length, vector& vals) { jobjectArray array = (jobjectArray)a; JPCleaner cleaner; jvalue v; for (int i = 0; i < length; i++) { HostRef* pv = vals[i]; v = convertToJava(pv); cleaner.addLocal(v.l); JPEnv::getJava()->SetObjectArrayElement(array, i+start, v.l); } } void JPObjectType::setArrayItem(jarray a, int ndx, HostRef* val) { jobjectArray array = (jobjectArray)a; JPCleaner cleaner; jvalue v = convertToJava(val); cleaner.addLocal(v.l); JPEnv::getJava()->SetObjectArrayElement(array, ndx, v.l); } HostRef* JPObjectType::getArrayItem(jarray a, int ndx) { TRACE_IN("JPObjectType::getArrayItem"); jobjectArray array = (jobjectArray)a; JPCleaner cleaner; jobject obj = JPEnv::getJava()->GetObjectArrayElement(array, ndx); cleaner.addLocal(obj); if (obj == NULL) { return JPEnv::getHost()->getNone(); } jvalue v; v.l = obj; JPTypeName name = JPJni::getClassName(v.l); JPType* t = JPTypeManager::getType(name); return t->asHostObject(v); TRACE_OUT; } jobject JPObjectType::convertToJavaObject(HostRef* obj) { jvalue v = convertToJava(obj); return v.l; } HostRef* JPObjectType::asHostObjectFromObject(jvalue val) { return asHostObject(val); } HostRef* JPObjectType::convertToDirectBuffer(HostRef* src) { RAISE(JPypeException, "Unable to convert to Direct Buffer"); } void JPObjectType::setArrayValues(jarray a, HostRef* values) { jobjectArray array = (jobjectArray)a; JPCleaner cleaner; try { bool converted = true; // Optimize what I can ... // TODO also optimize array.array ... if (JPEnv::getHost()->isSequence(values)) { int len = JPEnv::getHost()->getSequenceLength(values); for (int i = 0; i < len; i++) { HostRef* v = JPEnv::getHost()->getSequenceItem(values, i); JPEnv::getJava()->SetObjectArrayElement(array, i, convertToJava(v).l); delete v; } converted = true; } else { RAISE(JPypeException, "Unable to convert to Object array"); } } RETHROW_CATCH( ; ); } //------------------------------------------------------------------------------- HostRef* JPStringType::asHostObject(jvalue val) { TRACE_IN("JPStringType::asHostObject"); if (val.l == NULL) { return JPEnv::getHost()->getNone(); } jstring v = (jstring)val.l; if (JPEnv::getJava()->getConvertStringObjects()) { TRACE1(" Performing conversion"); jsize len = JPEnv::getJava()->GetStringLength(v); jboolean isCopy; const jchar* str = JPEnv::getJava()->GetStringChars(v, &isCopy); HostRef* res = JPEnv::getHost()->newStringFromUnicode(str, len); JPEnv::getJava()->ReleaseStringChars(v, str); return res; } else { TRACE1(" Performing wrapping"); HostRef* res = JPEnv::getHost()->newStringWrapper(v); TRACE1(" Wrapping successfull"); return res; } TRACE_OUT; } EMatchType JPStringType::canConvertToJava(HostRef* obj) { TRACE_IN("JPStringType::canConvertToJava"); JPCleaner cleaner; if (obj == NULL || JPEnv::getHost()->isNone(obj)) { return _implicit; } if (JPEnv::getHost()->isString(obj)) { return _exact; } if (JPEnv::getHost()->isWrapper(obj)) { JPTypeName name = JPEnv::getHost()->getWrapperTypeName(obj); if (name.getType() == JPTypeName::_string) { return _exact; } } if (JPEnv::getHost()->isObject(obj)) { JPObject* o = JPEnv::getHost()->asObject(obj); JPClass* oc = o->getClass(); if (oc->getName().getSimpleName() == "java.lang.String") { return _exact; } } return _none; TRACE_OUT; } jvalue JPStringType::convertToJava(HostRef* obj) { TRACE_IN("JPStringType::convertToJava"); JPCleaner cleaner; jvalue v; if (JPEnv::getHost()->isNone(obj)) { v.l = NULL; return v; } if (JPEnv::getHost()->isWrapper(obj)) { return JPEnv::getHost()->getWrapperValue(obj); } if (JPEnv::getHost()->isObject(obj)) { JPObject* o = JPEnv::getHost()->asObject(obj); JPClass* oc = o->getClass(); if (oc->getName().getSimpleName() == "java.lang.String") { v.l = o->getObject(); return v; } } JCharString wstr = JPEnv::getHost()->stringAsJCharString(obj); jchar* jstr = new jchar[wstr.length()+1]; jstr[wstr.length()] = 0; for (size_t i = 0; i < wstr.length(); i++) { jstr[i] = (jchar)wstr[i]; } jstring res = JPEnv::getJava()->NewString(jstr, (jint)wstr.length()); delete jstr; v.l = res; return v; TRACE_OUT; } jclass JPStringType::getClass() { return (jclass)JPEnv::getJava()->NewGlobalRef(JPJni::s_StringClass); } //------------------------------------------------------------------------------- HostRef* JPClassType::asHostObject(jvalue val) { jclass lclass = (jclass)val.l; JPTypeName name = JPJni::getName(lclass); JPClass* res = JPTypeManager::findClass(name); return JPEnv::getHost()->newClass(res); } EMatchType JPClassType::canConvertToJava(HostRef* obj) { JPCleaner cleaner; if (JPEnv::getHost()->isNone(obj)) { return _implicit; } if (JPEnv::getHost()->isClass(obj)) { return _exact; } if (JPEnv::getHost()->isWrapper(obj)) { JPTypeName name = JPEnv::getHost()->getWrapperTypeName(obj); if (name.getType() == JPTypeName::_class) { return _exact; } } return _none; } jvalue JPClassType::convertToJava(HostRef* obj) { JPCleaner cleaner; jvalue v; if (JPEnv::getHost()->isNone(obj)) { v.l = NULL; return v; } else if (JPEnv::getHost()->isWrapper(obj)) { v = JPEnv::getHost()->getWrapperValue(obj); } else { JPClass* w = JPEnv::getHost()->asClass(obj); jclass lr = w->getClass(); v.l = lr; } return v; } jclass JPClassType::getClass() { return (jclass)JPEnv::getJava()->NewGlobalRef(JPJni::s_ClassClass); } python-jpype-0.5.4.2/src/native/common/jp_typename.cpp0000666000175000017500000001114711614227744022224 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard 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. *****************************************************************************/ #include #undef JPYPE_TRACING_INTERNAL //AT's on porting: // 1) the original definition of global static object leads to crashing //on HP-UX platform. Cause: it is suspected to be an undefined order of initialization of static objects // // 2) TODO: in any case, use of static objects may impose problems in multi-threaded environment. //Therefore, they must be guarded with a mutex. map& GetNativeNamesMap() { static map nativeNames; return nativeNames; } map& GetDefinedTypesMap() { static map definedTypes; return definedTypes; } map& GetNativeTypesMap() { static map nativeTypes; return nativeTypes; } static string convertToNativeClassName(const std::string& str) { // simple names are of the form : // a.c.d.E // native names are of the form : // La/c/d/E; string name = str; string result = string("L")+name+";"; for (unsigned int j = 0; j < result.length(); j++) { if (result[j] == '.') { result[j] = '/'; } } return result; } void JPTypeName::init() { GetNativeNamesMap()["void"] = "V"; GetNativeNamesMap()["byte"] = "B"; GetNativeNamesMap()["short"] = "S"; GetNativeNamesMap()["int"] = "I"; GetNativeNamesMap()["long"] = "J"; GetNativeNamesMap()["float"] = "F"; GetNativeNamesMap()["double"] = "D"; GetNativeNamesMap()["boolean"] = "Z"; GetNativeNamesMap()["char"] = "C"; GetDefinedTypesMap()["void"] = _void; GetDefinedTypesMap()["byte"] = _byte; GetDefinedTypesMap()["short"] = _short; GetDefinedTypesMap()["int"] = _int; GetDefinedTypesMap()["long"] = _long; GetDefinedTypesMap()["float"] = _float; GetDefinedTypesMap()["double"] = _double; GetDefinedTypesMap()["boolean"] = _boolean; GetDefinedTypesMap()["char"] = _char; GetDefinedTypesMap()["java.lang.String"] = _string; GetDefinedTypesMap()["java.lang.Class"] = _class; for (map::iterator it = GetDefinedTypesMap().begin(); it != GetDefinedTypesMap().end(); ++it) { GetNativeTypesMap()[it->second] = it->first; } } JPTypeName JPTypeName::fromType(JPTypeName::ETypes t) { return fromSimple(GetNativeTypesMap()[t].c_str()); } JPTypeName JPTypeName::fromSimple(const char* name) { string simple = name; string componentName = simple; string nativeComponent; JPTypeName::ETypes t; // is it an array? size_t arrayDimCount = 0; if (simple.length() > 0 && simple[simple.length()-1] == ']') { size_t i = simple.length()-1; while (simple[i] == ']' || simple[i] == '[') { i--; } componentName = simple.substr(0, i+1); arrayDimCount = (simple.length() - componentName.length())/2; } map::iterator nativeIt = GetNativeNamesMap().find(componentName); if (nativeIt == GetNativeNamesMap().end()) { nativeComponent = convertToNativeClassName(componentName); } else { nativeComponent = nativeIt->second; } string native; if (arrayDimCount > 0) { stringstream str; for (unsigned int i = 0; i < arrayDimCount; i++) { str << "["; } str << nativeComponent; native = str.str(); } else { native = nativeComponent; } map::iterator typeIt = GetDefinedTypesMap().find(name); if (typeIt == GetDefinedTypesMap().end()) { if (native[0] == '[') { t = _array; } else { t = _object; } } else { t = typeIt->second; } return JPTypeName(simple, native, t); } JPTypeName JPTypeName::getComponentName() { if (m_Type != _array) { RAISE(JPypeException, "Not an array type"); } string sname = m_SimpleName.substr(0,m_SimpleName.length()-2); JPTypeName compName = fromSimple(sname.c_str()); return compName; } python-jpype-0.5.4.2/src/native/common/jp_javaenv_autogen.cpp0000666000175000017500000013352411614007722023552 0ustar takakitakaki /***************************************************************************** Copyright 2004-2008 Steve Menard 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. *****************************************************************************/ // This code has been automatically generated ... No not edit #include #define JAVA_CHECK(msg) \ if (JPEnv::getJava()->ExceptionCheck()) \ { \ RAISE(JavaException, msg); \ } \ jbyte JPJavaEnv::GetStaticByteField(jclass clazz, jfieldID fid) { JNIEnv* env = getJNIEnv(); jbyte res = env->functions->GetStaticByteField(env, clazz, fid); JAVA_CHECK("GetStaticByteField"); return res; } jbyte JPJavaEnv::GetByteField(jobject clazz, jfieldID fid) { JNIEnv* env = getJNIEnv(); jbyte res = env->functions->GetByteField(env, clazz, fid); JAVA_CHECK("GetByteField"); return res; } void JPJavaEnv::SetStaticByteField(jclass clazz, jfieldID fid, jbyte val) { JNIEnv* env = getJNIEnv(); env->functions->SetStaticByteField(env, clazz, fid, val); JAVA_CHECK("SetStaticByteField"); } void JPJavaEnv::SetByteField(jobject clazz, jfieldID fid, jbyte val) { JNIEnv* env = getJNIEnv(); env->functions->SetByteField(env, clazz, fid, val); JAVA_CHECK("SetByteField"); } jbyte JPJavaEnv::CallStaticByteMethodA(jclass clazz, jmethodID mid, jvalue* val) { jbyte res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallStaticByteMethodA(env, clazz, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Byte"); return res; } jbyte JPJavaEnv::CallStaticByteMethod(jclass clazz, jmethodID mid) { jbyte res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallStaticByteMethod(env, clazz, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Byte"); return res; } jbyte JPJavaEnv::CallByteMethodA(jobject obj, jmethodID mid, jvalue* val) { jbyte res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallByteMethodA(env, obj, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Byte"); return res; } jbyte JPJavaEnv::CallByteMethod(jobject obj, jmethodID mid) { jbyte res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallByteMethod(env, obj, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Byte"); return res; } jbyte JPJavaEnv::CallNonvirtualByteMethodA(jobject obj, jclass claz, jmethodID mid, jvalue* val) { jbyte res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallNonvirtualByteMethodA(env, obj, claz, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Byte"); return res; } jbyte JPJavaEnv::CallNonvirtualByteMethod(jobject obj, jclass claz, jmethodID mid) { jbyte res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallNonvirtualByteMethod(env, obj, claz, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Byte"); return res; } jshort JPJavaEnv::GetStaticShortField(jclass clazz, jfieldID fid) { JNIEnv* env = getJNIEnv(); jshort res = env->functions->GetStaticShortField(env, clazz, fid); JAVA_CHECK("GetStaticShortField"); return res; } jshort JPJavaEnv::GetShortField(jobject clazz, jfieldID fid) { JNIEnv* env = getJNIEnv(); jshort res = env->functions->GetShortField(env, clazz, fid); JAVA_CHECK("GetShortField"); return res; } void JPJavaEnv::SetStaticShortField(jclass clazz, jfieldID fid, jshort val) { JNIEnv* env = getJNIEnv(); env->functions->SetStaticShortField(env, clazz, fid, val); JAVA_CHECK("SetStaticShortField"); } void JPJavaEnv::SetShortField(jobject clazz, jfieldID fid, jshort val) { JNIEnv* env = getJNIEnv(); env->functions->SetShortField(env, clazz, fid, val); JAVA_CHECK("SetShortField"); } jshort JPJavaEnv::CallStaticShortMethodA(jclass clazz, jmethodID mid, jvalue* val) { jshort res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallStaticShortMethodA(env, clazz, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Short"); return res; } jshort JPJavaEnv::CallStaticShortMethod(jclass clazz, jmethodID mid) { jshort res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallStaticShortMethod(env, clazz, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Short"); return res; } jshort JPJavaEnv::CallShortMethodA(jobject obj, jmethodID mid, jvalue* val) { jshort res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallShortMethodA(env, obj, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Short"); return res; } jshort JPJavaEnv::CallShortMethod(jobject obj, jmethodID mid) { jshort res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallShortMethod(env, obj, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Short"); return res; } jshort JPJavaEnv::CallNonvirtualShortMethodA(jobject obj, jclass claz, jmethodID mid, jvalue* val) { jshort res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallNonvirtualShortMethodA(env, obj, claz, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Short"); return res; } jshort JPJavaEnv::CallNonvirtualShortMethod(jobject obj, jclass claz, jmethodID mid) { jshort res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallNonvirtualShortMethod(env, obj, claz, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Short"); return res; } jint JPJavaEnv::GetStaticIntField(jclass clazz, jfieldID fid) { JNIEnv* env = getJNIEnv(); jint res = env->functions->GetStaticIntField(env, clazz, fid); JAVA_CHECK("GetStaticIntField"); return res; } jint JPJavaEnv::GetIntField(jobject clazz, jfieldID fid) { JNIEnv* env = getJNIEnv(); jint res = env->functions->GetIntField(env, clazz, fid); JAVA_CHECK("GetIntField"); return res; } void JPJavaEnv::SetStaticIntField(jclass clazz, jfieldID fid, jint val) { JNIEnv* env = getJNIEnv(); env->functions->SetStaticIntField(env, clazz, fid, val); JAVA_CHECK("SetStaticIntField"); } void JPJavaEnv::SetIntField(jobject clazz, jfieldID fid, jint val) { JNIEnv* env = getJNIEnv(); env->functions->SetIntField(env, clazz, fid, val); JAVA_CHECK("SetIntField"); } jint JPJavaEnv::CallStaticIntMethodA(jclass clazz, jmethodID mid, jvalue* val) { jint res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallStaticIntMethodA(env, clazz, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Int"); return res; } jint JPJavaEnv::CallStaticIntMethod(jclass clazz, jmethodID mid) { jint res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallStaticIntMethod(env, clazz, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Int"); return res; } jint JPJavaEnv::CallIntMethodA(jobject obj, jmethodID mid, jvalue* val) { jint res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallIntMethodA(env, obj, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Int"); return res; } jint JPJavaEnv::CallIntMethod(jobject obj, jmethodID mid) { jint res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallIntMethod(env, obj, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Int"); return res; } jint JPJavaEnv::CallNonvirtualIntMethodA(jobject obj, jclass claz, jmethodID mid, jvalue* val) { jint res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallNonvirtualIntMethodA(env, obj, claz, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Int"); return res; } jint JPJavaEnv::CallNonvirtualIntMethod(jobject obj, jclass claz, jmethodID mid) { jint res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallNonvirtualIntMethod(env, obj, claz, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Int"); return res; } jlong JPJavaEnv::GetStaticLongField(jclass clazz, jfieldID fid) { JNIEnv* env = getJNIEnv(); jlong res = env->functions->GetStaticLongField(env, clazz, fid); JAVA_CHECK("GetStaticLongField"); return res; } jlong JPJavaEnv::GetLongField(jobject clazz, jfieldID fid) { JNIEnv* env = getJNIEnv(); jlong res = env->functions->GetLongField(env, clazz, fid); JAVA_CHECK("GetLongField"); return res; } void JPJavaEnv::SetStaticLongField(jclass clazz, jfieldID fid, jlong val) { JNIEnv* env = getJNIEnv(); env->functions->SetStaticLongField(env, clazz, fid, val); JAVA_CHECK("SetStaticLongField"); } void JPJavaEnv::SetLongField(jobject clazz, jfieldID fid, jlong val) { JNIEnv* env = getJNIEnv(); env->functions->SetLongField(env, clazz, fid, val); JAVA_CHECK("SetLongField"); } jlong JPJavaEnv::CallStaticLongMethodA(jclass clazz, jmethodID mid, jvalue* val) { jlong res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallStaticLongMethodA(env, clazz, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Long"); return res; } jlong JPJavaEnv::CallStaticLongMethod(jclass clazz, jmethodID mid) { jlong res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallStaticLongMethod(env, clazz, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Long"); return res; } jlong JPJavaEnv::CallLongMethodA(jobject obj, jmethodID mid, jvalue* val) { jlong res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallLongMethodA(env, obj, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Long"); return res; } jlong JPJavaEnv::CallLongMethod(jobject obj, jmethodID mid) { jlong res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallLongMethod(env, obj, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Long"); return res; } jlong JPJavaEnv::CallNonvirtualLongMethodA(jobject obj, jclass claz, jmethodID mid, jvalue* val) { jlong res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallNonvirtualLongMethodA(env, obj, claz, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Long"); return res; } jlong JPJavaEnv::CallNonvirtualLongMethod(jobject obj, jclass claz, jmethodID mid) { jlong res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallNonvirtualLongMethod(env, obj, claz, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Long"); return res; } jfloat JPJavaEnv::GetStaticFloatField(jclass clazz, jfieldID fid) { JNIEnv* env = getJNIEnv(); jfloat res = env->functions->GetStaticFloatField(env, clazz, fid); JAVA_CHECK("GetStaticFloatField"); return res; } jfloat JPJavaEnv::GetFloatField(jobject clazz, jfieldID fid) { JNIEnv* env = getJNIEnv(); jfloat res = env->functions->GetFloatField(env, clazz, fid); JAVA_CHECK("GetFloatField"); return res; } void JPJavaEnv::SetStaticFloatField(jclass clazz, jfieldID fid, jfloat val) { JNIEnv* env = getJNIEnv(); env->functions->SetStaticFloatField(env, clazz, fid, val); JAVA_CHECK("SetStaticFloatField"); } void JPJavaEnv::SetFloatField(jobject clazz, jfieldID fid, jfloat val) { JNIEnv* env = getJNIEnv(); env->functions->SetFloatField(env, clazz, fid, val); JAVA_CHECK("SetFloatField"); } jfloat JPJavaEnv::CallStaticFloatMethodA(jclass clazz, jmethodID mid, jvalue* val) { jfloat res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallStaticFloatMethodA(env, clazz, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Float"); return res; } jfloat JPJavaEnv::CallStaticFloatMethod(jclass clazz, jmethodID mid) { jfloat res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallStaticFloatMethod(env, clazz, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Float"); return res; } jfloat JPJavaEnv::CallFloatMethodA(jobject obj, jmethodID mid, jvalue* val) { jfloat res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallFloatMethodA(env, obj, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Float"); return res; } jfloat JPJavaEnv::CallFloatMethod(jobject obj, jmethodID mid) { jfloat res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallFloatMethod(env, obj, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Float"); return res; } jfloat JPJavaEnv::CallNonvirtualFloatMethodA(jobject obj, jclass claz, jmethodID mid, jvalue* val) { jfloat res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallNonvirtualFloatMethodA(env, obj, claz, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Float"); return res; } jfloat JPJavaEnv::CallNonvirtualFloatMethod(jobject obj, jclass claz, jmethodID mid) { jfloat res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallNonvirtualFloatMethod(env, obj, claz, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Float"); return res; } jdouble JPJavaEnv::GetStaticDoubleField(jclass clazz, jfieldID fid) { JNIEnv* env = getJNIEnv(); jdouble res = env->functions->GetStaticDoubleField(env, clazz, fid); JAVA_CHECK("GetStaticDoubleField"); return res; } jdouble JPJavaEnv::GetDoubleField(jobject clazz, jfieldID fid) { JNIEnv* env = getJNIEnv(); jdouble res = env->functions->GetDoubleField(env, clazz, fid); JAVA_CHECK("GetDoubleField"); return res; } void JPJavaEnv::SetStaticDoubleField(jclass clazz, jfieldID fid, jdouble val) { JNIEnv* env = getJNIEnv(); env->functions->SetStaticDoubleField(env, clazz, fid, val); JAVA_CHECK("SetStaticDoubleField"); } void JPJavaEnv::SetDoubleField(jobject clazz, jfieldID fid, jdouble val) { JNIEnv* env = getJNIEnv(); env->functions->SetDoubleField(env, clazz, fid, val); JAVA_CHECK("SetDoubleField"); } jdouble JPJavaEnv::CallStaticDoubleMethodA(jclass clazz, jmethodID mid, jvalue* val) { jdouble res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallStaticDoubleMethodA(env, clazz, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Double"); return res; } jdouble JPJavaEnv::CallStaticDoubleMethod(jclass clazz, jmethodID mid) { jdouble res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallStaticDoubleMethod(env, clazz, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Double"); return res; } jdouble JPJavaEnv::CallDoubleMethodA(jobject obj, jmethodID mid, jvalue* val) { jdouble res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallDoubleMethodA(env, obj, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Double"); return res; } jdouble JPJavaEnv::CallDoubleMethod(jobject obj, jmethodID mid) { jdouble res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallDoubleMethod(env, obj, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Double"); return res; } jdouble JPJavaEnv::CallNonvirtualDoubleMethodA(jobject obj, jclass claz, jmethodID mid, jvalue* val) { jdouble res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallNonvirtualDoubleMethodA(env, obj, claz, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Double"); return res; } jdouble JPJavaEnv::CallNonvirtualDoubleMethod(jobject obj, jclass claz, jmethodID mid) { jdouble res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallNonvirtualDoubleMethod(env, obj, claz, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Double"); return res; } jchar JPJavaEnv::GetStaticCharField(jclass clazz, jfieldID fid) { JNIEnv* env = getJNIEnv(); jchar res = env->functions->GetStaticCharField(env, clazz, fid); JAVA_CHECK("GetStaticCharField"); return res; } jchar JPJavaEnv::GetCharField(jobject clazz, jfieldID fid) { JNIEnv* env = getJNIEnv(); jchar res = env->functions->GetCharField(env, clazz, fid); JAVA_CHECK("GetCharField"); return res; } void JPJavaEnv::SetStaticCharField(jclass clazz, jfieldID fid, jchar val) { JNIEnv* env = getJNIEnv(); env->functions->SetStaticCharField(env, clazz, fid, val); JAVA_CHECK("SetStaticCharField"); } void JPJavaEnv::SetCharField(jobject clazz, jfieldID fid, jchar val) { JNIEnv* env = getJNIEnv(); env->functions->SetCharField(env, clazz, fid, val); JAVA_CHECK("SetCharField"); } jchar JPJavaEnv::CallStaticCharMethodA(jclass clazz, jmethodID mid, jvalue* val) { jchar res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallStaticCharMethodA(env, clazz, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Char"); return res; } jchar JPJavaEnv::CallStaticCharMethod(jclass clazz, jmethodID mid) { jchar res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallStaticCharMethod(env, clazz, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Char"); return res; } jchar JPJavaEnv::CallCharMethodA(jobject obj, jmethodID mid, jvalue* val) { jchar res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallCharMethodA(env, obj, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Char"); return res; } jchar JPJavaEnv::CallCharMethod(jobject obj, jmethodID mid) { jchar res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallCharMethod(env, obj, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Char"); return res; } jchar JPJavaEnv::CallNonvirtualCharMethodA(jobject obj, jclass claz, jmethodID mid, jvalue* val) { jchar res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallNonvirtualCharMethodA(env, obj, claz, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Char"); return res; } jchar JPJavaEnv::CallNonvirtualCharMethod(jobject obj, jclass claz, jmethodID mid) { jchar res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallNonvirtualCharMethod(env, obj, claz, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Char"); return res; } jboolean JPJavaEnv::GetStaticBooleanField(jclass clazz, jfieldID fid) { JNIEnv* env = getJNIEnv(); jboolean res = env->functions->GetStaticBooleanField(env, clazz, fid); JAVA_CHECK("GetStaticBooleanField"); return res; } jboolean JPJavaEnv::GetBooleanField(jobject clazz, jfieldID fid) { JNIEnv* env = getJNIEnv(); jboolean res = env->functions->GetBooleanField(env, clazz, fid); JAVA_CHECK("GetBooleanField"); return res; } void JPJavaEnv::SetStaticBooleanField(jclass clazz, jfieldID fid, jboolean val) { JNIEnv* env = getJNIEnv(); env->functions->SetStaticBooleanField(env, clazz, fid, val); JAVA_CHECK("SetStaticBooleanField"); } void JPJavaEnv::SetBooleanField(jobject clazz, jfieldID fid, jboolean val) { JNIEnv* env = getJNIEnv(); env->functions->SetBooleanField(env, clazz, fid, val); JAVA_CHECK("SetBooleanField"); } jboolean JPJavaEnv::CallStaticBooleanMethodA(jclass clazz, jmethodID mid, jvalue* val) { jboolean res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallStaticBooleanMethodA(env, clazz, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Boolean"); return res; } jboolean JPJavaEnv::CallStaticBooleanMethod(jclass clazz, jmethodID mid) { jboolean res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallStaticBooleanMethod(env, clazz, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Boolean"); return res; } jboolean JPJavaEnv::CallBooleanMethodA(jobject obj, jmethodID mid, jvalue* val) { jboolean res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallBooleanMethodA(env, obj, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Boolean"); return res; } jboolean JPJavaEnv::CallBooleanMethod(jobject obj, jmethodID mid) { jboolean res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallBooleanMethod(env, obj, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Boolean"); return res; } jboolean JPJavaEnv::CallNonvirtualBooleanMethodA(jobject obj, jclass claz, jmethodID mid, jvalue* val) { jboolean res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallNonvirtualBooleanMethodA(env, obj, claz, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Boolean"); return res; } jboolean JPJavaEnv::CallNonvirtualBooleanMethod(jobject obj, jclass claz, jmethodID mid) { jboolean res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallNonvirtualBooleanMethod(env, obj, claz, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Boolean"); return res; } jobject JPJavaEnv::GetStaticObjectField(jclass clazz, jfieldID fid) { JNIEnv* env = getJNIEnv(); jobject res = env->functions->GetStaticObjectField(env, clazz, fid); JAVA_CHECK("GetStaticObjectField"); return res; } jobject JPJavaEnv::GetObjectField(jobject clazz, jfieldID fid) { JNIEnv* env = getJNIEnv(); jobject res = env->functions->GetObjectField(env, clazz, fid); JAVA_CHECK("GetObjectField"); return res; } void JPJavaEnv::SetStaticObjectField(jclass clazz, jfieldID fid, jobject val) { JNIEnv* env = getJNIEnv(); env->functions->SetStaticObjectField(env, clazz, fid, val); JAVA_CHECK("SetStaticObjectField"); } void JPJavaEnv::SetObjectField(jobject clazz, jfieldID fid, jobject val) { JNIEnv* env = getJNIEnv(); env->functions->SetObjectField(env, clazz, fid, val); JAVA_CHECK("SetObjectField"); } jobject JPJavaEnv::CallStaticObjectMethodA(jclass clazz, jmethodID mid, jvalue* val) { jobject res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallStaticObjectMethodA(env, clazz, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Object"); return res; } jobject JPJavaEnv::CallStaticObjectMethod(jclass clazz, jmethodID mid) { jobject res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallStaticObjectMethod(env, clazz, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Object"); return res; } jobject JPJavaEnv::CallObjectMethodA(jobject obj, jmethodID mid, jvalue* val) { jobject res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallObjectMethodA(env, obj, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Object"); return res; } jobject JPJavaEnv::CallObjectMethod(jobject obj, jmethodID mid) { jobject res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallObjectMethod(env, obj, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Object"); return res; } jobject JPJavaEnv::CallNonvirtualObjectMethodA(jobject obj, jclass claz, jmethodID mid, jvalue* val) { jobject res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallNonvirtualObjectMethodA(env, obj, claz, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Object"); return res; } jobject JPJavaEnv::CallNonvirtualObjectMethod(jobject obj, jclass claz, jmethodID mid) { jobject res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallNonvirtualObjectMethod(env, obj, claz, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Object"); return res; } jbyteArray JPJavaEnv::NewByteArray(jint len) { JNIEnv* env = getJNIEnv(); jbyteArray res = env->functions->NewByteArray(env, len); JAVA_CHECK("NewByteArray"); return res; } void JPJavaEnv::SetByteArrayRegion(jbyteArray array, int start, int len, jbyte* vals) { JNIEnv* env = getJNIEnv(); env->functions->SetByteArrayRegion(env, array, start, len, vals); JAVA_CHECK("SetByteArrayRegion"); } void JPJavaEnv::GetByteArrayRegion(jbyteArray array, int start, int len, jbyte* vals) { JNIEnv* env = getJNIEnv(); env->functions->GetByteArrayRegion(env, array, start, len, vals); JAVA_CHECK("GetByteArrayRegion"); } jbyte* JPJavaEnv::GetByteArrayElements(jbyteArray array, jboolean* isCopy) { JNIEnv* env = getJNIEnv(); jbyte* res = env->functions->GetByteArrayElements(env, array, isCopy); JAVA_CHECK("GetByteArrayElements"); return res; } void JPJavaEnv::ReleaseByteArrayElements(jbyteArray array, jbyte* v, jint mode) { JNIEnv* env = getJNIEnv(); env->functions->ReleaseByteArrayElements(env, array, v, mode); JAVA_CHECK("ReleaseByteArrayElements"); } jshortArray JPJavaEnv::NewShortArray(jint len) { JNIEnv* env = getJNIEnv(); jshortArray res = env->functions->NewShortArray(env, len); JAVA_CHECK("NewShortArray"); return res; } void JPJavaEnv::SetShortArrayRegion(jshortArray array, int start, int len, jshort* vals) { JNIEnv* env = getJNIEnv(); env->functions->SetShortArrayRegion(env, array, start, len, vals); JAVA_CHECK("SetShortArrayRegion"); } void JPJavaEnv::GetShortArrayRegion(jshortArray array, int start, int len, jshort* vals) { JNIEnv* env = getJNIEnv(); env->functions->GetShortArrayRegion(env, array, start, len, vals); JAVA_CHECK("GetShortArrayRegion"); } jshort* JPJavaEnv::GetShortArrayElements(jshortArray array, jboolean* isCopy) { JNIEnv* env = getJNIEnv(); jshort* res = env->functions->GetShortArrayElements(env, array, isCopy); JAVA_CHECK("GetShortArrayElements"); return res; } void JPJavaEnv::ReleaseShortArrayElements(jshortArray array, jshort* v, jint mode) { JNIEnv* env = getJNIEnv(); env->functions->ReleaseShortArrayElements(env, array, v, mode); JAVA_CHECK("ReleaseShortArrayElements"); } jintArray JPJavaEnv::NewIntArray(jint len) { JNIEnv* env = getJNIEnv(); jintArray res = env->functions->NewIntArray(env, len); JAVA_CHECK("NewIntArray"); return res; } void JPJavaEnv::SetIntArrayRegion(jintArray array, int start, int len, jint* vals) { JNIEnv* env = getJNIEnv(); env->functions->SetIntArrayRegion(env, array, start, len, vals); JAVA_CHECK("SetIntArrayRegion"); } void JPJavaEnv::GetIntArrayRegion(jintArray array, int start, int len, jint* vals) { JNIEnv* env = getJNIEnv(); env->functions->GetIntArrayRegion(env, array, start, len, vals); JAVA_CHECK("GetIntArrayRegion"); } jint* JPJavaEnv::GetIntArrayElements(jintArray array, jboolean* isCopy) { JNIEnv* env = getJNIEnv(); jint* res = env->functions->GetIntArrayElements(env, array, isCopy); JAVA_CHECK("GetIntArrayElements"); return res; } void JPJavaEnv::ReleaseIntArrayElements(jintArray array, jint* v, jint mode) { JNIEnv* env = getJNIEnv(); env->functions->ReleaseIntArrayElements(env, array, v, mode); JAVA_CHECK("ReleaseIntArrayElements"); } jlongArray JPJavaEnv::NewLongArray(jint len) { JNIEnv* env = getJNIEnv(); jlongArray res = env->functions->NewLongArray(env, len); JAVA_CHECK("NewLongArray"); return res; } void JPJavaEnv::SetLongArrayRegion(jlongArray array, int start, int len, jlong* vals) { JNIEnv* env = getJNIEnv(); env->functions->SetLongArrayRegion(env, array, start, len, vals); JAVA_CHECK("SetLongArrayRegion"); } void JPJavaEnv::GetLongArrayRegion(jlongArray array, int start, int len, jlong* vals) { JNIEnv* env = getJNIEnv(); env->functions->GetLongArrayRegion(env, array, start, len, vals); JAVA_CHECK("GetLongArrayRegion"); } jlong* JPJavaEnv::GetLongArrayElements(jlongArray array, jboolean* isCopy) { JNIEnv* env = getJNIEnv(); jlong* res = env->functions->GetLongArrayElements(env, array, isCopy); JAVA_CHECK("GetLongArrayElements"); return res; } void JPJavaEnv::ReleaseLongArrayElements(jlongArray array, jlong* v, jint mode) { JNIEnv* env = getJNIEnv(); env->functions->ReleaseLongArrayElements(env, array, v, mode); JAVA_CHECK("ReleaseLongArrayElements"); } jfloatArray JPJavaEnv::NewFloatArray(jint len) { JNIEnv* env = getJNIEnv(); jfloatArray res = env->functions->NewFloatArray(env, len); JAVA_CHECK("NewFloatArray"); return res; } void JPJavaEnv::SetFloatArrayRegion(jfloatArray array, int start, int len, jfloat* vals) { JNIEnv* env = getJNIEnv(); env->functions->SetFloatArrayRegion(env, array, start, len, vals); JAVA_CHECK("SetFloatArrayRegion"); } void JPJavaEnv::GetFloatArrayRegion(jfloatArray array, int start, int len, jfloat* vals) { JNIEnv* env = getJNIEnv(); env->functions->GetFloatArrayRegion(env, array, start, len, vals); JAVA_CHECK("GetFloatArrayRegion"); } jfloat* JPJavaEnv::GetFloatArrayElements(jfloatArray array, jboolean* isCopy) { JNIEnv* env = getJNIEnv(); jfloat* res = env->functions->GetFloatArrayElements(env, array, isCopy); JAVA_CHECK("GetFloatArrayElements"); return res; } void JPJavaEnv::ReleaseFloatArrayElements(jfloatArray array, jfloat* v, jint mode) { JNIEnv* env = getJNIEnv(); env->functions->ReleaseFloatArrayElements(env, array, v, mode); JAVA_CHECK("ReleaseFloatArrayElements"); } jdoubleArray JPJavaEnv::NewDoubleArray(jint len) { JNIEnv* env = getJNIEnv(); jdoubleArray res = env->functions->NewDoubleArray(env, len); JAVA_CHECK("NewDoubleArray"); return res; } void JPJavaEnv::SetDoubleArrayRegion(jdoubleArray array, int start, int len, jdouble* vals) { JNIEnv* env = getJNIEnv(); env->functions->SetDoubleArrayRegion(env, array, start, len, vals); JAVA_CHECK("SetDoubleArrayRegion"); } void JPJavaEnv::GetDoubleArrayRegion(jdoubleArray array, int start, int len, jdouble* vals) { JNIEnv* env = getJNIEnv(); env->functions->GetDoubleArrayRegion(env, array, start, len, vals); JAVA_CHECK("GetDoubleArrayRegion"); } jdouble* JPJavaEnv::GetDoubleArrayElements(jdoubleArray array, jboolean* isCopy) { JNIEnv* env = getJNIEnv(); jdouble* res = env->functions->GetDoubleArrayElements(env, array, isCopy); JAVA_CHECK("GetDoubleArrayElements"); return res; } void JPJavaEnv::ReleaseDoubleArrayElements(jdoubleArray array, jdouble* v, jint mode) { JNIEnv* env = getJNIEnv(); env->functions->ReleaseDoubleArrayElements(env, array, v, mode); JAVA_CHECK("ReleaseDoubleArrayElements"); } jcharArray JPJavaEnv::NewCharArray(jint len) { JNIEnv* env = getJNIEnv(); jcharArray res = env->functions->NewCharArray(env, len); JAVA_CHECK("NewCharArray"); return res; } void JPJavaEnv::SetCharArrayRegion(jcharArray array, int start, int len, jchar* vals) { JNIEnv* env = getJNIEnv(); env->functions->SetCharArrayRegion(env, array, start, len, vals); JAVA_CHECK("SetCharArrayRegion"); } void JPJavaEnv::GetCharArrayRegion(jcharArray array, int start, int len, jchar* vals) { JNIEnv* env = getJNIEnv(); env->functions->GetCharArrayRegion(env, array, start, len, vals); JAVA_CHECK("GetCharArrayRegion"); } jchar* JPJavaEnv::GetCharArrayElements(jcharArray array, jboolean* isCopy) { JNIEnv* env = getJNIEnv(); jchar* res = env->functions->GetCharArrayElements(env, array, isCopy); JAVA_CHECK("GetCharArrayElements"); return res; } void JPJavaEnv::ReleaseCharArrayElements(jcharArray array, jchar* v, jint mode) { JNIEnv* env = getJNIEnv(); env->functions->ReleaseCharArrayElements(env, array, v, mode); JAVA_CHECK("ReleaseCharArrayElements"); } jbooleanArray JPJavaEnv::NewBooleanArray(jint len) { JNIEnv* env = getJNIEnv(); jbooleanArray res = env->functions->NewBooleanArray(env, len); JAVA_CHECK("NewBooleanArray"); return res; } void JPJavaEnv::SetBooleanArrayRegion(jbooleanArray array, int start, int len, jboolean* vals) { JNIEnv* env = getJNIEnv(); env->functions->SetBooleanArrayRegion(env, array, start, len, vals); JAVA_CHECK("SetBooleanArrayRegion"); } void JPJavaEnv::GetBooleanArrayRegion(jbooleanArray array, int start, int len, jboolean* vals) { JNIEnv* env = getJNIEnv(); env->functions->GetBooleanArrayRegion(env, array, start, len, vals); JAVA_CHECK("GetBooleanArrayRegion"); } jboolean* JPJavaEnv::GetBooleanArrayElements(jbooleanArray array, jboolean* isCopy) { JNIEnv* env = getJNIEnv(); jboolean* res = env->functions->GetBooleanArrayElements(env, array, isCopy); JAVA_CHECK("GetBooleanArrayElements"); return res; } void JPJavaEnv::ReleaseBooleanArrayElements(jbooleanArray array, jboolean* v, jint mode) { JNIEnv* env = getJNIEnv(); env->functions->ReleaseBooleanArrayElements(env, array, v, mode); JAVA_CHECK("ReleaseBooleanArrayElements"); } int JPJavaEnv::MonitorEnter(jobject a0) { int res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->MonitorEnter(env, a0); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("MonitorEnter"); return res; } int JPJavaEnv::MonitorExit(jobject a0) { int res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->MonitorExit(env, a0); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("MonitorExit"); return res; } jmethodID JPJavaEnv::FromReflectedMethod(jobject a0) { jmethodID res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->FromReflectedMethod(env, a0); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("FromReflectedMethod"); return res; } jfieldID JPJavaEnv::FromReflectedField(jobject a0) { jfieldID res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->FromReflectedField(env, a0); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("FromReflectedField"); return res; } jclass JPJavaEnv::FindClass(const char* a0) { jclass res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->FindClass(env, a0); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("FindClass"); return res; } jboolean JPJavaEnv::IsInstanceOf(jobject a0, jclass a1) { jboolean res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->IsInstanceOf(env, a0, a1); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("IsInstanceOf"); return res; } jobjectArray JPJavaEnv::NewObjectArray(int a0, jclass a1, jobject a2) { jobjectArray res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->NewObjectArray(env, a0, a1, a2); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("NewObjectArray"); return res; } void JPJavaEnv::SetObjectArrayElement(jobjectArray a0, int a1, jobject a2) { JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); env->functions->SetObjectArrayElement(env, a0, a1, a2); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("SetObjectArrayElement"); } void JPJavaEnv::CallStaticVoidMethodA(jclass a0, jmethodID a1, jvalue* a2) { JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); env->functions->CallStaticVoidMethodA(env, a0, a1, a2); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("CallStaticVoidMethodA"); } void JPJavaEnv::CallVoidMethodA(jobject a0, jmethodID a1, jvalue* a2) { JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); env->functions->CallVoidMethodA(env, a0, a1, a2); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("CallVoidMethodA"); } void JPJavaEnv::CallVoidMethod(jobject a0, jmethodID a1) { JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); env->functions->CallVoidMethod(env, a0, a1); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("CallVoidMethod"); } jboolean JPJavaEnv::IsAssignableFrom(jclass a0, jclass a1) { jboolean res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->IsAssignableFrom(env, a0, a1); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("IsAssignableFrom"); return res; } jstring JPJavaEnv::NewString(const jchar* a0, int a1) { jstring res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->NewString(env, a0, a1); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("NewString"); return res; } jclass JPJavaEnv::GetSuperclass(jclass a0) { jclass res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->GetSuperclass(env, a0); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("GetSuperclass"); return res; } const char* JPJavaEnv::GetStringUTFChars(jstring a0, jboolean* a1) { const char* res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->GetStringUTFChars(env, a0, a1); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("GetStringUTFChars"); return res; } void JPJavaEnv::ReleaseStringUTFChars(jstring a0, const char* a1) { JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); env->functions->ReleaseStringUTFChars(env, a0, a1); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("ReleaseStringUTFChars"); } jsize JPJavaEnv::GetArrayLength(jarray a0) { jsize res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->GetArrayLength(env, a0); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("GetArrayLength"); return res; } jobject JPJavaEnv::GetObjectArrayElement(jobjectArray a0, int a1) { jobject res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->GetObjectArrayElement(env, a0, a1); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("GetObjectArrayElement"); return res; } jclass JPJavaEnv::GetObjectClass(jobject a0) { jclass res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->GetObjectClass(env, a0); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("GetObjectClass"); return res; } jmethodID JPJavaEnv::GetMethodID(jclass a0, char* a1, char* a2) { jmethodID res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->GetMethodID(env, a0, a1, a2); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("GetMethodID"); return res; } jmethodID JPJavaEnv::GetStaticMethodID(jclass a0, char* a1, char* a2) { jmethodID res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->GetStaticMethodID(env, a0, a1, a2); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("GetStaticMethodID"); return res; } jfieldID JPJavaEnv::GetFieldID(jclass a0, char* a1, char* a2) { jfieldID res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->GetFieldID(env, a0, a1, a2); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("GetFieldID"); return res; } jfieldID JPJavaEnv::GetStaticFieldID(jclass a0, char* a1, char* a2) { jfieldID res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->GetStaticFieldID(env, a0, a1, a2); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("GetStaticFieldID"); return res; } const jchar* JPJavaEnv::GetStringChars(jstring a0, jboolean* a1) { const jchar* res; JNIEnv* env = getJNIEnv(); res = env->functions->GetStringChars(env, a0, a1); JAVA_CHECK("GetStringChars"); return res; } void JPJavaEnv::ReleaseStringChars(jstring a0, const jchar* a1) { JNIEnv* env = getJNIEnv(); env->functions->ReleaseStringChars(env, a0, a1); JAVA_CHECK("ReleaseStringChars"); } jsize JPJavaEnv::GetStringLength(jstring a0) { jsize res; JNIEnv* env = getJNIEnv(); res = env->functions->GetStringLength(env, a0); JAVA_CHECK("GetStringLength"); return res; } jclass JPJavaEnv::DefineClass(const char* a0, jobject a1, const jbyte* a2, jsize a3) { jclass res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->DefineClass(env, a0, a1, a2, a3); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("DefineClass"); return res; } jint JPJavaEnv::RegisterNatives(jclass a0, const JNINativeMethod* a1, jint a2) { jint res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->RegisterNatives(env, a0, a1, a2); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("RegisterNatives"); return res; } python-jpype-0.5.4.2/src/native/common/jp_jniutil.cpp0000666000175000017500000006501211614007722022050 0ustar takakitakaki/***************************************************************************** Copyright 2004-2008 Steve Menard 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. *****************************************************************************/ #include jclass JPJni::s_ClassClass; jclass JPJni::s_StringClass; jclass JPJni::s_NoSuchMethodErrorClass; jclass JPJni::s_RuntimeExceptionClass; jclass JPJni::s_ProxyClass; jmethodID JPJni::s_NewProxyInstanceID; jlong JPJni::s_minByte; jlong JPJni::s_maxByte; jlong JPJni::s_minShort; jlong JPJni::s_maxShort; jlong JPJni::s_minInt; jlong JPJni::s_maxInt; jfloat JPJni::s_minFloat; jfloat JPJni::s_maxFloat; static jclass objectClass; static jmethodID getClassID; static jmethodID toStringID; static jmethodID hashCodeID; static jmethodID getNameID; static jmethodID getDeclaredFieldsID; static jmethodID getDeclaredMethodsID; static jmethodID getInterfacesID; static jmethodID getFieldsID; static jmethodID getMethodsID; static jmethodID getDeclaredConstructorsID; static jmethodID getConstructorsID; static jmethodID isInterfaceID; static jmethodID getClassModifiersID; static jclass modifierClass; static jmethodID isStaticID; static jmethodID isPublicID; static jmethodID isAbstractID; static jmethodID isFinalID; static jclass classLoaderClass; static jmethodID getSystemClassLoaderID; static jclass memberClass; static jmethodID getModifiersID; static jmethodID getMemberNameID; static jclass fieldClass; static jmethodID getTypeID; static jclass methodClass; static jclass constructorClass; static jmethodID getReturnTypeID; static jmethodID getParameterTypesID; static jmethodID getConstructorParameterTypesID; static jclass throwableClass; static jmethodID getMessageID; static jmethodID printStackTraceID; static jclass stringWriterClass; static jclass printWriterClass; static jmethodID stringWriterID; static jmethodID printWriterID; static jmethodID flushID; static jclass numberClass; static jclass booleanClass; static jclass charClass; static jclass byteClass; static jclass shortClass; static jclass intClass; static jclass floatClass; static jmethodID intValueID; static jmethodID longValueID; static jmethodID doubleValueID; static jmethodID booleanValueID; static jmethodID charValueID; static jclass JPypeReferenceClass; static jmethodID JPypeReferenceConstructorMethod; static jclass JPypeReferenceQueueClass; static jmethodID JPypeReferenceQueueConstructorMethod; static jmethodID JPypeReferenceQueueRegisterMethod; static jmethodID JPypeReferenceQueueStartMethod; static jmethodID JPypeReferenceQueueRunMethod; static jmethodID JPypeReferenceQueueStopMethod; void JPJni::init() { objectClass = (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("Ljava/lang/Object;")); s_StringClass = (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("Ljava/lang/String;")); getClassID = JPEnv::getJava()->GetMethodID(objectClass, "getClass", "()Ljava/lang/Class;"); toStringID = JPEnv::getJava()->GetMethodID(objectClass, "toString", "()Ljava/lang/String;"); hashCodeID = JPEnv::getJava()->GetMethodID(objectClass, "hashCode", "()I"); s_ClassClass = (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("Ljava/lang/Class;")); getNameID = JPEnv::getJava()->GetMethodID(s_ClassClass, "getName", "()Ljava/lang/String;"); getDeclaredFieldsID = JPEnv::getJava()->GetMethodID(s_ClassClass, "getDeclaredFields", "()[Ljava/lang/reflect/Field;"); getDeclaredMethodsID = JPEnv::getJava()->GetMethodID(s_ClassClass, "getDeclaredMethods", "()[Ljava/lang/reflect/Method;"); getMethodsID = JPEnv::getJava()->GetMethodID(s_ClassClass, "getMethods", "()[Ljava/lang/reflect/Method;"); getDeclaredConstructorsID = JPEnv::getJava()->GetMethodID(s_ClassClass, "getDeclaredConstructors", "()[Ljava/lang/reflect/Constructor;"); getConstructorsID = JPEnv::getJava()->GetMethodID(s_ClassClass, "getConstructors", "()[Ljava/lang/reflect/Constructor;"); isInterfaceID = JPEnv::getJava()->GetMethodID(s_ClassClass, "isInterface", "()Z"); getClassModifiersID = JPEnv::getJava()->GetMethodID(s_ClassClass, "getModifiers", "()I"); getInterfacesID = JPEnv::getJava()->GetMethodID(s_ClassClass, "getInterfaces", "()[Ljava/lang/Class;"); modifierClass = (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("Ljava/lang/reflect/Modifier;")); isStaticID = JPEnv::getJava()->GetStaticMethodID(modifierClass, "isStatic", "(I)Z"); isPublicID = JPEnv::getJava()->GetStaticMethodID(modifierClass, "isPublic", "(I)Z"); isAbstractID = JPEnv::getJava()->GetStaticMethodID(modifierClass, "isAbstract", "(I)Z"); isFinalID = JPEnv::getJava()->GetStaticMethodID(modifierClass, "isFinal", "(I)Z"); classLoaderClass = (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("Ljava/lang/ClassLoader;")); getSystemClassLoaderID = JPEnv::getJava()->GetStaticMethodID(classLoaderClass, "getSystemClassLoader", "()Ljava/lang/ClassLoader;"); s_NoSuchMethodErrorClass = (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("Ljava/lang/NoSuchMethodError;") ); s_RuntimeExceptionClass = (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("Ljava/lang/RuntimeException;") ); s_ProxyClass = (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("Ljava/lang/reflect/Proxy;") ); s_NewProxyInstanceID = JPEnv::getJava()->GetStaticMethodID(s_ProxyClass, "newProxyInstance", "(Ljava/lang/ClassLoader;[Ljava/lang/Class;Ljava/lang/reflect/InvocationHandler;)Ljava/lang/Object;"); memberClass = (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("Ljava/lang/reflect/Member;")); getModifiersID = JPEnv::getJava()->GetMethodID(memberClass, "getModifiers", "()I"); getMemberNameID = JPEnv::getJava()->GetMethodID(memberClass, "getName", "()Ljava/lang/String;"); fieldClass = (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("Ljava/lang/reflect/Field;")); getTypeID = JPEnv::getJava()->GetMethodID(fieldClass, "getType", "()Ljava/lang/Class;"); methodClass = (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("Ljava/lang/reflect/Method;")); constructorClass = (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("Ljava/lang/reflect/Constructor;")); getReturnTypeID = JPEnv::getJava()->GetMethodID(methodClass, "getReturnType", "()Ljava/lang/Class;"); getParameterTypesID = JPEnv::getJava()->GetMethodID(methodClass, "getParameterTypes", "()[Ljava/lang/Class;"); getConstructorParameterTypesID = JPEnv::getJava()->GetMethodID(constructorClass, "getParameterTypes", "()[Ljava/lang/Class;"); throwableClass = (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("Ljava/lang/Throwable;")); getMessageID = JPEnv::getJava()->GetMethodID(throwableClass, "getMessage", "()Ljava/lang/String;"); printStackTraceID = JPEnv::getJava()->GetMethodID(throwableClass, "printStackTrace", "(Ljava/io/PrintWriter;)V"); stringWriterClass = (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("Ljava/io/StringWriter;")); printWriterClass = (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("Ljava/io/PrintWriter;")); stringWriterID = JPEnv::getJava()->GetMethodID(stringWriterClass, "", "()V"); printWriterID = JPEnv::getJava()->GetMethodID(printWriterClass, "", "(Ljava/io/Writer;)V"); flushID = JPEnv::getJava()->GetMethodID(printWriterClass, "flush", "()V"); numberClass = (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("Ljava/lang/Number;")); booleanClass= (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("Ljava/lang/Boolean;")); charClass= (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("Ljava/lang/Character;")); intValueID = JPEnv::getJava()->GetMethodID(numberClass, "intValue", "()I"); longValueID = JPEnv::getJava()->GetMethodID(numberClass, "longValue", "()J"); doubleValueID = JPEnv::getJava()->GetMethodID(numberClass, "doubleValue", "()D"); booleanValueID = JPEnv::getJava()->GetMethodID(booleanClass, "booleanValue", "()Z"); charValueID = JPEnv::getJava()->GetMethodID(charClass, "charValue", "()C"); byteClass= (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("Ljava/lang/Byte;")); shortClass= (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("Ljava/lang/Short;")); intClass= (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("Ljava/lang/Integer;")); floatClass= (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("Ljava/lang/Float;")); jfieldID fid = JPEnv::getJava()->GetStaticFieldID(byteClass, "MIN_VALUE", "B"); s_minByte = JPEnv::getJava()->GetStaticByteField(byteClass, fid); fid = JPEnv::getJava()->GetStaticFieldID(byteClass, "MAX_VALUE", "B"); s_maxByte = JPEnv::getJava()->GetStaticByteField(byteClass, fid); fid = JPEnv::getJava()->GetStaticFieldID(shortClass, "MIN_VALUE", "S"); s_minShort = JPEnv::getJava()->GetStaticShortField(shortClass, fid); fid = JPEnv::getJava()->GetStaticFieldID(shortClass, "MAX_VALUE", "S"); s_maxShort = JPEnv::getJava()->GetStaticShortField(shortClass, fid); fid = JPEnv::getJava()->GetStaticFieldID(intClass, "MIN_VALUE", "I"); s_minInt = JPEnv::getJava()->GetStaticIntField(intClass, fid); fid = JPEnv::getJava()->GetStaticFieldID(intClass, "MAX_VALUE", "I"); s_maxInt = JPEnv::getJava()->GetStaticIntField(intClass, fid); fid = JPEnv::getJava()->GetStaticFieldID(floatClass, "MIN_VALUE", "F"); s_minFloat = JPEnv::getJava()->GetStaticFloatField(floatClass, fid); fid = JPEnv::getJava()->GetStaticFieldID(floatClass, "MAX_VALUE", "F"); s_maxFloat = JPEnv::getJava()->GetStaticFloatField(floatClass, fid); } string JPJni::asciiFromJava(jstring str) { const char* cstr = NULL; jboolean isCopy; cstr = JPEnv::getJava()->GetStringUTFChars(str, &isCopy); int length = JPEnv::getJava()->GetStringLength(str); string res; for (int i = 0; i < length; i++) { res += (char)cstr[i]; } JPEnv::getJava()->ReleaseStringUTFChars(str, cstr); return res; } JCharString JPJni::unicodeFromJava(jstring str) { const jchar* cstr = NULL; jboolean isCopy; cstr = JPEnv::getJava()->GetStringChars(str, &isCopy); JCharString res = cstr; JPEnv::getJava()->ReleaseStringChars(str, cstr); return res; } jstring JPJni::javaStringFromJCharString(JCharString& wstr) { jstring result = JPEnv::getJava()->NewString(wstr.c_str(), (jint)wstr.length()); return result; } JPTypeName JPJni::getClassName(jobject o) { if (o == NULL) { return JPTypeName::fromSimple("java.lang.Object"); } JPCleaner cleaner; jclass c = getClass(o); cleaner.addLocal(c); return JPJni::getName(c); } jclass JPJni::getClass(jobject o) { return (jclass)JPEnv::getJava()->CallObjectMethod(o, getClassID); } jstring JPJni::toString(jobject o) { jstring str = (jstring)JPEnv::getJava()->CallObjectMethod(o, toStringID); return str; } static string convertToSimpleName(jclass c) { JPCleaner cleaner; jstring jname = (jstring)JPEnv::getJava()->CallObjectMethod(c, getNameID); cleaner.addLocal(jname); string name = JPJni::asciiFromJava(jname); // Class.getName returns something weird for arrays ... if (name[0] == '[') { // perform a little cleanup of the name ... unsigned int arrayCount = 0; for (unsigned int i = 0; i < name.length(); i++) { if (name[i] == '[') { arrayCount++; } } name = name.substr(arrayCount, name.length()-(arrayCount)); // Now, let's convert the "native" part switch(name[0]) { case 'B' : name = "byte"; break; case 'S' : name = "short"; break; case 'I' : name = "int"; break; case 'J' : name = "long"; break; case 'F' : name = "float"; break; case 'D' : name = "double"; break; case 'C' : name = "char"; break; case 'Z' : name = "boolean"; break; case 'L' : name = name.substr(1, name.length()-2); for (unsigned int i = 0; i < name.length(); i++) { if (name[i] == '/') { name[i] = '.'; } } break; } for (unsigned int j = 0; j < arrayCount; j++) { name = name + "[]"; } } return name; } bool JPJni::isInterface(jclass clazz) { jboolean b = JPEnv::getJava()->CallBooleanMethod(clazz, isInterfaceID); return (b ? true : false); } bool JPJni::isAbstract(jclass clazz) { jvalue modif; modif.i = JPEnv::getJava()->CallIntMethod(clazz, getClassModifiersID); jboolean res = JPEnv::getJava()->CallStaticBooleanMethodA(modifierClass, isAbstractID, &modif); return (res ? true : false); } long JPJni::getClassModifiers(jclass clazz) { long res = JPEnv::getJava()->CallIntMethod(clazz, getClassModifiersID); return res; } bool JPJni::isFinal(jclass clazz) { jvalue modif; modif.i = JPEnv::getJava()->CallIntMethod(clazz, getClassModifiersID); jboolean res = JPEnv::getJava()->CallStaticBooleanMethodA(modifierClass, isFinalID, &modif); return (res ? true : false); } JPTypeName JPJni::getName(jclass clazz) { string simpleName = convertToSimpleName(clazz); return JPTypeName::fromSimple(simpleName.c_str()); } vector JPJni::getInterfaces(jclass clazz) { JPCleaner cleaner; jobjectArray interfaces = (jobjectArray)JPEnv::getJava()->CallObjectMethod(clazz, getInterfacesID); cleaner.addLocal(interfaces); int len = JPEnv::getJava()->GetArrayLength(interfaces); vector res; for (int i = 0; i < len; i++) { jclass c = (jclass)JPEnv::getJava()->GetObjectArrayElement(interfaces, i); res.push_back(c); } return res; } vector JPJni::getDeclaredFields(jclass clazz) { JPCleaner cleaner; jobjectArray fields = (jobjectArray)JPEnv::getJava()->CallObjectMethod(clazz, getDeclaredFieldsID); cleaner.addLocal(fields); int len = JPEnv::getJava()->GetArrayLength(fields); vector res; for (int i = 0; i < len; i++) { jobject c = JPEnv::getJava()->GetObjectArrayElement(fields, i); res.push_back(c); } return res; } vector JPJni::getFields(jclass clazz) { JPCleaner cleaner; jobjectArray fields = (jobjectArray)JPEnv::getJava()->CallObjectMethod(clazz, getFieldsID); cleaner.addLocal(fields); int len = JPEnv::getJava()->GetArrayLength(fields); vector res; for (int i = 0; i < len; i++) { jobject c = JPEnv::getJava()->GetObjectArrayElement(fields, i); res.push_back(c); } return res; } vector JPJni::getDeclaredMethods(jclass clazz) { JPCleaner cleaner; jobjectArray methods = (jobjectArray)JPEnv::getJava()->CallObjectMethod(clazz, getDeclaredMethodsID); cleaner.addLocal(methods); int len = JPEnv::getJava()->GetArrayLength(methods); vector res; for (int i = 0; i < len; i++) { jobject c = JPEnv::getJava()->GetObjectArrayElement(methods, i); res.push_back(c); } return res; } vector JPJni::getDeclaredConstructors(jclass clazz) { JPCleaner cleaner; jobjectArray methods = (jobjectArray)JPEnv::getJava()->CallObjectMethod(clazz, getDeclaredConstructorsID); cleaner.addLocal(methods); int len = JPEnv::getJava()->GetArrayLength(methods); vector res; for (int i = 0; i < len; i++) { jobject c = JPEnv::getJava()->GetObjectArrayElement(methods, i); res.push_back(c); } return res; } vector JPJni::getConstructors(jclass clazz) { JPCleaner cleaner; jobjectArray methods = (jobjectArray)JPEnv::getJava()->CallObjectMethod(clazz, getConstructorsID); cleaner.addLocal(methods); int len = JPEnv::getJava()->GetArrayLength(methods); vector res; for (int i = 0; i < len; i++) { jobject c = JPEnv::getJava()->GetObjectArrayElement(methods, i); res.push_back(c); } return res; } vector JPJni::getMethods(jclass clazz) { JPCleaner cleaner; jobjectArray methods = (jobjectArray)JPEnv::getJava()->CallObjectMethod(clazz, getMethodsID); cleaner.addLocal(methods); int len = JPEnv::getJava()->GetArrayLength(methods); vector res; for (int i = 0; i < len; i++) { jobject c = JPEnv::getJava()->GetObjectArrayElement(methods, i); res.push_back(c); } return res; } jobject JPJni::getSystemClassLoader() { return JPEnv::getJava()->CallStaticObjectMethod(classLoaderClass, getSystemClassLoaderID) ; } string JPJni::getMemberName(jobject o) { JPCleaner cleaner; jstring name = (jstring)JPEnv::getJava()->CallObjectMethod(o, getMemberNameID); cleaner.addLocal(name); string simpleName = JPJni::asciiFromJava(name); return simpleName; } bool JPJni::isMemberPublic(jobject o) { jvalue modif; modif.i = JPEnv::getJava()->CallIntMethod(o, getModifiersID); jboolean res = JPEnv::getJava()->CallStaticBooleanMethodA(modifierClass, isPublicID, &modif); return (res ? true : false); } bool JPJni::isMemberStatic(jobject o) { jvalue modif; modif.i = JPEnv::getJava()->CallIntMethod(o, getModifiersID); jboolean res = JPEnv::getJava()->CallStaticBooleanMethodA(modifierClass, isStaticID, &modif); return (res ? true : false); } bool JPJni::isMemberFinal(jobject o) { jvalue modif; modif.i = JPEnv::getJava()->CallIntMethod(o, getModifiersID); jboolean res = JPEnv::getJava()->CallStaticBooleanMethodA(modifierClass, isFinalID, &modif); return (res ? true : false); } bool JPJni::isMemberAbstract(jobject o) { jvalue modif; modif.i = JPEnv::getJava()->CallIntMethod(o, getModifiersID); jboolean res = JPEnv::getJava()->CallStaticBooleanMethodA(modifierClass, isAbstractID, &modif); return (res ? true : false); } jint JPJni::hashCode(jobject obj) { jint res = JPEnv::getJava()->CallIntMethod(obj, hashCodeID); return res; } JPTypeName JPJni::getType(jobject fld) { TRACE_IN("JPJni::getType"); JPCleaner cleaner; jclass c = (jclass)JPEnv::getJava()->CallObjectMethod(fld, getTypeID); cleaner.addLocal(c); return JPJni::getName(c); TRACE_OUT; } JPTypeName JPJni::getReturnType(jobject o) { JPCleaner cleaner; jclass c = (jclass)JPEnv::getJava()->CallObjectMethod(o, getReturnTypeID); cleaner.addLocal(c); return JPJni::getName(c); } vector JPJni::getParameterTypes(jobject o, bool isConstructor) { JPCleaner cleaner; vector args; jobjectArray types ; if (isConstructor) { types = (jobjectArray)JPEnv::getJava()->CallObjectMethod(o, getConstructorParameterTypesID); } else { types = (jobjectArray)JPEnv::getJava()->CallObjectMethod(o, getParameterTypesID); } cleaner.addLocal(types); int len = JPEnv::getJava()->GetArrayLength(types); for (int i = 0; i < len; i++) { jclass c = (jclass)JPEnv::getJava()->GetObjectArrayElement(types, i); cleaner.addLocal(c); JPTypeName name = JPJni::getName(c); args.push_back(name); } return args; } bool JPJni::isConstructor(jobject obj) { jboolean r = JPEnv::getJava()->IsInstanceOf(obj, constructorClass); if (r) { return true; } return false; } string JPJni::getStackTrace(jthrowable th) { JPCleaner cleaner; jobject strWriter = JPEnv::getJava()->NewObject(stringWriterClass, stringWriterID); cleaner.addLocal(strWriter); jvalue v; v.l = strWriter; jobject printWriter = JPEnv::getJava()->NewObjectA(printWriterClass, printWriterID, &v); cleaner.addLocal(printWriter); v.l = printWriter; JPEnv::getJava()->CallVoidMethodA(th, printStackTraceID, &v); JPEnv::getJava()->CallVoidMethod(printWriter, flushID); jstring res = JPJni::toString(strWriter); cleaner.addLocal(res); return JPJni::asciiFromJava(res); } string JPJni::getMessage(jthrowable th) { JPCleaner cleaner; jstring jstr = (jstring)JPEnv::getJava()->CallObjectMethod(th, getMessageID); cleaner.addLocal(jstr); return JPJni::asciiFromJava(jstr); } bool JPJni::isThrowable(jclass c) { jboolean res = JPEnv::getJava()->IsAssignableFrom(c, throwableClass); if (res) { return true; } return false; } long JPJni::intValue(jobject obj) { return JPEnv::getJava()->CallIntMethod(obj, intValueID); } jlong JPJni::longValue(jobject obj) { return JPEnv::getJava()->CallLongMethod(obj, longValueID); } double JPJni::doubleValue(jobject obj) { return JPEnv::getJava()->CallDoubleMethod(obj, doubleValueID); } bool JPJni::booleanValue(jobject obj) { return JPEnv::getJava()->CallBooleanMethod(obj, booleanValueID) ? true : false; } jchar JPJni::charValue(jobject obj) { return JPEnv::getJava()->CallCharMethod(obj, charValueID); } jclass JPJni::getByteClass() { jclass byteClass = (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("Ljava/lang/Byte;")); jfieldID fid = JPEnv::getJava()->GetStaticFieldID(byteClass, "TYPE", "Ljava/lang/Class;"); jclass res = (jclass)JPEnv::getJava()->GetStaticObjectField(byteClass, fid); JPEnv::getJava()->DeleteLocalRef(byteClass); return res; } jclass JPJni::getShortClass() { jclass shortClass = (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("Ljava/lang/Short;")); jfieldID fid = JPEnv::getJava()->GetStaticFieldID(shortClass, "TYPE", "Ljava/lang/Class;"); jclass res = (jclass)JPEnv::getJava()->GetStaticObjectField(shortClass, fid); JPEnv::getJava()->DeleteLocalRef(shortClass); return res; } jclass JPJni::getIntegerClass() { jclass intClass = (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("Ljava/lang/Integer;")); jfieldID fid = JPEnv::getJava()->GetStaticFieldID(intClass, "TYPE", "Ljava/lang/Class;"); jclass res = (jclass)JPEnv::getJava()->GetStaticObjectField(intClass, fid); JPEnv::getJava()->DeleteLocalRef(intClass); return res; } jclass JPJni::getLongClass() { jclass longClass = (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("Ljava/lang/Long;")); jfieldID fid = JPEnv::getJava()->GetStaticFieldID(longClass, "TYPE", "Ljava/lang/Class;"); jclass res = (jclass)JPEnv::getJava()->GetStaticObjectField(longClass, fid); JPEnv::getJava()->DeleteLocalRef(longClass); return res; } jclass JPJni::getFloatClass() { jclass floatClass = (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("Ljava/lang/Float;")); jfieldID fid = JPEnv::getJava()->GetStaticFieldID(floatClass, "TYPE", "Ljava/lang/Class;"); jclass res = (jclass)JPEnv::getJava()->GetStaticObjectField(floatClass, fid); JPEnv::getJava()->DeleteLocalRef(floatClass); return res; } jclass JPJni::getDoubleClass() { jclass doubleClass= (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("Ljava/lang/Double;")); jfieldID fid = JPEnv::getJava()->GetStaticFieldID(doubleClass, "TYPE", "Ljava/lang/Class;"); jclass res = (jclass)JPEnv::getJava()->GetStaticObjectField(doubleClass, fid); JPEnv::getJava()->DeleteLocalRef(doubleClass); return res; } jclass JPJni::getCharacterClass() { jclass charClass = (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("Ljava/lang/Character;")); jfieldID fid = JPEnv::getJava()->GetStaticFieldID(charClass, "TYPE", "Ljava/lang/Class;"); jclass res = (jclass)JPEnv::getJava()->GetStaticObjectField(charClass, fid); JPEnv::getJava()->DeleteLocalRef(charClass); return res; } jclass JPJni::getBooleanClass() { jclass booleanClass = (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("Ljava/lang/Boolean;")); jfieldID fid = JPEnv::getJava()->GetStaticFieldID(booleanClass, "TYPE", "Ljava/lang/Class;"); jclass res = (jclass)JPEnv::getJava()->GetStaticObjectField(booleanClass, fid); JPEnv::getJava()->DeleteLocalRef(booleanClass); return res; } jclass JPJni::getVoidClass() { jclass voidClass= (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("Ljava/lang/Void;")); jfieldID fid = JPEnv::getJava()->GetStaticFieldID(voidClass, "TYPE", "Ljava/lang/Class;"); jclass res = (jclass)JPEnv::getJava()->GetStaticObjectField(voidClass, fid); JPEnv::getJava()->DeleteLocalRef(voidClass); return res; } void JPJni::startJPypeReferenceQueue(bool useJavaThread) { JPCleaner cleaner; JPypeReferenceQueueClass = (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("Ljpype/ref/JPypeReferenceQueue;")); JPypeReferenceQueueConstructorMethod = JPEnv::getJava()->GetMethodID(JPypeReferenceQueueClass, "", "()V"); JPypeReferenceQueueRegisterMethod = JPEnv::getJava()->GetMethodID(JPypeReferenceQueueClass, "registerRef", "(Ljpype/ref/JPypeReference;J)V"); JPypeReferenceQueueStartMethod = JPEnv::getJava()->GetMethodID(JPypeReferenceQueueClass, "startManaging", "()V"); JPypeReferenceQueueRunMethod = JPEnv::getJava()->GetMethodID(JPypeReferenceQueueClass, "run", "()V"); JPypeReferenceQueueStopMethod = JPEnv::getJava()->GetMethodID(JPypeReferenceQueueClass, "stop", "()V"); JPypeReferenceClass = (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("Ljpype/ref/JPypeReference;")); JPypeReferenceConstructorMethod = JPEnv::getJava()->GetMethodID(JPypeReferenceClass, "", "(Ljava/lang/Object;Ljava/lang/ref/ReferenceQueue;)V"); jobject obj = JPEnv::getJava()->NewObject(JPypeReferenceQueueClass, JPypeReferenceQueueConstructorMethod); cleaner.addLocal(obj); JPEnv::getJava()->setReferenceQueue(obj); if (useJavaThread) { JPEnv::getJava()->CallVoidMethod(obj, JPypeReferenceQueueStartMethod); } else { JPEnv::getJava()->CallVoidMethod(obj, JPypeReferenceQueueRunMethod); } } void JPJni::stopJPypeReferenceQueue() { JPEnv::getJava()->CallVoidMethod(JPEnv::getJava()->getReferenceQueue(), JPypeReferenceQueueStopMethod); } void JPJni::registerRef(jobject refQueue, jobject obj, jlong hostRef) { TRACE_IN("JPJni::registerRef"); // create the ref ... jvalue args[2]; args[0].l = obj; args[1].l = refQueue; JPCleaner cleaner; jobject refObj = JPEnv::getJava()->NewObjectA(JPypeReferenceClass, JPypeReferenceConstructorMethod, args); cleaner.addLocal(refObj); args[0].l = refObj; args[1].j = hostRef; JPEnv::getJava()->CallVoidMethodA(refQueue, JPypeReferenceQueueRegisterMethod, args); TRACE_OUT; } python-jpype-0.5.4.2/src/native/common/jp_object.cpp0000666000175000017500000000475511614007722021647 0ustar takakitakaki/***************************************************************************** Copyright 2004-2008 Steve Menard 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. *****************************************************************************/ #include JPObject::JPObject(JPTypeName& c, jobject o) { m_Class = JPTypeManager::findClass(c); m_Object = JPEnv::getJava()->NewGlobalRef(o); } JPObject::JPObject(JPClass* c, jobject o) { m_Class = c; m_Object = JPEnv::getJava()->NewGlobalRef(o); } JPObject::~JPObject() { JPEnv::getJava()->DeleteGlobalRef(m_Object); } JCharString JPObject::toString() { if (m_Object == NULL) { static const char* value = "null"; jchar res[5]; res[4] = 0; for (int i = 0; value[i] != 0; i++) { res[i] = value[i]; } return res; } JPCleaner cleaner; jstring jval = JPJni::toString(m_Object); cleaner.addLocal(jval); JCharString result = JPJni::unicodeFromJava(jval); return result; } HostRef* JPObject::getAttribute(string name) { TRACE_IN("JPObject::getAttribute"); TRACE1(name); JPCleaner cleaner; // instance fields ... JPField* fld = m_Class->getInstanceField(name); if (fld != NULL) { return fld->getAttribute(m_Object); } // static fields ... fld = m_Class->getStaticField(name); if (fld != NULL) { return fld->getStaticAttribute(); } JPEnv::getHost()->setAttributeError(name.c_str()); JPEnv::getHost()->raise("getAttribute"); return NULL; // never reached ... TRACE_OUT; } void JPObject::setAttribute(string name, HostRef* val) { // instance fields ... JPField* fld = m_Class->getInstanceField(name); if (fld != NULL) { fld->setAttribute(m_Object, val); return; } // static fields ... fld = m_Class->getStaticField(name); if (fld != NULL) { fld->setStaticAttribute(val); return; } JPEnv::getHost()->setAttributeError(name.c_str()); JPEnv::getHost()->raise("setAttribute"); } python-jpype-0.5.4.2/src/native/common/jp_referencequeue.cpp0000666000175000017500000005531111614007722023376 0ustar takakitakaki#include jbyte JPypeReferenceQueue[] = { (jbyte)0xCA,(jbyte)0xFE,(jbyte)0xBA,(jbyte)0xBE,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x2E,(jbyte)0x00,(jbyte)0x62,(jbyte)0x01,(jbyte)0x00,(jbyte)0x1D,(jbyte)0x6A,(jbyte)0x70,(jbyte)0x79,(jbyte)0x70,(jbyte)0x65,(jbyte)0x2F,(jbyte)0x72 ,(jbyte)0x65,(jbyte)0x66,(jbyte)0x2F,(jbyte)0x4A,(jbyte)0x50,(jbyte)0x79,(jbyte)0x70,(jbyte)0x65,(jbyte)0x52,(jbyte)0x65,(jbyte)0x66,(jbyte)0x65,(jbyte)0x72,(jbyte)0x65,(jbyte)0x6E,(jbyte)0x63,(jbyte)0x65,(jbyte)0x51,(jbyte)0x75,(jbyte)0x65 ,(jbyte)0x75,(jbyte)0x65,(jbyte)0x07,(jbyte)0x00,(jbyte)0x01,(jbyte)0x01,(jbyte)0x00,(jbyte)0x1C,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x72,(jbyte)0x65 ,(jbyte)0x66,(jbyte)0x2F,(jbyte)0x52,(jbyte)0x65,(jbyte)0x66,(jbyte)0x65,(jbyte)0x72,(jbyte)0x65,(jbyte)0x6E,(jbyte)0x63,(jbyte)0x65,(jbyte)0x51,(jbyte)0x75,(jbyte)0x65,(jbyte)0x75,(jbyte)0x65,(jbyte)0x07,(jbyte)0x00,(jbyte)0x03,(jbyte)0x01 ,(jbyte)0x00,(jbyte)0x12,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x52,(jbyte)0x75,(jbyte)0x6E,(jbyte)0x6E,(jbyte)0x61,(jbyte)0x62,(jbyte)0x6C,(jbyte)0x65 ,(jbyte)0x07,(jbyte)0x00,(jbyte)0x05,(jbyte)0x01,(jbyte)0x00,(jbyte)0x0F,(jbyte)0x6D,(jbyte)0x48,(jbyte)0x6F,(jbyte)0x73,(jbyte)0x74,(jbyte)0x52,(jbyte)0x65,(jbyte)0x66,(jbyte)0x65,(jbyte)0x72,(jbyte)0x65,(jbyte)0x6E,(jbyte)0x63,(jbyte)0x65 ,(jbyte)0x73,(jbyte)0x01,(jbyte)0x00,(jbyte)0x0F,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x75,(jbyte)0x74,(jbyte)0x69,(jbyte)0x6C,(jbyte)0x2F,(jbyte)0x53,(jbyte)0x65,(jbyte)0x74,(jbyte)0x3B,(jbyte)0x01 ,(jbyte)0x00,(jbyte)0x08,(jbyte)0x6D,(jbyte)0x53,(jbyte)0x74,(jbyte)0x6F,(jbyte)0x70,(jbyte)0x70,(jbyte)0x65,(jbyte)0x64,(jbyte)0x01,(jbyte)0x00,(jbyte)0x01,(jbyte)0x5A,(jbyte)0x01,(jbyte)0x00,(jbyte)0x0C,(jbyte)0x6D,(jbyte)0x51,(jbyte)0x75 ,(jbyte)0x65,(jbyte)0x75,(jbyte)0x65,(jbyte)0x54,(jbyte)0x68,(jbyte)0x72,(jbyte)0x65,(jbyte)0x61,(jbyte)0x64,(jbyte)0x01,(jbyte)0x00,(jbyte)0x12,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61 ,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x54,(jbyte)0x68,(jbyte)0x72,(jbyte)0x65,(jbyte)0x61,(jbyte)0x64,(jbyte)0x3B,(jbyte)0x01,(jbyte)0x00,(jbyte)0x0F,(jbyte)0x6D,(jbyte)0x51,(jbyte)0x75,(jbyte)0x65,(jbyte)0x75,(jbyte)0x65,(jbyte)0x53 ,(jbyte)0x74,(jbyte)0x6F,(jbyte)0x70,(jbyte)0x4D,(jbyte)0x75,(jbyte)0x74,(jbyte)0x65,(jbyte)0x78,(jbyte)0x01,(jbyte)0x00,(jbyte)0x12,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E ,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x4F,(jbyte)0x62,(jbyte)0x6A,(jbyte)0x65,(jbyte)0x63,(jbyte)0x74,(jbyte)0x3B,(jbyte)0x01,(jbyte)0x00,(jbyte)0x06,(jbyte)0x3C,(jbyte)0x69,(jbyte)0x6E,(jbyte)0x69,(jbyte)0x74,(jbyte)0x3E,(jbyte)0x01,(jbyte)0x00 ,(jbyte)0x03,(jbyte)0x28,(jbyte)0x29,(jbyte)0x56,(jbyte)0x01,(jbyte)0x00,(jbyte)0x04,(jbyte)0x43,(jbyte)0x6F,(jbyte)0x64,(jbyte)0x65,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x0F,(jbyte)0x00,(jbyte)0x10,(jbyte)0x0A,(jbyte)0x00,(jbyte)0x04,(jbyte)0x00 ,(jbyte)0x12,(jbyte)0x01,(jbyte)0x00,(jbyte)0x11,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x75,(jbyte)0x74,(jbyte)0x69,(jbyte)0x6C,(jbyte)0x2F,(jbyte)0x48,(jbyte)0x61,(jbyte)0x73,(jbyte)0x68,(jbyte)0x53,(jbyte)0x65 ,(jbyte)0x74,(jbyte)0x07,(jbyte)0x00,(jbyte)0x14,(jbyte)0x0A,(jbyte)0x00,(jbyte)0x15,(jbyte)0x00,(jbyte)0x12,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x07,(jbyte)0x00,(jbyte)0x08,(jbyte)0x09,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x17,(jbyte)0x0C ,(jbyte)0x00,(jbyte)0x09,(jbyte)0x00,(jbyte)0x0A,(jbyte)0x09,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x19,(jbyte)0x01,(jbyte)0x00,(jbyte)0x10,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E ,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x4F,(jbyte)0x62,(jbyte)0x6A,(jbyte)0x65,(jbyte)0x63,(jbyte)0x74,(jbyte)0x07,(jbyte)0x00,(jbyte)0x1B,(jbyte)0x0A,(jbyte)0x00,(jbyte)0x1C,(jbyte)0x00,(jbyte)0x12,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x0D,(jbyte)0x00 ,(jbyte)0x0E,(jbyte)0x09,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x1E,(jbyte)0x01,(jbyte)0x00,(jbyte)0x0F,(jbyte)0x4C,(jbyte)0x69,(jbyte)0x6E,(jbyte)0x65,(jbyte)0x4E,(jbyte)0x75,(jbyte)0x6D,(jbyte)0x62,(jbyte)0x65,(jbyte)0x72,(jbyte)0x54 ,(jbyte)0x61,(jbyte)0x62,(jbyte)0x6C,(jbyte)0x65,(jbyte)0x01,(jbyte)0x00,(jbyte)0x12,(jbyte)0x4C,(jbyte)0x6F,(jbyte)0x63,(jbyte)0x61,(jbyte)0x6C,(jbyte)0x56,(jbyte)0x61,(jbyte)0x72,(jbyte)0x69,(jbyte)0x61,(jbyte)0x62,(jbyte)0x6C,(jbyte)0x65 ,(jbyte)0x54,(jbyte)0x61,(jbyte)0x62,(jbyte)0x6C,(jbyte)0x65,(jbyte)0x01,(jbyte)0x00,(jbyte)0x04,(jbyte)0x74,(jbyte)0x68,(jbyte)0x69,(jbyte)0x73,(jbyte)0x01,(jbyte)0x00,(jbyte)0x1F,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x70,(jbyte)0x79,(jbyte)0x70 ,(jbyte)0x65,(jbyte)0x2F,(jbyte)0x72,(jbyte)0x65,(jbyte)0x66,(jbyte)0x2F,(jbyte)0x4A,(jbyte)0x50,(jbyte)0x79,(jbyte)0x70,(jbyte)0x65,(jbyte)0x52,(jbyte)0x65,(jbyte)0x66,(jbyte)0x65,(jbyte)0x72,(jbyte)0x65,(jbyte)0x6E,(jbyte)0x63,(jbyte)0x65 ,(jbyte)0x51,(jbyte)0x75,(jbyte)0x65,(jbyte)0x75,(jbyte)0x65,(jbyte)0x3B,(jbyte)0x01,(jbyte)0x00,(jbyte)0x0B,(jbyte)0x72,(jbyte)0x65,(jbyte)0x67,(jbyte)0x69,(jbyte)0x73,(jbyte)0x74,(jbyte)0x65,(jbyte)0x72,(jbyte)0x52,(jbyte)0x65,(jbyte)0x66 ,(jbyte)0x01,(jbyte)0x00,(jbyte)0x1E,(jbyte)0x28,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x70,(jbyte)0x79,(jbyte)0x70,(jbyte)0x65,(jbyte)0x2F,(jbyte)0x72,(jbyte)0x65,(jbyte)0x66,(jbyte)0x2F,(jbyte)0x4A,(jbyte)0x50,(jbyte)0x79,(jbyte)0x70,(jbyte)0x65 ,(jbyte)0x52,(jbyte)0x65,(jbyte)0x66,(jbyte)0x65,(jbyte)0x72,(jbyte)0x65,(jbyte)0x6E,(jbyte)0x63,(jbyte)0x65,(jbyte)0x3B,(jbyte)0x4A,(jbyte)0x29,(jbyte)0x56,(jbyte)0x01,(jbyte)0x00,(jbyte)0x18,(jbyte)0x6A,(jbyte)0x70,(jbyte)0x79,(jbyte)0x70 ,(jbyte)0x65,(jbyte)0x2F,(jbyte)0x72,(jbyte)0x65,(jbyte)0x66,(jbyte)0x2F,(jbyte)0x4A,(jbyte)0x50,(jbyte)0x79,(jbyte)0x70,(jbyte)0x65,(jbyte)0x52,(jbyte)0x65,(jbyte)0x66,(jbyte)0x65,(jbyte)0x72,(jbyte)0x65,(jbyte)0x6E,(jbyte)0x63,(jbyte)0x65 ,(jbyte)0x07,(jbyte)0x00,(jbyte)0x26,(jbyte)0x01,(jbyte)0x00,(jbyte)0x10,(jbyte)0x73,(jbyte)0x65,(jbyte)0x74,(jbyte)0x48,(jbyte)0x6F,(jbyte)0x73,(jbyte)0x74,(jbyte)0x52,(jbyte)0x65,(jbyte)0x66,(jbyte)0x65,(jbyte)0x72,(jbyte)0x65,(jbyte)0x6E ,(jbyte)0x63,(jbyte)0x65,(jbyte)0x01,(jbyte)0x00,(jbyte)0x04,(jbyte)0x28,(jbyte)0x4A,(jbyte)0x29,(jbyte)0x56,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x28,(jbyte)0x00,(jbyte)0x29,(jbyte)0x0A,(jbyte)0x00,(jbyte)0x27,(jbyte)0x00,(jbyte)0x2A,(jbyte)0x01 ,(jbyte)0x00,(jbyte)0x0D,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x75,(jbyte)0x74,(jbyte)0x69,(jbyte)0x6C,(jbyte)0x2F,(jbyte)0x53,(jbyte)0x65,(jbyte)0x74,(jbyte)0x07,(jbyte)0x00,(jbyte)0x2C,(jbyte)0x01,(jbyte)0x00 ,(jbyte)0x03,(jbyte)0x61,(jbyte)0x64,(jbyte)0x64,(jbyte)0x01,(jbyte)0x00,(jbyte)0x15,(jbyte)0x28,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x4F ,(jbyte)0x62,(jbyte)0x6A,(jbyte)0x65,(jbyte)0x63,(jbyte)0x74,(jbyte)0x3B,(jbyte)0x29,(jbyte)0x5A,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x2E,(jbyte)0x00,(jbyte)0x2F,(jbyte)0x0B,(jbyte)0x00,(jbyte)0x2D,(jbyte)0x00,(jbyte)0x30,(jbyte)0x01,(jbyte)0x00 ,(jbyte)0x03,(jbyte)0x72,(jbyte)0x65,(jbyte)0x66,(jbyte)0x01,(jbyte)0x00,(jbyte)0x1A,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x70,(jbyte)0x79,(jbyte)0x70,(jbyte)0x65,(jbyte)0x2F,(jbyte)0x72,(jbyte)0x65,(jbyte)0x66,(jbyte)0x2F,(jbyte)0x4A,(jbyte)0x50 ,(jbyte)0x79,(jbyte)0x70,(jbyte)0x65,(jbyte)0x52,(jbyte)0x65,(jbyte)0x66,(jbyte)0x65,(jbyte)0x72,(jbyte)0x65,(jbyte)0x6E,(jbyte)0x63,(jbyte)0x65,(jbyte)0x3B,(jbyte)0x01,(jbyte)0x00,(jbyte)0x07,(jbyte)0x68,(jbyte)0x6F,(jbyte)0x73,(jbyte)0x74 ,(jbyte)0x52,(jbyte)0x65,(jbyte)0x66,(jbyte)0x01,(jbyte)0x00,(jbyte)0x01,(jbyte)0x4A,(jbyte)0x01,(jbyte)0x00,(jbyte)0x0D,(jbyte)0x73,(jbyte)0x74,(jbyte)0x61,(jbyte)0x72,(jbyte)0x74,(jbyte)0x4D,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x61,(jbyte)0x67 ,(jbyte)0x69,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x01,(jbyte)0x00,(jbyte)0x10,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x54,(jbyte)0x68,(jbyte)0x72,(jbyte)0x65 ,(jbyte)0x61,(jbyte)0x64,(jbyte)0x07,(jbyte)0x00,(jbyte)0x37,(jbyte)0x01,(jbyte)0x00,(jbyte)0x17,(jbyte)0x28,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F ,(jbyte)0x52,(jbyte)0x75,(jbyte)0x6E,(jbyte)0x6E,(jbyte)0x61,(jbyte)0x62,(jbyte)0x6C,(jbyte)0x65,(jbyte)0x3B,(jbyte)0x29,(jbyte)0x56,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x0F,(jbyte)0x00,(jbyte)0x39,(jbyte)0x0A,(jbyte)0x00,(jbyte)0x38,(jbyte)0x00 ,(jbyte)0x3A,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x0B,(jbyte)0x00,(jbyte)0x0C,(jbyte)0x09,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x3C,(jbyte)0x01,(jbyte)0x00,(jbyte)0x05,(jbyte)0x73,(jbyte)0x74,(jbyte)0x61,(jbyte)0x72,(jbyte)0x74,(jbyte)0x0C ,(jbyte)0x00,(jbyte)0x3E,(jbyte)0x00,(jbyte)0x10,(jbyte)0x0A,(jbyte)0x00,(jbyte)0x38,(jbyte)0x00,(jbyte)0x3F,(jbyte)0x01,(jbyte)0x00,(jbyte)0x03,(jbyte)0x72,(jbyte)0x75,(jbyte)0x6E,(jbyte)0x05,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00 ,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0xFA,(jbyte)0x01,(jbyte)0x00,(jbyte)0x06,(jbyte)0x72,(jbyte)0x65,(jbyte)0x6D,(jbyte)0x6F,(jbyte)0x76,(jbyte)0x65,(jbyte)0x01,(jbyte)0x00,(jbyte)0x1C,(jbyte)0x28,(jbyte)0x4A,(jbyte)0x29,(jbyte)0x4C ,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x72,(jbyte)0x65,(jbyte)0x66,(jbyte)0x2F,(jbyte)0x52,(jbyte)0x65,(jbyte)0x66,(jbyte)0x65,(jbyte)0x72,(jbyte)0x65 ,(jbyte)0x6E,(jbyte)0x63,(jbyte)0x65,(jbyte)0x3B,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x44,(jbyte)0x00,(jbyte)0x45,(jbyte)0x0A,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x46,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x44,(jbyte)0x00,(jbyte)0x2F,(jbyte)0x0B ,(jbyte)0x00,(jbyte)0x2D,(jbyte)0x00,(jbyte)0x48,(jbyte)0x01,(jbyte)0x00,(jbyte)0x10,(jbyte)0x67,(jbyte)0x65,(jbyte)0x74,(jbyte)0x48,(jbyte)0x6F,(jbyte)0x73,(jbyte)0x74,(jbyte)0x52,(jbyte)0x65,(jbyte)0x66,(jbyte)0x65,(jbyte)0x72,(jbyte)0x65 ,(jbyte)0x6E,(jbyte)0x63,(jbyte)0x65,(jbyte)0x01,(jbyte)0x00,(jbyte)0x03,(jbyte)0x28,(jbyte)0x29,(jbyte)0x4A,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x4A,(jbyte)0x00,(jbyte)0x4B,(jbyte)0x0A,(jbyte)0x00,(jbyte)0x27,(jbyte)0x00,(jbyte)0x4C,(jbyte)0x01 ,(jbyte)0x00,(jbyte)0x13,(jbyte)0x72,(jbyte)0x65,(jbyte)0x6D,(jbyte)0x6F,(jbyte)0x76,(jbyte)0x65,(jbyte)0x48,(jbyte)0x6F,(jbyte)0x73,(jbyte)0x74,(jbyte)0x52,(jbyte)0x65,(jbyte)0x66,(jbyte)0x65,(jbyte)0x72,(jbyte)0x65,(jbyte)0x6E,(jbyte)0x63 ,(jbyte)0x65,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x4E,(jbyte)0x00,(jbyte)0x29,(jbyte)0x0A,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x4F,(jbyte)0x05,(jbyte)0xFF,(jbyte)0xFF,(jbyte)0xFF,(jbyte)0xFF,(jbyte)0xFF,(jbyte)0xFF,(jbyte)0xFF,(jbyte)0xFF ,(jbyte)0x01,(jbyte)0x00,(jbyte)0x09,(jbyte)0x6E,(jbyte)0x6F,(jbyte)0x74,(jbyte)0x69,(jbyte)0x66,(jbyte)0x79,(jbyte)0x41,(jbyte)0x6C,(jbyte)0x6C,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x53,(jbyte)0x00,(jbyte)0x10,(jbyte)0x0A,(jbyte)0x00,(jbyte)0x1C ,(jbyte)0x00,(jbyte)0x54,(jbyte)0x01,(jbyte)0x00,(jbyte)0x1E,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x49,(jbyte)0x6E,(jbyte)0x74,(jbyte)0x65,(jbyte)0x72 ,(jbyte)0x72,(jbyte)0x75,(jbyte)0x70,(jbyte)0x74,(jbyte)0x65,(jbyte)0x64,(jbyte)0x45,(jbyte)0x78,(jbyte)0x63,(jbyte)0x65,(jbyte)0x70,(jbyte)0x74,(jbyte)0x69,(jbyte)0x6F,(jbyte)0x6E,(jbyte)0x07,(jbyte)0x00,(jbyte)0x56,(jbyte)0x01,(jbyte)0x00 ,(jbyte)0x04,(jbyte)0x73,(jbyte)0x74,(jbyte)0x6F,(jbyte)0x70,(jbyte)0x05,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x13,(jbyte)0x88,(jbyte)0x01,(jbyte)0x00,(jbyte)0x04,(jbyte)0x77,(jbyte)0x61,(jbyte)0x69 ,(jbyte)0x74,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x5B,(jbyte)0x00,(jbyte)0x29,(jbyte)0x0A,(jbyte)0x00,(jbyte)0x1C,(jbyte)0x00,(jbyte)0x5C,(jbyte)0x01,(jbyte)0x00,(jbyte)0x02,(jbyte)0x65,(jbyte)0x78,(jbyte)0x01,(jbyte)0x00,(jbyte)0x20,(jbyte)0x4C ,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x49,(jbyte)0x6E,(jbyte)0x74,(jbyte)0x65,(jbyte)0x72,(jbyte)0x72,(jbyte)0x75,(jbyte)0x70,(jbyte)0x74,(jbyte)0x65 ,(jbyte)0x64,(jbyte)0x45,(jbyte)0x78,(jbyte)0x63,(jbyte)0x65,(jbyte)0x70,(jbyte)0x74,(jbyte)0x69,(jbyte)0x6F,(jbyte)0x6E,(jbyte)0x3B,(jbyte)0x01,(jbyte)0x00,(jbyte)0x0A,(jbyte)0x53,(jbyte)0x6F,(jbyte)0x75,(jbyte)0x72,(jbyte)0x63,(jbyte)0x65 ,(jbyte)0x46,(jbyte)0x69,(jbyte)0x6C,(jbyte)0x65,(jbyte)0x01,(jbyte)0x00,(jbyte)0x18,(jbyte)0x4A,(jbyte)0x50,(jbyte)0x79,(jbyte)0x70,(jbyte)0x65,(jbyte)0x52,(jbyte)0x65,(jbyte)0x66,(jbyte)0x65,(jbyte)0x72,(jbyte)0x65,(jbyte)0x6E,(jbyte)0x63 ,(jbyte)0x65,(jbyte)0x51,(jbyte)0x75,(jbyte)0x65,(jbyte)0x75,(jbyte)0x65,(jbyte)0x2E,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x00,(jbyte)0x21,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x04,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00 ,(jbyte)0x06,(jbyte)0x00,(jbyte)0x04,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x07,(jbyte)0x00,(jbyte)0x08,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x09,(jbyte)0x00,(jbyte)0x0A,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00 ,(jbyte)0x02,(jbyte)0x00,(jbyte)0x0B,(jbyte)0x00,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x0D,(jbyte)0x00,(jbyte)0x0E,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x06,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00 ,(jbyte)0x0F,(jbyte)0x00,(jbyte)0x10,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x11,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x5A,(jbyte)0x00,(jbyte)0x03,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x20,(jbyte)0x2A ,(jbyte)0xB7,(jbyte)0x00,(jbyte)0x13,(jbyte)0x2A,(jbyte)0xBB,(jbyte)0x00,(jbyte)0x15,(jbyte)0x59,(jbyte)0xB7,(jbyte)0x00,(jbyte)0x16,(jbyte)0xB5,(jbyte)0x00,(jbyte)0x18,(jbyte)0x2A,(jbyte)0x03,(jbyte)0xB5,(jbyte)0x00,(jbyte)0x1A,(jbyte)0x2A ,(jbyte)0xBB,(jbyte)0x00,(jbyte)0x1C,(jbyte)0x59,(jbyte)0xB7,(jbyte)0x00,(jbyte)0x1D,(jbyte)0xB5,(jbyte)0x00,(jbyte)0x1F,(jbyte)0xB1,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x20,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00 ,(jbyte)0x16,(jbyte)0x00,(jbyte)0x05,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x0D,(jbyte)0x00,(jbyte)0x04,(jbyte)0x00,(jbyte)0x10,(jbyte)0x00,(jbyte)0x0F,(jbyte)0x00,(jbyte)0x11,(jbyte)0x00,(jbyte)0x14,(jbyte)0x00,(jbyte)0x13,(jbyte)0x00 ,(jbyte)0x1F,(jbyte)0x00,(jbyte)0x0D,(jbyte)0x00,(jbyte)0x21,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x20,(jbyte)0x00,(jbyte)0x22,(jbyte)0x00,(jbyte)0x23,(jbyte)0x00 ,(jbyte)0x00,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x24,(jbyte)0x00,(jbyte)0x25,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x11,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x57,(jbyte)0x00,(jbyte)0x03,(jbyte)0x00,(jbyte)0x04,(jbyte)0x00 ,(jbyte)0x00,(jbyte)0x00,(jbyte)0x11,(jbyte)0x2B,(jbyte)0x20,(jbyte)0xB6,(jbyte)0x00,(jbyte)0x2B,(jbyte)0x2A,(jbyte)0xB4,(jbyte)0x00,(jbyte)0x18,(jbyte)0x2B,(jbyte)0xB9,(jbyte)0x00,(jbyte)0x31,(jbyte)0x02,(jbyte)0x00,(jbyte)0x57,(jbyte)0xB1 ,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x20,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x0E,(jbyte)0x00,(jbyte)0x03,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x18,(jbyte)0x00,(jbyte)0x05,(jbyte)0x00,(jbyte)0x19 ,(jbyte)0x00,(jbyte)0x10,(jbyte)0x00,(jbyte)0x1A,(jbyte)0x00,(jbyte)0x21,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x20,(jbyte)0x00,(jbyte)0x03,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x11,(jbyte)0x00,(jbyte)0x22,(jbyte)0x00,(jbyte)0x23 ,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x11,(jbyte)0x00,(jbyte)0x32,(jbyte)0x00,(jbyte)0x33,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x11,(jbyte)0x00,(jbyte)0x34,(jbyte)0x00,(jbyte)0x35 ,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x36,(jbyte)0x00,(jbyte)0x10,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x11,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x46,(jbyte)0x00,(jbyte)0x04,(jbyte)0x00,(jbyte)0x01 ,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x14,(jbyte)0x2A,(jbyte)0xBB,(jbyte)0x00,(jbyte)0x38,(jbyte)0x59,(jbyte)0x2A,(jbyte)0xB7,(jbyte)0x00,(jbyte)0x3B,(jbyte)0xB5,(jbyte)0x00,(jbyte)0x3D,(jbyte)0x2A,(jbyte)0xB4,(jbyte)0x00,(jbyte)0x3D ,(jbyte)0xB6,(jbyte)0x00,(jbyte)0x40,(jbyte)0xB1,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x20,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x0E,(jbyte)0x00,(jbyte)0x03,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x23 ,(jbyte)0x00,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x24,(jbyte)0x00,(jbyte)0x13,(jbyte)0x00,(jbyte)0x25,(jbyte)0x00,(jbyte)0x21,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x14 ,(jbyte)0x00,(jbyte)0x22,(jbyte)0x00,(jbyte)0x23,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x41,(jbyte)0x00,(jbyte)0x10,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x11,(jbyte)0x00,(jbyte)0x00,(jbyte)0x01,(jbyte)0x24 ,(jbyte)0x00,(jbyte)0x03,(jbyte)0x00,(jbyte)0x04,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x70,(jbyte)0xA7,(jbyte)0x00,(jbyte)0x4D,(jbyte)0x2A,(jbyte)0x14,(jbyte)0x00,(jbyte)0x42,(jbyte)0xB6,(jbyte)0x00,(jbyte)0x47,(jbyte)0xC0,(jbyte)0x00 ,(jbyte)0x27,(jbyte)0x4C,(jbyte)0x2B,(jbyte)0xC6,(jbyte)0x00,(jbyte)0x3E,(jbyte)0x2A,(jbyte)0xB4,(jbyte)0x00,(jbyte)0x18,(jbyte)0x59,(jbyte)0x4D,(jbyte)0xC2,(jbyte)0x2A,(jbyte)0xB4,(jbyte)0x00,(jbyte)0x18,(jbyte)0x2B,(jbyte)0xB9,(jbyte)0x00 ,(jbyte)0x49,(jbyte)0x02,(jbyte)0x00,(jbyte)0x57,(jbyte)0x2C,(jbyte)0xC3,(jbyte)0xA7,(jbyte)0x00,(jbyte)0x06,(jbyte)0x2C,(jbyte)0xC3,(jbyte)0xBF,(jbyte)0x2B,(jbyte)0xB6,(jbyte)0x00,(jbyte)0x4D,(jbyte)0xB8,(jbyte)0x00,(jbyte)0x50,(jbyte)0xA7 ,(jbyte)0x00,(jbyte)0x13,(jbyte)0x4E,(jbyte)0xA8,(jbyte)0x00,(jbyte)0x05,(jbyte)0x2D,(jbyte)0xBF,(jbyte)0x4D,(jbyte)0x2B,(jbyte)0x14,(jbyte)0x00,(jbyte)0x51,(jbyte)0xB6,(jbyte)0x00,(jbyte)0x2B,(jbyte)0xA9,(jbyte)0x02,(jbyte)0xA8,(jbyte)0xFF ,(jbyte)0xF6,(jbyte)0xA7,(jbyte)0x00,(jbyte)0x04,(jbyte)0x4C,(jbyte)0x2A,(jbyte)0xB4,(jbyte)0x00,(jbyte)0x1A,(jbyte)0x99,(jbyte)0xFF,(jbyte)0xB2,(jbyte)0x2A,(jbyte)0x01,(jbyte)0xB5,(jbyte)0x00,(jbyte)0x18,(jbyte)0x2A,(jbyte)0xB4,(jbyte)0x00 ,(jbyte)0x1F,(jbyte)0x59,(jbyte)0x4C,(jbyte)0xC2,(jbyte)0x2A,(jbyte)0xB4,(jbyte)0x00,(jbyte)0x1F,(jbyte)0xB6,(jbyte)0x00,(jbyte)0x55,(jbyte)0x2B,(jbyte)0xC3,(jbyte)0xA7,(jbyte)0x00,(jbyte)0x06,(jbyte)0x2B,(jbyte)0xC3,(jbyte)0xBF,(jbyte)0xB1 ,(jbyte)0x00,(jbyte)0x07,(jbyte)0x00,(jbyte)0x19,(jbyte)0x00,(jbyte)0x26,(jbyte)0x00,(jbyte)0x29,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x29,(jbyte)0x00,(jbyte)0x2B,(jbyte)0x00,(jbyte)0x29,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x2C ,(jbyte)0x00,(jbyte)0x36,(jbyte)0x00,(jbyte)0x36,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x46,(jbyte)0x00,(jbyte)0x49,(jbyte)0x00,(jbyte)0x36,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x03,(jbyte)0x00,(jbyte)0x4C,(jbyte)0x00,(jbyte)0x4C ,(jbyte)0x00,(jbyte)0x57,(jbyte)0x00,(jbyte)0x60,(jbyte)0x00,(jbyte)0x69,(jbyte)0x00,(jbyte)0x6C,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x6C,(jbyte)0x00,(jbyte)0x6E,(jbyte)0x00,(jbyte)0x6C,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x02 ,(jbyte)0x00,(jbyte)0x20,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x4E,(jbyte)0x00,(jbyte)0x13,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x29,(jbyte)0x00,(jbyte)0x03,(jbyte)0x00,(jbyte)0x2F,(jbyte)0x00,(jbyte)0x0E,(jbyte)0x00,(jbyte)0x30 ,(jbyte)0x00,(jbyte)0x12,(jbyte)0x00,(jbyte)0x33,(jbyte)0x00,(jbyte)0x19,(jbyte)0x00,(jbyte)0x35,(jbyte)0x00,(jbyte)0x24,(jbyte)0x00,(jbyte)0x33,(jbyte)0x00,(jbyte)0x2C,(jbyte)0x00,(jbyte)0x39,(jbyte)0x00,(jbyte)0x36,(jbyte)0x00,(jbyte)0x3C ,(jbyte)0x00,(jbyte)0x3A,(jbyte)0x00,(jbyte)0x3E,(jbyte)0x00,(jbyte)0x3C,(jbyte)0x00,(jbyte)0x3C,(jbyte)0x00,(jbyte)0x3D,(jbyte)0x00,(jbyte)0x3D,(jbyte)0x00,(jbyte)0x44,(jbyte)0x00,(jbyte)0x3E,(jbyte)0x00,(jbyte)0x4C,(jbyte)0x00,(jbyte)0x41 ,(jbyte)0x00,(jbyte)0x4D,(jbyte)0x00,(jbyte)0x29,(jbyte)0x00,(jbyte)0x54,(jbyte)0x00,(jbyte)0x46,(jbyte)0x00,(jbyte)0x59,(jbyte)0x00,(jbyte)0x48,(jbyte)0x00,(jbyte)0x60,(jbyte)0x00,(jbyte)0x4A,(jbyte)0x00,(jbyte)0x67,(jbyte)0x00,(jbyte)0x48 ,(jbyte)0x00,(jbyte)0x6F,(jbyte)0x00,(jbyte)0x4C,(jbyte)0x00,(jbyte)0x21,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x16,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x70,(jbyte)0x00,(jbyte)0x22,(jbyte)0x00,(jbyte)0x23 ,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x0E,(jbyte)0x00,(jbyte)0x3E,(jbyte)0x00,(jbyte)0x32,(jbyte)0x00,(jbyte)0x33,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x58,(jbyte)0x00,(jbyte)0x10,(jbyte)0x00,(jbyte)0x01 ,(jbyte)0x00,(jbyte)0x11,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x88,(jbyte)0x00,(jbyte)0x03,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x24,(jbyte)0x2A,(jbyte)0x04,(jbyte)0xB5,(jbyte)0x00,(jbyte)0x1A,(jbyte)0x2A ,(jbyte)0xB4,(jbyte)0x00,(jbyte)0x1F,(jbyte)0x59,(jbyte)0x4C,(jbyte)0xC2,(jbyte)0x2A,(jbyte)0xB4,(jbyte)0x00,(jbyte)0x1F,(jbyte)0x14,(jbyte)0x00,(jbyte)0x59,(jbyte)0xB6,(jbyte)0x00,(jbyte)0x5D,(jbyte)0x2B,(jbyte)0xC3,(jbyte)0xA7,(jbyte)0x00 ,(jbyte)0x0B,(jbyte)0x2B,(jbyte)0xC3,(jbyte)0xBF,(jbyte)0xA7,(jbyte)0x00,(jbyte)0x05,(jbyte)0x4C,(jbyte)0xB1,(jbyte)0xB1,(jbyte)0x00,(jbyte)0x03,(jbyte)0x00,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x18,(jbyte)0x00,(jbyte)0x1B,(jbyte)0x00,(jbyte)0x00 ,(jbyte)0x00,(jbyte)0x1B,(jbyte)0x00,(jbyte)0x1D,(jbyte)0x00,(jbyte)0x1B,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x05,(jbyte)0x00,(jbyte)0x21,(jbyte)0x00,(jbyte)0x21,(jbyte)0x00,(jbyte)0x57,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x20 ,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x1E,(jbyte)0x00,(jbyte)0x07,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x51,(jbyte)0x00,(jbyte)0x05,(jbyte)0x00,(jbyte)0x55,(jbyte)0x00,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x57,(jbyte)0x00,(jbyte)0x16 ,(jbyte)0x00,(jbyte)0x55,(jbyte)0x00,(jbyte)0x21,(jbyte)0x00,(jbyte)0x5A,(jbyte)0x00,(jbyte)0x22,(jbyte)0x00,(jbyte)0x5D,(jbyte)0x00,(jbyte)0x23,(jbyte)0x00,(jbyte)0x5F,(jbyte)0x00,(jbyte)0x21,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x16 ,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x24,(jbyte)0x00,(jbyte)0x22,(jbyte)0x00,(jbyte)0x23,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x22,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x5E,(jbyte)0x00,(jbyte)0x5F ,(jbyte)0x00,(jbyte)0x01,(jbyte)0x01,(jbyte)0x0A,(jbyte)0x00,(jbyte)0x4E,(jbyte)0x00,(jbyte)0x29,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x60,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x61 }; jsize getJPypeReferenceQueueLength() { return 1880; } python-jpype-0.5.4.2/src/native/common/include/0000775000175000017500000000000011620747357020626 5ustar takakitakakipython-jpype-0.5.4.2/src/native/common/include/jp_reference.h0000666000175000017500000000161711614007722023421 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard 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. *****************************************************************************/ #ifndef _JPREFERENCE_H_ #define _JPREFERENCE_H_ extern jbyte JPypeReference[]; jsize getJPypeReferenceLength(); #endif // _JPREFERENCE_H_ python-jpype-0.5.4.2/src/native/common/include/jp_array.h0000666000175000017500000000317311614007722022600 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard 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. *****************************************************************************/ #ifndef _JPARRAY_H_ #define _JPARRAY_H_ /** * Class to wrap Java Class and provide low-level behavior */ class JPArray : public JPObjectBase { public : JPArray(JPTypeName name, jarray inst); virtual~ JPArray(); public : JPArrayClass* getClass() { return m_Class; } int getLength(); vector getRange(int start, int stop); void setRange(int start, int stop, vector& val); void setItem(int ndx, HostRef*); HostRef* getItem(int ndx); void setContent(vector& data) { setRange(0, getLength(), data); } jobject getObject() { return JPEnv::getJava()->NewLocalRef(m_Object); } public : // Wrapper virtual JPType* getType(); virtual jvalue getValue(); virtual JCharString toString(); private : JPArrayClass* m_Class; jarray m_Object; }; #endif // _JPARRAY_H_ python-jpype-0.5.4.2/src/native/common/include/jp_utility.h0000666000175000017500000000635111614227532023171 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard 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. *****************************************************************************/ #ifndef _JPYPE_UTILITY_H_ #define _JPYPE_UTILITY_H_ #define RAISE(exClass, msg) { throw new exClass(msg, __FILE__, __LINE__); } /** Support Exception for JPype-generated exception */ class JPypeException { public : JPypeException(char* msn, const char* f, int l) { file=f, line=l; std::stringstream str; str << msn << " at " << f << ":" << l; this->msg = str.str(); } JPypeException(string msn, const char* f, int l) { file=f, line=l; std::stringstream str; str << msn << " at " << f << ":" << l; this->msg = str.str(); } JPypeException(const JPypeException& ex) : file(ex.file), line(ex.line) { this->msg = ex.msg;} virtual ~JPypeException() {} const char* getMsg() { return msg.c_str(); } const char* file; int line; private : string msg; }; /* #define STANDARD_CATCH \ catch(JavaException EXCEPTION_PTR ex) \ { \ JPEnv::getJava()->ExceptionDescribe(); \ JPEnv::getJava()->ExceptionClear(); \ stringstream msg; \ msg << "Java Exception Occured at " << ex EXCEPTION_DEREF file << ":" << ex EXCEPTION_DEREF line << ":" << ex EXCEPTION_DEREF message; \ JPEnv::getHost()->setRuntimeException(msg.str().c_str());\ EXCEPTION_CLEANUP(ex); \ }\ catch(JPypeException EXCEPTION_PTR ex)\ {\ JPEnv::getHost()->setRuntimeException(ex EXCEPTION_DEREF getMsg()); \ EXCEPTION_CLEANUP(ex); \ }\ catch(...) \ {\ JPEnv::getHost()->setRuntimeException("Unknown Exception"); \ } \ */ #define RETHROW_CATCH(cleanup) \ catch(...) \ { \ cleanup ; \ throw; \ } class JPypeTracer { private : string m_Name; bool m_Error; public : JPypeTracer(const char* name) : m_Name(name) { traceIn(name); m_Error = false; } virtual ~JPypeTracer() { traceOut(m_Name.c_str(), m_Error); } void gotError() { m_Error = true; } template void trace(T msg) { stringstream str; str << msg; trace1(m_Name.c_str(), str.str()); } template void trace(T msg1, U msg2) { stringstream str; str << msg1 << " " << msg2; trace1(m_Name.c_str(), str.str()); } template void trace(T msg1, U msg2, V msg3) { stringstream str; str << msg1 << " " << msg2 << " " << msg3; trace1(m_Name.c_str(), str.str()); } private : static void traceIn(const char* msg); static void traceOut(const char* msg, bool error); static void trace1(const char* name, const string& msg); }; #endif // _JPYPE_UTILITY_H_ python-jpype-0.5.4.2/src/native/common/include/jp_hostenv.h0000666000175000017500000001176511614007722023156 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve M�nard 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. *****************************************************************************/ #ifndef _JPHOSTENV_H_ #define _JPHOSTENV_H_ class HostRef { public : HostRef(void* data, bool acquire); HostRef(void* data); virtual ~HostRef(); public : HostRef* copy(); void release(); bool isNull(); void* data(); private : void* m_HostData; }; // Pre-delcare those required types class JPArray; class JPArrayClass; class JPClass; class JPMethod; class JPObject; class JPProxy; class HostEnvironment { public : virtual ~HostEnvironment() {} virtual void* acquireRef(void*) = 0; virtual void releaseRef(void*) = 0; virtual bool isRefNull(void*) = 0; virtual string describeRef(HostRef*) = 0; virtual void* gotoExternal() = 0; virtual void returnExternal(void*) = 0; virtual void setRuntimeException(const char* msg) = 0; virtual void setAttributeError(const char* msg) = 0; virtual void setTypeError(const char* msg) = 0; virtual void raise(const char* msg) = 0; virtual HostRef* getNone() = 0; virtual bool isNone(HostRef*) = 0; virtual bool isBoolean(HostRef*) = 0; virtual jboolean booleanAsBoolean(HostRef*) = 0; virtual HostRef* getTrue() = 0; virtual HostRef* getFalse() = 0; virtual bool isSequence(HostRef*) = 0; virtual HostRef* newMutableSequence(jsize) = 0; virtual HostRef* newImmutableSequence(jsize) = 0; virtual jsize getSequenceLength(HostRef*) = 0; virtual HostRef* getSequenceItem(HostRef*, jsize) = 0; virtual void setSequenceItem(HostRef*, jsize, HostRef*) = 0; virtual bool isInt(HostRef*) = 0; virtual HostRef* newInt(jint) = 0; virtual jint intAsInt(HostRef*) = 0; virtual bool isLong(HostRef*) = 0; virtual HostRef* newLong(jlong) = 0; virtual jlong longAsLong(HostRef*) = 0; virtual bool isFloat(HostRef*) = 0; virtual HostRef* newFloat(jdouble) = 0; virtual jdouble floatAsDouble(HostRef*) = 0; virtual bool isMethod(HostRef*) = 0; virtual HostRef* newMethod(JPMethod*) = 0; virtual JPMethod* asMethod(HostRef*) = 0; virtual bool isObject(HostRef*) = 0; virtual JPObject* asObject(HostRef*) = 0; virtual HostRef* newObject(JPObject*) = 0; virtual bool isClass(HostRef*) = 0; virtual HostRef* newClass(JPClass*) = 0; virtual JPClass* asClass(HostRef*) = 0; virtual bool isArrayClass(HostRef*) = 0; virtual HostRef* newArrayClass(JPArrayClass*) = 0; virtual JPArrayClass* asArrayClass(HostRef*) = 0; virtual bool isArray(HostRef*) = 0; virtual HostRef* newArray(JPArray*) = 0; virtual JPArray* asArray(HostRef*) = 0; virtual bool isProxy(HostRef*) = 0; virtual JPProxy* asProxy(HostRef*) = 0; virtual HostRef* getCallableFrom(HostRef*, string&) = 0; virtual bool isWrapper(HostRef*) = 0; virtual JPTypeName getWrapperTypeName(HostRef*) = 0; virtual jvalue getWrapperValue(HostRef*) = 0; virtual HostRef* newStringWrapper(jstring) = 0; virtual bool isString(HostRef*) = 0; virtual jsize getStringLength(HostRef*) = 0; virtual string stringAsString(HostRef*) = 0; virtual JCharString stringAsJCharString(HostRef*) = 0; virtual HostRef* newStringFromUnicode(const jchar*, unsigned int) = 0; virtual HostRef* newStringFromASCII(const char*, unsigned int) = 0; virtual bool isByteString(HostRef*) = 0; virtual bool isUnicodeString(HostRef*) = 0; virtual void getRawByteString(HostRef*, char**, long&) = 0; virtual void getRawUnicodeString(HostRef*, jchar**, long&) = 0; virtual size_t getUnicodeSize() = 0; virtual void* prepareCallbackBegin() = 0; virtual void prepareCallbackFinish(void* state) = 0; virtual HostRef* callObject(HostRef* callable, vector& args) = 0; virtual bool mapContains(HostRef* map, HostRef* key) = 0; virtual HostRef* getMapItem(HostRef* map, HostRef* key) = 0; virtual bool objectHasAttribute(HostRef* obj, HostRef* key) = 0; virtual HostRef* getObjectAttribute(HostRef* obj, HostRef* key) = 0; virtual bool isJavaException(HostException*) = 0; virtual HostRef* getJavaException(HostException*) = 0; virtual void printError() = 0; virtual void clearError() = 0; virtual void printReferenceInfo(HostRef* obj) = 0; }; #endif // _JPHOSTENV_H_ python-jpype-0.5.4.2/src/native/common/include/jp_javaenv_autogen.h0000666000175000017500000004041711614007722024640 0ustar takakitakaki /***************************************************************************** Copyright 2004-2008 Steve Menard 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. *****************************************************************************/ // This code has been automatically generated ... No not edit /** GetStaticByteField */ jbyte GetStaticByteField(jclass clazz, jfieldID fid); /** GetByteField */ jbyte GetByteField(jobject clazz, jfieldID fid); /** SetStaticByteField */ void SetStaticByteField(jclass clazz, jfieldID fid, jbyte val); /** SetByteField */ void SetByteField(jobject clazz, jfieldID fid, jbyte val); /** CallStaticByteMethodA */ jbyte CallStaticByteMethodA(jclass clazz, jmethodID mid, jvalue* val); /** CallStaticByteMethod */ jbyte CallStaticByteMethod(jclass clazz, jmethodID mid); /** CallByteMethodA */ jbyte CallByteMethodA(jobject obj, jmethodID mid, jvalue* val); /** CallByteMethod */ jbyte CallByteMethod(jobject obj, jmethodID mid); /** CallByteMethodA */ jbyte CallNonvirtualByteMethodA(jobject obj, jclass claz, jmethodID mid, jvalue* val); /** CallByteMethod */ jbyte CallNonvirtualByteMethod(jobject obj, jclass claz, jmethodID mid); /** GetStaticShortField */ jshort GetStaticShortField(jclass clazz, jfieldID fid); /** GetShortField */ jshort GetShortField(jobject clazz, jfieldID fid); /** SetStaticShortField */ void SetStaticShortField(jclass clazz, jfieldID fid, jshort val); /** SetShortField */ void SetShortField(jobject clazz, jfieldID fid, jshort val); /** CallStaticShortMethodA */ jshort CallStaticShortMethodA(jclass clazz, jmethodID mid, jvalue* val); /** CallStaticShortMethod */ jshort CallStaticShortMethod(jclass clazz, jmethodID mid); /** CallShortMethodA */ jshort CallShortMethodA(jobject obj, jmethodID mid, jvalue* val); /** CallShortMethod */ jshort CallShortMethod(jobject obj, jmethodID mid); /** CallShortMethodA */ jshort CallNonvirtualShortMethodA(jobject obj, jclass claz, jmethodID mid, jvalue* val); /** CallShortMethod */ jshort CallNonvirtualShortMethod(jobject obj, jclass claz, jmethodID mid); /** GetStaticIntField */ jint GetStaticIntField(jclass clazz, jfieldID fid); /** GetIntField */ jint GetIntField(jobject clazz, jfieldID fid); /** SetStaticIntField */ void SetStaticIntField(jclass clazz, jfieldID fid, jint val); /** SetIntField */ void SetIntField(jobject clazz, jfieldID fid, jint val); /** CallStaticIntMethodA */ jint CallStaticIntMethodA(jclass clazz, jmethodID mid, jvalue* val); /** CallStaticIntMethod */ jint CallStaticIntMethod(jclass clazz, jmethodID mid); /** CallIntMethodA */ jint CallIntMethodA(jobject obj, jmethodID mid, jvalue* val); /** CallIntMethod */ jint CallIntMethod(jobject obj, jmethodID mid); /** CallIntMethodA */ jint CallNonvirtualIntMethodA(jobject obj, jclass claz, jmethodID mid, jvalue* val); /** CallIntMethod */ jint CallNonvirtualIntMethod(jobject obj, jclass claz, jmethodID mid); /** GetStaticLongField */ jlong GetStaticLongField(jclass clazz, jfieldID fid); /** GetLongField */ jlong GetLongField(jobject clazz, jfieldID fid); /** SetStaticLongField */ void SetStaticLongField(jclass clazz, jfieldID fid, jlong val); /** SetLongField */ void SetLongField(jobject clazz, jfieldID fid, jlong val); /** CallStaticLongMethodA */ jlong CallStaticLongMethodA(jclass clazz, jmethodID mid, jvalue* val); /** CallStaticLongMethod */ jlong CallStaticLongMethod(jclass clazz, jmethodID mid); /** CallLongMethodA */ jlong CallLongMethodA(jobject obj, jmethodID mid, jvalue* val); /** CallLongMethod */ jlong CallLongMethod(jobject obj, jmethodID mid); /** CallLongMethodA */ jlong CallNonvirtualLongMethodA(jobject obj, jclass claz, jmethodID mid, jvalue* val); /** CallLongMethod */ jlong CallNonvirtualLongMethod(jobject obj, jclass claz, jmethodID mid); /** GetStaticFloatField */ jfloat GetStaticFloatField(jclass clazz, jfieldID fid); /** GetFloatField */ jfloat GetFloatField(jobject clazz, jfieldID fid); /** SetStaticFloatField */ void SetStaticFloatField(jclass clazz, jfieldID fid, jfloat val); /** SetFloatField */ void SetFloatField(jobject clazz, jfieldID fid, jfloat val); /** CallStaticFloatMethodA */ jfloat CallStaticFloatMethodA(jclass clazz, jmethodID mid, jvalue* val); /** CallStaticFloatMethod */ jfloat CallStaticFloatMethod(jclass clazz, jmethodID mid); /** CallFloatMethodA */ jfloat CallFloatMethodA(jobject obj, jmethodID mid, jvalue* val); /** CallFloatMethod */ jfloat CallFloatMethod(jobject obj, jmethodID mid); /** CallFloatMethodA */ jfloat CallNonvirtualFloatMethodA(jobject obj, jclass claz, jmethodID mid, jvalue* val); /** CallFloatMethod */ jfloat CallNonvirtualFloatMethod(jobject obj, jclass claz, jmethodID mid); /** GetStaticDoubleField */ jdouble GetStaticDoubleField(jclass clazz, jfieldID fid); /** GetDoubleField */ jdouble GetDoubleField(jobject clazz, jfieldID fid); /** SetStaticDoubleField */ void SetStaticDoubleField(jclass clazz, jfieldID fid, jdouble val); /** SetDoubleField */ void SetDoubleField(jobject clazz, jfieldID fid, jdouble val); /** CallStaticDoubleMethodA */ jdouble CallStaticDoubleMethodA(jclass clazz, jmethodID mid, jvalue* val); /** CallStaticDoubleMethod */ jdouble CallStaticDoubleMethod(jclass clazz, jmethodID mid); /** CallDoubleMethodA */ jdouble CallDoubleMethodA(jobject obj, jmethodID mid, jvalue* val); /** CallDoubleMethod */ jdouble CallDoubleMethod(jobject obj, jmethodID mid); /** CallDoubleMethodA */ jdouble CallNonvirtualDoubleMethodA(jobject obj, jclass claz, jmethodID mid, jvalue* val); /** CallDoubleMethod */ jdouble CallNonvirtualDoubleMethod(jobject obj, jclass claz, jmethodID mid); /** GetStaticCharField */ jchar GetStaticCharField(jclass clazz, jfieldID fid); /** GetCharField */ jchar GetCharField(jobject clazz, jfieldID fid); /** SetStaticCharField */ void SetStaticCharField(jclass clazz, jfieldID fid, jchar val); /** SetCharField */ void SetCharField(jobject clazz, jfieldID fid, jchar val); /** CallStaticCharMethodA */ jchar CallStaticCharMethodA(jclass clazz, jmethodID mid, jvalue* val); /** CallStaticCharMethod */ jchar CallStaticCharMethod(jclass clazz, jmethodID mid); /** CallCharMethodA */ jchar CallCharMethodA(jobject obj, jmethodID mid, jvalue* val); /** CallCharMethod */ jchar CallCharMethod(jobject obj, jmethodID mid); /** CallCharMethodA */ jchar CallNonvirtualCharMethodA(jobject obj, jclass claz, jmethodID mid, jvalue* val); /** CallCharMethod */ jchar CallNonvirtualCharMethod(jobject obj, jclass claz, jmethodID mid); /** GetStaticBooleanField */ jboolean GetStaticBooleanField(jclass clazz, jfieldID fid); /** GetBooleanField */ jboolean GetBooleanField(jobject clazz, jfieldID fid); /** SetStaticBooleanField */ void SetStaticBooleanField(jclass clazz, jfieldID fid, jboolean val); /** SetBooleanField */ void SetBooleanField(jobject clazz, jfieldID fid, jboolean val); /** CallStaticBooleanMethodA */ jboolean CallStaticBooleanMethodA(jclass clazz, jmethodID mid, jvalue* val); /** CallStaticBooleanMethod */ jboolean CallStaticBooleanMethod(jclass clazz, jmethodID mid); /** CallBooleanMethodA */ jboolean CallBooleanMethodA(jobject obj, jmethodID mid, jvalue* val); /** CallBooleanMethod */ jboolean CallBooleanMethod(jobject obj, jmethodID mid); /** CallBooleanMethodA */ jboolean CallNonvirtualBooleanMethodA(jobject obj, jclass claz, jmethodID mid, jvalue* val); /** CallBooleanMethod */ jboolean CallNonvirtualBooleanMethod(jobject obj, jclass claz, jmethodID mid); /** GetStaticObjectField */ jobject GetStaticObjectField(jclass clazz, jfieldID fid); /** GetObjectField */ jobject GetObjectField(jobject clazz, jfieldID fid); /** SetStaticObjectField */ void SetStaticObjectField(jclass clazz, jfieldID fid, jobject val); /** SetObjectField */ void SetObjectField(jobject clazz, jfieldID fid, jobject val); /** CallStaticObjectMethodA */ jobject CallStaticObjectMethodA(jclass clazz, jmethodID mid, jvalue* val); /** CallStaticObjectMethod */ jobject CallStaticObjectMethod(jclass clazz, jmethodID mid); /** CallObjectMethodA */ jobject CallObjectMethodA(jobject obj, jmethodID mid, jvalue* val); /** CallObjectMethod */ jobject CallObjectMethod(jobject obj, jmethodID mid); /** CallObjectMethodA */ jobject CallNonvirtualObjectMethodA(jobject obj, jclass claz, jmethodID mid, jvalue* val); /** CallObjectMethod */ jobject CallNonvirtualObjectMethod(jobject obj, jclass claz, jmethodID mid); /** NewByteArray */ jbyteArray NewByteArray(jint len); /** SetByteArrayRegion */ void SetByteArrayRegion(jbyteArray array, int start, int len, jbyte* vals); /** GetByteArrayRegion */ void GetByteArrayRegion(jbyteArray array, int start, int len, jbyte* vals); /** GetByteArrayElements */ jbyte* GetByteArrayElements(jbyteArray array, jboolean* isCopy); /** ReleaseByteArrayElements */ void ReleaseByteArrayElements(jbyteArray, jbyte* v, jint mode); /** NewShortArray */ jshortArray NewShortArray(jint len); /** SetShortArrayRegion */ void SetShortArrayRegion(jshortArray array, int start, int len, jshort* vals); /** GetShortArrayRegion */ void GetShortArrayRegion(jshortArray array, int start, int len, jshort* vals); /** GetShortArrayElements */ jshort* GetShortArrayElements(jshortArray array, jboolean* isCopy); /** ReleaseShortArrayElements */ void ReleaseShortArrayElements(jshortArray, jshort* v, jint mode); /** NewIntArray */ jintArray NewIntArray(jint len); /** SetIntArrayRegion */ void SetIntArrayRegion(jintArray array, int start, int len, jint* vals); /** GetIntArrayRegion */ void GetIntArrayRegion(jintArray array, int start, int len, jint* vals); /** GetIntArrayElements */ jint* GetIntArrayElements(jintArray array, jboolean* isCopy); /** ReleaseIntArrayElements */ void ReleaseIntArrayElements(jintArray, jint* v, jint mode); /** NewLongArray */ jlongArray NewLongArray(jint len); /** SetLongArrayRegion */ void SetLongArrayRegion(jlongArray array, int start, int len, jlong* vals); /** GetLongArrayRegion */ void GetLongArrayRegion(jlongArray array, int start, int len, jlong* vals); /** GetLongArrayElements */ jlong* GetLongArrayElements(jlongArray array, jboolean* isCopy); /** ReleaseLongArrayElements */ void ReleaseLongArrayElements(jlongArray, jlong* v, jint mode); /** NewFloatArray */ jfloatArray NewFloatArray(jint len); /** SetFloatArrayRegion */ void SetFloatArrayRegion(jfloatArray array, int start, int len, jfloat* vals); /** GetFloatArrayRegion */ void GetFloatArrayRegion(jfloatArray array, int start, int len, jfloat* vals); /** GetFloatArrayElements */ jfloat* GetFloatArrayElements(jfloatArray array, jboolean* isCopy); /** ReleaseFloatArrayElements */ void ReleaseFloatArrayElements(jfloatArray, jfloat* v, jint mode); /** NewDoubleArray */ jdoubleArray NewDoubleArray(jint len); /** SetDoubleArrayRegion */ void SetDoubleArrayRegion(jdoubleArray array, int start, int len, jdouble* vals); /** GetDoubleArrayRegion */ void GetDoubleArrayRegion(jdoubleArray array, int start, int len, jdouble* vals); /** GetDoubleArrayElements */ jdouble* GetDoubleArrayElements(jdoubleArray array, jboolean* isCopy); /** ReleaseDoubleArrayElements */ void ReleaseDoubleArrayElements(jdoubleArray, jdouble* v, jint mode); /** NewCharArray */ jcharArray NewCharArray(jint len); /** SetCharArrayRegion */ void SetCharArrayRegion(jcharArray array, int start, int len, jchar* vals); /** GetCharArrayRegion */ void GetCharArrayRegion(jcharArray array, int start, int len, jchar* vals); /** GetCharArrayElements */ jchar* GetCharArrayElements(jcharArray array, jboolean* isCopy); /** ReleaseCharArrayElements */ void ReleaseCharArrayElements(jcharArray, jchar* v, jint mode); /** NewBooleanArray */ jbooleanArray NewBooleanArray(jint len); /** SetBooleanArrayRegion */ void SetBooleanArrayRegion(jbooleanArray array, int start, int len, jboolean* vals); /** GetBooleanArrayRegion */ void GetBooleanArrayRegion(jbooleanArray array, int start, int len, jboolean* vals); /** GetBooleanArrayElements */ jboolean* GetBooleanArrayElements(jbooleanArray array, jboolean* isCopy); /** ReleaseBooleanArrayElements */ void ReleaseBooleanArrayElements(jbooleanArray, jboolean* v, jint mode); /** MonitorEnter */ int MonitorEnter(jobject a0); /** MonitorExit */ int MonitorExit(jobject a0); /** FromReflectedMethod */ jmethodID FromReflectedMethod(jobject a0); /** FromReflectedField */ jfieldID FromReflectedField(jobject a0); /** FindClass */ jclass FindClass(const char* a0); /** IsInstanceOf */ jboolean IsInstanceOf(jobject a0, jclass a1); /** NewObjectArray */ jobjectArray NewObjectArray(int a0, jclass a1, jobject a2); /** SetObjectArrayElement */ void SetObjectArrayElement(jobjectArray a0, int a1, jobject a2); /** CallStaticVoidMethodA */ void CallStaticVoidMethodA(jclass a0, jmethodID a1, jvalue* a2); /** CallVoidMethodA */ void CallVoidMethodA(jobject a0, jmethodID a1, jvalue* a2); /** CallVoidMethod */ void CallVoidMethod(jobject a0, jmethodID a1); /** IsAssignableFrom */ jboolean IsAssignableFrom(jclass a0, jclass a1); /** NewString */ jstring NewString(const jchar* a0, int a1); /** GetSuperclass */ jclass GetSuperclass(jclass a0); /** GetStringUTFChars */ const char* GetStringUTFChars(jstring a0, jboolean* a1); /** ReleaseStringUTFChars */ void ReleaseStringUTFChars(jstring a0, const char* a1); /** GetArrayLength */ jsize GetArrayLength(jarray a0); /** GetObjectArrayElement */ jobject GetObjectArrayElement(jobjectArray a0, int a1); /** GetObjectClass */ jclass GetObjectClass(jobject a0); /** GetMethodID */ jmethodID GetMethodID(jclass a0, char* a1, char* a2); /** GetStaticMethodID */ jmethodID GetStaticMethodID(jclass a0, char* a1, char* a2); /** GetFieldID */ jfieldID GetFieldID(jclass a0, char* a1, char* a2); /** GetStaticFieldID */ jfieldID GetStaticFieldID(jclass a0, char* a1, char* a2); /** GetStringChars */ const jchar* GetStringChars(jstring a0, jboolean* a1); /** ReleaseStringChars */ void ReleaseStringChars(jstring a0, const jchar* a1); /** GetStringLength */ jsize GetStringLength(jstring a0); /** DefineClass */ jclass DefineClass(const char* a0, jobject a1, const jbyte* a2, jsize a3); /** RegisterNatives */ jint RegisterNatives(jclass a0, const JNINativeMethod* a1, jint a2); python-jpype-0.5.4.2/src/native/common/include/jp_javaenv.h0000666000175000017500000000702011614007722023107 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard 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. *****************************************************************************/ #ifndef _JAVA_ENV_H_ #define _JAVA_ENV_H_ /** * Simple exception class to wrap java-sourced exceptions */ class JavaException { public : JavaException(const char* msg, const char* f, int l) : file(f), line(l) {message = msg;} JavaException(JavaException& ex) : file(ex.file), line(ex.line) {message = ex.message;} virtual ~JavaException() {} const char* file; int line; string message; }; class HostException { public : HostException() {} virtual ~HostException() {} virtual const char* getFile() { return "";} virtual int getLine() {return 0;} virtual string getMessage() { return ""; } }; /** * the platform adapter's implementation is chosen by the JPYPE_??? macros */ class JPPlatformAdapter { public : virtual ~JPPlatformAdapter() {}; virtual void loadLibrary(const char* path) = 0; virtual void* getSymbol(const char* name)= 0; }; /** * Wrap all the needed parts of JNI to provide centralized error detection and dynamic loading */ class JPJavaEnv { public : JPJavaEnv(JavaVM* vm) { jvm = vm; convertStringObjects = true; } virtual ~JPJavaEnv() {} private : static JPPlatformAdapter* GetAdapter(); // static JPPlatformAdapter* adapter; static jint (JNICALL *CreateJVM_Method)(JavaVM **pvm, void **penv, void *args); static jint (JNICALL *GetCreatedJVMs_Method)(JavaVM **pvm, jsize size, jsize* nVms); JavaVM* jvm; jobject referenceQueue; bool convertStringObjects; JNIEnv* getJNIEnv(); public : static void load(const string& path); static JPJavaEnv* CreateJavaVM(void* arg); static JPJavaEnv* GetCreatedJavaVM(); jint AttachCurrentThread(); jint AttachCurrentThreadAsDaemon(); static bool isThreadAttached(); void setConvertStringObjects(bool flag) { convertStringObjects = flag; } bool getConvertStringObjects() { return convertStringObjects; } void setReferenceQueue(jobject obj) { referenceQueue = NewGlobalRef(obj); } jobject getReferenceQueue() { return referenceQueue; } void shutdown(); void checkInitialized(); int DestroyJavaVM(); jobject NewGlobalRef(jobject obj); void DeleteGlobalRef(jobject obj); jobject NewLocalRef(jobject obj); void DeleteLocalRef(jobject obj); bool ExceptionCheck(); void ExceptionDescribe(); void ExceptionClear(); jthrowable ExceptionOccurred(); jint DetachCurrentThread(); jint GetEnv(JNIEnv** env); jint ThrowNew(jclass clazz, const char* msg); jint Throw(jthrowable th); jobject NewDirectByteBuffer(void* address, jlong capacity); /** NewObjectA */ jobject NewObjectA(jclass a0, jmethodID a1, jvalue* a2); /** NewObject */ jobject NewObject(jclass a0, jmethodID a1); #include "jp_javaenv_autogen.h" }; #endif // _JAVA_ENV_H_ python-jpype-0.5.4.2/src/native/common/include/jp_field.h0000666000175000017500000000327311614007722022546 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard 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. *****************************************************************************/ #ifndef _JPFIELD_H_ #define _JPFIELD_H_ /** * Field object */ class JPField { public : /** * default constructor */ JPField(); /** * Create a new field based on class and java.lang.Field object */ JPField(JPClass* clazz, jobject fld); JPField(const JPField&); /** * destructor */ virtual ~JPField(); public : bool isStatic(); string getName(); JPTypeName getType() { return m_Type; } HostRef* getStaticAttribute(); void setStaticAttribute(HostRef* val); HostRef* getAttribute(jobject inst); void setAttribute(jobject inst, HostRef* val); bool isFinal() { return m_IsFinal; } private : string m_Name; JPClass* m_Class; bool m_IsStatic; bool m_IsFinal; jobject m_Field; jfieldID m_FieldID; JPTypeName m_Type; }; #endif // _JPFIELD_H_ python-jpype-0.5.4.2/src/native/common/include/jp_object.h0000666000175000017500000000244711614007722022733 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard 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. *****************************************************************************/ #ifndef _JPOBJECT_H_ #define _JPOBJECT_H_ class JPObject : public JPObjectBase { public : JPObject(JPClass* clazz, jobject inst); JPObject(JPTypeName& clazz, jobject inst); virtual ~JPObject(); JPClass* getClass() { return m_Class; } jobject getObject() { return JPEnv::getJava()->NewLocalRef(m_Object); } JCharString toString(); HostRef* getAttribute(string name); void setAttribute(string name, HostRef* value); private : JPClass* m_Class; jobject m_Object; }; #endif // _JPOBJECT_H_ python-jpype-0.5.4.2/src/native/common/include/jp_env.h0000666000175000017500000000554511614007722022257 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve M�nard 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. *****************************************************************************/ #ifndef _JPENV_H_ #define _JPENV_H_ /** * Simple tample class for managing local java references. */ class JPCleaner { public : JPCleaner(); virtual ~JPCleaner(); void addGlobal(jobject r); void removeGlobal(jobject r); void addAllGlobal(vector& r); void addAllGlobal(vector& r); void removeAllGlobal(vector& r); void addLocal(jobject r); void removeLocal(jobject r); void addAllLocal(vector& r); void addAllLocal(vector& r); void removeAllLocal(vector& r); void add(HostRef* r); void addAll(vector& r); void remove(HostRef* r); void removeAll(vector& r); private : vector m_GlobalJavaObjects; vector m_LocalJavaObjects; vector m_HostObjects; }; template class JPMallocCleaner { public : JPMallocCleaner(size_t size) { mData = (T*)malloc(sizeof(T)*size); } ~JPMallocCleaner() { free(mData); } T& operator[](size_t ndx) { return mData[ndx]; } T* borrow() { return mData; } private : T* mData; }; class JPEnv { public : /** * Initialize the JPype subs-system. Does NOT load the JVM */ static void init(HostEnvironment* hostEnv); /** * Load the JVM * TODO : add the non-string parameters, for possible callbacks */ static void loadJVM(const string& vmPath, char ignoreUnrecognized, const StringVector& args); static void attachJVM(const string& vmPath); /** * Check if the JPype environment has been initialized */ static bool isInitialized() { return getJava() != NULL && getHost() != NULL; } static void attachCurrentThread(); static void attachCurrentThreadAsDaemon(); static bool isThreadAttached(); static JPJavaEnv* getJava() { return s_Java; } static HostEnvironment* getHost() { return s_Host; } static void registerRef(HostRef*, HostRef* targetRef); private : static void postLoadJVM(); private : static HostEnvironment* s_Host; static JPJavaEnv* s_Java; }; #endif // _JPENV_H_ python-jpype-0.5.4.2/src/native/common/include/jp_jniutil.h0000666000175000017500000001125511614007722023140 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard 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. *****************************************************************************/ #ifndef _JPJNIUTIL_H_ #define _JPJNIUTIL_H_ class JPJni { public : static jclass s_ClassClass; static jclass s_StringClass; static jclass s_NoSuchMethodErrorClass; static jclass s_RuntimeExceptionClass; static jclass s_ProxyClass; static jmethodID s_NewProxyInstanceID; static jlong s_minByte; static jlong s_maxByte; static jlong s_minShort; static jlong s_maxShort; static jlong s_minInt; static jlong s_maxInt; static jfloat s_minFloat; static jfloat s_maxFloat; public : static void init(); static void startJPypeReferenceQueue(bool); static void stopJPypeReferenceQueue(); static void registerRef(jobject refQueue, jobject obj, jlong hostRef); static string asciiFromJava(jstring str); static JCharString unicodeFromJava(jstring str); static jstring javaStringFromJCharString(JCharString& str); static JPTypeName getClassName(jobject obj); static jclass getClass(jobject obj); static jstring toString(jobject obj); /** * java.lang.Class.isInterface() */ static bool isInterface(jclass); /** * java.lang.reflect.Modifier.isAbstract(java.lang.Class.getModifiers() */ static bool isAbstract(jclass); /** * java.lang.reflect.Modifier.isFinal(java.lang.Class.getModifiers() */ static bool isFinal(jclass); /** * java.lang.Class.getName() */ static JPTypeName getName(jclass); /** * java.lang.Class.getInterfaces() */ static vector getInterfaces(jclass); /** * java.lang.Class.getDeclaredFields() */ static vector getDeclaredFields(jclass); /** * java.lang.Class.getConstructors() */ static vector getConstructors(jclass); /** * java.lang.Class.getFields() */ static vector getFields(jclass); /** * java.lang.Class.getDeclaredMethods() */ static vector getDeclaredMethods(jclass); /** * java.lang.Class.getDeclaredMethods() */ static vector getMethods(jclass); /** * java.lang.Class.getDeclaredMethods() */ static vector getDeclaredConstructors(jclass); /** * java.lang.Class.getModifiers() */ static long getClassModifiers(jclass); static jobject getSystemClassLoader(); /** * java.lang.reflect.Member.getName() */ static string getMemberName(jobject); /** * java.lang.reflect.Modifier.isPublic(java.lang.reflect.member.getModifiers()) */ static bool isMemberPublic(jobject); /** * java.lang.reflect.Modifier.isStatic(java.lang.reflect.member.getModifiers()) */ static bool isMemberStatic(jobject); /** * java.lang.reflect.Modifier.isFinal(java.lang.reflect.member.getModifiers()) */ static bool isMemberFinal(jobject); /** * java.lang.reflect.Modifier.isStatic(java.lang.reflect.member.getModifiers()) */ static bool isMemberAbstract(jobject); /** * java.lang.reflect.Field.getType */ static JPTypeName getType(jobject fld); /** * java.lang.reflect.Method.getReturnType */ static JPTypeName getReturnType(jobject); static jint hashCode(jobject); /** * java.lang.reflect.Method.getParameterTypes */ static vector getParameterTypes(jobject, bool); static bool isConstructor(jobject); static string getStackTrace(jthrowable th); static string getMessage(jthrowable th); static bool isThrowable(jclass c); static long intValue(jobject); static jlong longValue(jobject); static double doubleValue(jobject); static bool booleanValue(jobject); static jchar charValue(jobject); static jclass getByteClass(); static jclass getShortClass(); static jclass getIntegerClass(); static jclass getLongClass(); static jclass getFloatClass(); static jclass getDoubleClass(); static jclass getCharacterClass(); static jclass getBooleanClass(); static jclass getVoidClass(); }; #endif // _JPJNIUTIL_H_ python-jpype-0.5.4.2/src/native/common/include/jp_methodoverload.h0000666000175000017500000000404511614007722024475 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard 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. *****************************************************************************/ #ifndef _JPMETHODOVERLOAD_H_ #define _JPMETHODOVERLOAD_H_ class JPObject; class JPMethodOverload { public : JPMethodOverload(); JPMethodOverload(const JPMethodOverload& o); JPMethodOverload(JPClass* claz, jobject mth); virtual ~JPMethodOverload(); EMatchType matches(bool ignoreFirst, vector& args) ; HostRef* invokeInstance(vector& arg); HostRef* invokeStatic(vector& arg); JPObject* invokeConstructor(jclass, vector& arg); public : string getSignature(); bool isStatic() { return m_IsStatic; } bool isFinal() { return m_IsFinal; } JPTypeName getReturnType() { return m_ReturnType; } unsigned char getArgumentCount() { return (unsigned char)m_Arguments.size(); } string getArgumentString(); bool isSameOverload(JPMethodOverload& o); string matchReport(vector& args); private : JPClass* m_Class; jobject m_Method; jmethodID m_MethodID; JPTypeName m_ReturnType; vector m_Arguments; bool m_IsStatic; bool m_IsFinal; bool m_IsConstructor; }; #endif // _JPMETHODOVERLOAD_H_ python-jpype-0.5.4.2/src/native/common/include/jp_arrayclass.h0000666000175000017500000000256711614007722023634 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard 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. *****************************************************************************/ #ifndef _JPARRAYCLASS_H_ #define _JPARRAYCLASS_H_ /** * Class to wrap Java Class and provide low-level behavior */ class JPArrayClass : public JPClassBase { public : JPArrayClass(const JPTypeName& tname, jclass c); virtual~ JPArrayClass(); public : // JPType implementation virtual HostRef* asHostObject(jvalue val); virtual EMatchType canConvertToJava(HostRef* obj); virtual jvalue convertToJava(HostRef* obj); virtual JPType* getComponentType() { return m_ComponentType; } JPArray* newInstance(int length); public : JPType* m_ComponentType; }; #endif // _JPARRAYCLASS_H_ python-jpype-0.5.4.2/src/native/common/include/jp_invocationhandler.h0000666000175000017500000000166511614007722025175 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard 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. *****************************************************************************/ #ifndef _JPINVOCATIONHANDLER_H_ #define _JPINVOCATIONHANDLER_H_ extern jbyte JPypeInvocationHandler[]; jsize getJPypeInvocationHandlerLength(); #endif // JPINVOCATIONHANDLER_H python-jpype-0.5.4.2/src/native/common/include/jp_proxy.h0000666000175000017500000000301511614007722022636 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard 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. *****************************************************************************/ #ifndef _JPPROXY_H_ #define _JPPROXY_H_ class JPProxy { public: JPProxy(HostRef* inst, vector& intf); virtual ~JPProxy() { if (m_Instance != NULL) { m_Instance->release(); } JPEnv::getJava()->DeleteGlobalRef(m_Handler); for (unsigned int i = 0; i < m_InterfaceClasses.size(); i++) { JPEnv::getJava()->DeleteGlobalRef(m_InterfaceClasses[i]); } } static void init(); vector getInterfaces() { return m_InterfaceClasses; } // jobject getHandler() // { // return JPEnv::getJava()->NewGlobalRef(m_Handler); // } jobject getProxy(); private : vector m_InterfaceClasses; jobjectArray m_Interfaces; jobject m_Handler; HostRef* m_Instance; }; #endif // JPPROXY_H python-jpype-0.5.4.2/src/native/common/include/jp_primitivetypes.h0000666000175000017500000003247011614007722024561 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard 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. *****************************************************************************/ #ifndef _JPPRIMITIVETYPE_H_ #define _JPPRIMITIVETYPE_H_ class JPPrimitiveType : public JPType { protected : JPPrimitiveType(JPTypeName::ETypes type, bool isObject, JPTypeName objectType) { m_Type = JPTypeName::fromType(type); m_IsObject = isObject; m_ObjectTypeName = objectType; } virtual ~JPPrimitiveType() { } private : JPTypeName m_Type; bool m_IsObject; JPTypeName m_ObjectTypeName; public : virtual bool isObjectType() { return m_IsObject; } virtual JPTypeName getName() { return m_Type; } virtual JPTypeName getObjectType() { return m_ObjectTypeName; } virtual jobject convertToJavaObject(HostRef* obj); }; class JPVoidType : public JPPrimitiveType { public : JPVoidType() : JPPrimitiveType(JPTypeName::_void, false, JPTypeName::fromSimple("java.lang.Void")) { } virtual ~JPVoidType() { } public : // JPType implementation virtual HostRef* getStaticValue(jclass c, jfieldID fid, JPTypeName& tgtType); virtual void setStaticValue(jclass c, jfieldID fid, HostRef* val); virtual HostRef* getInstanceValue(jobject c, jfieldID fid, JPTypeName& tgtType); virtual void setInstanceValue(jobject c, jfieldID fid, HostRef* val); virtual HostRef* asHostObject(jvalue val); virtual HostRef* asHostObjectFromObject(jvalue val); virtual EMatchType canConvertToJava(HostRef* obj); virtual jvalue convertToJava(HostRef* obj); virtual HostRef* invokeStatic(jclass, jmethodID, jvalue*); virtual HostRef* invoke(jobject, jclass, jmethodID, jvalue*); virtual jarray newArrayInstance(int size); virtual vector getArrayRange(jarray, int start, int length); virtual void setArrayRange(jarray, int start, int length, vector& vals); virtual HostRef* getArrayItem(jarray, int ndx); virtual void setArrayItem(jarray, int ndx, HostRef* val); virtual void setArrayValues(jarray, HostRef*); virtual HostRef* convertToDirectBuffer(HostRef* src); }; class JPByteType : public JPPrimitiveType { public : JPByteType() : JPPrimitiveType(JPTypeName::_byte, false, JPTypeName::fromSimple("java.lang.Byte")) { } virtual ~JPByteType() { } public : // JPType implementation virtual HostRef* getStaticValue(jclass c, jfieldID fid, JPTypeName& tgtType); virtual void setStaticValue(jclass c, jfieldID fid, HostRef* val); virtual HostRef* getInstanceValue(jobject c, jfieldID fid, JPTypeName& tgtType); virtual void setInstanceValue(jobject c, jfieldID fid, HostRef* val); virtual HostRef* asHostObject(jvalue val); virtual HostRef* asHostObjectFromObject(jvalue val); virtual EMatchType canConvertToJava(HostRef* obj); virtual jvalue convertToJava(HostRef* obj); virtual HostRef* invokeStatic(jclass, jmethodID, jvalue*); virtual HostRef* invoke(jobject, jclass, jmethodID, jvalue*); virtual jarray newArrayInstance(int size); virtual vector getArrayRange(jarray, int start, int length); virtual void setArrayRange(jarray, int start, int length, vector& vals); virtual HostRef* getArrayItem(jarray, int ndx); virtual void setArrayItem(jarray, int ndx, HostRef* val); virtual void setArrayValues(jarray, HostRef*); virtual HostRef* convertToDirectBuffer(HostRef* src); }; class JPShortType : public JPPrimitiveType { public : JPShortType() : JPPrimitiveType(JPTypeName::_short, false, JPTypeName::fromSimple("java.lang.Short")) { } virtual ~JPShortType() { } public : // JPType implementation virtual HostRef* getStaticValue(jclass c, jfieldID fid, JPTypeName& tgtType); virtual void setStaticValue(jclass c, jfieldID fid, HostRef* val); virtual HostRef* getInstanceValue(jobject c, jfieldID fid, JPTypeName& tgtType); virtual void setInstanceValue(jobject c, jfieldID fid, HostRef* val); virtual HostRef* asHostObject(jvalue val); virtual HostRef* asHostObjectFromObject(jvalue val); virtual EMatchType canConvertToJava(HostRef* obj); virtual jvalue convertToJava(HostRef* obj); virtual HostRef* invokeStatic(jclass, jmethodID, jvalue*); virtual HostRef* invoke(jobject, jclass, jmethodID, jvalue*); virtual jarray newArrayInstance(int size); virtual vector getArrayRange(jarray, int start, int length); virtual void setArrayRange(jarray, int start, int length, vector& vals); virtual HostRef* getArrayItem(jarray, int ndx); virtual void setArrayItem(jarray, int ndx, HostRef* val); virtual void setArrayValues(jarray, HostRef*); virtual HostRef* convertToDirectBuffer(HostRef* src); }; class JPIntType : public JPPrimitiveType { public : JPIntType(): JPPrimitiveType(JPTypeName::_int, false, JPTypeName::fromSimple("java.lang.Integer")) { } virtual ~JPIntType() { } public : // JPType implementation virtual HostRef* getStaticValue(jclass c, jfieldID fid, JPTypeName& tgtType); virtual void setStaticValue(jclass c, jfieldID fid, HostRef* val); virtual HostRef* getInstanceValue(jobject c, jfieldID fid, JPTypeName& tgtType); virtual void setInstanceValue(jobject c, jfieldID fid, HostRef* val); virtual HostRef* asHostObject(jvalue val); virtual HostRef* asHostObjectFromObject(jvalue val); virtual EMatchType canConvertToJava(HostRef* obj); virtual jvalue convertToJava(HostRef* obj); virtual HostRef* invokeStatic(jclass, jmethodID, jvalue*); virtual HostRef* invoke(jobject, jclass, jmethodID, jvalue*); virtual jarray newArrayInstance(int size); virtual vector getArrayRange(jarray, int start, int length); virtual void setArrayRange(jarray, int start, int length, vector& vals); virtual HostRef* getArrayItem(jarray, int ndx); virtual void setArrayItem(jarray, int ndx, HostRef* val); virtual void setArrayValues(jarray, HostRef*); virtual HostRef* convertToDirectBuffer(HostRef* src); }; class JPLongType : public JPPrimitiveType { public : JPLongType() : JPPrimitiveType(JPTypeName::_long, false, JPTypeName::fromSimple("java.lang.Long")) { } virtual ~JPLongType() { } public : // JPType implementation virtual HostRef* getStaticValue(jclass c, jfieldID fid, JPTypeName& tgtType); virtual void setStaticValue(jclass c, jfieldID fid, HostRef* val); virtual HostRef* getInstanceValue(jobject c, jfieldID fid, JPTypeName& tgtType); virtual void setInstanceValue(jobject c, jfieldID fid, HostRef* val); virtual HostRef* asHostObject(jvalue val); virtual HostRef* asHostObjectFromObject(jvalue val); virtual EMatchType canConvertToJava(HostRef* obj); virtual jvalue convertToJava(HostRef* obj); virtual HostRef* invokeStatic(jclass, jmethodID, jvalue*); virtual HostRef* invoke(jobject, jclass, jmethodID, jvalue*); virtual jarray newArrayInstance(int size); virtual vector getArrayRange(jarray, int start, int length); virtual void setArrayRange(jarray, int start, int length, vector& vals); virtual HostRef* getArrayItem(jarray, int ndx); virtual void setArrayItem(jarray, int ndx, HostRef* val); virtual void setArrayValues(jarray, HostRef*); virtual HostRef* convertToDirectBuffer(HostRef* src); }; class JPFloatType : public JPPrimitiveType { public : JPFloatType() : JPPrimitiveType(JPTypeName::_float, false, JPTypeName::fromSimple("java.lang.Float")) { } virtual ~JPFloatType() { } public : // JPType implementation virtual HostRef* getStaticValue(jclass c, jfieldID fid, JPTypeName& tgtType); virtual void setStaticValue(jclass c, jfieldID fid, HostRef* val); virtual HostRef* getInstanceValue(jobject c, jfieldID fid, JPTypeName& tgtType); virtual void setInstanceValue(jobject c, jfieldID fid, HostRef* val); virtual HostRef* asHostObject(jvalue val); virtual HostRef* asHostObjectFromObject(jvalue val); virtual EMatchType canConvertToJava(HostRef* obj); virtual jvalue convertToJava(HostRef* obj); virtual HostRef* invokeStatic(jclass, jmethodID, jvalue*); virtual HostRef* invoke(jobject, jclass, jmethodID, jvalue*); virtual jarray newArrayInstance(int size); virtual vector getArrayRange(jarray, int start, int length); virtual void setArrayRange(jarray, int start, int length, vector& vals); virtual HostRef* getArrayItem(jarray, int ndx); virtual void setArrayItem(jarray, int ndx, HostRef* val); virtual void setArrayValues(jarray, HostRef*); virtual HostRef* convertToDirectBuffer(HostRef* src); }; class JPDoubleType : public JPPrimitiveType { public : JPDoubleType() : JPPrimitiveType(JPTypeName::_double, false, JPTypeName::fromSimple("java.lang.Double")) { } virtual ~JPDoubleType() { } public : // JPType implementation virtual HostRef* getStaticValue(jclass c, jfieldID fid, JPTypeName& tgtType); virtual void setStaticValue(jclass c, jfieldID fid, HostRef* val); virtual HostRef* getInstanceValue(jobject c, jfieldID fid, JPTypeName& tgtType); virtual void setInstanceValue(jobject c, jfieldID fid, HostRef* val); virtual HostRef* asHostObject(jvalue val); virtual HostRef* asHostObjectFromObject(jvalue val); virtual EMatchType canConvertToJava(HostRef* obj); virtual jvalue convertToJava(HostRef* obj); virtual HostRef* invokeStatic(jclass, jmethodID, jvalue*); virtual HostRef* invoke(jobject, jclass, jmethodID, jvalue*); virtual jarray newArrayInstance(int size); virtual vector getArrayRange(jarray, int start, int length); virtual void setArrayRange(jarray, int start, int length, vector& vals); virtual HostRef* getArrayItem(jarray, int ndx); virtual void setArrayItem(jarray, int ndx, HostRef* val); virtual void setArrayValues(jarray, HostRef*); virtual HostRef* convertToDirectBuffer(HostRef* src); }; class JPCharType : public JPPrimitiveType { public : JPCharType() : JPPrimitiveType(JPTypeName::_char, false, JPTypeName::fromSimple("java.lang.Character")) { } virtual ~JPCharType() { } public : // JPType implementation virtual HostRef* getStaticValue(jclass c, jfieldID fid, JPTypeName& tgtType); virtual void setStaticValue(jclass c, jfieldID fid, HostRef* val); virtual HostRef* getInstanceValue(jobject c, jfieldID fid, JPTypeName& tgtType); virtual void setInstanceValue(jobject c, jfieldID fid, HostRef* val); virtual HostRef* asHostObject(jvalue val); virtual HostRef* asHostObjectFromObject(jvalue val); virtual EMatchType canConvertToJava(HostRef* obj); virtual jvalue convertToJava(HostRef* obj); virtual HostRef* invokeStatic(jclass, jmethodID, jvalue*); virtual HostRef* invoke(jobject, jclass, jmethodID, jvalue*); virtual jarray newArrayInstance(int size); virtual vector getArrayRange(jarray, int start, int length); virtual void setArrayRange(jarray, int start, int length, vector& vals); virtual HostRef* getArrayItem(jarray, int ndx); virtual void setArrayItem(jarray, int ndx, HostRef* val); virtual void setArrayValues(jarray, HostRef*); virtual HostRef* convertToDirectBuffer(HostRef* src); }; class JPBooleanType : public JPPrimitiveType { public : JPBooleanType() : JPPrimitiveType(JPTypeName::_boolean, false, JPTypeName::fromSimple("java.lang.Boolean")) { } virtual ~JPBooleanType() { } public : // JPType implementation virtual HostRef* getStaticValue(jclass c, jfieldID fid, JPTypeName& tgtType); virtual void setStaticValue(jclass c, jfieldID fid, HostRef* val); virtual HostRef* getInstanceValue(jobject c, jfieldID fid, JPTypeName& tgtType); virtual void setInstanceValue(jobject c, jfieldID fid, HostRef* val); virtual HostRef* asHostObject(jvalue val); virtual HostRef* asHostObjectFromObject(jvalue val); virtual EMatchType canConvertToJava(HostRef* obj); virtual jvalue convertToJava(HostRef* obj); virtual HostRef* invokeStatic(jclass, jmethodID, jvalue*); virtual HostRef* invoke(jobject, jclass, jmethodID, jvalue*); virtual jarray newArrayInstance(int size); virtual vector getArrayRange(jarray, int start, int length); virtual void setArrayRange(jarray, int start, int length, vector& vals); virtual HostRef* getArrayItem(jarray, int ndx); virtual void setArrayItem(jarray, int ndx, HostRef* val); virtual void setArrayValues(jarray, HostRef*); virtual HostRef* convertToDirectBuffer(HostRef* src); }; #endif // _JPPRIMITIVETYPE_H_ python-jpype-0.5.4.2/src/native/common/include/jp_referencequeue.h0000666000175000017500000000165011614007722024463 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard 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. *****************************************************************************/ #ifndef _JPREFERENCEQUEUE_H_ #define _JPREFERENCEQUEUE_H_ extern jbyte JPypeReferenceQueue[]; jsize getJPypeReferenceQueueLength(); #endif // _JPREFERENCEQUEUE_H_ python-jpype-0.5.4.2/src/native/common/include/jp_objectbase.h0000666000175000017500000000165111614007722023562 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard 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. *****************************************************************************/ #ifndef _JPOBJECTBASE_H_ #define _JPOBJECTBASE_H_ class JPObjectBase { protected : JPObjectBase() {} virtual ~JPObjectBase() {} }; #endif // _JPOBJECTBASE_H_ python-jpype-0.5.4.2/src/native/common/include/jp_platform_win32.h0000666000175000017500000000374311614007722024333 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard 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. *****************************************************************************/ #ifndef _PLATFORM_WIN32_H_ #define _PLATFORM_WIN32_H_ #include /** * Windows-specific platform adapter */ class Win32PlatformAdapter : public JPPlatformAdapter { private : HINSTANCE jvmLibrary; std::string formatMessage(DWORD msgCode) { LPVOID lpMsgBuf; FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, msgCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL ); std::string res = std::string((LPTSTR)lpMsgBuf); LocalFree(lpMsgBuf); return res; } public : virtual void loadLibrary(const char* path) { jvmLibrary = LoadLibrary(path); if (jvmLibrary == NULL) { std::stringstream msg; msg << "Unable to load DLL [" << path << "], error = " << formatMessage(GetLastError()); RAISE(JPypeException, msg.str().c_str()); } } virtual void* getSymbol(const char* name) { void* res = (void*)GetProcAddress(jvmLibrary, name); if (res == NULL) { std::stringstream msg; msg << "Unable to load symbol [" << name << "], error = " << formatMessage(GetLastError()); RAISE(JPypeException, msg.str().c_str()); } return res; } }; #endif // _PLATFORM_WIN32_H_ python-jpype-0.5.4.2/src/native/common/include/jp_typename.h0000666000175000017500000000507111614007722023303 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard 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. *****************************************************************************/ #ifndef _JPTYPENAME_H_ #define _JPTYPENAME_H_ /** * Enum for all kinds of well-known types. */ /** * Since types have multiple name representation (simple, native) and a type, this class encapsulates it all. */ class JPTypeName { public: //AT's comments on porting: // 1) Originally this ETypes enum was declraed outside of this JPTypeName class. // This, however, broke compilation on AIX platform because of a conflict with some system headers; // As a compromise, it was made part of JPTypeName enum ETypes { _unknown, _void, _byte, _short, _int, _long, _float, _double, _char, _boolean, _object, _class, _string, _array }; JPTypeName() : m_Type(_unknown) { } private : JPTypeName(string simple, string native, ETypes t): m_SimpleName(simple), m_NativeName(native), m_Type(t) { } public : /** Copy Constructor */ JPTypeName(const JPTypeName& tn) : m_SimpleName(tn.m_SimpleName), m_NativeName(tn.m_NativeName), m_Type(tn.m_Type) { } /** Destructor */ virtual ~JPTypeName() {} public : /** * Initialize the cache of type-name to ETypes */ static void init(); /** Factory method from a simple, human-readable name */ static JPTypeName fromSimple(const char* name); static JPTypeName fromType(ETypes t); string getSimpleName() { return m_SimpleName; } string getNativeName() { return m_NativeName; } JPTypeName getComponentName(); ETypes getType() { return m_Type; } bool isObjectType() { return m_Type >= _object; } private : string m_SimpleName; string m_NativeName; ETypes m_Type; }; #endif // _JPTYPENAME_H_ python-jpype-0.5.4.2/src/native/common/include/jp_typemanager.h0000666000175000017500000000277711614007722024007 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard 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. *****************************************************************************/ #ifndef _JPTYPE_MANAGER_H_ #define _JPTYPE_MANAGER_H_ /** * This class will manage the cache of found type, be it primitive types, class types or the "magic" types. */ class JPTypeManager { public : /** * Initialize the type manager caches */ static void init(); static JPType* getType(JPTypeName& name); /** * The pointer returned is NOT owned by the caller */ static JPClass* findClass(JPTypeName&); /** * The pointer returned is NOT owned by the caller */ static JPArrayClass* findArrayClass(JPTypeName&); static void flushCache(); static int getLoadedClasses(); public: }; #endif // _JPCLASS_H_ python-jpype-0.5.4.2/src/native/common/include/jp_class.h0000666000175000017500000000544111614007722022567 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard 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. *****************************************************************************/ #ifndef _JPCLASS_H_ #define _JPCLASS_H_ /** * Class to wrap Java Class and provide low-level behavior */ class JPClass : public JPClassBase { public : JPClass(const JPTypeName& tname, jclass c); virtual~ JPClass(); public : /** * Called to fully load base classes and members */ void postLoad(); HostRef* getStaticAttribute(string attr_name); void setStaticAttribute(string attr_name, HostRef* val); JPObject* newInstance(vector& args); JPField* getInstanceField(const string& name); JPField* getStaticField(const string& name); JPMethod* getMethod(const string& name); vector getMethods() { vector res; for (map::iterator cur = m_Methods.begin(); cur != m_Methods.end(); cur++) { res.push_back(cur->second); } return res; } jclass getClass() { return (jclass)JPEnv::getJava()->NewGlobalRef(m_Class); } map& getStaticFields() { return m_StaticFields; } map& getInstanceFields() { return m_InstanceFields; } bool isFinal(); bool isAbstract(); bool isInterface() { return m_IsInterface; } JPClass* getSuperClass(); vector getInterfaces(); bool isSubclass(JPClass*); string describe(); public : // JPType implementation virtual HostRef* asHostObject(jvalue val); virtual EMatchType canConvertToJava(HostRef* obj); virtual jvalue convertToJava(HostRef* obj); private : void loadSuperClass(); void loadSuperInterfaces(); void loadFields(); void loadMethods(); void loadConstructors(); jvalue buildObjectWrapper(HostRef* obj); private : bool m_IsInterface; JPClass* m_SuperClass; vector m_SuperInterfaces; map m_StaticFields; map m_InstanceFields; map m_Methods; JPMethod* m_Constructors; }; #endif // _JPCLASS_H_ python-jpype-0.5.4.2/src/native/common/include/jp_method.h0000666000175000017500000000356311614007722022745 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard 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. *****************************************************************************/ #ifndef _JPMETHOD_H_ #define _JPMETHOD_H_ class JPObject; class JPMethod { public : /** * Create a new method based on class and a name; */ JPMethod(jclass clazz, string name, bool isConstructor); virtual ~JPMethod() { JPEnv::getJava()->DeleteGlobalRef(m_Class); } public : string getName(); string getClassName(); void addOverload(JPClass* clazz, jobject mth); void addOverloads(JPMethod* o); bool hasStatic(); size_t getCount() { return m_Overloads.size(); } bool isBeanMutator(); bool isBeanAccessor(); HostRef* invoke(vector&); HostRef* invokeStatic(vector&); HostRef* invokeInstance(vector&); JPObject* invokeConstructor(vector& args); string describe(string prefix); string matchReport(vector&); private : JPMethodOverload* findOverload(vector& arg, bool needStatic); jclass m_Class; string m_Name; map m_Overloads; bool m_IsConstructor; }; #endif // _JPMETHOD_H_ python-jpype-0.5.4.2/src/native/common/include/jp_objecttypes.h0000666000175000017500000000633411614007722024017 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard 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. *****************************************************************************/ #ifndef _JPPOBJECTTYPE_H_ #define _JPPOBJECTTYPE_H_ class JPObjectType : public JPType { protected : JPObjectType(JPTypeName::ETypes type, JPTypeName objectType) : m_Type(JPTypeName::fromType(type)), m_ObjectTypeName(objectType) { } virtual ~JPObjectType() { } public : virtual JPTypeName getName() { return m_Type; } virtual JPTypeName getObjectType() { return m_ObjectTypeName; } virtual bool isObjectType() { return true; } virtual HostRef* getStaticValue(jclass c, jfieldID fid, JPTypeName& tgtType); virtual void setStaticValue(jclass c, jfieldID fid, HostRef* val); virtual HostRef* getInstanceValue(jobject c, jfieldID fid, JPTypeName& tgtType); virtual void setInstanceValue(jobject c, jfieldID fid, HostRef* val); virtual HostRef* asHostObjectFromObject(jvalue val); virtual jobject convertToJavaObject(HostRef* obj); virtual HostRef* invokeStatic(jclass, jmethodID, jvalue*); virtual HostRef* invoke(jobject, jclass clazz, jmethodID, jvalue*); virtual jarray newArrayInstance(int size); virtual vector getArrayRange(jarray, int start, int length); virtual void setArrayRange(jarray, int start, int length, vector& vals); virtual HostRef* getArrayItem(jarray, int ndx); virtual void setArrayItem(jarray, int ndx, HostRef* val); virtual void setArrayValues(jarray, HostRef*); virtual HostRef* convertToDirectBuffer(HostRef* src); protected : virtual jclass getClass() = 0; private : JPTypeName m_Type; JPTypeName m_ObjectTypeName; }; class JPStringType : public JPObjectType { public : JPStringType() : JPObjectType(JPTypeName::_string, JPTypeName::fromSimple("java.lang.String")) { } virtual ~JPStringType() { } protected : virtual jclass getClass(); public : // JPType implementation virtual HostRef* asHostObject(jvalue val); virtual EMatchType canConvertToJava(HostRef* obj); virtual jvalue convertToJava(HostRef* obj); }; class JPClassType : public JPObjectType { public : JPClassType() : JPObjectType(JPTypeName::_class, JPTypeName::fromSimple("java.lang.Class")) { } virtual ~JPClassType() { } protected : virtual jclass getClass(); public : // JPType implementation virtual HostRef* asHostObject(jvalue val); virtual EMatchType canConvertToJava(HostRef* obj); virtual jvalue convertToJava(HostRef* obj); }; #endif // _JPPOBJECTTYPE_H_ python-jpype-0.5.4.2/src/native/common/include/jp_platform_linux.h0000666000175000017500000000347611614007722024533 0ustar takakitakaki/***************************************************************************** Copyright 2004-2008 Steve Menard 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. *****************************************************************************/ #ifndef _PLATFORM_LINUX_H_ #define _PLATFORM_LINUX_H_ //AT's comments on porting: // this file should be better called jp_platform_unix.h #if defined(_HPUX) && !defined(_IA64) #include #else #include #endif // HPUX class LinuxPlatformAdapter : public JPPlatformAdapter { private : void* jvmLibrary; public : virtual void loadLibrary(const char* path) { #if defined(_HPUX) && !defined(_IA64) jvmLibrary = shl_load(path, BIND_DEFERRED|BIND_VERBOSE, 0L); #else jvmLibrary = dlopen(path, RTLD_LAZY|RTLD_GLOBAL); #endif // HPUX if (jvmLibrary == NULL) { std::stringstream msg; msg << "Unable to load DLL [" << path << "], error = " << dlerror(); RAISE(JPypeException, msg.str().c_str()); } } virtual void* getSymbol(const char* name) { void* res = dlsym(jvmLibrary, name); if (res == NULL) { std::stringstream msg; msg << "Unable to load symbol [" << name << "], error = " << dlerror(); RAISE(JPypeException, msg.str().c_str()); } return res; } }; #endif // _PLATFORM_LINUX_H_ python-jpype-0.5.4.2/src/native/common/include/jp_classbase.h0000666000175000017500000000253511614007722023423 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard 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. *****************************************************************************/ #ifndef _JPCLASS_BASE_H_ #define _JPCLASS_BASE_H_ /** * Base class for Java Class based types */ class JPClassBase : public JPObjectType { protected : JPClassBase(const JPTypeName& tname, jclass c); virtual ~JPClassBase(); public : // JPType implementation virtual JPTypeName getName() { return m_Name; } virtual JPTypeName getObjectType() { return m_Name; } virtual jclass getClass() { return (jclass)JPEnv::getJava()->NewLocalRef(m_Class); } protected : JPTypeName m_Name; jclass m_Class; }; #endif // _JPCLASS_BASE_H_ python-jpype-0.5.4.2/src/native/common/include/jp_type.h0000666000175000017500000000462311614007722022444 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard 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. *****************************************************************************/ #ifndef _JPTYPE_H_ #define _JPTYPE_H_ enum EMatchType { _none, _explicit, _implicit, _exact }; /** * Base class for all JPype Types, be it primitive, class or array */ class JPType { protected : JPType() { } virtual ~JPType() { } public : virtual HostRef* getStaticValue(jclass c, jfieldID fid, JPTypeName& tgtType) = 0 ; virtual void setStaticValue(jclass c, jfieldID fid, HostRef* val) = 0 ; virtual HostRef* getInstanceValue(jobject c, jfieldID fid, JPTypeName& tgtType) = 0 ; virtual void setInstanceValue(jobject c, jfieldID fid, HostRef* val) = 0 ; virtual HostRef* asHostObject(jvalue val) = 0 ; virtual HostRef* asHostObjectFromObject(jvalue val) = 0; virtual JPTypeName getName() = 0; virtual EMatchType canConvertToJava(HostRef* obj) = 0; virtual jvalue convertToJava(HostRef* obj) = 0; virtual jobject convertToJavaObject(HostRef* obj) = 0; virtual bool isObjectType() = 0; virtual JPTypeName getObjectType() = 0; virtual HostRef* invokeStatic(jclass, jmethodID, jvalue*) = 0; virtual HostRef* invoke(jobject, jclass, jmethodID, jvalue*) = 0; virtual jarray newArrayInstance(int size) = 0; virtual vector getArrayRange(jarray, int start, int length) = 0; virtual void setArrayRange(jarray, int start, int length, vector& vals) = 0; virtual HostRef* getArrayItem(jarray, int ndx) = 0; virtual void setArrayItem(jarray, int ndx, HostRef* val) = 0; virtual void setArrayValues(jarray, HostRef*) = 0; virtual HostRef* convertToDirectBuffer(HostRef* src) = 0; }; #endif // _JPTYPE_H_ python-jpype-0.5.4.2/src/native/common/include/jpype.h0000666000175000017500000000640611614007722022122 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Menard 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. *****************************************************************************/ #ifndef _JPYPE_H_ #define _JPYPE_H_ // Define this to generate the trace calls // Define this to make the trace calls do their output. If you change this only the core.cpp needs to be recompiled //#define JPYPE_TRACING_INTERNAL #define JPYPE_TRACING_OUTPUT cerr #define TRACE_IN(n) JPypeTracer _trace(n); try { #define TRACE_OUT } catch(...) { _trace.gotError(); throw; } #define TRACE1(m) _trace.trace(m) #define TRACE2(m,n) _trace.trace(m,n) #define TRACE3(m,n,o) _trace.trace(m,n,o) #ifdef WIN32 #define JPYPE_WIN32 #ifndef __GNUC__ // Then this must mean a variant of GCC on win32 ... #define JPYPE_WIN32_VCPP #pragma warning (disable:4786) #else #endif #else #define JPYPE_LINUX #endif #include #ifdef WIN32 #ifdef __GNUC__ // JNICALL causes problem for funtions prototypes .. since I am nto defining any JNI methods there isno need for it #undef JNICALL #define JNICALL #endif #endif #include #include #include #include #include #include #include #include using namespace std; /** The following functions are delcared here but actually defined in the platform_specific file */ void longToHexString(long value, char* outStr); /** Definition of commonly used template types */ typedef vector StringVector; /** Use this class instewad of basic_string because compiler support is not great cross-platform */ class JCharString { public : JCharString(const jchar*); JCharString(const JCharString&); JCharString(size_t); virtual ~JCharString(); const jchar* c_str(); size_t length() { return m_Length; } jchar& operator[](size_t ndx) { return m_Value[ndx]; } private : jchar* m_Value; size_t m_Length; }; // Base utility headers #include "jp_typename.h" #include "jp_utility.h" #include "jp_javaenv.h" #include "jp_jniutil.h" #include "jp_hostenv.h" #include "jp_env.h" // Other header files #include "jp_type.h" #include "jp_primitivetypes.h" #include "jp_objecttypes.h" #include "jp_field.h" #include "jp_methodoverload.h" #include "jp_method.h" #include "jp_classbase.h" #include "jp_class.h" #include "jp_arrayclass.h" #include "jp_typemanager.h" #include "jp_objectbase.h" #include "jp_object.h" #include "jp_array.h" #include "jp_invocationhandler.h" #include "jp_reference.h" #include "jp_referencequeue.h" #include "jp_proxy.h" #include "jp_monitor.h" #include "jp_env.h" #endif // _JPYPE_H_ python-jpype-0.5.4.2/src/native/common/include/jp_monitor.h0000666000175000017500000000167511614007722023156 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard 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. *****************************************************************************/ #ifndef _JPMONITOR_H_ #define _JPMONITOR_H_ class JPMonitor { public : JPMonitor(jobject obj); virtual ~JPMonitor(); private : jobject m_Object; }; #endif // _JPMONITOR_H_ python-jpype-0.5.4.2/src/native/common/jp_voidtype.cpp0000666000175000017500000000573511614007722022243 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard 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. *****************************************************************************/ #include HostRef* JPVoidType::getStaticValue(jclass c, jfieldID fid, JPTypeName& tgtType) { RAISE(JPypeException, "void cannot be the type of a static field."); } HostRef* JPVoidType::getInstanceValue(jobject c, jfieldID fid, JPTypeName& tgtType) { RAISE(JPypeException, "void cannot be the type of a field."); } HostRef* JPVoidType::asHostObject(jvalue val) { return JPEnv::getHost()->getNone(); } HostRef* JPVoidType::asHostObjectFromObject(jvalue val) { return JPEnv::getHost()->getNone(); } EMatchType JPVoidType::canConvertToJava(HostRef* obj) { return _none; } jvalue JPVoidType::convertToJava(HostRef* obj) { jvalue res; res.l = NULL; return res; } HostRef* JPVoidType::invokeStatic(jclass claz, jmethodID mth, jvalue* val) { JPEnv::getJava()->CallStaticVoidMethodA(claz, mth, val); return JPEnv::getHost()->getNone(); } HostRef* JPVoidType::invoke(jobject claz, jclass clazz, jmethodID mth, jvalue* val) { JPEnv::getJava()->CallVoidMethodA(claz, mth, val); return JPEnv::getHost()->getNone(); } void JPVoidType::setStaticValue(jclass c, jfieldID fid, HostRef*) { RAISE(JPypeException, "void cannot be the type of a static field."); } void JPVoidType::setInstanceValue(jobject c, jfieldID fid, HostRef*) { RAISE(JPypeException, "void cannot be the type of a field."); } vector JPVoidType::getArrayRange(jarray, int, int) { RAISE(JPypeException, "void cannot be the type of an array."); } void JPVoidType::setArrayRange(jarray, int, int, vector&) { RAISE(JPypeException, "void cannot be the type of an array."); } HostRef* JPVoidType::getArrayItem(jarray, int) { RAISE(JPypeException, "void cannot be the type of an array."); } void JPVoidType::setArrayItem(jarray, int, HostRef*) { RAISE(JPypeException, "void cannot be the type of an array."); } jarray JPVoidType::newArrayInstance(int) { RAISE(JPypeException, "void cannot be the type of an array."); } HostRef* JPVoidType::convertToDirectBuffer(HostRef* src) { RAISE(JPypeException, "Unable to convert to Direct Buffer"); } void JPVoidType::setArrayValues(jarray a, HostRef* values) { RAISE(JPypeException, "Unable to convert to Direct Buffer"); } python-jpype-0.5.4.2/src/native/common/jp_javaenv.cpp0000666000175000017500000001707711614007722022034 0ustar takakitakaki/***************************************************************************** Copyright 2004-2008 Steve Menard 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. *****************************************************************************/ #include //AT's on porting: // 1) the original definition of global static object leads to crashing //on HP-UX platform. Cause: it is suspected to be an undefined order of initialization of static objects // // 2) TODO: in any case, use of static objects may impose problems in multi-threaded environment. //Therefore, they must be guarded with a mutex. #ifdef WIN32 #include "jp_platform_win32.h" #define PLATFORM_ADAPTER Win32PlatformAdapter #else #include "jp_platform_linux.h" #define PLATFORM_ADAPTER LinuxPlatformAdapter #endif JPPlatformAdapter* JPJavaEnv::GetAdapter() { static JPPlatformAdapter* adapter = new PLATFORM_ADAPTER(); return adapter; } #define JAVA_CHECK(msg) \ if (JPEnv::getJava()->ExceptionCheck()) \ { \ RAISE(JavaException, msg); \ } \ jint (JNICALL *JPJavaEnv::CreateJVM_Method)(JavaVM **pvm, void **penv, void *args); jint (JNICALL *JPJavaEnv::GetCreatedJVMs_Method)(JavaVM **pvm, jsize size, jsize* nVms); JNIEnv* JPJavaEnv::getJNIEnv() { JNIEnv* env; GetEnv(&env); return env; } void JPJavaEnv::load(const string& path) { TRACE_IN("JPJavaEnv::load"); // WIN32 GetAdapter()->loadLibrary((char*)path.c_str()); CreateJVM_Method = (jint (JNICALL *)(struct JavaVM_ ** ,void ** ,void *))GetAdapter()->getSymbol("JNI_CreateJavaVM"); GetCreatedJVMs_Method = (jint (JNICALL *)(struct JavaVM_ ** , jsize, jsize*))GetAdapter()->getSymbol("JNI_GetCreatedJavaVMs"); // No idea why I can't find this symbol .... no matter, it does not work anyway. //JNI_DestroyJavaVM = (jint (__stdcall *)(struct JavaVM_ *))GetAdapter()->getSymbol("DestroyJavaVM"); TRACE_OUT; } void JPJavaEnv::shutdown() { jvm = NULL; // TODO unload the library } /** throw a JPypeException if the JVM is not started */ void JPJavaEnv::checkInitialized() { if (! JPEnv::isInitialized()) { RAISE( JPypeException, "Java Subsystem not started"); } } JPJavaEnv* JPJavaEnv::GetCreatedJavaVM() { /* TRACE_IN("JPJavaEnv::GetCreatedJavaVM"); JavaVM* vm = NULL; jsize numVms; jint ret = GetCreatedJVMs_Method(&vm, 1, &numVms); if (ret < 0) { return NULL; } return new JPJavaEnv(vm); TRACE_OUT; */ return NULL; } JPJavaEnv* JPJavaEnv::CreateJavaVM(void* arg) { TRACE_IN("JPJavaEnv::CreateJavaVM"); JavaVM* vm = NULL; void* env; CreateJVM_Method(&vm, &env, arg); if (vm == NULL) { return NULL; } TRACE1("A"); return new JPJavaEnv(vm); TRACE_OUT; } int JPJavaEnv::DestroyJavaVM() { if (jvm != NULL) { int res = jvm->functions->DestroyJavaVM(jvm); if (res == 0) { jvm = NULL; } } return 0; } void JPJavaEnv::DeleteLocalRef(jobject obj) { //TRACE_IN("JPJavaEnv::DeleteLocalRef"); //TRACE1((long)obj); JNIEnv* env = getJNIEnv(); if (env != NULL) { env->functions->DeleteLocalRef(env, obj); } //TRACE_OUT; } void JPJavaEnv::DeleteGlobalRef(jobject obj) { //TRACE_IN("JPJavaEnv::DeleteGlobalRef"); //TRACE1((long)obj); JNIEnv* env = getJNIEnv(); if (env != NULL) { env->functions->DeleteGlobalRef(env, obj); } //TRACE_OUT; } jobject JPJavaEnv::NewLocalRef(jobject a0) { //TRACE_IN("JPJavaEnv::NewLocalRef"); //TRACE1((long)a0); jobject res; JNIEnv* env = getJNIEnv(); res = env->functions->NewLocalRef(env, a0); //TRACE1((long)res); //, JPJni::getClassName(a0).getSimpleName()); return res; //TRACE_OUT; } jobject JPJavaEnv::NewGlobalRef(jobject a0) { //TRACE_IN("JPJavaEnv::NewGlobalRef"); //TRACE1((long)a0); jobject res; JNIEnv* env = getJNIEnv(); res = env->functions->NewGlobalRef(env, a0); //TRACE1((long)res); //, JPJni::getClassName(a0).getSimpleName()); return res; //TRACE_OUT; } bool JPJavaEnv::ExceptionCheck() { JNIEnv* env = getJNIEnv(); if (env != NULL) { return (env->functions->ExceptionCheck(env) ? true : false); } return false; } void JPJavaEnv::ExceptionDescribe() { JNIEnv* env = getJNIEnv(); env->functions->ExceptionDescribe(env); } void JPJavaEnv::ExceptionClear() { JNIEnv* env = getJNIEnv(); if (env != NULL) { env->functions->ExceptionClear(env); } } jint JPJavaEnv::AttachCurrentThread() { // TODO find a way to get A JVM once JPJavaEnv is not a singleton anymore ... JNIEnv* env; jint res = jvm->functions->AttachCurrentThread(jvm, (void**)&env, NULL); JAVA_CHECK("AttachCurrentThread"); return res; } jint JPJavaEnv::AttachCurrentThreadAsDaemon() { // TODO find a way to get A JVM once JPJavaEnv is not a singleton anymore ... JNIEnv* env; jint res = jvm->functions->AttachCurrentThreadAsDaemon(jvm, (void**)&env, NULL); JAVA_CHECK("AttachCurrentThreadAsDaemon"); return res; } bool JPJavaEnv::isThreadAttached() { return JPEnv::getJava()->getJNIEnv() != NULL; } jint JPJavaEnv::DetachCurrentThread() { return jvm->functions->DetachCurrentThread(jvm); } jint JPJavaEnv::GetEnv(JNIEnv** env) { if (jvm == NULL) { *env = NULL; return JNI_EDETACHED; } // This function must not be put in GOTO_EXTERNAL/RETURN_EXTERNAL because it is called from WITHIN such a block already jint res; res = jvm->functions->GetEnv(jvm, (void**)env, JNI_VERSION_1_2); return res; } jint JPJavaEnv::ThrowNew(jclass clazz, const char* msg) { JNIEnv* env = getJNIEnv(); return env->functions->ThrowNew(env, clazz, msg); } jint JPJavaEnv::Throw(jthrowable th) { JNIEnv* env = getJNIEnv(); return env->functions->Throw(env, th); } jthrowable JPJavaEnv::ExceptionOccurred() { jthrowable res; JNIEnv* env = getJNIEnv(); res = env->functions->ExceptionOccurred(env); return res; } jobject JPJavaEnv::NewDirectByteBuffer(void* address, jlong capacity) { TRACE_IN("JPJavaEnv::NewDirectByteBuffer"); JNIEnv* env = getJNIEnv(); jobject res = env->functions->NewDirectByteBuffer(env, address, capacity); JAVA_CHECK("NewDirectByteBuffer"); TRACE1((long)res); return res; TRACE_OUT; } jobject JPJavaEnv::NewObjectA(jclass a0, jmethodID a1, jvalue* a2) { jobject res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->AllocObject(env, a0); JAVA_CHECK("NewObjectA"); env->functions->CallVoidMethodA(env, res, a1, a2); if (ExceptionCheck()) { DeleteLocalRef(res); } JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("NewObjectA"); return res; } jobject JPJavaEnv::NewObject(jclass a0, jmethodID a1) { jobject res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->AllocObject(env, a0); JAVA_CHECK("NewObject"); env->functions->CallVoidMethod(env, res, a1); if (ExceptionCheck()) { DeleteLocalRef(res); } JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("NewObject"); return res; } python-jpype-0.5.4.2/src/native/common/jp_reference.cpp0000666000175000017500000002566411614007722022341 0ustar takakitakaki#include jbyte JPypeReference[] = { (jbyte)0xCA,(jbyte)0xFE,(jbyte)0xBA,(jbyte)0xBE,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x2E,(jbyte)0x00,(jbyte)0x21,(jbyte)0x01,(jbyte)0x00,(jbyte)0x18,(jbyte)0x6A,(jbyte)0x70,(jbyte)0x79,(jbyte)0x70,(jbyte)0x65,(jbyte)0x2F,(jbyte)0x72 ,(jbyte)0x65,(jbyte)0x66,(jbyte)0x2F,(jbyte)0x4A,(jbyte)0x50,(jbyte)0x79,(jbyte)0x70,(jbyte)0x65,(jbyte)0x52,(jbyte)0x65,(jbyte)0x66,(jbyte)0x65,(jbyte)0x72,(jbyte)0x65,(jbyte)0x6E,(jbyte)0x63,(jbyte)0x65,(jbyte)0x07,(jbyte)0x00,(jbyte)0x01 ,(jbyte)0x01,(jbyte)0x00,(jbyte)0x1E,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x72,(jbyte)0x65,(jbyte)0x66,(jbyte)0x2F,(jbyte)0x50,(jbyte)0x68,(jbyte)0x61 ,(jbyte)0x6E,(jbyte)0x74,(jbyte)0x6F,(jbyte)0x6D,(jbyte)0x52,(jbyte)0x65,(jbyte)0x66,(jbyte)0x65,(jbyte)0x72,(jbyte)0x65,(jbyte)0x6E,(jbyte)0x63,(jbyte)0x65,(jbyte)0x07,(jbyte)0x00,(jbyte)0x03,(jbyte)0x01,(jbyte)0x00,(jbyte)0x0E,(jbyte)0x6D ,(jbyte)0x48,(jbyte)0x6F,(jbyte)0x73,(jbyte)0x74,(jbyte)0x52,(jbyte)0x65,(jbyte)0x66,(jbyte)0x65,(jbyte)0x72,(jbyte)0x65,(jbyte)0x6E,(jbyte)0x63,(jbyte)0x65,(jbyte)0x01,(jbyte)0x00,(jbyte)0x01,(jbyte)0x4A,(jbyte)0x01,(jbyte)0x00,(jbyte)0x06 ,(jbyte)0x3C,(jbyte)0x69,(jbyte)0x6E,(jbyte)0x69,(jbyte)0x74,(jbyte)0x3E,(jbyte)0x01,(jbyte)0x00,(jbyte)0x33,(jbyte)0x28,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67 ,(jbyte)0x2F,(jbyte)0x4F,(jbyte)0x62,(jbyte)0x6A,(jbyte)0x65,(jbyte)0x63,(jbyte)0x74,(jbyte)0x3B,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x72 ,(jbyte)0x65,(jbyte)0x66,(jbyte)0x2F,(jbyte)0x52,(jbyte)0x65,(jbyte)0x66,(jbyte)0x65,(jbyte)0x72,(jbyte)0x65,(jbyte)0x6E,(jbyte)0x63,(jbyte)0x65,(jbyte)0x51,(jbyte)0x75,(jbyte)0x65,(jbyte)0x75,(jbyte)0x65,(jbyte)0x3B,(jbyte)0x29,(jbyte)0x56 ,(jbyte)0x01,(jbyte)0x00,(jbyte)0x04,(jbyte)0x43,(jbyte)0x6F,(jbyte)0x64,(jbyte)0x65,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x07,(jbyte)0x00,(jbyte)0x08,(jbyte)0x0A,(jbyte)0x00,(jbyte)0x04,(jbyte)0x00,(jbyte)0x0A,(jbyte)0x01,(jbyte)0x00,(jbyte)0x0F ,(jbyte)0x4C,(jbyte)0x69,(jbyte)0x6E,(jbyte)0x65,(jbyte)0x4E,(jbyte)0x75,(jbyte)0x6D,(jbyte)0x62,(jbyte)0x65,(jbyte)0x72,(jbyte)0x54,(jbyte)0x61,(jbyte)0x62,(jbyte)0x6C,(jbyte)0x65,(jbyte)0x01,(jbyte)0x00,(jbyte)0x12,(jbyte)0x4C,(jbyte)0x6F ,(jbyte)0x63,(jbyte)0x61,(jbyte)0x6C,(jbyte)0x56,(jbyte)0x61,(jbyte)0x72,(jbyte)0x69,(jbyte)0x61,(jbyte)0x62,(jbyte)0x6C,(jbyte)0x65,(jbyte)0x54,(jbyte)0x61,(jbyte)0x62,(jbyte)0x6C,(jbyte)0x65,(jbyte)0x01,(jbyte)0x00,(jbyte)0x04,(jbyte)0x74 ,(jbyte)0x68,(jbyte)0x69,(jbyte)0x73,(jbyte)0x01,(jbyte)0x00,(jbyte)0x1A,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x70,(jbyte)0x79,(jbyte)0x70,(jbyte)0x65,(jbyte)0x2F,(jbyte)0x72,(jbyte)0x65,(jbyte)0x66,(jbyte)0x2F,(jbyte)0x4A,(jbyte)0x50,(jbyte)0x79 ,(jbyte)0x70,(jbyte)0x65,(jbyte)0x52,(jbyte)0x65,(jbyte)0x66,(jbyte)0x65,(jbyte)0x72,(jbyte)0x65,(jbyte)0x6E,(jbyte)0x63,(jbyte)0x65,(jbyte)0x3B,(jbyte)0x01,(jbyte)0x00,(jbyte)0x04,(jbyte)0x61,(jbyte)0x72,(jbyte)0x67,(jbyte)0x30,(jbyte)0x01 ,(jbyte)0x00,(jbyte)0x12,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x4F,(jbyte)0x62,(jbyte)0x6A,(jbyte)0x65,(jbyte)0x63,(jbyte)0x74,(jbyte)0x3B ,(jbyte)0x01,(jbyte)0x00,(jbyte)0x04,(jbyte)0x61,(jbyte)0x72,(jbyte)0x67,(jbyte)0x31,(jbyte)0x01,(jbyte)0x00,(jbyte)0x1E,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67 ,(jbyte)0x2F,(jbyte)0x72,(jbyte)0x65,(jbyte)0x66,(jbyte)0x2F,(jbyte)0x52,(jbyte)0x65,(jbyte)0x66,(jbyte)0x65,(jbyte)0x72,(jbyte)0x65,(jbyte)0x6E,(jbyte)0x63,(jbyte)0x65,(jbyte)0x51,(jbyte)0x75,(jbyte)0x65,(jbyte)0x75,(jbyte)0x65,(jbyte)0x3B ,(jbyte)0x01,(jbyte)0x00,(jbyte)0x10,(jbyte)0x67,(jbyte)0x65,(jbyte)0x74,(jbyte)0x48,(jbyte)0x6F,(jbyte)0x73,(jbyte)0x74,(jbyte)0x52,(jbyte)0x65,(jbyte)0x66,(jbyte)0x65,(jbyte)0x72,(jbyte)0x65,(jbyte)0x6E,(jbyte)0x63,(jbyte)0x65,(jbyte)0x01 ,(jbyte)0x00,(jbyte)0x03,(jbyte)0x28,(jbyte)0x29,(jbyte)0x4A,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x05,(jbyte)0x00,(jbyte)0x06,(jbyte)0x09,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x16,(jbyte)0x01,(jbyte)0x00,(jbyte)0x10,(jbyte)0x73,(jbyte)0x65 ,(jbyte)0x74,(jbyte)0x48,(jbyte)0x6F,(jbyte)0x73,(jbyte)0x74,(jbyte)0x52,(jbyte)0x65,(jbyte)0x66,(jbyte)0x65,(jbyte)0x72,(jbyte)0x65,(jbyte)0x6E,(jbyte)0x63,(jbyte)0x65,(jbyte)0x01,(jbyte)0x00,(jbyte)0x04,(jbyte)0x28,(jbyte)0x4A,(jbyte)0x29 ,(jbyte)0x56,(jbyte)0x01,(jbyte)0x00,(jbyte)0x0E,(jbyte)0x61,(jbyte)0x48,(jbyte)0x6F,(jbyte)0x73,(jbyte)0x74,(jbyte)0x52,(jbyte)0x65,(jbyte)0x66,(jbyte)0x65,(jbyte)0x72,(jbyte)0x65,(jbyte)0x6E,(jbyte)0x63,(jbyte)0x65,(jbyte)0x01,(jbyte)0x00 ,(jbyte)0x08,(jbyte)0x68,(jbyte)0x61,(jbyte)0x73,(jbyte)0x68,(jbyte)0x43,(jbyte)0x6F,(jbyte)0x64,(jbyte)0x65,(jbyte)0x01,(jbyte)0x00,(jbyte)0x03,(jbyte)0x28,(jbyte)0x29,(jbyte)0x49,(jbyte)0x01,(jbyte)0x00,(jbyte)0x06,(jbyte)0x65,(jbyte)0x71 ,(jbyte)0x75,(jbyte)0x61,(jbyte)0x6C,(jbyte)0x73,(jbyte)0x01,(jbyte)0x00,(jbyte)0x15,(jbyte)0x28,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x4F ,(jbyte)0x62,(jbyte)0x6A,(jbyte)0x65,(jbyte)0x63,(jbyte)0x74,(jbyte)0x3B,(jbyte)0x29,(jbyte)0x5A,(jbyte)0x01,(jbyte)0x00,(jbyte)0x0A,(jbyte)0x53,(jbyte)0x6F,(jbyte)0x75,(jbyte)0x72,(jbyte)0x63,(jbyte)0x65,(jbyte)0x46,(jbyte)0x69,(jbyte)0x6C ,(jbyte)0x65,(jbyte)0x01,(jbyte)0x00,(jbyte)0x13,(jbyte)0x4A,(jbyte)0x50,(jbyte)0x79,(jbyte)0x70,(jbyte)0x65,(jbyte)0x52,(jbyte)0x65,(jbyte)0x66,(jbyte)0x65,(jbyte)0x72,(jbyte)0x65,(jbyte)0x6E,(jbyte)0x63,(jbyte)0x65,(jbyte)0x2E,(jbyte)0x6A ,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x00,(jbyte)0x21,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x04,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x05,(jbyte)0x00,(jbyte)0x06,(jbyte)0x00 ,(jbyte)0x00,(jbyte)0x00,(jbyte)0x05,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x07,(jbyte)0x00,(jbyte)0x08,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x09,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x49,(jbyte)0x00,(jbyte)0x03,(jbyte)0x00 ,(jbyte)0x03,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x07,(jbyte)0x2A,(jbyte)0x2B,(jbyte)0x2C,(jbyte)0xB7,(jbyte)0x00,(jbyte)0x0B,(jbyte)0xB1,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x00 ,(jbyte)0x00,(jbyte)0x0A,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x06,(jbyte)0x00,(jbyte)0x0D,(jbyte)0x00,(jbyte)0x0D,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x20,(jbyte)0x00,(jbyte)0x03 ,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x07,(jbyte)0x00,(jbyte)0x0E,(jbyte)0x00,(jbyte)0x0F,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x07,(jbyte)0x00,(jbyte)0x10,(jbyte)0x00,(jbyte)0x11,(jbyte)0x00,(jbyte)0x01 ,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x07,(jbyte)0x00,(jbyte)0x12,(jbyte)0x00,(jbyte)0x13,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x14,(jbyte)0x00,(jbyte)0x15,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x09 ,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x2F,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x05,(jbyte)0x2A,(jbyte)0xB4,(jbyte)0x00,(jbyte)0x17,(jbyte)0xAD,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00 ,(jbyte)0x02,(jbyte)0x00,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x06,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x11,(jbyte)0x00,(jbyte)0x0D,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x0C,(jbyte)0x00 ,(jbyte)0x01,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x05,(jbyte)0x00,(jbyte)0x0E,(jbyte)0x00,(jbyte)0x0F,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x18,(jbyte)0x00,(jbyte)0x19,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00 ,(jbyte)0x09,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x3E,(jbyte)0x00,(jbyte)0x03,(jbyte)0x00,(jbyte)0x03,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x06,(jbyte)0x2A,(jbyte)0x1F,(jbyte)0xB5,(jbyte)0x00,(jbyte)0x17,(jbyte)0xB1,(jbyte)0x00 ,(jbyte)0x00,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x0A,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x16,(jbyte)0x00,(jbyte)0x05,(jbyte)0x00,(jbyte)0x17,(jbyte)0x00 ,(jbyte)0x0D,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x16,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x06,(jbyte)0x00,(jbyte)0x0E,(jbyte)0x00,(jbyte)0x0F,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00 ,(jbyte)0x06,(jbyte)0x00,(jbyte)0x1A,(jbyte)0x00,(jbyte)0x06,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x1B,(jbyte)0x00,(jbyte)0x1C,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x09,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00 ,(jbyte)0x30,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x06,(jbyte)0x2A,(jbyte)0xB4,(jbyte)0x00,(jbyte)0x17,(jbyte)0x88,(jbyte)0xAC,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00 ,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x06,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x1B,(jbyte)0x00,(jbyte)0x0D,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00 ,(jbyte)0x00,(jbyte)0x00,(jbyte)0x06,(jbyte)0x00,(jbyte)0x0E,(jbyte)0x00,(jbyte)0x0F,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x1D,(jbyte)0x00,(jbyte)0x1E,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x09,(jbyte)0x00 ,(jbyte)0x00,(jbyte)0x00,(jbyte)0x58,(jbyte)0x00,(jbyte)0x04,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x1C,(jbyte)0x2B,(jbyte)0xC1,(jbyte)0x00,(jbyte)0x02,(jbyte)0x9A,(jbyte)0x00,(jbyte)0x05,(jbyte)0x03,(jbyte)0xAC ,(jbyte)0x2B,(jbyte)0xC0,(jbyte)0x00,(jbyte)0x02,(jbyte)0xB4,(jbyte)0x00,(jbyte)0x17,(jbyte)0x2A,(jbyte)0xB4,(jbyte)0x00,(jbyte)0x17,(jbyte)0x94,(jbyte)0x9A,(jbyte)0x00,(jbyte)0x05,(jbyte)0x04,(jbyte)0xAC,(jbyte)0x03,(jbyte)0xAC,(jbyte)0x00 ,(jbyte)0x00,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x0E,(jbyte)0x00,(jbyte)0x03,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x20,(jbyte)0x00,(jbyte)0x07,(jbyte)0x00,(jbyte)0x22,(jbyte)0x00 ,(jbyte)0x09,(jbyte)0x00,(jbyte)0x25,(jbyte)0x00,(jbyte)0x0D,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x16,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x1C,(jbyte)0x00,(jbyte)0x0E,(jbyte)0x00,(jbyte)0x0F,(jbyte)0x00 ,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x1C,(jbyte)0x00,(jbyte)0x10,(jbyte)0x00,(jbyte)0x11,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x1F,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00 ,(jbyte)0x20 }; jsize getJPypeReferenceLength() { return 901; } python-jpype-0.5.4.2/src/native/common/jp_primitivetypes.cpp0000666000175000017500000005060411614007722023470 0ustar takakitakaki/***************************************************************************** Copyright 2004-2008 Steve Menard 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. *****************************************************************************/ #include jobject JPPrimitiveType::convertToJavaObject(HostRef* obj) { JPCleaner cleaner; JPTypeName tname = getObjectType(); JPClass* c = JPTypeManager::findClass(tname); jclass jc = c->getClass(); cleaner.addLocal(jc); vector args(1); args[0] = obj; JPObject* o = c->newInstance(args); jobject res = o->getObject(); delete o; return res; } HostRef* JPByteType::asHostObject(jvalue val) { return JPEnv::getHost()->newInt(val.b); } HostRef* JPByteType::asHostObjectFromObject(jvalue val) { long v = JPJni::intValue(val.l); return JPEnv::getHost()->newInt(v); } EMatchType JPByteType::canConvertToJava(HostRef* obj) { JPCleaner cleaner; if (JPEnv::getHost()->isNone(obj)) { return _none; } if (JPEnv::getHost()->isInt(obj)) { return _implicit; } if (JPEnv::getHost()->isLong(obj)) { return _implicit; } if (JPEnv::getHost()->isWrapper(obj)) { JPTypeName name = JPEnv::getHost()->getWrapperTypeName(obj); if (name.getType() == JPTypeName::_byte) { return _exact; } } return _none; } void JPByteType::setArrayValues(jarray a, HostRef* values) { jbyteArray array = (jbyteArray)a; jbyte* val = NULL; jboolean isCopy; JPCleaner cleaner; try { val = JPEnv::getJava()->GetByteArrayElements(array, &isCopy); bool converted = true; // Optimize what I can ... if (JPEnv::getHost()->isByteString(values)) { // Strings are also jbyte[] long len; char* data; JPEnv::getHost()->getRawByteString(values, &data, len); memcpy(val, data, len); converted = true; } // TODO also optimize array.array ... else if (JPEnv::getHost()->isSequence(values)) { int len = JPEnv::getHost()->getSequenceLength(values); for (int i = 0; i < len; i++) { HostRef* v = JPEnv::getHost()->getSequenceItem(values, i); val[i] = convertToJava(v).b; delete v; } converted = true; } else { RAISE(JPypeException, "Unable to convert to Byte array"); } JPEnv::getJava()->ReleaseByteArrayElements(array, val, JNI_COMMIT); } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseByteArrayElements(array, val, JNI_ABORT); } ); } jvalue JPByteType::convertToJava(HostRef* obj) { JPCleaner cleaner; jvalue res; if (JPEnv::getHost()->isInt(obj)) { jint l = JPEnv::getHost()->intAsInt(obj);; if (l < JPJni::s_minByte || l > JPJni::s_maxByte) { JPEnv::getHost()->setTypeError("Cannot convert value to Java byte"); } res.b = (jbyte)l; } else if (JPEnv::getHost()->isLong(obj)) { jlong l = JPEnv::getHost()->longAsLong(obj); if (l < JPJni::s_minByte || l > JPJni::s_maxByte) { JPEnv::getHost()->setTypeError("Cannot convert value to Java byte"); } res.b = (jbyte)l; } else if (JPEnv::getHost()->isWrapper(obj)) { return JPEnv::getHost()->getWrapperValue(obj); } return res; } HostRef* JPByteType::convertToDirectBuffer(HostRef* src) { JPCleaner cleaner; if (JPEnv::getHost()->isByteString(src)) { char* rawData; long size; JPEnv::getHost()->getRawByteString(src, &rawData, size); jobject obj = JPEnv::getJava()->NewDirectByteBuffer(rawData, size); cleaner.addLocal(obj); jvalue v; v.l = obj; JPTypeName name = JPJni::getClassName(v.l); JPType* type = JPTypeManager::getType(name); return type->asHostObject(v); } RAISE(JPypeException, "Unable to convert to Direct Buffer"); } //---------------------------------------------------------------------------- HostRef* JPShortType::asHostObject(jvalue val) { return JPEnv::getHost()->newInt(val.s); } HostRef* JPShortType::asHostObjectFromObject(jvalue val) { long v = JPJni::intValue(val.l); return JPEnv::getHost()->newInt(v); } EMatchType JPShortType::canConvertToJava(HostRef* obj) { JPCleaner cleaner; if (JPEnv::getHost()->isNone(obj)) { return _none; } if (JPEnv::getHost()->isInt(obj)) { return _implicit; } if (JPEnv::getHost()->isLong(obj)) { return _implicit; } if (JPEnv::getHost()->isWrapper(obj)) { JPTypeName name = JPEnv::getHost()->getWrapperTypeName(obj); if (name.getType() == JPTypeName::_short) { return _exact; } } return _none; } jvalue JPShortType::convertToJava(HostRef* obj) { JPCleaner cleaner; jvalue res; if (JPEnv::getHost()->isInt(obj)) { jint l = JPEnv::getHost()->intAsInt(obj);; if (l < JPJni::s_minShort || l > JPJni::s_maxShort) { JPEnv::getHost()->setTypeError("Cannot convert value to Java short"); } res.s = (jshort)l; } else if (JPEnv::getHost()->isLong(obj)) { jlong l = JPEnv::getHost()->longAsLong(obj);; if (l < JPJni::s_minShort || l > JPJni::s_maxShort) { JPEnv::getHost()->setTypeError("Cannot convert value to Java short"); } res.s = (jshort)l; } else if (JPEnv::getHost()->isWrapper(obj)) { return JPEnv::getHost()->getWrapperValue(obj); } return res; } HostRef* JPShortType::convertToDirectBuffer(HostRef* src) { RAISE(JPypeException, "Unable to convert to Direct Buffer"); } void JPShortType::setArrayValues(jarray a, HostRef* values) { jshortArray array = (jshortArray)a; jshort* val = NULL; jboolean isCopy; JPCleaner cleaner; try { val = JPEnv::getJava()->GetShortArrayElements(array, &isCopy); bool converted = true; // Optimize what I can ... // TODO also optimize array.array ... if (JPEnv::getHost()->isSequence(values)) { int len = JPEnv::getHost()->getSequenceLength(values); for (int i = 0; i < len; i++) { HostRef* v = JPEnv::getHost()->getSequenceItem(values, i); val[i] = convertToJava(v).s; delete v; } converted = true; } else { RAISE(JPypeException, "Unable to convert to Short array"); } JPEnv::getJava()->ReleaseShortArrayElements(array, val, JNI_COMMIT); } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseShortArrayElements(array, val, JNI_ABORT); } ); } //------------------------------------------------------------------------------- HostRef* JPIntType::asHostObject(jvalue val) { return JPEnv::getHost()->newInt(val.i); } HostRef* JPIntType::asHostObjectFromObject(jvalue val) { long v = JPJni::intValue(val.l); return JPEnv::getHost()->newInt(v); } EMatchType JPIntType::canConvertToJava(HostRef* obj) { JPCleaner cleaner; if (JPEnv::getHost()->isNone(obj)) { return _none; } if (JPEnv::getHost()->isInt(obj)) { return _exact; } if (JPEnv::getHost()->isLong(obj)) { return _implicit; } if (JPEnv::getHost()->isWrapper(obj)) { JPTypeName name = JPEnv::getHost()->getWrapperTypeName(obj); if (name.getType() == JPTypeName::_int) { return _exact; } } return _none; } jvalue JPIntType::convertToJava(HostRef* obj) { JPCleaner cleaner; jvalue res; if (JPEnv::getHost()->isInt(obj)) { jint l = JPEnv::getHost()->intAsInt(obj);; if (l < JPJni::s_minInt || l > JPJni::s_maxInt) { JPEnv::getHost()->setTypeError("Cannot convert value to Java int"); } res.i = (jint)l; } else if (JPEnv::getHost()->isLong(obj)) { jlong l = JPEnv::getHost()->longAsLong(obj);; if (l < JPJni::s_minInt || l > JPJni::s_maxInt) { JPEnv::getHost()->setTypeError("Cannot convert value to Java int"); } res.i = (jint)l; } else if (JPEnv::getHost()->isWrapper(obj)) { return JPEnv::getHost()->getWrapperValue(obj); } return res; } HostRef* JPIntType::convertToDirectBuffer(HostRef* src) { RAISE(JPypeException, "Unable to convert to Direct Buffer"); } void JPIntType::setArrayValues(jarray a, HostRef* values) { jintArray array = (jintArray)a; jint* val = NULL; jboolean isCopy; JPCleaner cleaner; try { val = JPEnv::getJava()->GetIntArrayElements(array, &isCopy); bool converted = true; // Optimize what I can ... // TODO also optimize array.array ... if (JPEnv::getHost()->isSequence(values)) { int len = JPEnv::getHost()->getSequenceLength(values); for (int i = 0; i < len; i++) { HostRef* v = JPEnv::getHost()->getSequenceItem(values, i); val[i] = convertToJava(v).i; delete v; } converted = true; } else { RAISE(JPypeException, "Unable to convert to Int array"); } JPEnv::getJava()->ReleaseIntArrayElements(array, val, JNI_COMMIT); } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseIntArrayElements(array, val, JNI_ABORT); } ); } //------------------------------------------------------------------------------- HostRef* JPLongType::asHostObject(jvalue val) { TRACE_IN("JPLongType::asHostObject"); return JPEnv::getHost()->newLong(val.j); TRACE_OUT; } HostRef* JPLongType::asHostObjectFromObject(jvalue val) { jlong v = JPJni::longValue(val.l); return JPEnv::getHost()->newLong(v); } EMatchType JPLongType::canConvertToJava(HostRef* obj) { JPCleaner cleaner; if (JPEnv::getHost()->isNone(obj)) { return _none; } if (JPEnv::getHost()->isInt(obj)) { return _implicit; } if (JPEnv::getHost()->isLong(obj)) { return _exact; } if (JPEnv::getHost()->isWrapper(obj)) { JPTypeName name = JPEnv::getHost()->getWrapperTypeName(obj); if (name.getType() == JPTypeName::_int) { return _exact; } } return _none; } jvalue JPLongType::convertToJava(HostRef* obj) { JPCleaner cleaner; jvalue res; if (JPEnv::getHost()->isInt(obj)) { res.j = (jlong)JPEnv::getHost()->intAsInt(obj); } else if (JPEnv::getHost()->isLong(obj)) { res.j = (jlong)JPEnv::getHost()->longAsLong(obj); } else if (JPEnv::getHost()->isWrapper(obj)) { return JPEnv::getHost()->getWrapperValue(obj); } return res; } HostRef* JPLongType::convertToDirectBuffer(HostRef* src) { RAISE(JPypeException, "Unable to convert to Direct Buffer"); } void JPLongType::setArrayValues(jarray a, HostRef* values) { jlongArray array = (jlongArray)a; jlong* val = NULL; jboolean isCopy; JPCleaner cleaner; try { val = JPEnv::getJava()->GetLongArrayElements(array, &isCopy); bool converted = true; // Optimize what I can ... // TODO also optimize array.array ... if (JPEnv::getHost()->isSequence(values)) { int len = JPEnv::getHost()->getSequenceLength(values); for (int i = 0; i < len; i++) { HostRef* v = JPEnv::getHost()->getSequenceItem(values, i); val[i] = convertToJava(v).j; delete v; } converted = true; } else { RAISE(JPypeException, "Unable to convert to Long array"); } JPEnv::getJava()->ReleaseLongArrayElements(array, val, JNI_COMMIT); } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseLongArrayElements(array, val, JNI_ABORT); } ); } //------------------------------------------------------------------------------- HostRef* JPFloatType::asHostObject(jvalue val) { return JPEnv::getHost()->newFloat(val.f); } HostRef* JPFloatType::asHostObjectFromObject(jvalue val) { double v = JPJni::doubleValue(val.l); return JPEnv::getHost()->newFloat(v); } EMatchType JPFloatType::canConvertToJava(HostRef* obj) { JPCleaner cleaner; if (JPEnv::getHost()->isNone(obj)) { return _none; } if (JPEnv::getHost()->isFloat(obj)) { return _implicit; } if (JPEnv::getHost()->isWrapper(obj)) { JPTypeName name = JPEnv::getHost()->getWrapperTypeName(obj); if (name.getType() == JPTypeName::_float) { return _exact; } } return _none; } jvalue JPFloatType::convertToJava(HostRef* obj) { JPCleaner cleaner; jvalue res; if (JPEnv::getHost()->isWrapper(obj)) { return JPEnv::getHost()->getWrapperValue(obj); } else { double l = JPEnv::getHost()->floatAsDouble(obj); if (l > 0 && (l < JPJni::s_minFloat || l > JPJni::s_maxFloat)) { JPEnv::getHost()->setTypeError("Cannot convert value to Java float"); } else if (l < 0 && (l > -JPJni::s_minFloat || l < -JPJni::s_maxFloat)) { JPEnv::getHost()->setTypeError("Cannot convert value to Java float"); } res.f = (jfloat)l; } return res; } HostRef* JPFloatType::convertToDirectBuffer(HostRef* src) { RAISE(JPypeException, "Unable to convert to Direct Buffer"); } void JPFloatType::setArrayValues(jarray a, HostRef* values) { jfloatArray array = (jfloatArray)a; jfloat* val = NULL; jboolean isCopy; JPCleaner cleaner; try { val = JPEnv::getJava()->GetFloatArrayElements(array, &isCopy); bool converted = true; // Optimize what I can ... // TODO also optimize array.array ... if (JPEnv::getHost()->isSequence(values)) { int len = JPEnv::getHost()->getSequenceLength(values); for (int i = 0; i < len; i++) { HostRef* v = JPEnv::getHost()->getSequenceItem(values, i); val[i] = convertToJava(v).f; delete v; } converted = true; } else { RAISE(JPypeException, "Unable to convert to Float array"); } JPEnv::getJava()->ReleaseFloatArrayElements(array, val, JNI_COMMIT); } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseFloatArrayElements(array, val, JNI_ABORT); } ); } //--------------------------------------------------------------------------- HostRef* JPDoubleType::asHostObject(jvalue val) { HostRef* res = JPEnv::getHost()->newFloat(val.d); return res; } HostRef* JPDoubleType::asHostObjectFromObject(jvalue val) { double v = JPJni::doubleValue(val.l); return JPEnv::getHost()->newFloat(v); } EMatchType JPDoubleType::canConvertToJava(HostRef* obj) { JPCleaner cleaner; if (JPEnv::getHost()->isNone(obj)) { return _none; } if (JPEnv::getHost()->isFloat(obj)) { return _exact; } if (JPEnv::getHost()->isWrapper(obj)) { JPTypeName name = JPEnv::getHost()->getWrapperTypeName(obj); if (name.getType() == JPTypeName::_double) { return _exact; } } return _none; } jvalue JPDoubleType::convertToJava(HostRef* obj) { JPCleaner cleaner; jvalue res; if (JPEnv::getHost()->isWrapper(obj)) { return JPEnv::getHost()->getWrapperValue(obj); } else { res.d = (jdouble)JPEnv::getHost()->floatAsDouble(obj); } return res; } HostRef* JPDoubleType::convertToDirectBuffer(HostRef* src) { RAISE(JPypeException, "Unable to convert to Direct Buffer"); } void JPDoubleType::setArrayValues(jarray a, HostRef* values) { jdoubleArray array = (jdoubleArray)a; jdouble* val = NULL; jboolean isCopy; JPCleaner cleaner; try { val = JPEnv::getJava()->GetDoubleArrayElements(array, &isCopy); bool converted = true; // Optimize what I can ... // TODO also optimize array.array ... if (JPEnv::getHost()->isSequence(values)) { int len = JPEnv::getHost()->getSequenceLength(values); for (int i = 0; i < len; i++) { HostRef* v = JPEnv::getHost()->getSequenceItem(values, i); val[i] = convertToJava(v).d; delete v; } converted = true; } else { RAISE(JPypeException, "Unable to convert to Double array"); } JPEnv::getJava()->ReleaseDoubleArrayElements(array, val, JNI_COMMIT); } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseDoubleArrayElements(array, val, JNI_ABORT); } ); } //---------------------------------------------------------------- HostRef* JPCharType::asHostObject(jvalue val) { jchar str[2]; str[0] = val.c; str[1] = 0; return JPEnv::getHost()->newStringFromUnicode(str, 1); } HostRef* JPCharType::asHostObjectFromObject(jvalue val) { jchar str[2]; str[0] = JPJni::charValue(val.l); str[1] = 0; return JPEnv::getHost()->newStringFromUnicode(str, 1); } EMatchType JPCharType::canConvertToJava(HostRef* obj) { JPCleaner cleaner; if (JPEnv::getHost()->isNone(obj)) { return _none; } if (JPEnv::getHost()->isString(obj) && JPEnv::getHost()->getStringLength(obj) == 1) { return _implicit; } if (JPEnv::getHost()->isWrapper(obj)) { JPTypeName name = JPEnv::getHost()->getWrapperTypeName(obj); if (name.getType() == JPTypeName::_char) { return _exact; } } return _none; } jvalue JPCharType::convertToJava(HostRef* obj) { JPCleaner cleaner; jvalue res; if (JPEnv::getHost()->isWrapper(obj)) { return JPEnv::getHost()->getWrapperValue(obj); } else { JCharString str = JPEnv::getHost()->stringAsJCharString(obj); res.c = str[0]; } return res; } HostRef* JPCharType::convertToDirectBuffer(HostRef* src) { RAISE(JPypeException, "Unable to convert to Direct Buffer"); } void JPCharType::setArrayValues(jarray a, HostRef* values) { jcharArray array = (jcharArray)a; jchar* val = NULL; jboolean isCopy; JPCleaner cleaner; try { val = JPEnv::getJava()->GetCharArrayElements(array, &isCopy); bool converted = true; // Optimize what I can ... // TODO also optimize array.array ... if (JPEnv::getHost()->isSequence(values)) { int len = JPEnv::getHost()->getSequenceLength(values); for (int i = 0; i < len; i++) { HostRef* v = JPEnv::getHost()->getSequenceItem(values, i); val[i] = convertToJava(v).c; delete v; } converted = true; } else { RAISE(JPypeException, "Unable to convert to Char array"); } JPEnv::getJava()->ReleaseCharArrayElements(array, val, JNI_COMMIT); } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseCharArrayElements(array, val, JNI_ABORT); } ); } //---------------------------------------------------------------------------------------- HostRef* JPBooleanType::asHostObject(jvalue val) { if (val.z) { return JPEnv::getHost()->getTrue(); } return JPEnv::getHost()->getFalse(); } HostRef* JPBooleanType::asHostObjectFromObject(jvalue val) { bool z = JPJni::booleanValue(val.l); if (z) { return JPEnv::getHost()->getTrue(); } return JPEnv::getHost()->getFalse(); } EMatchType JPBooleanType::canConvertToJava(HostRef* obj) { JPCleaner cleaner; if (JPEnv::getHost()->isInt(obj)) { return _implicit; } if (JPEnv::getHost()->isWrapper(obj)) { JPTypeName name = JPEnv::getHost()->getWrapperTypeName(obj); if (name.getType() == JPTypeName::_boolean) { return _exact; } } return _none; } jvalue JPBooleanType::convertToJava(HostRef* obj) { JPCleaner cleaner; jvalue res; if (JPEnv::getHost()->isWrapper(obj)) { return JPEnv::getHost()->getWrapperValue(obj); } else { res.z = (jboolean)JPEnv::getHost()->intAsInt(obj); } return res; } HostRef* JPBooleanType::convertToDirectBuffer(HostRef* src) { RAISE(JPypeException, "Unable to convert to Direct Buffer"); } void JPBooleanType::setArrayValues(jarray a, HostRef* values) { jbooleanArray array = (jbooleanArray)a; jboolean* val = NULL; jboolean isCopy; JPCleaner cleaner; try { val = JPEnv::getJava()->GetBooleanArrayElements(array, &isCopy); bool converted = true; // Optimize what I can ... // TODO also optimize array.array ... if (JPEnv::getHost()->isSequence(values)) { int len = JPEnv::getHost()->getSequenceLength(values); for (int i = 0; i < len; i++) { HostRef* v = JPEnv::getHost()->getSequenceItem(values, i); val[i] = convertToJava(v).z; delete v; } converted = true; } else { RAISE(JPypeException, "Unable to convert to Boolean array"); } JPEnv::getJava()->ReleaseBooleanArrayElements(array, val, JNI_COMMIT); } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseBooleanArrayElements(array, val, JNI_ABORT); } ); } python-jpype-0.5.4.2/src/native/common/jp_method.cpp0000666000175000017500000001335711614007722021657 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve M�nard 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. *****************************************************************************/ #include JPMethod::JPMethod(jclass clazz, string name, bool isConstructor) : m_Name(name), m_IsConstructor(isConstructor) { m_Class = (jclass)JPEnv::getJava()->NewGlobalRef(clazz); } string JPMethod::getName() { return m_Name; } string JPMethod::getClassName() { JPTypeName name = JPJni::getClassName(m_Class); return name.getSimpleName(); } bool JPMethod::hasStatic() { for (map::iterator it = m_Overloads.begin(); it != m_Overloads.end(); it++) { if (it->second.isStatic()) { return true; } } return false; } void JPMethod::addOverload(JPClass* claz, jobject mth) { JPMethodOverload over(claz, mth); m_Overloads[over.getSignature()] = over; } void JPMethod::addOverloads(JPMethod* o) { TRACE_IN("JPMethod::addOverloads"); for (map::iterator it = o->m_Overloads.begin(); it != o->m_Overloads.end(); it++) { bool found = false; for (map::iterator cur = m_Overloads.begin(); cur != m_Overloads.end(); cur++) { if (cur->second.isSameOverload(it->second)) { found = true; break; } } if (! found) { // Add it only if we do not already overload it ... m_Overloads[it->first] = it->second; } } TRACE_OUT; } JPMethodOverload* JPMethod::findOverload(vector& arg, bool needStatic) { TRACE_IN("JPMethod::findOverload"); TRACE2("Got overlaod to check", m_Overloads.size()); JPMethodOverload* currentMatch = NULL; EMatchType isExact = _none; for (map::iterator it = m_Overloads.begin(); it != m_Overloads.end(); it++) { if ((! needStatic) || it->second.isStatic()) { TRACE2("Trying t match", it->second.getSignature()); EMatchType match = it->second.matches(false, arg); TRACE2(" match ended", match); if (match >= isExact && match >= _implicit) { if (currentMatch == NULL) { currentMatch = &(it->second); isExact = match; } else if (match == _exact && isExact != _exact) { currentMatch = &(it->second); isExact = _exact; } else { RAISE(JPypeException, "Multiple overloads possible."); } } else { TRACE1(" Match is smaller than exact AND explicit"); } } } if (currentMatch == NULL) { RAISE(JPypeException, "No matching overloads found."); } return currentMatch; TRACE_OUT; } HostRef* JPMethod::invoke(vector& args) { JPMethodOverload* currentMatch = findOverload(args, false); HostRef* res; if (currentMatch->isStatic()) { res = currentMatch->invokeStatic(args); } else { res = currentMatch->invokeInstance(args); } return res; } HostRef* JPMethod::invokeInstance(vector& args) { JPMethodOverload* currentMatch = findOverload(args, false); if (currentMatch->isStatic()) { RAISE(JPypeException, "No matching overloads found."); } else { return currentMatch->invokeInstance(args); } } HostRef* JPMethod::invokeStatic(vector& args) { JPMethodOverload* currentMatch = findOverload(args, true); return currentMatch->invokeStatic(args); } JPObject* JPMethod::invokeConstructor(vector& arg) { JPMethodOverload* currentMatch = findOverload(arg, false); return currentMatch->invokeConstructor(m_Class, arg); } string JPMethod::describe(string prefix) { string name = m_Name; if (name == "[init") { name = "__init__"; } stringstream str; for (map::iterator cur = m_Overloads.begin(); cur != m_Overloads.end(); cur++) { str << prefix << "public "; if (! m_IsConstructor) { if (cur->second.isStatic()) { str << "static "; } else if (cur->second.isFinal()) { str << "final "; } str << cur->second.getReturnType().getSimpleName() << " "; } str << name << cur->second.getArgumentString() << ";" << endl; } return str.str(); } bool JPMethod::isBeanMutator() { for (map::iterator cur = m_Overloads.begin(); cur != m_Overloads.end(); cur++) { if ( (! cur->second.isStatic()) && cur->second.getReturnType().getSimpleName() == "void" && cur->second.getArgumentCount() == 2) { return true; } } return false; } bool JPMethod::isBeanAccessor() { for (map::iterator cur = m_Overloads.begin(); cur != m_Overloads.end(); cur++) { if ( (! cur->second.isStatic()) && cur->second.getReturnType().getSimpleName() != "void" && cur->second.getArgumentCount() == 1) { return true; } } return false; } string JPMethod::matchReport(vector& args) { stringstream res; res << "Match report for method " << m_Name << ", has " << m_Overloads.size() << " overloads." << endl; for (map::iterator cur = m_Overloads.begin(); cur != m_Overloads.end(); cur++) { res << " " << cur->second.matchReport(args); } return res.str(); } python-jpype-0.5.4.2/src/native/common/jp_env.cpp0000666000175000017500000002002611614007722021156 0ustar takakitakaki/***************************************************************************** Copyright 2004-2008 Steve Menard 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. *****************************************************************************/ #include HostEnvironment* JPEnv::s_Host = NULL; JPJavaEnv* JPEnv::s_Java = NULL; void JPEnv::init(HostEnvironment* hostEnv) { s_Host = hostEnv; JPTypeName::init(); } void JPEnv::loadJVM(const string& vmPath, char ignoreUnrecognized, const StringVector& args) { TRACE_IN("JPEnv::loadJVM"); JavaVMInitArgs jniArgs; jniArgs.options = NULL; JPJavaEnv::load(vmPath); // prepare this ... jniArgs.version = JNI_VERSION_1_4; jniArgs.ignoreUnrecognized = ignoreUnrecognized; jniArgs.nOptions = (jint)args.size(); jniArgs.options = (JavaVMOption*)malloc(sizeof(JavaVMOption)*jniArgs.nOptions); memset(jniArgs.options, 0, sizeof(JavaVMOption)*jniArgs.nOptions); for (int i = 0; i < jniArgs.nOptions; i++) { jniArgs.options[i].optionString = (char*)args[i].c_str(); } s_Java = JPJavaEnv::CreateJavaVM((void*)&jniArgs); if (s_Java == NULL) { RAISE(JPypeException, "Unable to start JVM"); } JPTypeManager::init(); JPJni::init(); JPProxy::init(); TRACE_OUT; } void JPEnv::attachJVM(const string& vmPath) { TRACE_IN("JPEnv::attachJVM"); JPJavaEnv::load(vmPath); s_Java = JPJavaEnv::GetCreatedJavaVM(); if (s_Java == NULL) { RAISE(JPypeException, "Unable to attach to JVM"); } JPTypeManager::init(); JPJni::init(); JPProxy::init(); TRACE_OUT; } void JPEnv::attachCurrentThread() { s_Java->AttachCurrentThread(); } void JPEnv::attachCurrentThreadAsDaemon() { s_Java->AttachCurrentThreadAsDaemon(); } bool JPEnv::isThreadAttached() { return s_Java->isThreadAttached(); } void JPEnv::registerRef(HostRef* ref, HostRef* targetRef) { TRACE_IN("JPEnv::registerRef"); JPObject* objRef = s_Host->asObject(ref); JPCleaner cleaner; TRACE1("A"); jobject srcObject = objRef->getObject(); cleaner.addLocal(srcObject); JPJni::registerRef(s_Java->getReferenceQueue(), srcObject, (jlong)targetRef->copy()); TRACE_OUT; TRACE1("B"); } static int jpype_traceLevel = 0; #ifdef JPYPE_TRACING_INTERNAL static const bool trace_internal = true; #else static const bool trace_internal = false; #endif void JPypeTracer::traceIn(const char* msg) { if (trace_internal) { for (int i = 0; i < jpype_traceLevel; i++) { JPYPE_TRACING_OUTPUT << " "; } JPYPE_TRACING_OUTPUT << "" << endl; JPYPE_TRACING_OUTPUT.flush(); jpype_traceLevel ++; } } void JPypeTracer::traceOut(const char* msg, bool error) { if (trace_internal) { jpype_traceLevel --; for (int i = 0; i < jpype_traceLevel; i++) { JPYPE_TRACING_OUTPUT << " "; } if (error) { JPYPE_TRACING_OUTPUT << " " << endl; } else { JPYPE_TRACING_OUTPUT << " " << endl; } JPYPE_TRACING_OUTPUT.flush(); } } void JPypeTracer::trace1(const char* name, const string& msg) { if (trace_internal) { for (int i = 0; i < jpype_traceLevel; i++) { JPYPE_TRACING_OUTPUT << " "; } JPYPE_TRACING_OUTPUT << "" << name << " : " << msg << "" << endl; JPYPE_TRACING_OUTPUT.flush(); } } JPCleaner::JPCleaner() { } JPCleaner::~JPCleaner() { //AT's comments on porting: // A variety of Unix compilers do not allow redifinition of the same variable in "for" cycless vector::iterator cur; for (cur = m_GlobalJavaObjects.begin(); cur != m_GlobalJavaObjects.end(); cur++) { JPEnv::getJava()->DeleteGlobalRef(*cur); } for (cur = m_LocalJavaObjects.begin(); cur != m_LocalJavaObjects.end(); cur++) { JPEnv::getJava()->DeleteLocalRef(*cur); } for (vector::iterator cur2 = m_HostObjects.begin(); cur2 != m_HostObjects.end(); cur2++) { (*cur2)->release(); } } void JPCleaner::addGlobal(jobject obj) { m_GlobalJavaObjects.push_back(obj); } void JPCleaner::addLocal(jobject obj) { m_LocalJavaObjects.push_back(obj); } void JPCleaner::add(HostRef* obj) { m_HostObjects.push_back(obj); } void JPCleaner::removeGlobal(jobject obj) { for (vector::iterator cur = m_GlobalJavaObjects.begin(); cur != m_GlobalJavaObjects.end(); cur++) { if (*cur == obj) { m_GlobalJavaObjects.erase(cur); return; } } } void JPCleaner::removeLocal(jobject obj) { for (vector::iterator cur = m_LocalJavaObjects.begin(); cur != m_LocalJavaObjects.end(); cur++) { if (*cur == obj) { m_LocalJavaObjects.erase(cur); return; } } } void JPCleaner::remove(HostRef* obj) { for (vector::iterator cur2 = m_HostObjects.begin(); cur2 != m_HostObjects.end(); cur2++) { if (*cur2 == obj) { m_HostObjects.erase(cur2); return; } } } void JPCleaner::addAllGlobal(vector& r) { for (vector::iterator cur = r.begin(); cur != r.end(); cur++) { addGlobal(*cur); } } void JPCleaner::addAllGlobal(vector& r) { for (vector::iterator cur = r.begin(); cur != r.end(); cur++) { addGlobal(*cur); } } void JPCleaner::addAllLocal(vector& r) { for (vector::iterator cur = r.begin(); cur != r.end(); cur++) { addLocal(*cur); } } void JPCleaner::addAllLocal(vector& r) { for (vector::iterator cur = r.begin(); cur != r.end(); cur++) { addLocal(*cur); } } void JPCleaner::addAll(vector& r) { for (vector::iterator cur = r.begin(); cur != r.end(); cur++) { add(*cur); } } void JPCleaner::removeAllGlobal(vector& r) { for (vector::iterator cur = r.begin(); cur != r.end(); cur++) { removeGlobal(*cur); } } void JPCleaner::removeAllLocal(vector& r) { for (vector::iterator cur = r.begin(); cur != r.end(); cur++) { removeLocal(*cur); } } void JPCleaner::removeAll(vector& r) { for (vector::iterator cur = r.begin(); cur != r.end(); cur++) { remove(*cur); } } HostRef::HostRef(void* data, bool acquire) { if (acquire) { m_HostData = JPEnv::getHost()->acquireRef(data); } else { m_HostData = data; } } HostRef::HostRef(void* data) { m_HostData = JPEnv::getHost()->acquireRef(data); } HostRef::~HostRef() { JPEnv::getHost()->releaseRef(m_HostData); } HostRef* HostRef::copy() { return new HostRef(m_HostData); } void HostRef::release() { delete this; } bool HostRef::isNull() { return JPEnv::getHost()->isRefNull(m_HostData); } void* HostRef::data() { return m_HostData; } JCharString::JCharString(const jchar* c) { m_Length = 0; while (c[m_Length] != 0) { m_Length ++; } m_Value = new jchar[m_Length+1]; m_Value[m_Length] = 0; for (unsigned int i = 0; i < m_Length; i++) { m_Value[i] = c[i]; } } JCharString::JCharString(const JCharString& c) { m_Length = c.m_Length; m_Value = new jchar[m_Length+1]; m_Value[m_Length] = 0; for (unsigned int i = 0; i < m_Length; i++) { m_Value[i] = c.m_Value[i]; } } JCharString::JCharString(size_t len) { m_Length = len; m_Value = new jchar[len+1]; for (size_t i = 0; i <= len; i++) { m_Value[i] = 0; } } JCharString::~JCharString() { if (m_Value != NULL) { delete m_Value; } } const jchar* JCharString::c_str() { return m_Value; } python-jpype-0.5.4.2/src/native/common/jp_class.cpp0000666000175000017500000003321211614007722021474 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve M�nard 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. *****************************************************************************/ #include JPClass::JPClass(const JPTypeName& n, jclass c) : JPClassBase(n, c), m_SuperClass(NULL), m_Constructors(NULL) { } JPClass::~JPClass() { delete m_Constructors; for (vector::iterator clit = m_SuperInterfaces.begin(); clit != m_SuperInterfaces.end(); clit ++) { delete (*clit); } for (map::iterator mthit = m_Methods.begin(); mthit != m_Methods.end(); mthit ++) { delete mthit->second; } for (map::iterator fldit = m_InstanceFields.begin(); fldit != m_InstanceFields.end(); fldit++) { delete fldit->second; } for (map::iterator fldit2 = m_StaticFields.begin(); fldit2 != m_StaticFields.end(); fldit2++) { delete fldit2->second; } } void JPClass::postLoad() { // Is this an interface? m_IsInterface = JPJni::isInterface(m_Class); loadSuperClass(); loadSuperInterfaces(); loadFields(); loadMethods(); loadConstructors(); } void JPClass::loadSuperClass() { JPCleaner cleaner; // base class .. if any if (!m_IsInterface && m_Name.getSimpleName() != "java.lang.Object") { jclass baseClass = JPEnv::getJava()->GetSuperclass(m_Class); cleaner.addLocal(baseClass); if (baseClass != NULL) { JPTypeName baseClassName = JPJni::getName(baseClass); m_SuperClass = JPTypeManager::findClass(baseClassName); } } } void JPClass::loadSuperInterfaces() { JPCleaner cleaner; // Super interfaces vector intf = JPJni::getInterfaces(m_Class); cleaner.addAllLocal(intf); for (vector::iterator it = intf.begin(); it != intf.end(); it++) { JPTypeName intfName = JPJni::getName(*it); JPClass* intf = JPTypeManager::findClass(intfName); m_SuperInterfaces.push_back(intf); } } void JPClass::loadFields() { JPCleaner cleaner; // fields vector fields = JPJni::getDeclaredFields(m_Class); cleaner.addAllLocal(fields); for (vector::iterator it = fields.begin(); it != fields.end(); it++) { JPField* field = new JPField(this, *it); if (field->isStatic()) { m_StaticFields[field->getName()] = field; } else { m_InstanceFields[field->getName()] = field; } } } void JPClass::loadMethods() { JPCleaner cleaner; JPCleaner pcleaner; // methods vector methods = JPJni::getDeclaredMethods(m_Class); cleaner.addAllLocal(methods); for (vector::iterator it = methods.begin(); it != methods.end(); it++) { string name = JPJni::getMemberName(*it); if (JPJni::isMemberPublic(*it) && !JPJni::isMemberAbstract(*it) ) { JPMethod* method = getMethod(name); if (method == NULL) { method = new JPMethod(m_Class, name, false); m_Methods[name] = method; } method->addOverload(this, *it); } } // add previous overloads to methods defined in THIS class if (m_SuperClass != NULL) { for (map::iterator cur = m_Methods.begin(); cur != m_Methods.end(); cur ++) { string name = cur->first; JPMethod* superMethod = m_SuperClass->getMethod(name); if (superMethod != NULL) { cur->second->addOverloads(superMethod); } } } } void JPClass::loadConstructors() { JPCleaner cleaner; m_Constructors = new JPMethod(m_Class, "[init", true); if (JPJni::isAbstract(m_Class)) { // NO constructor ... return; } vector methods = JPJni::getDeclaredConstructors(m_Class); cleaner.addAllLocal(methods); for (vector::iterator it = methods.begin(); it != methods.end(); it++) { if (JPJni::isMemberPublic(*it)) { m_Constructors->addOverload(this, *it); } } } JPField* JPClass::getInstanceField(const string& name) { map::iterator it = m_InstanceFields.find(name); if (it == m_InstanceFields.end()) { return NULL; } return it->second; } JPField* JPClass::getStaticField(const string& name) { map::iterator it = m_StaticFields.find(name); if (it == m_StaticFields.end()) { return NULL; } return it->second; } JPMethod* JPClass::getMethod(const string& name) { map::iterator it = m_Methods.find(name); if (it == m_Methods.end()) { return NULL; } return it->second; } HostRef* JPClass::getStaticAttribute(string name) { // static fields map::iterator fld = m_StaticFields.find(name); if (fld != m_StaticFields.end()) { return fld->second->getStaticAttribute(); } JPEnv::getHost()->setAttributeError(name.c_str()); JPEnv::getHost()->raise("getAttribute"); return NULL; // never reached } HostRef* JPClass::asHostObject(jvalue obj) { TRACE_IN("JPClass::asPyObject"); if (obj.l == NULL) { return JPEnv::getHost()->getNone(); } JPTypeName name = JPJni::getClassName(obj.l); if (name.getType() ==JPTypeName::_array) { JPType* arrayType = JPTypeManager::getType(name); return arrayType->asHostObject(obj); } return JPEnv::getHost()->newObject(new JPObject(name, obj.l)); TRACE_OUT; } EMatchType JPClass::canConvertToJava(HostRef* obj) { if (JPEnv::getHost()->isNone(obj)) { return _implicit; } JPCleaner cleaner; string simpleName = m_Name.getSimpleName(); if (simpleName == "java.lang.Byte" || simpleName == "java.lang.Short" || simpleName == "java.lang.Integer") { if (JPEnv::getHost()->isInt(obj)) { return _explicit; } } if (simpleName == "java.lang.Long" && JPEnv::getHost()->isLong(obj)) { return _explicit; } if (simpleName == "java.lang.Float" || simpleName == "java.lang.Double") { if (JPEnv::getHost()->isFloat(obj)) { return _explicit; } } if (JPEnv::getHost()->isObject(obj)) { JPObject* o = JPEnv::getHost()->asObject(obj); JPClass* oc = o->getClass(); if (oc == this) { // hey, this is me! :) return _exact; } if (JPEnv::getJava()->IsAssignableFrom(oc->m_Class, m_Class)) { return _implicit; } } if (JPEnv::getHost()->isProxy(obj)) { JPProxy* proxy = JPEnv::getHost()->asProxy(obj); // Check if any of the interfaces matches ... vector itf = proxy->getInterfaces(); for (unsigned int i = 0; i < itf.size(); i++) { if (JPEnv::getJava()->IsAssignableFrom(itf[i], m_Class)) { return _implicit; } } } if (JPEnv::getHost()->isWrapper(obj)) { JPTypeName o = JPEnv::getHost()->getWrapperTypeName(obj); if (o.getSimpleName() == m_Name.getSimpleName()) { return _exact; } } if (m_Name.getSimpleName() == "java.lang.Object") { // arrays are objects if (JPEnv::getHost()->isArray(obj)) { return _implicit; } // Strings are objects too if (JPEnv::getHost()->isString(obj)) { return _implicit; } // Class are objects too if (JPEnv::getHost()->isClass(obj) || JPEnv::getHost()->isArrayClass(obj)) { return _implicit; } // Let'a allow primitives (int, long, float and boolean) to convert implicitly too ... if (JPEnv::getHost()->isInt(obj)) { return _implicit; } if (JPEnv::getHost()->isLong(obj)) { return _implicit; } if (JPEnv::getHost()->isFloat(obj)) { return _implicit; } if (JPEnv::getHost()->isBoolean(obj)) { return _implicit; } } return _none; } jvalue JPClass::buildObjectWrapper(HostRef* obj) { jvalue res; JPCleaner cleaner; vector args(1); args.push_back(obj); JPObject* pobj = newInstance(args); res.l = pobj->getObject(); delete pobj; return res; } jvalue JPClass::convertToJava(HostRef* obj) { jvalue res; JPCleaner cleaner; res.l = NULL; // assume it is convertible; if (JPEnv::getHost()->isNone(obj)) { res.l = NULL; } string simpleName = m_Name.getSimpleName(); if (JPEnv::getHost()->isInt(obj) && (simpleName == "java.lang.Byte" || simpleName == "java.lang.Short" || simpleName == "java.lang.Integer")) { return buildObjectWrapper(obj); } if ((JPEnv::getHost()->isInt(obj) || JPEnv::getHost()->isLong(obj)) && simpleName == "java.lang.Long" && JPEnv::getHost()->isLong(obj)) { return buildObjectWrapper(obj); } if (JPEnv::getHost()->isFloat(obj) && (simpleName == "java.lang.Float" || simpleName == "java.lang.Double")) { if (JPEnv::getHost()->isFloat(obj)) { return buildObjectWrapper(obj); } } if (JPEnv::getHost()->isString(obj)) { JPTypeName name = JPTypeName::fromSimple("java.lang.String"); JPType* type = JPTypeManager::getType(name); return type->convertToJava(obj); } if (JPEnv::getHost()->isObject(obj)) { JPObject* ref = JPEnv::getHost()->asObject(obj); res.l = ref->getObject(); } if (JPEnv::getHost()->isProxy(obj)) { JPProxy* proxy = JPEnv::getHost()->asProxy(obj); res.l = proxy->getProxy(); } if (JPEnv::getHost()->isWrapper(obj)) { res = JPEnv::getHost()->getWrapperValue(obj); } if (JPEnv::getHost()->isInt(obj)) { JPTypeName tname = JPTypeName::fromType(JPTypeName::_int); JPType* t = JPTypeManager::getType(tname); res.l = t->convertToJavaObject(obj); } if (JPEnv::getHost()->isLong(obj)) { JPTypeName tname = JPTypeName::fromType(JPTypeName::_long); JPType* t = JPTypeManager::getType(tname); res.l = t->convertToJavaObject(obj); } if (JPEnv::getHost()->isFloat(obj)) { JPTypeName tname = JPTypeName::fromType(JPTypeName::_double); JPType* t = JPTypeManager::getType(tname); res.l = t->convertToJavaObject(obj); } if (JPEnv::getHost()->isBoolean(obj)) { JPTypeName tname = JPTypeName::fromType(JPTypeName::_boolean); JPType* t = JPTypeManager::getType(tname); res.l = t->convertToJavaObject(obj); } if (JPEnv::getHost()->isArray(obj) && simpleName == "java.lang.Object") { JPArray* a = JPEnv::getHost()->asArray(obj); res = a->getValue(); } return res; } JPObject* JPClass::newInstance(vector& args) { return m_Constructors->invokeConstructor(args); } void JPClass::setStaticAttribute(string name, HostRef* val) { map::iterator it = m_StaticFields.find(name); if (it == m_StaticFields.end()) { JPEnv::getHost()->setAttributeError(name.c_str()); JPEnv::getHost()->raise("__setattr__"); } it->second->setStaticAttribute(val); } string JPClass::describe() { stringstream out; JPCleaner cleaner; out << "public "; if (isAbstract()) { out << "abstract "; } if (isFinal()) { out << "final "; } out << "class " << m_Name.getSimpleName(); if (m_SuperClass != NULL) { out << " extends " << m_SuperClass->getName().getSimpleName(); } if (m_SuperInterfaces.size() > 0) { out << " implements"; bool first = true; for (vector::iterator itf = m_SuperInterfaces.begin(); itf != m_SuperInterfaces.end(); itf++) { if (!first) { out << ","; } else { first = false; } JPClass* pc = *itf; out << " " << pc->getName().getSimpleName(); } } out << endl << "{" << endl; // Fields out << " // Accessible Static Fields" << endl; for (map::iterator curField = m_StaticFields.begin(); curField != m_StaticFields.end(); curField++) { JPField* f = curField->second; out << " public static "; if (f->isFinal()) { out << "final "; } out << f->getType().getSimpleName() << " " << f->getName() << ";" << endl; } out << endl; out << " // Accessible Instance Fields" << endl; for (map::iterator curInstField = m_InstanceFields.begin(); curInstField != m_InstanceFields.end(); curInstField++) { JPField* f = curInstField->second; out << " public "; if (f->isFinal()) { out << "final "; } out << f->getType().getSimpleName() << " " << f->getName() << ";" << endl; } out << endl; // Constructors out << " // Accessible Constructors" << endl; out << m_Constructors->describe(" ") << endl; out << " // Accessible Methods" << endl; for (map::iterator curMethod = m_Methods.begin(); curMethod != m_Methods.end(); curMethod++) { JPMethod* f = curMethod->second; out << f->describe(" "); out << endl; } out << "}"; return out.str(); } bool JPClass::isAbstract() { return JPJni::isAbstract(m_Class); } bool JPClass::isFinal() { return JPJni::isFinal(m_Class); } JPClass* JPClass::getSuperClass() { return m_SuperClass; } vector JPClass::getInterfaces() { vector res; for (vector::iterator cur = m_SuperInterfaces.begin(); cur != m_SuperInterfaces.end(); cur++) { JPClass* c = *cur; res.push_back(c); } return res; } bool JPClass::isSubclass(JPClass* o) { JPCleaner cleaner; jclass jo = o->getClass(); cleaner.addLocal(jo); if (JPEnv::getJava()->IsAssignableFrom(m_Class, jo)) { return true; } return false; } python-jpype-0.5.4.2/src/native/common/jp_typemanager.cpp0000666000175000017500000001246111614007722022706 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard 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. *****************************************************************************/ #include //AT's on porting: // 1) the original definition of global static object leads to crashing //on HP-UX platform. Cause: it is suspected to be an undefined order of initialization of static objects // // 2) TODO: in any case, use of static objects may impose problems in multi-threaded environment. //Therefore, they must be guarded with a mutex. typedef map TypeMap; typedef map JavaClassMap; typedef map JavaArrayClassMap; static JavaArrayClassMap javaArrayClassMap; // Warning: this eliminates "static initalization order" problem but should also be guarded with a lock for MT template _T& GetMap() { static _T container; return container; } #define GET_TypeMap GetMap #define GET_JavaClassMap GetMap #define GET_JavaArrayClassMap GetMap void JPTypeManager::init() { GET_TypeMap()[JPTypeName::_void] = new JPVoidType(); GET_TypeMap()[JPTypeName::_byte] = new JPByteType(); GET_TypeMap()[JPTypeName::_short] = new JPShortType(); GET_TypeMap()[JPTypeName::_int] = new JPIntType(); GET_TypeMap()[JPTypeName::_long] = new JPLongType(); GET_TypeMap()[JPTypeName::_float] = new JPFloatType(); GET_TypeMap()[JPTypeName::_double] = new JPDoubleType(); GET_TypeMap()[JPTypeName::_char] = new JPCharType(); GET_TypeMap()[JPTypeName::_boolean] = new JPBooleanType(); GET_TypeMap()[JPTypeName::_string] = new JPStringType(); GET_TypeMap()[JPTypeName::_class] = new JPClassType(); // Preload the "primitive" types GET_JavaClassMap()["byte"] = new JPClass(JPTypeName::fromSimple("byte"), JPJni::getByteClass()); GET_JavaClassMap()["short"] = new JPClass(JPTypeName::fromSimple("short"), JPJni::getShortClass()); GET_JavaClassMap()["int"] = new JPClass(JPTypeName::fromSimple("int"), JPJni::getIntegerClass()); GET_JavaClassMap()["long"] = new JPClass(JPTypeName::fromSimple("long"), JPJni::getLongClass()); GET_JavaClassMap()["float"] = new JPClass(JPTypeName::fromSimple("float"), JPJni::getFloatClass()); GET_JavaClassMap()["double"] = new JPClass(JPTypeName::fromSimple("double"), JPJni::getDoubleClass()); GET_JavaClassMap()["char"] = new JPClass(JPTypeName::fromSimple("char"), JPJni::getCharacterClass()); GET_JavaClassMap()["boolean"] = new JPClass(JPTypeName::fromSimple("boolean"), JPJni::getBooleanClass()); GET_JavaClassMap()["void"] = new JPClass(JPTypeName::fromSimple("void"), JPJni::getVoidClass()); } JPClass* JPTypeManager::findClass(JPTypeName& name) { // Fist check in the map ... JavaClassMap::iterator cur = GET_JavaClassMap().find(name.getSimpleName()); if (cur != GET_JavaClassMap().end()) { return cur->second; } TRACE_IN("JPTypeManager::findClass"); TRACE1(name.getSimpleName()); // No we havent got it .. lets load it!!! JPCleaner cleaner; jclass cls = JPEnv::getJava()->FindClass(name.getNativeName().c_str()); cleaner.addLocal(cls); JPClass* res = new JPClass(name, cls); // Register it here before we do anything else GET_JavaClassMap()[name.getSimpleName()] = res; // Finish loading it res->postLoad(); return res; TRACE_OUT; } JPArrayClass* JPTypeManager::findArrayClass(JPTypeName& name) { // Fist check in the map ... JavaArrayClassMap::iterator cur = GET_JavaArrayClassMap().find(name.getSimpleName()); if (cur != GET_JavaArrayClassMap().end()) { return cur->second; } // No we havent got it .. lets load it!!! JPCleaner cleaner; jclass cls = JPEnv::getJava()->FindClass(name.getNativeName().c_str()); cleaner.addLocal(cls); JPArrayClass* res = new JPArrayClass(name, cls); // Register it here before we do anything else GET_JavaArrayClassMap()[name.getSimpleName()] = res; return res; } JPType* JPTypeManager::getType(JPTypeName& t) { JPCleaner cleaner; TRACE_IN("JPTypeManager::getType"); map::iterator it = GET_TypeMap().find(t.getType()); if (it != GET_TypeMap().end()) { return it->second; } if (t.getType() == JPTypeName::_array) { JPArrayClass* c = findArrayClass(t); return c; } else { JPClass* c = findClass(t); return c; } TRACE_OUT; } void JPTypeManager::flushCache() { // TODO delete the values GET_JavaClassMap().clear(); GET_JavaArrayClassMap().clear(); } int JPTypeManager::getLoadedClasses() { // dignostic tools ... unlikely to load more classes than int can hold ... return (int)(GET_JavaClassMap().size() + GET_JavaArrayClassMap().size()); } python-jpype-0.5.4.2/src/native/common/jp_invocationhandler.cpp0000666000175000017500000002762011614007722024104 0ustar takakitakaki#include jbyte JPypeInvocationHandler[] = { (jbyte)0xCA,(jbyte)0xFE,(jbyte)0xBA,(jbyte)0xBE,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x2E,(jbyte)0x00,(jbyte)0x30,(jbyte)0x01,(jbyte)0x00,(jbyte)0x1C,(jbyte)0x6A,(jbyte)0x70,(jbyte)0x79,(jbyte)0x70,(jbyte)0x65,(jbyte)0x2F,(jbyte)0x4A ,(jbyte)0x50,(jbyte)0x79,(jbyte)0x70,(jbyte)0x65,(jbyte)0x49,(jbyte)0x6E,(jbyte)0x76,(jbyte)0x6F,(jbyte)0x63,(jbyte)0x61,(jbyte)0x74,(jbyte)0x69,(jbyte)0x6F,(jbyte)0x6E,(jbyte)0x48,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x64,(jbyte)0x6C,(jbyte)0x65 ,(jbyte)0x72,(jbyte)0x07,(jbyte)0x00,(jbyte)0x01,(jbyte)0x01,(jbyte)0x00,(jbyte)0x10,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x4F,(jbyte)0x62,(jbyte)0x6A ,(jbyte)0x65,(jbyte)0x63,(jbyte)0x74,(jbyte)0x07,(jbyte)0x00,(jbyte)0x03,(jbyte)0x01,(jbyte)0x00,(jbyte)0x23,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x72 ,(jbyte)0x65,(jbyte)0x66,(jbyte)0x6C,(jbyte)0x65,(jbyte)0x63,(jbyte)0x74,(jbyte)0x2F,(jbyte)0x49,(jbyte)0x6E,(jbyte)0x76,(jbyte)0x6F,(jbyte)0x63,(jbyte)0x61,(jbyte)0x74,(jbyte)0x69,(jbyte)0x6F,(jbyte)0x6E,(jbyte)0x48,(jbyte)0x61,(jbyte)0x6E ,(jbyte)0x64,(jbyte)0x6C,(jbyte)0x65,(jbyte)0x72,(jbyte)0x07,(jbyte)0x00,(jbyte)0x05,(jbyte)0x01,(jbyte)0x00,(jbyte)0x0A,(jbyte)0x68,(jbyte)0x6F,(jbyte)0x73,(jbyte)0x74,(jbyte)0x4F,(jbyte)0x62,(jbyte)0x6A,(jbyte)0x65,(jbyte)0x63,(jbyte)0x74 ,(jbyte)0x01,(jbyte)0x00,(jbyte)0x01,(jbyte)0x4A,(jbyte)0x01,(jbyte)0x00,(jbyte)0x06,(jbyte)0x3C,(jbyte)0x69,(jbyte)0x6E,(jbyte)0x69,(jbyte)0x74,(jbyte)0x3E,(jbyte)0x01,(jbyte)0x00,(jbyte)0x03,(jbyte)0x28,(jbyte)0x29,(jbyte)0x56,(jbyte)0x01 ,(jbyte)0x00,(jbyte)0x04,(jbyte)0x43,(jbyte)0x6F,(jbyte)0x64,(jbyte)0x65,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x09,(jbyte)0x00,(jbyte)0x0A,(jbyte)0x0A,(jbyte)0x00,(jbyte)0x04,(jbyte)0x00,(jbyte)0x0C,(jbyte)0x01,(jbyte)0x00,(jbyte)0x0F,(jbyte)0x4C ,(jbyte)0x69,(jbyte)0x6E,(jbyte)0x65,(jbyte)0x4E,(jbyte)0x75,(jbyte)0x6D,(jbyte)0x62,(jbyte)0x65,(jbyte)0x72,(jbyte)0x54,(jbyte)0x61,(jbyte)0x62,(jbyte)0x6C,(jbyte)0x65,(jbyte)0x01,(jbyte)0x00,(jbyte)0x12,(jbyte)0x4C,(jbyte)0x6F,(jbyte)0x63 ,(jbyte)0x61,(jbyte)0x6C,(jbyte)0x56,(jbyte)0x61,(jbyte)0x72,(jbyte)0x69,(jbyte)0x61,(jbyte)0x62,(jbyte)0x6C,(jbyte)0x65,(jbyte)0x54,(jbyte)0x61,(jbyte)0x62,(jbyte)0x6C,(jbyte)0x65,(jbyte)0x01,(jbyte)0x00,(jbyte)0x04,(jbyte)0x74,(jbyte)0x68 ,(jbyte)0x69,(jbyte)0x73,(jbyte)0x01,(jbyte)0x00,(jbyte)0x1E,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x70,(jbyte)0x79,(jbyte)0x70,(jbyte)0x65,(jbyte)0x2F,(jbyte)0x4A,(jbyte)0x50,(jbyte)0x79,(jbyte)0x70,(jbyte)0x65,(jbyte)0x49,(jbyte)0x6E,(jbyte)0x76 ,(jbyte)0x6F,(jbyte)0x63,(jbyte)0x61,(jbyte)0x74,(jbyte)0x69,(jbyte)0x6F,(jbyte)0x6E,(jbyte)0x48,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x64,(jbyte)0x6C,(jbyte)0x65,(jbyte)0x72,(jbyte)0x3B,(jbyte)0x01,(jbyte)0x00,(jbyte)0x06,(jbyte)0x69,(jbyte)0x6E ,(jbyte)0x76,(jbyte)0x6F,(jbyte)0x6B,(jbyte)0x65,(jbyte)0x01,(jbyte)0x00,(jbyte)0x53,(jbyte)0x28,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x4F ,(jbyte)0x62,(jbyte)0x6A,(jbyte)0x65,(jbyte)0x63,(jbyte)0x74,(jbyte)0x3B,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x72,(jbyte)0x65,(jbyte)0x66 ,(jbyte)0x6C,(jbyte)0x65,(jbyte)0x63,(jbyte)0x74,(jbyte)0x2F,(jbyte)0x4D,(jbyte)0x65,(jbyte)0x74,(jbyte)0x68,(jbyte)0x6F,(jbyte)0x64,(jbyte)0x3B,(jbyte)0x5B,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C ,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x4F,(jbyte)0x62,(jbyte)0x6A,(jbyte)0x65,(jbyte)0x63,(jbyte)0x74,(jbyte)0x3B,(jbyte)0x29,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61 ,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x4F,(jbyte)0x62,(jbyte)0x6A,(jbyte)0x65,(jbyte)0x63,(jbyte)0x74,(jbyte)0x3B,(jbyte)0x01,(jbyte)0x00,(jbyte)0x18,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61 ,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x72,(jbyte)0x65,(jbyte)0x66,(jbyte)0x6C,(jbyte)0x65,(jbyte)0x63,(jbyte)0x74,(jbyte)0x2F,(jbyte)0x4D,(jbyte)0x65,(jbyte)0x74,(jbyte)0x68,(jbyte)0x6F,(jbyte)0x64,(jbyte)0x07,(jbyte)0x00,(jbyte)0x14 ,(jbyte)0x01,(jbyte)0x00,(jbyte)0x07,(jbyte)0x67,(jbyte)0x65,(jbyte)0x74,(jbyte)0x4E,(jbyte)0x61,(jbyte)0x6D,(jbyte)0x65,(jbyte)0x01,(jbyte)0x00,(jbyte)0x14,(jbyte)0x28,(jbyte)0x29,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61 ,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x53,(jbyte)0x74,(jbyte)0x72,(jbyte)0x69,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x3B,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x16,(jbyte)0x00,(jbyte)0x17,(jbyte)0x0A,(jbyte)0x00 ,(jbyte)0x15,(jbyte)0x00,(jbyte)0x18,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x07,(jbyte)0x00,(jbyte)0x08,(jbyte)0x09,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x1A,(jbyte)0x01,(jbyte)0x00,(jbyte)0x11,(jbyte)0x67,(jbyte)0x65,(jbyte)0x74,(jbyte)0x50 ,(jbyte)0x61,(jbyte)0x72,(jbyte)0x61,(jbyte)0x6D,(jbyte)0x65,(jbyte)0x74,(jbyte)0x65,(jbyte)0x72,(jbyte)0x54,(jbyte)0x79,(jbyte)0x70,(jbyte)0x65,(jbyte)0x73,(jbyte)0x01,(jbyte)0x00,(jbyte)0x14,(jbyte)0x28,(jbyte)0x29,(jbyte)0x5B,(jbyte)0x4C ,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x43,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x73,(jbyte)0x73,(jbyte)0x3B,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x1C,(jbyte)0x00 ,(jbyte)0x1D,(jbyte)0x0A,(jbyte)0x00,(jbyte)0x15,(jbyte)0x00,(jbyte)0x1E,(jbyte)0x01,(jbyte)0x00,(jbyte)0x0D,(jbyte)0x67,(jbyte)0x65,(jbyte)0x74,(jbyte)0x52,(jbyte)0x65,(jbyte)0x74,(jbyte)0x75,(jbyte)0x72,(jbyte)0x6E,(jbyte)0x54,(jbyte)0x79 ,(jbyte)0x70,(jbyte)0x65,(jbyte)0x01,(jbyte)0x00,(jbyte)0x13,(jbyte)0x28,(jbyte)0x29,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x43,(jbyte)0x6C ,(jbyte)0x61,(jbyte)0x73,(jbyte)0x73,(jbyte)0x3B,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x20,(jbyte)0x00,(jbyte)0x21,(jbyte)0x0A,(jbyte)0x00,(jbyte)0x15,(jbyte)0x00,(jbyte)0x22,(jbyte)0x01,(jbyte)0x00,(jbyte)0x0A,(jbyte)0x68,(jbyte)0x6F,(jbyte)0x73 ,(jbyte)0x74,(jbyte)0x49,(jbyte)0x6E,(jbyte)0x76,(jbyte)0x6F,(jbyte)0x6B,(jbyte)0x65,(jbyte)0x01,(jbyte)0x00,(jbyte)0x5D,(jbyte)0x28,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E ,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x53,(jbyte)0x74,(jbyte)0x72,(jbyte)0x69,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x3B,(jbyte)0x4A,(jbyte)0x5B,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E ,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x4F,(jbyte)0x62,(jbyte)0x6A,(jbyte)0x65,(jbyte)0x63,(jbyte)0x74,(jbyte)0x3B,(jbyte)0x5B,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67 ,(jbyte)0x2F,(jbyte)0x43,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x73,(jbyte)0x73,(jbyte)0x3B,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x43,(jbyte)0x6C ,(jbyte)0x61,(jbyte)0x73,(jbyte)0x73,(jbyte)0x3B,(jbyte)0x29,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x4F,(jbyte)0x62,(jbyte)0x6A,(jbyte)0x65 ,(jbyte)0x63,(jbyte)0x74,(jbyte)0x3B,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x24,(jbyte)0x00,(jbyte)0x25,(jbyte)0x0A,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x26,(jbyte)0x01,(jbyte)0x00,(jbyte)0x05,(jbyte)0x70,(jbyte)0x72,(jbyte)0x6F,(jbyte)0x78 ,(jbyte)0x79,(jbyte)0x01,(jbyte)0x00,(jbyte)0x12,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x4F,(jbyte)0x62,(jbyte)0x6A,(jbyte)0x65,(jbyte)0x63 ,(jbyte)0x74,(jbyte)0x3B,(jbyte)0x01,(jbyte)0x00,(jbyte)0x06,(jbyte)0x6D,(jbyte)0x65,(jbyte)0x74,(jbyte)0x68,(jbyte)0x6F,(jbyte)0x64,(jbyte)0x01,(jbyte)0x00,(jbyte)0x1A,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F ,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x72,(jbyte)0x65,(jbyte)0x66,(jbyte)0x6C,(jbyte)0x65,(jbyte)0x63,(jbyte)0x74,(jbyte)0x2F,(jbyte)0x4D,(jbyte)0x65,(jbyte)0x74,(jbyte)0x68,(jbyte)0x6F,(jbyte)0x64,(jbyte)0x3B ,(jbyte)0x01,(jbyte)0x00,(jbyte)0x04,(jbyte)0x61,(jbyte)0x72,(jbyte)0x67,(jbyte)0x73,(jbyte)0x01,(jbyte)0x00,(jbyte)0x13,(jbyte)0x5B,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E ,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x4F,(jbyte)0x62,(jbyte)0x6A,(jbyte)0x65,(jbyte)0x63,(jbyte)0x74,(jbyte)0x3B,(jbyte)0x01,(jbyte)0x00,(jbyte)0x0A,(jbyte)0x53,(jbyte)0x6F,(jbyte)0x75,(jbyte)0x72,(jbyte)0x63,(jbyte)0x65,(jbyte)0x46,(jbyte)0x69 ,(jbyte)0x6C,(jbyte)0x65,(jbyte)0x01,(jbyte)0x00,(jbyte)0x1B,(jbyte)0x4A,(jbyte)0x50,(jbyte)0x79,(jbyte)0x70,(jbyte)0x65,(jbyte)0x49,(jbyte)0x6E,(jbyte)0x76,(jbyte)0x6F,(jbyte)0x63,(jbyte)0x61,(jbyte)0x74,(jbyte)0x69,(jbyte)0x6F,(jbyte)0x6E ,(jbyte)0x48,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x64,(jbyte)0x6C,(jbyte)0x65,(jbyte)0x72,(jbyte)0x2E,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x00,(jbyte)0x20,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x04,(jbyte)0x00,(jbyte)0x01 ,(jbyte)0x00,(jbyte)0x06,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x07,(jbyte)0x00,(jbyte)0x08,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x03,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x09,(jbyte)0x00,(jbyte)0x0A ,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x0B,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x2F,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x05,(jbyte)0x2A,(jbyte)0xB7,(jbyte)0x00,(jbyte)0x0D ,(jbyte)0xB1,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x0E,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x06,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x05,(jbyte)0x00,(jbyte)0x0F,(jbyte)0x00 ,(jbyte)0x00,(jbyte)0x00,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x05,(jbyte)0x00,(jbyte)0x10,(jbyte)0x00,(jbyte)0x11,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x12,(jbyte)0x00 ,(jbyte)0x13,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x0B,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x5D,(jbyte)0x00,(jbyte)0x06,(jbyte)0x00,(jbyte)0x04,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x15,(jbyte)0x2C,(jbyte)0xB6,(jbyte)0x00 ,(jbyte)0x19,(jbyte)0x2A,(jbyte)0xB4,(jbyte)0x00,(jbyte)0x1B,(jbyte)0x2D,(jbyte)0x2C,(jbyte)0xB6,(jbyte)0x00,(jbyte)0x1F,(jbyte)0x2C,(jbyte)0xB6,(jbyte)0x00,(jbyte)0x23,(jbyte)0xB8,(jbyte)0x00,(jbyte)0x27,(jbyte)0xB0,(jbyte)0x00,(jbyte)0x00 ,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x0E,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x06,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x0A,(jbyte)0x00,(jbyte)0x0F,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x2A ,(jbyte)0x00,(jbyte)0x04,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x15,(jbyte)0x00,(jbyte)0x10,(jbyte)0x00,(jbyte)0x11,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x15,(jbyte)0x00,(jbyte)0x28,(jbyte)0x00,(jbyte)0x29 ,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x15,(jbyte)0x00,(jbyte)0x2A,(jbyte)0x00,(jbyte)0x2B,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x15,(jbyte)0x00,(jbyte)0x2C,(jbyte)0x00,(jbyte)0x2D ,(jbyte)0x00,(jbyte)0x03,(jbyte)0x01,(jbyte)0x0A,(jbyte)0x00,(jbyte)0x24,(jbyte)0x00,(jbyte)0x25,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x2E,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x2F }; jsize getJPypeInvocationHandlerLength() { return 980; } python-jpype-0.5.4.2/src/native/common/jp_field.cpp0000666000175000017500000000675311614007722021464 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard 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. *****************************************************************************/ #include JPField::JPField() { } JPField::JPField(JPClass* clazz, jobject fld) { TRACE_IN("JPField::JPField1"); m_Class = clazz; m_Field = JPEnv::getJava()->NewGlobalRef(fld); m_Name = JPJni::getMemberName(fld); m_IsStatic = JPJni::isMemberStatic(fld); m_IsFinal = JPJni::isMemberFinal(fld); m_FieldID = JPEnv::getJava()->FromReflectedField(fld); m_Type = JPJni::getType(m_Field); TRACE2("field type", m_Type.getSimpleName()); TRACE_OUT } JPField::JPField(const JPField& fld) { TRACE_IN("JPField::JPField2"); m_Name = fld.m_Name; m_IsStatic = fld.m_IsStatic; m_IsFinal = fld.m_IsFinal; m_FieldID = fld.m_FieldID; m_Type = fld.m_Type; m_Class = fld.m_Class; m_Field = JPEnv::getJava()->NewGlobalRef(fld.m_Field); TRACE_OUT; } JPField::~JPField() { TRACE_IN("JPField::~JPField"); JPEnv::getJava()->DeleteGlobalRef(m_Field); TRACE_OUT; } bool JPField::isStatic() { return m_IsStatic; } string JPField::getName() { return m_Name; } HostRef* JPField::getStaticAttribute() { TRACE_IN("JPField::getStaticAttribute"); JPType* type = JPTypeManager::getType(m_Type); JPCleaner cleaner; jclass claz = m_Class->getClass(); cleaner.addLocal(claz); return type->getStaticValue(claz, m_FieldID, m_Type); TRACE_OUT; } void JPField::setStaticAttribute(HostRef* val) { TRACE_IN("JPField::setStaticAttribute"); if (m_IsFinal) { stringstream err; err << "Field " << m_Name << " is read-only"; RAISE(JPypeException, err.str().c_str()); } JPType* type = JPTypeManager::getType(m_Type); if (type->canConvertToJava(val) <= _explicit) { stringstream err; err << "unable to convert to " << type->getName().getSimpleName(); RAISE(JPypeException, err.str().c_str()); } JPCleaner cleaner; jclass claz = m_Class->getClass(); cleaner.addLocal(claz); type->setStaticValue(claz, m_FieldID, val); TRACE_OUT; } HostRef* JPField::getAttribute(jobject inst) { TRACE_IN("JPField::getAttribute"); TRACE2("field type", m_Type.getSimpleName()); JPType* type = JPTypeManager::getType(m_Type); return type->getInstanceValue(inst, m_FieldID, m_Type); TRACE_OUT; } void JPField::setAttribute(jobject inst, HostRef* val) { TRACE_IN("JPField::setAttribute"); if (m_IsFinal) { stringstream err; err << "Field " << m_Name << " is read-only"; RAISE(JPypeException, err.str().c_str()); } JPType* type = JPTypeManager::getType(m_Type); if (type->canConvertToJava(val) <= _explicit) { stringstream err; err << "unable to convert to " << type->getName().getSimpleName(); RAISE(JPypeException, err.str().c_str()); } type->setInstanceValue(inst, m_FieldID, val); TRACE_OUT; } python-jpype-0.5.4.2/src/native/common/jp_platform_linux.cpp0000666000175000017500000000156711614007722023442 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard 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. *****************************************************************************/ #ifdef JPYPE_LINUX void longToHexString(long value, char* outStr) { sprintf(outStr, "%lx", value); } #endif python-jpype-0.5.4.2/src/native/common/jp_primitivetypes_autogen.cpp0000666000175000017500000007506711614007722025224 0ustar takakitakaki /***************************************************************************** Copyright 2004-2008 Steve Menard 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. *****************************************************************************/ // This code has been automatically generated ... No not edit #include jarray JPByteType::newArrayInstance(int sz) { return JPEnv::getJava()->NewByteArray(sz); } HostRef* JPByteType::getStaticValue(jclass c, jfieldID fid, JPTypeName& tgtType) { jvalue v; v.b = JPEnv::getJava()->GetStaticByteField(c, fid); return asHostObject(v); } HostRef* JPByteType::getInstanceValue(jobject c, jfieldID fid, JPTypeName& tgtType) { jvalue v; v.b = JPEnv::getJava()->GetByteField(c, fid); return asHostObject(v); } HostRef* JPByteType::invokeStatic(jclass claz, jmethodID mth, jvalue* val) { jvalue v; v.b = JPEnv::getJava()->CallStaticByteMethodA(claz, mth, val); return asHostObject(v); } HostRef* JPByteType::invoke(jobject obj, jclass clazz, jmethodID mth, jvalue* val) { jvalue v; v.b = JPEnv::getJava()->CallNonvirtualByteMethodA(obj, clazz, mth, val); return asHostObject(v); } void JPByteType::setStaticValue(jclass c, jfieldID fid, HostRef* obj) { jbyte val = convertToJava(obj).b; JPEnv::getJava()->SetStaticByteField(c, fid, val); } void JPByteType::setInstanceValue(jobject c, jfieldID fid, HostRef* obj) { jbyte val = convertToJava(obj).b; JPEnv::getJava()->SetByteField(c, fid, val); } vector JPByteType::getArrayRange(jarray a, int start, int length) { jbyteArray array = (jbyteArray)a; jbyte* val = NULL; jboolean isCopy; JPCleaner cleaner; try { val = JPEnv::getJava()->GetByteArrayElements(array, &isCopy); vector res; jvalue v; for (int i = 0; i < length; i++) { v.b = val[i+start]; HostRef* pv = asHostObject(v); res.push_back(pv); } JPEnv::getJava()->ReleaseByteArrayElements(array, val, JNI_ABORT); return res; } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseByteArrayElements(array, val, JNI_ABORT); } ); } void JPByteType::setArrayRange(jarray a, int start, int length, vector& vals) { jbyteArray array = (jbyteArray)a; jbyte* val = NULL; jboolean isCopy; JPCleaner cleaner; try { val = JPEnv::getJava()->GetByteArrayElements(array, &isCopy); for (int i = 0; i < length; i++) { HostRef* pv = vals[i]; val[start+i] = convertToJava(pv).b; } JPEnv::getJava()->ReleaseByteArrayElements(array, val, 0); } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseByteArrayElements(array, val, JNI_ABORT); } ); } HostRef* JPByteType::getArrayItem(jarray a, int ndx) { jbyteArray array = (jbyteArray)a; jbyte* val = NULL; jboolean isCopy; JPCleaner cleaner; try { val = JPEnv::getJava()->GetByteArrayElements(array, &isCopy); jvalue v; v.b = val[ndx]; JPEnv::getJava()->ReleaseByteArrayElements(array, val, JNI_ABORT); return asHostObject(v); } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseByteArrayElements(array, val, JNI_ABORT); } ); } void JPByteType::setArrayItem(jarray a, int ndx , HostRef* obj) { jbyteArray array = (jbyteArray)a; jbyte* val = NULL; jboolean isCopy; try { val = JPEnv::getJava()->GetByteArrayElements(array, &isCopy); val[ndx] = convertToJava(obj).b; JPEnv::getJava()->ReleaseByteArrayElements(array, val, 0); } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseByteArrayElements(array, val, JNI_ABORT); } ); } //---------------------------------------------------------- jarray JPShortType::newArrayInstance(int sz) { return JPEnv::getJava()->NewShortArray(sz); } HostRef* JPShortType::getStaticValue(jclass c, jfieldID fid, JPTypeName& tgtType) { jvalue v; v.s = JPEnv::getJava()->GetStaticShortField(c, fid); return asHostObject(v); } HostRef* JPShortType::getInstanceValue(jobject c, jfieldID fid, JPTypeName& tgtType) { jvalue v; v.s = JPEnv::getJava()->GetShortField(c, fid); return asHostObject(v); } HostRef* JPShortType::invokeStatic(jclass claz, jmethodID mth, jvalue* val) { jvalue v; v.s = JPEnv::getJava()->CallStaticShortMethodA(claz, mth, val); return asHostObject(v); } HostRef* JPShortType::invoke(jobject obj, jclass clazz, jmethodID mth, jvalue* val) { jvalue v; v.s = JPEnv::getJava()->CallNonvirtualShortMethodA(obj, clazz, mth, val); return asHostObject(v); } void JPShortType::setStaticValue(jclass c, jfieldID fid, HostRef* obj) { jshort val = convertToJava(obj).s; JPEnv::getJava()->SetStaticShortField(c, fid, val); } void JPShortType::setInstanceValue(jobject c, jfieldID fid, HostRef* obj) { jshort val = convertToJava(obj).s; JPEnv::getJava()->SetShortField(c, fid, val); } vector JPShortType::getArrayRange(jarray a, int start, int length) { jshortArray array = (jshortArray)a; jshort* val = NULL; jboolean isCopy; JPCleaner cleaner; try { val = JPEnv::getJava()->GetShortArrayElements(array, &isCopy); vector res; jvalue v; for (int i = 0; i < length; i++) { v.s = val[i+start]; HostRef* pv = asHostObject(v); res.push_back(pv); } JPEnv::getJava()->ReleaseShortArrayElements(array, val, JNI_ABORT); return res; } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseShortArrayElements(array, val, JNI_ABORT); } ); } void JPShortType::setArrayRange(jarray a, int start, int length, vector& vals) { jshortArray array = (jshortArray)a; jshort* val = NULL; jboolean isCopy; JPCleaner cleaner; try { val = JPEnv::getJava()->GetShortArrayElements(array, &isCopy); for (int i = 0; i < length; i++) { HostRef* pv = vals[i]; val[start+i] = convertToJava(pv).s; } JPEnv::getJava()->ReleaseShortArrayElements(array, val, 0); } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseShortArrayElements(array, val, JNI_ABORT); } ); } HostRef* JPShortType::getArrayItem(jarray a, int ndx) { jshortArray array = (jshortArray)a; jshort* val = NULL; jboolean isCopy; JPCleaner cleaner; try { val = JPEnv::getJava()->GetShortArrayElements(array, &isCopy); jvalue v; v.s = val[ndx]; JPEnv::getJava()->ReleaseShortArrayElements(array, val, JNI_ABORT); return asHostObject(v); } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseShortArrayElements(array, val, JNI_ABORT); } ); } void JPShortType::setArrayItem(jarray a, int ndx , HostRef* obj) { jshortArray array = (jshortArray)a; jshort* val = NULL; jboolean isCopy; try { val = JPEnv::getJava()->GetShortArrayElements(array, &isCopy); val[ndx] = convertToJava(obj).s; JPEnv::getJava()->ReleaseShortArrayElements(array, val, 0); } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseShortArrayElements(array, val, JNI_ABORT); } ); } //---------------------------------------------------------- jarray JPIntType::newArrayInstance(int sz) { return JPEnv::getJava()->NewIntArray(sz); } HostRef* JPIntType::getStaticValue(jclass c, jfieldID fid, JPTypeName& tgtType) { jvalue v; v.i = JPEnv::getJava()->GetStaticIntField(c, fid); return asHostObject(v); } HostRef* JPIntType::getInstanceValue(jobject c, jfieldID fid, JPTypeName& tgtType) { jvalue v; v.i = JPEnv::getJava()->GetIntField(c, fid); return asHostObject(v); } HostRef* JPIntType::invokeStatic(jclass claz, jmethodID mth, jvalue* val) { jvalue v; v.i = JPEnv::getJava()->CallStaticIntMethodA(claz, mth, val); return asHostObject(v); } HostRef* JPIntType::invoke(jobject obj, jclass clazz, jmethodID mth, jvalue* val) { jvalue v; v.i = JPEnv::getJava()->CallNonvirtualIntMethodA(obj, clazz, mth, val); return asHostObject(v); } void JPIntType::setStaticValue(jclass c, jfieldID fid, HostRef* obj) { jint val = convertToJava(obj).i; JPEnv::getJava()->SetStaticIntField(c, fid, val); } void JPIntType::setInstanceValue(jobject c, jfieldID fid, HostRef* obj) { jint val = convertToJava(obj).i; JPEnv::getJava()->SetIntField(c, fid, val); } vector JPIntType::getArrayRange(jarray a, int start, int length) { jintArray array = (jintArray)a; jint* val = NULL; jboolean isCopy; JPCleaner cleaner; try { val = JPEnv::getJava()->GetIntArrayElements(array, &isCopy); vector res; jvalue v; for (int i = 0; i < length; i++) { v.i = val[i+start]; HostRef* pv = asHostObject(v); res.push_back(pv); } JPEnv::getJava()->ReleaseIntArrayElements(array, val, JNI_ABORT); return res; } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseIntArrayElements(array, val, JNI_ABORT); } ); } void JPIntType::setArrayRange(jarray a, int start, int length, vector& vals) { jintArray array = (jintArray)a; jint* val = NULL; jboolean isCopy; JPCleaner cleaner; try { val = JPEnv::getJava()->GetIntArrayElements(array, &isCopy); for (int i = 0; i < length; i++) { HostRef* pv = vals[i]; val[start+i] = convertToJava(pv).i; } JPEnv::getJava()->ReleaseIntArrayElements(array, val, 0); } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseIntArrayElements(array, val, JNI_ABORT); } ); } HostRef* JPIntType::getArrayItem(jarray a, int ndx) { jintArray array = (jintArray)a; jint* val = NULL; jboolean isCopy; JPCleaner cleaner; try { val = JPEnv::getJava()->GetIntArrayElements(array, &isCopy); jvalue v; v.i = val[ndx]; JPEnv::getJava()->ReleaseIntArrayElements(array, val, JNI_ABORT); return asHostObject(v); } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseIntArrayElements(array, val, JNI_ABORT); } ); } void JPIntType::setArrayItem(jarray a, int ndx , HostRef* obj) { jintArray array = (jintArray)a; jint* val = NULL; jboolean isCopy; try { val = JPEnv::getJava()->GetIntArrayElements(array, &isCopy); val[ndx] = convertToJava(obj).i; JPEnv::getJava()->ReleaseIntArrayElements(array, val, 0); } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseIntArrayElements(array, val, JNI_ABORT); } ); } //---------------------------------------------------------- jarray JPLongType::newArrayInstance(int sz) { return JPEnv::getJava()->NewLongArray(sz); } HostRef* JPLongType::getStaticValue(jclass c, jfieldID fid, JPTypeName& tgtType) { jvalue v; v.j = JPEnv::getJava()->GetStaticLongField(c, fid); return asHostObject(v); } HostRef* JPLongType::getInstanceValue(jobject c, jfieldID fid, JPTypeName& tgtType) { jvalue v; v.j = JPEnv::getJava()->GetLongField(c, fid); return asHostObject(v); } HostRef* JPLongType::invokeStatic(jclass claz, jmethodID mth, jvalue* val) { jvalue v; v.j = JPEnv::getJava()->CallStaticLongMethodA(claz, mth, val); return asHostObject(v); } HostRef* JPLongType::invoke(jobject obj, jclass clazz, jmethodID mth, jvalue* val) { jvalue v; v.j = JPEnv::getJava()->CallNonvirtualLongMethodA(obj, clazz, mth, val); return asHostObject(v); } void JPLongType::setStaticValue(jclass c, jfieldID fid, HostRef* obj) { jlong val = convertToJava(obj).j; JPEnv::getJava()->SetStaticLongField(c, fid, val); } void JPLongType::setInstanceValue(jobject c, jfieldID fid, HostRef* obj) { jlong val = convertToJava(obj).j; JPEnv::getJava()->SetLongField(c, fid, val); } vector JPLongType::getArrayRange(jarray a, int start, int length) { jlongArray array = (jlongArray)a; jlong* val = NULL; jboolean isCopy; JPCleaner cleaner; try { val = JPEnv::getJava()->GetLongArrayElements(array, &isCopy); vector res; jvalue v; for (int i = 0; i < length; i++) { v.j = val[i+start]; HostRef* pv = asHostObject(v); res.push_back(pv); } JPEnv::getJava()->ReleaseLongArrayElements(array, val, JNI_ABORT); return res; } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseLongArrayElements(array, val, JNI_ABORT); } ); } void JPLongType::setArrayRange(jarray a, int start, int length, vector& vals) { jlongArray array = (jlongArray)a; jlong* val = NULL; jboolean isCopy; JPCleaner cleaner; try { val = JPEnv::getJava()->GetLongArrayElements(array, &isCopy); for (int i = 0; i < length; i++) { HostRef* pv = vals[i]; val[start+i] = convertToJava(pv).j; } JPEnv::getJava()->ReleaseLongArrayElements(array, val, 0); } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseLongArrayElements(array, val, JNI_ABORT); } ); } HostRef* JPLongType::getArrayItem(jarray a, int ndx) { jlongArray array = (jlongArray)a; jlong* val = NULL; jboolean isCopy; JPCleaner cleaner; try { val = JPEnv::getJava()->GetLongArrayElements(array, &isCopy); jvalue v; v.j = val[ndx]; JPEnv::getJava()->ReleaseLongArrayElements(array, val, JNI_ABORT); return asHostObject(v); } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseLongArrayElements(array, val, JNI_ABORT); } ); } void JPLongType::setArrayItem(jarray a, int ndx , HostRef* obj) { jlongArray array = (jlongArray)a; jlong* val = NULL; jboolean isCopy; try { val = JPEnv::getJava()->GetLongArrayElements(array, &isCopy); val[ndx] = convertToJava(obj).j; JPEnv::getJava()->ReleaseLongArrayElements(array, val, 0); } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseLongArrayElements(array, val, JNI_ABORT); } ); } //---------------------------------------------------------- jarray JPFloatType::newArrayInstance(int sz) { return JPEnv::getJava()->NewFloatArray(sz); } HostRef* JPFloatType::getStaticValue(jclass c, jfieldID fid, JPTypeName& tgtType) { jvalue v; v.f = JPEnv::getJava()->GetStaticFloatField(c, fid); return asHostObject(v); } HostRef* JPFloatType::getInstanceValue(jobject c, jfieldID fid, JPTypeName& tgtType) { jvalue v; v.f = JPEnv::getJava()->GetFloatField(c, fid); return asHostObject(v); } HostRef* JPFloatType::invokeStatic(jclass claz, jmethodID mth, jvalue* val) { jvalue v; v.f = JPEnv::getJava()->CallStaticFloatMethodA(claz, mth, val); return asHostObject(v); } HostRef* JPFloatType::invoke(jobject obj, jclass clazz, jmethodID mth, jvalue* val) { jvalue v; v.f = JPEnv::getJava()->CallNonvirtualFloatMethodA(obj, clazz, mth, val); return asHostObject(v); } void JPFloatType::setStaticValue(jclass c, jfieldID fid, HostRef* obj) { jfloat val = convertToJava(obj).f; JPEnv::getJava()->SetStaticFloatField(c, fid, val); } void JPFloatType::setInstanceValue(jobject c, jfieldID fid, HostRef* obj) { jfloat val = convertToJava(obj).f; JPEnv::getJava()->SetFloatField(c, fid, val); } vector JPFloatType::getArrayRange(jarray a, int start, int length) { jfloatArray array = (jfloatArray)a; jfloat* val = NULL; jboolean isCopy; JPCleaner cleaner; try { val = JPEnv::getJava()->GetFloatArrayElements(array, &isCopy); vector res; jvalue v; for (int i = 0; i < length; i++) { v.f = val[i+start]; HostRef* pv = asHostObject(v); res.push_back(pv); } JPEnv::getJava()->ReleaseFloatArrayElements(array, val, JNI_ABORT); return res; } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseFloatArrayElements(array, val, JNI_ABORT); } ); } void JPFloatType::setArrayRange(jarray a, int start, int length, vector& vals) { jfloatArray array = (jfloatArray)a; jfloat* val = NULL; jboolean isCopy; JPCleaner cleaner; try { val = JPEnv::getJava()->GetFloatArrayElements(array, &isCopy); for (int i = 0; i < length; i++) { HostRef* pv = vals[i]; val[start+i] = convertToJava(pv).f; } JPEnv::getJava()->ReleaseFloatArrayElements(array, val, 0); } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseFloatArrayElements(array, val, JNI_ABORT); } ); } HostRef* JPFloatType::getArrayItem(jarray a, int ndx) { jfloatArray array = (jfloatArray)a; jfloat* val = NULL; jboolean isCopy; JPCleaner cleaner; try { val = JPEnv::getJava()->GetFloatArrayElements(array, &isCopy); jvalue v; v.f = val[ndx]; JPEnv::getJava()->ReleaseFloatArrayElements(array, val, JNI_ABORT); return asHostObject(v); } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseFloatArrayElements(array, val, JNI_ABORT); } ); } void JPFloatType::setArrayItem(jarray a, int ndx , HostRef* obj) { jfloatArray array = (jfloatArray)a; jfloat* val = NULL; jboolean isCopy; try { val = JPEnv::getJava()->GetFloatArrayElements(array, &isCopy); val[ndx] = convertToJava(obj).f; JPEnv::getJava()->ReleaseFloatArrayElements(array, val, 0); } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseFloatArrayElements(array, val, JNI_ABORT); } ); } //---------------------------------------------------------- jarray JPDoubleType::newArrayInstance(int sz) { return JPEnv::getJava()->NewDoubleArray(sz); } HostRef* JPDoubleType::getStaticValue(jclass c, jfieldID fid, JPTypeName& tgtType) { jvalue v; v.d = JPEnv::getJava()->GetStaticDoubleField(c, fid); return asHostObject(v); } HostRef* JPDoubleType::getInstanceValue(jobject c, jfieldID fid, JPTypeName& tgtType) { jvalue v; v.d = JPEnv::getJava()->GetDoubleField(c, fid); return asHostObject(v); } HostRef* JPDoubleType::invokeStatic(jclass claz, jmethodID mth, jvalue* val) { jvalue v; v.d = JPEnv::getJava()->CallStaticDoubleMethodA(claz, mth, val); return asHostObject(v); } HostRef* JPDoubleType::invoke(jobject obj, jclass clazz, jmethodID mth, jvalue* val) { jvalue v; v.d = JPEnv::getJava()->CallNonvirtualDoubleMethodA(obj, clazz, mth, val); return asHostObject(v); } void JPDoubleType::setStaticValue(jclass c, jfieldID fid, HostRef* obj) { jdouble val = convertToJava(obj).d; JPEnv::getJava()->SetStaticDoubleField(c, fid, val); } void JPDoubleType::setInstanceValue(jobject c, jfieldID fid, HostRef* obj) { jdouble val = convertToJava(obj).d; JPEnv::getJava()->SetDoubleField(c, fid, val); } vector JPDoubleType::getArrayRange(jarray a, int start, int length) { jdoubleArray array = (jdoubleArray)a; jdouble* val = NULL; jboolean isCopy; JPCleaner cleaner; try { val = JPEnv::getJava()->GetDoubleArrayElements(array, &isCopy); vector res; jvalue v; for (int i = 0; i < length; i++) { v.d = val[i+start]; HostRef* pv = asHostObject(v); res.push_back(pv); } JPEnv::getJava()->ReleaseDoubleArrayElements(array, val, JNI_ABORT); return res; } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseDoubleArrayElements(array, val, JNI_ABORT); } ); } void JPDoubleType::setArrayRange(jarray a, int start, int length, vector& vals) { jdoubleArray array = (jdoubleArray)a; jdouble* val = NULL; jboolean isCopy; JPCleaner cleaner; try { val = JPEnv::getJava()->GetDoubleArrayElements(array, &isCopy); for (int i = 0; i < length; i++) { HostRef* pv = vals[i]; val[start+i] = convertToJava(pv).d; } JPEnv::getJava()->ReleaseDoubleArrayElements(array, val, 0); } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseDoubleArrayElements(array, val, JNI_ABORT); } ); } HostRef* JPDoubleType::getArrayItem(jarray a, int ndx) { jdoubleArray array = (jdoubleArray)a; jdouble* val = NULL; jboolean isCopy; JPCleaner cleaner; try { val = JPEnv::getJava()->GetDoubleArrayElements(array, &isCopy); jvalue v; v.d = val[ndx]; JPEnv::getJava()->ReleaseDoubleArrayElements(array, val, JNI_ABORT); return asHostObject(v); } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseDoubleArrayElements(array, val, JNI_ABORT); } ); } void JPDoubleType::setArrayItem(jarray a, int ndx , HostRef* obj) { jdoubleArray array = (jdoubleArray)a; jdouble* val = NULL; jboolean isCopy; try { val = JPEnv::getJava()->GetDoubleArrayElements(array, &isCopy); val[ndx] = convertToJava(obj).d; JPEnv::getJava()->ReleaseDoubleArrayElements(array, val, 0); } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseDoubleArrayElements(array, val, JNI_ABORT); } ); } //---------------------------------------------------------- jarray JPCharType::newArrayInstance(int sz) { return JPEnv::getJava()->NewCharArray(sz); } HostRef* JPCharType::getStaticValue(jclass c, jfieldID fid, JPTypeName& tgtType) { jvalue v; v.c = JPEnv::getJava()->GetStaticCharField(c, fid); return asHostObject(v); } HostRef* JPCharType::getInstanceValue(jobject c, jfieldID fid, JPTypeName& tgtType) { jvalue v; v.c = JPEnv::getJava()->GetCharField(c, fid); return asHostObject(v); } HostRef* JPCharType::invokeStatic(jclass claz, jmethodID mth, jvalue* val) { jvalue v; v.c = JPEnv::getJava()->CallStaticCharMethodA(claz, mth, val); return asHostObject(v); } HostRef* JPCharType::invoke(jobject obj, jclass clazz, jmethodID mth, jvalue* val) { jvalue v; v.c = JPEnv::getJava()->CallNonvirtualCharMethodA(obj, clazz, mth, val); return asHostObject(v); } void JPCharType::setStaticValue(jclass c, jfieldID fid, HostRef* obj) { jchar val = convertToJava(obj).c; JPEnv::getJava()->SetStaticCharField(c, fid, val); } void JPCharType::setInstanceValue(jobject c, jfieldID fid, HostRef* obj) { jchar val = convertToJava(obj).c; JPEnv::getJava()->SetCharField(c, fid, val); } vector JPCharType::getArrayRange(jarray a, int start, int length) { jcharArray array = (jcharArray)a; jchar* val = NULL; jboolean isCopy; JPCleaner cleaner; try { val = JPEnv::getJava()->GetCharArrayElements(array, &isCopy); vector res; jvalue v; for (int i = 0; i < length; i++) { v.c = val[i+start]; HostRef* pv = asHostObject(v); res.push_back(pv); } JPEnv::getJava()->ReleaseCharArrayElements(array, val, JNI_ABORT); return res; } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseCharArrayElements(array, val, JNI_ABORT); } ); } void JPCharType::setArrayRange(jarray a, int start, int length, vector& vals) { jcharArray array = (jcharArray)a; jchar* val = NULL; jboolean isCopy; JPCleaner cleaner; try { val = JPEnv::getJava()->GetCharArrayElements(array, &isCopy); for (int i = 0; i < length; i++) { HostRef* pv = vals[i]; val[start+i] = convertToJava(pv).c; } JPEnv::getJava()->ReleaseCharArrayElements(array, val, 0); } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseCharArrayElements(array, val, JNI_ABORT); } ); } HostRef* JPCharType::getArrayItem(jarray a, int ndx) { jcharArray array = (jcharArray)a; jchar* val = NULL; jboolean isCopy; JPCleaner cleaner; try { val = JPEnv::getJava()->GetCharArrayElements(array, &isCopy); jvalue v; v.c = val[ndx]; JPEnv::getJava()->ReleaseCharArrayElements(array, val, JNI_ABORT); return asHostObject(v); } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseCharArrayElements(array, val, JNI_ABORT); } ); } void JPCharType::setArrayItem(jarray a, int ndx , HostRef* obj) { jcharArray array = (jcharArray)a; jchar* val = NULL; jboolean isCopy; try { val = JPEnv::getJava()->GetCharArrayElements(array, &isCopy); val[ndx] = convertToJava(obj).c; JPEnv::getJava()->ReleaseCharArrayElements(array, val, 0); } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseCharArrayElements(array, val, JNI_ABORT); } ); } //---------------------------------------------------------- jarray JPBooleanType::newArrayInstance(int sz) { return JPEnv::getJava()->NewBooleanArray(sz); } HostRef* JPBooleanType::getStaticValue(jclass c, jfieldID fid, JPTypeName& tgtType) { jvalue v; v.z = JPEnv::getJava()->GetStaticBooleanField(c, fid); return asHostObject(v); } HostRef* JPBooleanType::getInstanceValue(jobject c, jfieldID fid, JPTypeName& tgtType) { jvalue v; v.z = JPEnv::getJava()->GetBooleanField(c, fid); return asHostObject(v); } HostRef* JPBooleanType::invokeStatic(jclass claz, jmethodID mth, jvalue* val) { jvalue v; v.z = JPEnv::getJava()->CallStaticBooleanMethodA(claz, mth, val); return asHostObject(v); } HostRef* JPBooleanType::invoke(jobject obj, jclass clazz, jmethodID mth, jvalue* val) { jvalue v; v.z = JPEnv::getJava()->CallNonvirtualBooleanMethodA(obj, clazz, mth, val); return asHostObject(v); } void JPBooleanType::setStaticValue(jclass c, jfieldID fid, HostRef* obj) { jboolean val = convertToJava(obj).z; JPEnv::getJava()->SetStaticBooleanField(c, fid, val); } void JPBooleanType::setInstanceValue(jobject c, jfieldID fid, HostRef* obj) { jboolean val = convertToJava(obj).z; JPEnv::getJava()->SetBooleanField(c, fid, val); } vector JPBooleanType::getArrayRange(jarray a, int start, int length) { jbooleanArray array = (jbooleanArray)a; jboolean* val = NULL; jboolean isCopy; JPCleaner cleaner; try { val = JPEnv::getJava()->GetBooleanArrayElements(array, &isCopy); vector res; jvalue v; for (int i = 0; i < length; i++) { v.z = val[i+start]; HostRef* pv = asHostObject(v); res.push_back(pv); } JPEnv::getJava()->ReleaseBooleanArrayElements(array, val, JNI_ABORT); return res; } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseBooleanArrayElements(array, val, JNI_ABORT); } ); } void JPBooleanType::setArrayRange(jarray a, int start, int length, vector& vals) { jbooleanArray array = (jbooleanArray)a; jboolean* val = NULL; jboolean isCopy; JPCleaner cleaner; try { val = JPEnv::getJava()->GetBooleanArrayElements(array, &isCopy); for (int i = 0; i < length; i++) { HostRef* pv = vals[i]; val[start+i] = convertToJava(pv).z; } JPEnv::getJava()->ReleaseBooleanArrayElements(array, val, 0); } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseBooleanArrayElements(array, val, JNI_ABORT); } ); } HostRef* JPBooleanType::getArrayItem(jarray a, int ndx) { jbooleanArray array = (jbooleanArray)a; jboolean* val = NULL; jboolean isCopy; JPCleaner cleaner; try { val = JPEnv::getJava()->GetBooleanArrayElements(array, &isCopy); jvalue v; v.z = val[ndx]; JPEnv::getJava()->ReleaseBooleanArrayElements(array, val, JNI_ABORT); return asHostObject(v); } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseBooleanArrayElements(array, val, JNI_ABORT); } ); } void JPBooleanType::setArrayItem(jarray a, int ndx , HostRef* obj) { jbooleanArray array = (jbooleanArray)a; jboolean* val = NULL; jboolean isCopy; try { val = JPEnv::getJava()->GetBooleanArrayElements(array, &isCopy); val[ndx] = convertToJava(obj).z; JPEnv::getJava()->ReleaseBooleanArrayElements(array, val, 0); } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseBooleanArrayElements(array, val, JNI_ABORT); } ); } //---------------------------------------------------------- python-jpype-0.5.4.2/src/python/0000775000175000017500000000000011620747357015746 5ustar takakitakakipython-jpype-0.5.4.2/src/python/jpype/0000775000175000017500000000000011620747357017075 5ustar takakitakakipython-jpype-0.5.4.2/src/python/jpype/_jpackage.py0000666000175000017500000000370411614007722021345 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # 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. # #***************************************************************************** import _jpype import _jclass class JPackage(object) : def __init__(self, name) : self.__name = name def __getattribute__(self, n) : try : return object.__getattribute__(self, n) except : # not found ... # perhaps it is a class? subname = "%s.%s" % (self.__name, n) cc = _jpype.findClass(subname) if cc is None : # can only assume it is a sub-package then ... cc = JPackage(subname) else: cc = _jclass._getClassFor(cc) self.__setattr__(n, cc, True) return cc def __setattr__(self, n, v, intern=False) : if not n[:len("_JPackage")] == '_JPackage' and not intern : # NOTE this shadows name mangling raise RuntimeError, "Cannot set attributes in a package"+n object.__setattr__(self, n, v) def __str__(self) : return "" % self.__name def __call__(self, *arg, **kwarg) : raise TypeError, "Package "+self.__name+" is not Callable" python-jpype-0.5.4.2/src/python/jpype/awt/0000775000175000017500000000000011620747357017670 5ustar takakitakakipython-jpype-0.5.4.2/src/python/jpype/awt/__init__.py0000666000175000017500000000143211614007722021767 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # 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. # #***************************************************************************** import event python-jpype-0.5.4.2/src/python/jpype/awt/event/0000775000175000017500000000000011620747357021011 5ustar takakitakakipython-jpype-0.5.4.2/src/python/jpype/awt/event/__init__.py0000666000175000017500000000145311614007722023113 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # 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. # #***************************************************************************** from WindowAdapter import * python-jpype-0.5.4.2/src/python/jpype/awt/event/WindowAdapter.py0000666000175000017500000000116011614007722024117 0ustar takakitakakiclass WindowAdapter(object) : def __init__(self, *mth, **kw) : object.__init__(self) for i, j in kw.items() : setattr(self, i, j) def windowActivated(self, e) : pass def windowClosed(self, e) : pass def windowClosing(self, e) : pass def windowDeactivated(self, e) : pass def windowDeiconified(self, e) : pass def windowIconified(self, e) : pass def windowOpened(self, e) : pass python-jpype-0.5.4.2/src/python/jpype/_jcollection.py0000666000175000017500000001732511614007722022111 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # 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. # #***************************************************************************** import operator import _jclass def _initialize() : _jclass.registerClassCustomizer(CollectionCustomizer()) _jclass.registerClassCustomizer(ListCustomizer()) _jclass.registerClassCustomizer(MapCustomizer()) _jclass.registerClassCustomizer(IteratorCustomizer()) _jclass.registerClassCustomizer(EnumerationCustomizer()) def isPythonSequence(v): if operator.isSequenceType(v) : if not hasattr(v.__class__, '__metaclass__') or v.__class__.__metaclass__ is _jclass._JavaClass : return True return False def _colLength(self) : return self.size() def _colIter(self) : return self.iterator() def _colDelItem(self, i) : return self.remove(i) def _colAddAll(self, v): if isPythonSequence(v) : r = False for i in v : r = self.add(i) or r return r else: return self._addAll(v) def _colRemoveAll(self, v): if isPythonSequence(v) : r = False for i in v : r = self.remove(i) or r return r else: return self._removeAll(v) def _colRetainAll(self, v): if isPythonSequence(v) : r = _jclass.JClass("java.util.ArrayList")(len(v)) for i in v : r.add(i) else: r = v return self._retainAll(r) class CollectionCustomizer(object) : _METHODS = { '__len__' : _colLength, '__iter__' : _colIter, '__delitem__' : _colDelItem, } def canCustomize(self, name, jc) : if name == 'java.util.Collection' : return True return jc.isSubclass('java.util.Collection') def customize(self, name, jc, bases, members) : if name == 'java.util.Collection' : members.update(CollectionCustomizer._METHODS) else: # AddAll is handled by List if (not jc.isSubclass("java.util.List")) and 'addAll' in members : members['_addAll'] = members['addAll'] members['addAll'] = _colAddAll if 'removeAll' in members : members['_removeAll'] = members['removeAll'] members['removeAll'] = _colRemoveAll if 'retainAll' in members : members['_retainAll'] = members['retainAll'] members['retainAll'] = _colRetainAll def _listGetItem(self, ndx) : if isinstance(ndx, slice) : start = ndx.start stop = ndx.stop if start < 0 : start = self.size() + start if stop < 0 : stop = self.size() + stop return self.subList(start, stop) else: if ndx < 0 : ndx = self.size() + ndx return self.get(ndx) def _listSetItem(self, ndx, v) : if isinstance(ndx, slice) : start = ndx.start stop = ndx.stop if start < 0 : start = self.size() + start if stop < 0 : stop = self.size() + stop for i in range(start, stop) : self.remove(start) if operator.isSequenceType(v) : ndx = start for i in v : self.add(ndx, i) ndx += 1 else: if ndx < 0 : ndx = self.size() + ndx self.set(ndx, v) def _listAddAll(self, v, v2=None): if isPythonSequence(v) : r = False if v2 is not None : # assume form (int, values) for i in range(len(v2)) : r = r or self.add(v+i, v2[i]) ndx +=1 else: for i in v : r = self.add(i) or r return r else: return self._addAll(v) class ListCustomizer(object) : _METHODS = { '__setitem__' : _listSetItem, '__getitem__' : _listGetItem, } def canCustomize(self, name, jc) : if name == 'java.util.List' : return True return jc.isSubclass('java.util.List') def customize(self, name, jc, bases, members) : if name == 'java.util.List' : members.update(ListCustomizer._METHODS) else: if 'addAll' in members : members['_addAll'] = members['addAll'] members['addAll'] = _listAddAll def isPythonMapping(v): if operator.isMappingType(v) : if not hasattr(v.__class__, '__metaclass__') or v.__class__.__metaclass__ is _jclass._JavaClass : return True return False def _mapLength(self) : return self.size() def _mapIter(self) : return self.keySet().iterator() def _mapDelItem(self, i) : return self.remove(i) def _mapGetItem(self, ndx) : return self.get(ndx) def _mapSetItem(self, ndx, v) : self.put(ndx, v) def _mapPutAll(self, v): if isPythonMapping(v) : for i in v : self.put(i, v[i]) else: #do the regular method ... self._putAll(v) class MapCustomizer(object) : _METHODS = { '__len__' : _mapLength, '__iter__' : _mapIter, '__delitem__' : _mapDelItem, '__getitem__' : _mapGetItem, '__setitem__' : _mapSetItem, } def canCustomize(self, name, jc) : if name == 'java.util.Map' : return True return jc.isSubclass('java.util.Map') def customize(self, name, jc, bases, members) : if name == 'java.util.Map' : members.update(MapCustomizer._METHODS) else: if "putAll" in members : members["_putAll"] = members["putAll"] members["putAll"] = _mapPutAll def _iterNext(self) : if self.hasNext() : return self._next() raise StopIteration def _iterIter(self) : return self class IteratorCustomizer(object) : _METHODS = { '__iter__' : _iterIter, } def canCustomize(self, name, jc) : if name == 'java.util.Iterator' : return True return jc.isSubclass('java.util.Iterator') def customize(self, name, jc, bases, members) : if name == 'java.util.Iterator' : members.update(IteratorCustomizer._METHODS) elif jc.isSubclass('java.util.Iterator') and 'next' in members: members['_next'] = members['next'] members['next'] = _iterNext def _enumNext(self) : if self.hasMoreElements() : return self.nextElement() raise StopIteration def _enumIter(self) : return self class EnumerationCustomizer(object) : _METHODS = { 'next' : _enumNext, '__iter__' : _enumIter, } def canCustomize(self, name, jc) : return name == 'java.util.Enumeration' def customize(self, name, jc, bases, members) : members.update(EnumerationCustomizer._METHODS) python-jpype-0.5.4.2/src/python/jpype/nio.py0000666000175000017500000000202011614007722020214 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # 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. # #***************************************************************************** import array import _jpype def _initialize() : pass def convertToDirectBuffer(obj): __doc__ = '''Efficiently convert all array.array types, string and unicode to java.nio.Buffer objects.''' return _jpype.convertToDirectBuffer(obj) python-jpype-0.5.4.2/src/python/jpype/_pykeywords.py0000666000175000017500000000213211614007722022012 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # 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. # #***************************************************************************** import sets KEYWORDS = sets.Set( ( "del", "for", "is", "raise", "assert", "elif", "from", "lambda", "return", "break", "else", "global", "not", "try", "class", "except", "if", "or", "while", "continue", "exec", "import", "pass", "yield", "def", "finally", "in", "print", "as", "None" )) python-jpype-0.5.4.2/src/python/jpype/_refdaemon.py0000666000175000017500000000207411614007722021537 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # 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. # #***************************************************************************** import thread import _jpype def startJava(): _jpype.startReferenceQueue(1) def startPython(): def _run() : _jpype.attachThreadToJVM() _jpype.startReferenceQueue(0) thread.start_new_thread(_run, tuple()) def stop(): _jpype.stopReferenceQueue()python-jpype-0.5.4.2/src/python/jpype/_windows.py0000666000175000017500000000243111614007722021266 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # 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. # #***************************************************************************** import _winreg def getDefaultJVMPath() : try : jreKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\JavaSoft\Java Runtime Environment") cv = _winreg.QueryValueEx(jreKey, "CurrentVersion") versionKey = _winreg.OpenKey(jreKey, cv[0]) _winreg.CloseKey(jreKey) cv = _winreg.QueryValueEx(versionKey, "RuntimeLib") _winreg.CloseKey(versionKey) return cv[0] except WindowsError, ex : pass return Nonepython-jpype-0.5.4.2/src/python/jpype/_properties.py0000666000175000017500000000271011614007722021770 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # 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. # #***************************************************************************** import _jclass, _jpype def _initialize() : _jclass.registerClassCustomizer(PropertiesCustomizer()) class PropertiesCustomizer(object) : def canCustomize(self, name, jc) : return True def customize(self, name, jc, bases, members) : gets = {} sets = {} for i in members : if not isinstance(members[i], _jpype._JavaMethod) : continue if i[:3] == 'get' : if len(i) > 3 and members[i].isBeanAccessor() : gets[i[3:]] = members[i] elif i[:3] == 'set' : if len(i) > 3 and members[i].isBeanMutator() : sets[i[3:]] = members[i] for i in gets : members[i[0].lower()+i[1:]] = property(gets[i], sets.get(i, None)) python-jpype-0.5.4.2/src/python/jpype/_jarray.py0000666000175000017500000001046011614007722021065 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # 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. # #***************************************************************************** import operator import _jpype import _jclass import _jwrapper _CLASSES = {} _CUSTOMIZERS = [] def _initialize() : _jpype.setJavaArrayClass(_JavaArrayClass) _jpype.setGetJavaArrayClassMethod(_getClassFor) registerArrayCustomizer(CharArrayCustomizer()) registerArrayCustomizer(ByteArrayCustomizer()) def registerArrayCustomizer(c) : _CUSTOMIZERS.append(c) class _JavaArrayClass(object) : def __init__(self, jo) : self.__javaobject__ = jo def __str__(self) : return str(tuple(self)) def __len__(self) : return _jpype.getArrayLength(self.__javaobject__) def __iter__(self) : return _JavaArrayIter(self) def __getitem__(self, ndx ) : return _jpype.getArrayItem(self.__javaobject__, ndx) def __setitem__(self, ndx, val) : _jpype.setArrayItem(self.__javaobject__, ndx, val) def __getslice__(self, i, j) : return _jpype.getArraySlice(self.__javaobject__, i, j) def __setslice__(self, i, j, v) : _jpype.setArraySlice(self.__javaobject__, i, j, v) def _jarrayInit(self, *args) : if len(args) == 2 and args[0] == _jclass._SPECIAL_CONSTRUCTOR_KEY : _JavaArrayClass.__init__(self, args[1]) elif len(args) != 1 : raise ParameterException, "Array classes only take 2 parameters, %s given" % (len(args)+1,) else: values = None if operator.isSequenceType(args[0]) : sz = len(args[0]) values = args[0] else : sz = args[0] _JavaArrayClass.__init__(self, _jpype.newArray(self.__class__.__javaclass__, sz)) if values is not None : _jpype.setArrayValues(self.__javaobject__, values) class _JavaArrayIter(object) : def __init__(self, a) : self._array = a self._ndx = -1 def __iter__(self) : return self def next(self) : self._ndx += 1 if self._ndx >= len(self._array) : raise StopIteration return self._array[self._ndx] class _JavaArray(type) : pass def _defineArrayClass(name, jt): members = { "__init__" : _jarrayInit, "__javaclass__" : jt, } bases = [_JavaArrayClass] for i in _CUSTOMIZERS : if i.canCustomize(name, jt) : i.customize(name, jt, bases, members) return _JavaArray(name, tuple(bases), members) def _getClassFor(name) : if not _CLASSES.has_key(name) : jc = _jpype.findArrayClass(name) _CLASSES[name] = _defineArrayClass(name, jc) return _CLASSES[name] def JArray(t, ndims=1) : if issubclass(t, _jwrapper._JWrapper) : t = t.typeName elif isinstance(t, _JavaArray) : t = t.typeName elif issubclass(t, _jclass._JAVAOBJECT): t = t.__name__ elif not isinstance(t, str) and not isinstance(t, unicode) : raise TypeError, "Argument must be a java class, java array class, java wrapper or string represeing a java class" arrayTypeName = t + ('[]'*ndims) return _getClassFor(arrayTypeName) def _charArrayStr(self) : return ''.join(self) def _charArrayUnicode(self) : return u''.join(self) class CharArrayCustomizer(object) : def canCustomize(self, name, jc) : if name == 'char[]' : return True return False def customize(self, name, jc, bases, members) : members['__str__'] = _charArrayStr members['__unicode__'] = _charArrayUnicode def _byteArrayStr(self) : s = _jclass.JClass('java.lang.String')(self) return s.toString() class ByteArrayCustomizer(object) : def canCustomize(self, name, jc) : if name == 'byte[]' : return True return False def customize(self, name, jc, bases, members) : members['__str__'] = _byteArrayStr python-jpype-0.5.4.2/src/python/jpype/__init__.py0000666000175000017500000000217411614007722021200 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # 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. # #***************************************************************************** from _jpackage import * from _jclass import * from _jarray import * from _jwrapper import * from _jproxy import * from _jexception import * from _core import * from _gui import * import reflect import nio import JClassUtil def JIterator(it) : """Deprecated""" return it java = JPackage("java") javax = JPackage("javax") python-jpype-0.5.4.2/src/python/jpype/_jwrapper.py0000666000175000017500000000520311614007722021426 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # 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. # #***************************************************************************** import _jpype import _jclass def _initialize() : _jpype.setWrapperClass(_JWrapper) _jpype.setStringWrapperClass(JString) class _JWrapper(object) : def __init__(self, v) : if v is not None : self._value = _jpype.convertToJValue(self.typeName, v) else: self._value = None class JByte(_JWrapper) : typeName = "byte" class JInt(_JWrapper) : typeName = "int" class JLong(_JWrapper) : typeName = "long" class JFloat(_JWrapper) : typeName = "float" class JDouble(_JWrapper) : typeName = "double" class JChar(_JWrapper) : typeName = "char" class JBoolean(_JWrapper) : typeName = "boolean" class JString(_JWrapper) : typeName = "java.lang.String" def _getDefaultTypeName(obj) : if obj is True or obj is False : return 'java.lang.Boolean' if isinstance(obj, str) or isinstance(obj, unicode) : return "java.lang.String" if isinstance(obj, int) : return "java.lang.Integer" if isinstance(obj, long) : return "java.lang.Long" if isinstance(obj, float) : return "java.lang.Double" if isinstance(obj, _jclass._JavaClass) : return obj.__javaclassname__ if isinstance(obj, _jclass.java.lang.Class) : return obj.__class__.__javaclass__.getName() if instance(obj, _JWrapper) : return obj.typeName raise RuntimeException, "Unable to determine the default type of "+obj.__class__ class JObject(_JWrapper) : def __init__(self, v, tp = None) : if tp is None : tp = _getDefaultTypeName(v) if isinstance(tp, _jclass._JavaClass) : tp = tp.__javaclass__.getName() self.typeName = tp self._value = _jpype.convertToJValue(tp, v)python-jpype-0.5.4.2/src/python/jpype/findjvm.py0000666000175000017500000000157111614007722021076 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # 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. # #***************************************************************************** import jpype, os.path jvmlib = jpype.getDefaultJVMPath() print os.path.dirname(os.path.dirname(jvmlib)) python-jpype-0.5.4.2/src/python/jpype/_jproxy.py0000666000175000017500000000472711614007722021141 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # 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. # #***************************************************************************** import _jpype, _jclass, JClassUtil import operator def _initialize() : _jpype.setProxyClass(JProxy) class JProxy(object) : def __init__(self, intf, dict=None, inst=None) : actualIntf = None if isinstance(intf, str) or isinstance(intf, unicode) : actualIntf = [ _jclass.JClass(intf) ] elif isinstance(intf, _jclass._JavaClass) : actualIntf = [ intf ] elif operator.isSequenceType(intf) : actualIntf = [] for i in intf : if isinstance(i, str) or isinstance(i, unicode) : actualIntf.append(_jclass.JClass(i)) elif isinstance(i, _jclass._JavaClass) : actualIntf.append(i) else: raise TypeError, "JProxy requires java interface classes or the names of java interfaces classes" else: raise TypeError, "JProxy requires java interface classes or the names of java interfaces classes" for i in actualIntf : if not JClassUtil.isInterface(i) : raise TypeError, "JProxy requires java interface classes or the names of java interfaces classes : "+i.__name__ if dict is not None and inst is not None : raise RuntimeError, "Specify only one of dict and inst" self._dict = dict self._inst = inst self._proxy = _jpype.createProxy(self, actualIntf) def getCallable(self, name) : if self._dict is not None : return self._dict[name] else : return getattr(self._inst, name) python-jpype-0.5.4.2/src/python/jpype/_darwin.py0000666000175000017500000000165611614007722021070 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # 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. # #***************************************************************************** def getDefaultJVMPath() : # on darwin, the JVM is always in the same location it seems ... return '/System/Library/Frameworks/JavaVM.framework/JavaVM'python-jpype-0.5.4.2/src/python/jpype/reflect.py0000666000175000017500000000420511614007722021062 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # 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. # #***************************************************************************** import _jpype def _initialize() : pass def getConstructors(clas): return clas.__javaclass__.getConstructors() def getDeclaredConstructors(clas): return clas.__javaclass__.getDeclaredConstructors() def getDeclaredFields(clas) : '''Returns an array of Field objects reflecting all the fields declared by the class or interface represented by this Class object.''' return clas.__javaclass__.getDeclaredFields() def getDeclaredMethods(clas): '''Returns an array of Method objects reflecting all the methods declared by the class or interface represented by this Class object.''' return clas.__javaclass__.getDeclaredMethods() def getFields(clas): '''Returns an array containing Field objects reflecting all the accessible public fields of the class or interface represented by this Class object.''' return clas.__javaclass__.getFields() def getMethods(clas): '''Returns an array containing Method objects reflecting all the public member methods of the class or interface represented by this Class object, including those declared by the class or interface and those inherited from superclasses and superinterfaces.''' return clas.__javaclass__.getMethods() def getModifiers(clas): '''Returns the Java language modifiers for this class or interface, encoded in an integer.''' return clas.__javaclass__.getModifiers()python-jpype-0.5.4.2/src/python/jpype/JClassUtil.py0000666000175000017500000000166011614007722021455 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # 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. # #***************************************************************************** import _jclass def isInterface(t) : if not isinstance(t, _jclass._JavaClass) : return False return t.__javaclass__.isInterface() python-jpype-0.5.4.2/src/python/jpype/_linux.py0000666000175000017500000000472311614007722020741 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # 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. # #***************************************************************************** import os, re _KNOWN_LOCATIONS = [ ("/opt/sun/", re.compile(r"j2sdk(.+)/jre/lib/i386/client/libjvm.so") ), ("/usr/java/", re.compile(r"j2sdk(.+)/jre/lib/i386/client/libjvm.so") ), ("/usr/java/", re.compile(r"jdk(.+)/jre/lib/i386/client/libjvm.so") ), ] JRE_ARCHS = [ "amd64/server/libjvm.so", "i386/client/libjvm.so", "i386/server/libjvm.so", ] def getDefaultJVMPath() : jvm = _getJVMFromJavaHome() if jvm is not None : return jvm #on linux, the JVM has to be in the LD_LIBRARY_PATH anyway, so might as well inspect it first jvm = _getJVMFromLibPath() if jvm is not None : return jvm # failing that, lets look in the "known" locations for i in _KNOWN_LOCATIONS : # TODO pass return "/usr/java/jre1.5.0_05/lib/i386/client/libjvm.so" def _getJVMFromJavaHome(): java_home = os.getenv("JAVA_HOME") rootJre = None if os.path.exists(java_home+"/bin/javac") : # this is a JDK home rootJre = java_home + '/jre/lib' elif os.path.exists(java_home+"/bin/java") : # this is a JRE home rootJre = java_home + '/lib' else: return None for i in JRE_ARCHS : if os.path.exists(rootJre+"/"+i) : return rootJre+"/"+i return None def _getJVMFromLibPath() : if 'LD_LIBRARY_PATH' in os.environ : libpath = os.environ['LD_LIBRARY_PATH'] if libpath is None : return None paths = libpath.split(os.pathsep) for i in paths : if i.find('jre') != -1 : # this could be it! # TODO pass return None python-jpype-0.5.4.2/src/python/jpype/_core.py0000666000175000017500000000614011614007722020525 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # 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. # #***************************************************************************** import sys import _jpype import _jclass import _jarray import _jwrapper import _jproxy import _jexception import _jcollection import _jobject import _properties import nio import reflect import _refdaemon _usePythonThreadForDaemon = False def setUsePythonThreadForDeamon(v): global _usePythonThreadForDaemon _usePythonThreadForDaemon = v def isJVMStarted() : return _jpype.isStarted() def startJVM(jvm, *args) : _jpype.startup(jvm, tuple(args), True) _jclass._initialize() _jarray._initialize() _jwrapper._initialize() _jproxy._initialize() _jexception._initialize() _jcollection._initialize() _jobject._initialize() _properties._initialize() nio._initialize() reflect._initialize() # start the reference deamon thread if _usePythonThreadForDaemon : _refdaemon.startPython() else: _refdaemon.startJava() def attachToJVM(jvm) : _jpype.attach(jvm) _jclass._initialize() _jarray._initialize() _jwrapper._initialize() _jproxy._initialize() _jexception._initialize() _jcollection._initialize() _jobject._initialize() _properties._initialize() def shutdownJVM() : _refdaemon.stop() _jpype.shutdown() def isThreadAttachedToJVM() : return _jpype.isThreadAttachedToJVM() def attachThreadToJVM() : _jpype.attachThreadToJVM() def detachThreadFromJVM() : _jpype.detachThreadFromJVM() def getDefaultJVMPath() : if sys.platform == "win32" : import _windows return _windows.getDefaultJVMPath() elif sys.platform == "darwin" : import _darwin return _darwin.getDefaultJVMPath() else: import _linux return _linux.getDefaultJVMPath() class ConversionConfigClass(object): def __init__(self): self._convertString = 1 def _getConvertString(self): return self._convertString def _setConvertString(self, value): if value : self._convertString = 1 else: self._convertString = 0 _jpype.setConvertStringObjects(self._convertString) string = property(_getConvertString, _setConvertString, None ) ConversionConfig = ConversionConfigClass() python-jpype-0.5.4.2/src/python/jpype/_gui.py0000666000175000017500000000240211614007722020356 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # 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. # #***************************************************************************** import sys import _core import _jproxy import _jclass def setupGuiEnvironment(cb): if sys.platform == 'darwin' : from PyObjCTools import AppHelper m = {'run' : cb} proxy = _jproxy.JProxy('java.lang.Runnable', m) cbthread = _jclass.JClass("java.lang.Thread")(proxy) cbthread.start() AppHelper.runConsoleEventLoop() else: cb() def shutdownGuiEnvironment() : if sys.platform == 'darwin' : from PyObjCTools import AppHelper AppHelper.stopEventLoop() python-jpype-0.5.4.2/src/python/jpype/_jexception.py0000666000175000017500000000427611614007722021755 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # 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. # #***************************************************************************** import _jclass, _jpype import new _CLASSES = {} def JException(t) : return t.PYEXC class JavaException(Exception) : def __init__(self, *data) : if isinstance(data[0], tuple) and data[0][0] is _jclass._SPECIAL_CONSTRUCTOR_KEY : # this is wrapped : self.__javaobject__ = data[0][1] self.__javaclass__ = self.__javaobject__.__class__ else: self.__javaclass__ = _jclass.JClass(self.__class__.JAVACLASSNAME) self.__javaobject__ = self.__javaclass__(*data) Exception.__init__(self, self.__javaobject__) def javaClass(self) : return self.__javaclass__ def message(self) : return self.__javaobject__.getMessage() def stacktrace(self) : StringWriter = _jclass.JClass("java.io.StringWriter") PrintWriter = _jclass.JClass("java.io.PrintWriter") sw = StringWriter() pw = PrintWriter(sw) self.__javaobject__.printStackTrace(pw) pw.flush() r = sw.toString() sw.close() return r def __str__(self) : return self.__javaobject__.toString() def _initialize() : _jpype.setJavaExceptionClass(JavaException) def _makePythonException(name, bc) : name = bc.getName() if _CLASSES.has_key(name) : return _CLASSES[name] if name == 'java.lang.Throwable' : bases = (JavaException,) else: bases = (_makePythonException(bc.getName(), bc.getBaseClass()) ,) ec = new.classobj(name+"PyRaisable", bases, {'JAVACLASSNAME' : name}) return ec python-jpype-0.5.4.2/src/python/jpype/_jclass.py0000666000175000017500000001223611614007722021057 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # 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. # #***************************************************************************** import _jpype, _jexception, _jcollection from _pykeywords import KEYWORDS import sets _CLASSES = {} _SPECIAL_CONSTRUCTOR_KEY = "This is the special constructor key" _JAVAOBJECT = None _JAVATHROWABLE = None _COMPARABLE = None _RUNTIMEEXCEPTION = None _CUSTOMIZERS = [] _COMPARABLE_METHODS = { "__cmp__" : lambda self, o : self.compareTo(o) } def _initialize() : global _COMPARABLE, _JAVAOBJECT, _JAVATHROWABLE, _RUNTIMEEXCEPTION import _jpackage _JAVAOBJECT = JClass("java.lang.Object") _JAVATHROWABLE = JClass("java.lang.Throwable") _RUNTIMEEXCEPTION = JClass("java.lang.RuntimeException") _jpype.setJavaLangObjectClass(_JAVAOBJECT) _jpype.setGetClassMethod(_getClassFor) _jpype.setSpecialConstructorKey(_SPECIAL_CONSTRUCTOR_KEY) def registerClassCustomizer(c) : _CUSTOMIZERS.append(c) def JClass(name) : jc = _jpype.findClass(name) if jc is None : raise _RUNTIMEEXCEPTION.PYEXC("Class %s not found" % name) return _getClassFor(jc) def _getClassFor(javaClass) : name = javaClass.getName() if _CLASSES.has_key(name) : return _CLASSES[name] pyJavaClass = _JavaClass(javaClass) _CLASSES[name] = pyJavaClass return pyJavaClass def _javaNew(self, *args) : return object.__new__(self) def _javaExceptionNew(self, *args) : return Exception.__new__(self) def _javaInit(self, *args) : object.__init__(self) if len(args) == 1 and isinstance(args[0], tuple) and args[0][0] is _SPECIAL_CONSTRUCTOR_KEY : self.__javaobject__ = args[0][1] else: self.__javaobject__ = self.__class__.__javaclass__.newClassInstance(*args) def _javaGetAttr(self, name) : try : r = object.__getattribute__(self, name) except AttributeError, ex : if name in dir(self.__class__.__metaclass__) : r = object.__getattribute__(self.__class__, name) else: raise ex if isinstance(r, _jpype._JavaMethod) : return _jpype._JavaBoundMethod(r, self) return r class _JavaClass(type) : def __new__(mcs, jc) : bases = [] name = jc.getName() static_fields = {} constants = [] members = { "__javaclass__" : jc, "__init__" : _javaInit, "__str__" : lambda self : self.toString(), "__hash__" : lambda self : self.hashCode(), "__eq__" : lambda self, o : self.equals(o), "__ne__" : lambda self, o : not self.equals(o), "__getattribute__" : _javaGetAttr, } if name == 'java.lang.Object' or jc.isPrimitive(): bases.append(object) elif not jc.isInterface() : bjc = jc.getBaseClass(jc) bases.append( _getClassFor(bjc) ) if _JAVATHROWABLE is not None and jc.isSubclass("java.lang.Throwable") : members["PYEXC"] = _jexception._makePythonException(name, bjc) itf = jc.getBaseInterfaces() for ic in itf : bases.append( _getClassFor(ic) ) if len(bases) == 0 : bases.append(_JAVAOBJECT) # add the fields fields = jc.getClassFields() for i in fields : fname = i.getName() if fname in KEYWORDS : fname = fname + "_" if i.isStatic() : g = lambda self, fld=i : fld.getStaticAttribute() s = None if not i.isFinal() : s = lambda self, v, fld=i : fld.setStaticAttribute(v) static_fields[fname] = property(g, s) else: g = lambda self, fld=i : fld.getInstanceAttribute(self.__javaobject__) s = None if not i.isFinal() : s = lambda self, v, fld=i : fld.setInstanceAttribute(self.__javaobject__, v) members[fname] = property(g, s) # methods methods = jc.getClassMethods() # return tuple of tuple (name, method) for jm in methods : mname = jm.getName() if mname in KEYWORDS : mname = mname + "_" members[mname] = jm for i in _CUSTOMIZERS : if i.canCustomize(name, jc) : i.customize(name, jc, bases, members) # remove multiple bases that would cause a MRO problem toRemove = sets.Set() for c in bases : for d in bases : if c == d : continue if issubclass(c, d) : toRemove.add(d) for i in toRemove : bases.remove(i) # Prepare the meta-metaclass meta_bases = [] for i in bases : if i is object : meta_bases.append(mcs) else: meta_bases.append(i.__metaclass__) metaclass = type.__new__(type, name+"$$Static", tuple(meta_bases), static_fields) members['__metaclass__'] = metaclass result = type.__new__(metaclass, name, tuple(bases), members) return result python-jpype-0.5.4.2/src/python/jpype/_jobject.py0000666000175000017500000000221711614007722021216 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # 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. # #***************************************************************************** import _jclass def _initialize() : _jclass.registerClassCustomizer(ComparableCustomizer()) class ComparableCustomizer(object) : _METHODS = { "__cmp__" : lambda self, o : self.compareTo(o) } def canCustomize(self, name, jc) : return name == 'java.lang.Comparable' def customize(self, name, jc, bases, members) : members.update(ComparableCustomizer._METHODS)python-jpype-0.5.4.2/src/python/jpypex/0000775000175000017500000000000011620747357017265 5ustar takakitakakipython-jpype-0.5.4.2/src/python/jpypex/swing/0000775000175000017500000000000011620747357020414 5ustar takakitakakipython-jpype-0.5.4.2/src/python/jpypex/swing/AbstractAction.py0000666000175000017500000000420111614007722023652 0ustar takakitakakifrom jpype import *; class AbstractAction(object) : ACCELERATOR_KEY = javax.swing.Action.ACCELERATOR_KEY ACTION_COMMAND_KEY = javax.swing.Action.ACTION_COMMAND_KEY DEFAULT = javax.swing.Action.DEFAULT LONG_DESCRIPTION = javax.swing.Action.LONG_DESCRIPTION MNEMONIC_KEY = javax.swing.Action.MNEMONIC_KEY NAME = javax.swing.Action.NAME SHORT_DESCRIPTION = javax.swing.Action.SHORT_DESCRIPTION SMALL_ICON = javax.swing.Action.SMALL_ICON def __init__(self, cb, name=None, icon=None) : object.__init__(self) self.__proxy = JProxy(javax.swing.Action, inst=self) self.__values = {} self.__cb = cb self.__listeners = [] self.__enabled = True if name is not None : self.putValue(AbstractAction.NAME, name) if icon is not None : self.putValue(AbstractAction.SMALL_ICON, icon) proxy = property(lambda self : self.__proxy) def addPropertyChangeListener(self, listener) : self.__listeners.append(listener) def getValue(self, key) : return self.__values.get(key, None) def isEnabled(self) : if self.__enabled : return True return False def putValue(self, key, value) : oldVal = self.__values.get(key, None) if oldVal != value : self.__values[key] = value self.__notify(key, oldVal, value) def removePropertyChangeListener(self,listener) : self.__listeners.remove(listener) def setEnabled(self,b) : if (b and not self.__enabled) or ( not b and self.__enabled) : self.__enabled = b self.__notify("enabled", java.lang.Boolean(not b), java.lang.Boolean(b)) def actionPerformed(self, ev) : self.__cb(ev) def __notify(self, k, oldVal, newVal) : ev = java.beans.PropertyChangeEvent(self.__proxy, k, oldVal, newVal) for i in self.__listeners : i.propertyChange(ev) python-jpype-0.5.4.2/src/python/jpypex/swing/__init__.py0000666000175000017500000000147011614007722022515 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # 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. # #***************************************************************************** from AbstractAction import * python-jpype-0.5.4.2/src/python/jpypex/swing/pyutils.py0000666000175000017500000000117211614007722022466 0ustar takakitakakiimport sys from jpype import * __JMenuBar = javax.swing.JMenuBar __JMenu = javax.swing.JMenu def buildMenuBar(menuDef) : mb = __JMenuBar() for i in menuDef : jm = buildMenu(i[0], i[1]) mb.add( JObject(jm, __JMenu) ) return mb def buildMenu(name, menuDef) : jm = __JMenu(name) for i in menuDef : if i is None : jm.addSeparator() elif isinstance(i, list) or isinstance(i, tuple) : jm2 = buildMenu(i[0], i[1]) jm.add(jm2) else: jm.add(i.proxy) return jmpython-jpype-0.5.4.2/src/python/jpypex/__init__.py0000666000175000017500000000145011614007722021364 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # 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. # #***************************************************************************** import swing python-jpype-0.5.4.2/examples/0000775000175000017500000000000011620747357015454 5ustar takakitakakipython-jpype-0.5.4.2/examples/rmi.py0000666000175000017500000000227511614007722016611 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # 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. # #***************************************************************************** #the hava classes used are defined the the test harness. the class jpype.rmi.ServerImpl must be started before this script can be run. from jpype import * import os.path root = os.path.abspath(os.path.dirname(__file__)) startJVM(getDefaultJVMPath(), "-ea", "-Djava.class.path=%s/../test/classes" % root) p = java.rmi.Naming.lookup("rmi://localhost:2004/server") print p, p.__class__ p.callRemote() shutdownJVM()python-jpype-0.5.4.2/examples/jms/0000775000175000017500000000000011620747357016245 5ustar takakitakakipython-jpype-0.5.4.2/examples/jms/testJpypeSubscriber.py0000666000175000017500000000264511614007722022627 0ustar takakitakakifrom jpype import * import time def pySubscriber (proxy, javaNamingFactory="weblogic.jndi.WLInitialContextFactory", javaNamingProvider="t3://158.188.40.21:7001", connectionFactory="weblogic.jms.ConnectionFactory", topicName="defaultTopic"): return messaging.JpypeSubscriber(proxy,javaNamingFactory,javaNamingProvider, connectionFactory,topicName) ## Startup Jpype and import the messaging java package startJVM("C:\\program files\\Java\\j2re1.4.2_02\\bin\\client\\jvm.dll", "-Djava.class.path=D:/jIRAD/JpypeJMS/src;D:/jIRAD/JpypeJMS/classes;C:/bea/weblogic81/server/lib/weblogic.jar") messaging = JPackage('messaging') # Setup the JProxy for the messaging.JpypeSubscriberCallback interface class pyCallback: startTime = 0 count = 0 def onMessage (self,text): print text if text=='Start': pyCallback.startTime=time.time() pyCallback.count = 0 elif text=='Stop': print "Message Rate =",float(pyCallback.count)/(time.time()-pyCallback.startTime) else: pyCallback.count += 1 c = pyCallback() proxy = JProxy(messaging.JpypeSubscriberCallback,inst=c) # Get a subscriber sub = pySubscriber(proxy) print "Listening..." # Prevent this thread from exiting time.sleep(1000) # exit shutdownJVM() python-jpype-0.5.4.2/examples/jms/README.TXT0000666000175000017500000000374411614007722017601 0ustar takakitakakiThis example of using JPype and JMS contributed by David Morgenthaler Here is the message that accompanied it when he posted it on comp.lang.python : ============================================================================= Your question intrigued me, so I gave it a try. And the anwer (at least for JMS Publish/Subscribe TextMessages) is YES. It includes: - Java classes for a publisher (src/messaging/JpypePublisher) and a subscriber (src/messaging/JpypeSubscriber). These Java classes, which do most of the dirty work of connecting to the JMS server, are used from python via jpype. - Java classes that test the publisher and subscriber (src/messaging/testJpepePublisher, src/messaging/testJpypeSubscriber) - A Java interface that is used by python for the JProxy - python scripts for publishing and subscribing - An build.xml for ant to build and run the Java classes The Java and python publishers and subscribers work in any reasonable combination (J pub/J sub, J pub/p sub, p pub/p sub, p pub/J sub, and even with multiple subscribers) Copy conveniently located folder. You'll find a build.xml for ant to build the Java. You'll have to edit (in the testers and in the python scripts) the naming and connection factory stuff for your situation. You'll also have to edit the python scripts to correctly locate your jvm and other classpath information. Once you're correctly configured, you can use ant to build and/or execute the Java (type "ant help"). And once the Java is built, you can try the python versions. I can't imagine that this approach wouldn't work for JMS Queues. And while I haven't tested it, I don't see anything preventing the use of other message types (BinaryMessage, ObjectMessage,...). BTW, I don't detect any noticable slowdown in the python versions from the Java versions (probably because of the strightforward conversion of python strings to Java Strings). =============================================================================python-jpype-0.5.4.2/examples/jms/testJpypePublisher.py0000666000175000017500000000227511614007722022460 0ustar takakitakakifrom jpype import * import time NUMMSGS = 10 def pyPublisher (javaNamingFactory="weblogic.jndi.WLInitialContextFactory", javaNamingProvider="t3://158.188.40.21:7001", connectionFactory="weblogic.jms.ConnectionFactory", topicName="defaultTopic"): return messaging.JpypePublisher(javaNamingFactory,javaNamingProvider, connectionFactory,topicName) ## Startup Jpype and import the messaging java package startJVM("C:\\program files\\Java\\j2re1.4.2_02\\bin\\client\\jvm.dll", "-Djava.class.path=D:/jIRAD/JpypeJMS/src;D:/jIRAD/JpypeJMS/classes;C:/bea/weblogic81/server/lib/weblogic.jar") messaging = JPackage('messaging') # Get a publisher publisher = pyPublisher() ## Timing test # The "Start" message signals the subscriber to start timing message receipts publisher.publish("Start") t0 = time.time() for i in range(NUMMSGS): publisher.publish("Hello World! %s"%i) print "MessageRate =",float(NUMMSGS)/(time.time()-t0) # The "Stop" message signals the subscriber to stop timing message receipts publisher.publish("Stop") # Close and quit publisher.close() shutdownJVM() python-jpype-0.5.4.2/examples/linux/0000775000175000017500000000000011620747357016613 5ustar takakitakakipython-jpype-0.5.4.2/examples/linux/README.TXT0000666000175000017500000000163111614007722020140 0ustar takakitakakiThe 2 scripts in this derectory are here to resolve a weakness in the linux implementation. Since the JVM is loaded dynamically, the LD_LIBRARY_PATH may not contain the proper directories. Unfortunately, dlopen() will ignore any changes made to the LD_LIBRARY_PATH in the current process. The jpype.sh is meant as an example for people redistributing apps using jpype. Instead of having users launch python script.py directly, have then launch script.sh. The companion finjvm.py can be delivered along your app, but is also present in the ptyhon distribution of jpype. Developpers are encouraged to make their lives simpler by adding the correct directories to their LD_LIBRARY_PATH directly. To learn more about the dlopen problem, you can look at : http://forum.java.sun.com/thread.jsp?forum=52&thread=303583&message=1210441 and http://www.nathanr.net/diary/index.php?year=2004&month=05 python-jpype-0.5.4.2/examples/linux/jpype.sh0000666000175000017500000000174611614007722020274 0ustar takakitakaki#!/bin/sh #***************************************************************************** # Copyright 2004-2008 Steve Menard # # 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. # #***************************************************************************** # # this script contributed by Dave Kuhlman, and modified By Steve menard # export JAVA_LIB_PATH=`python findjvm.py` export LD_LIBRARY_PATH=LD_LIBRARY_PATH:$JAVA_LIB_PATH:$JAVA_LIB_PATH/client python $*python-jpype-0.5.4.2/examples/linux/findjvm.py0000666000175000017500000000157111614007722020614 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # 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. # #***************************************************************************** import jpype, os.path jvmlib = jpype.getDefaultJVMPath() print os.path.dirname(os.path.dirname(jvmlib)) python-jpype-0.5.4.2/setup.py0000666000175000017500000000652711614231174015350 0ustar takakitakakifrom distutils.core import setup as distSetup, Extension import os, os.path, sys class JPypeSetup(object): def __init__(self) : self.extra_compile_args = [] self.macros = [] def setupFiles(self) : cpp_files = [ map(lambda x : "src/native/common/"+x, os.listdir("src/native/common")), map(lambda x : "src/native/python/"+x, os.listdir("src/native/python")), ] all_src = [] for i in cpp_files : all_src += i self.cpp = filter(lambda x : x[-4:] == '.cpp', all_src) self.objc = filter(lambda x : x[-2:] == '.m', all_src) def setupWindows(self): print 'Choosing the Windows profile' self.javaHome = os.getenv("JAVA_HOME") if self.javaHome is None : print "environment variable JAVA_HOME must be set" sys.exit(-1) self.jdkInclude = "win32" self.libraries = ["Advapi32"] self.libraryDir = [self.javaHome+"/lib"] self.macros = [ ("WIN32",1) ] self.extra_compile_args = ['/EHsc'] def setupMacOSX(self): self.javaHome = '/Library/Java/Home' self.jdkInclude = "" self.libraries = ["dl"] self.libraryDir = [self.javaHome+"/lib"] self.macros = [('MACOSX',1)] def setupLinux(self): self.javaHome = os.getenv("JAVA_HOME") if self.javaHome is None : self.javaHome = '/usr/lib/jvm/java-1.5.0-sun-1.5.0.08' # Ubuntu linux # self.javaHome = '/usr/java/jdk1.5.0_05' self.jdkInclude = "linux" self.libraries = ["dl"] self.libraryDir = [self.javaHome+"/lib"] def setupPlatform(self): if sys.platform == 'win32' : self.setupWindows() elif sys.platform == 'darwin' : self.setupMacOSX() else: self.setupLinux() def setupInclusion(self): self.includeDirs = [ self.javaHome+"/include", self.javaHome+"/include/"+self.jdkInclude, "src/native/common/include", "src/native/python/include", ] def setup(self): self.setupFiles() self.setupPlatform() self.setupInclusion() jpypeLib = Extension("_jpype", self.cpp, libraries=self.libraries, define_macros=self.macros, include_dirs=self.includeDirs, library_dirs=self.libraryDir, extra_compile_args=self.extra_compile_args ) distSetup( name="JPype", version="0.5.4.2", description="Python-Java bridge", author="Steve Menard", author_email="devilwolf@users.sourceforge.net", url="http://jpype.sourceforge.net/", packages=[ "jpype", 'jpype.awt', 'jpype.awt.event', 'jpypex', 'jpypex.swing'], package_dir={ "jpype" : "src/python/jpype", 'jpypex' : 'src/python/jpypex', }, ext_modules=[jpypeLib] ) JPypeSetup().setup()python-jpype-0.5.4.2/README.txt0000666000175000017500000000222111614007722015317 0ustar takakitakakiWhat is JPype : --------------- JPype is an effort to allow python programs full access to java class libraries. This is achieved not through re-implementing Python, as Jython/JPython has done, but rather through interfacing at the native level in both Virtual Machines. Eventually, it should be possible to replace Java with python in many, though not all, situations. JSP, Servlets, RMI servers and IDE plugins are good candidates. Once this integration is achieved, a second phase will be started to separate the Java logic from the Python logic, eventually allowing the bridging technology to be used in other environments, I.E. Ruby, Perl, COM, etc ... Known Bugs/Limitations : * Java classes outside of a package (in the ) cannot be imported. * unable to access a field or method if it conflicts with a python keyword. * Because of lack of JVM support, you cannot shutdown the JVM and then restart it. * Some methods rely on the "current" class/caller. Since calls coming directly from python code do not have a current class, these methods do not work. The User Manual lists all the known methods like that.