Return-Path: Delivered-To: apmail-lucene-commits-archive@www.apache.org Received: (qmail 10095 invoked from network); 9 Jan 2009 03:29:34 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 9 Jan 2009 03:29:34 -0000 Received: (qmail 93673 invoked by uid 500); 9 Jan 2009 03:29:34 -0000 Mailing-List: contact commits-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@lucene.apache.org Delivered-To: mailing list commits@lucene.apache.org Received: (qmail 93664 invoked by uid 99); 9 Jan 2009 03:29:34 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 08 Jan 2009 19:29:34 -0800 X-ASF-Spam-Status: No, hits=-1996.5 required=10.0 tests=ALL_TRUSTED,FB_WORD1_END_DOLLAR,URIBL_BLACK X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 09 Jan 2009 03:29:15 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id A6D612388988; Thu, 8 Jan 2009 19:28:52 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r732916 [2/14] - in /lucene/pylucene/trunk: ./ java/ java/org/ java/org/osafoundation/ java/org/osafoundation/lucene/ java/org/osafoundation/lucene/analysis/ java/org/osafoundation/lucene/queryParser/ java/org/osafoundation/lucene/search/ j... Date: Fri, 09 Jan 2009 03:28:41 -0000 To: commits@lucene.apache.org From: vajda@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090109032852.A6D612388988@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Propchange: lucene/pylucene/trunk/java/org/osafoundation/lucene/search/PythonSimilarity.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: lucene/pylucene/trunk/java/org/osafoundation/lucene/search/PythonSimilarity.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: lucene/pylucene/trunk/java/org/osafoundation/lucene/search/PythonSimilarityDelegator.java URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/java/org/osafoundation/lucene/search/PythonSimilarityDelegator.java?rev=732916&view=auto ============================================================================== --- lucene/pylucene/trunk/java/org/osafoundation/lucene/search/PythonSimilarityDelegator.java (added) +++ lucene/pylucene/trunk/java/org/osafoundation/lucene/search/PythonSimilarityDelegator.java Thu Jan 8 19:28:33 2009 @@ -0,0 +1,59 @@ +/* ==================================================================== + * Copyright (c) 2004-2008 Open Source Applications Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.osafoundation.lucene.search; + +import org.apache.lucene.search.Similarity; +import org.apache.lucene.search.SimilarityDelegator; +import org.apache.lucene.search.Searcher; +import org.apache.lucene.index.Term; + + +public class PythonSimilarityDelegator extends SimilarityDelegator { + + private long pythonObject; + + public PythonSimilarityDelegator(Similarity delegee) + { + super(delegee); + } + + public void pythonExtension(long pythonObject) + { + this.pythonObject = pythonObject; + } + public long pythonExtension() + { + return this.pythonObject; + } + + public void finalize() + throws Throwable + { + pythonDecRef(); + } + + public native void pythonDecRef(); + public native float lengthNorm(String fieldName, int numTokens); + public native float queryNorm(float sumOfSquaredWeights); + public native float tf(float freq); + public native float sloppyFreq(int distance); + public native float idf(int docFreq, int numDocs); + public native float coord(int overlap, int maxOverlap); + public native float scorePayload(String fieldName, byte[] payload, + int offset, int length); +} Propchange: lucene/pylucene/trunk/java/org/osafoundation/lucene/search/PythonSimilarityDelegator.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: lucene/pylucene/trunk/java/org/osafoundation/lucene/search/PythonSimilarityDelegator.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: lucene/pylucene/trunk/java/org/osafoundation/lucene/search/PythonSortComparator.java URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/java/org/osafoundation/lucene/search/PythonSortComparator.java?rev=732916&view=auto ============================================================================== --- lucene/pylucene/trunk/java/org/osafoundation/lucene/search/PythonSortComparator.java (added) +++ lucene/pylucene/trunk/java/org/osafoundation/lucene/search/PythonSortComparator.java Thu Jan 8 19:28:33 2009 @@ -0,0 +1,54 @@ +/* ==================================================================== + * Copyright (c) 2004-2008 Open Source Applications Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.osafoundation.lucene.search; + +import org.apache.lucene.index.IndexReader; +import org.apache.lucene.search.SortComparatorSource; +import org.apache.lucene.search.SortComparator; +import org.apache.lucene.search.ScoreDocComparator; +import java.io.IOException; + + +public class PythonSortComparator extends SortComparator { + + private long pythonObject; + + public PythonSortComparator() + { + } + + public void pythonExtension(long pythonObject) + { + this.pythonObject = pythonObject; + } + public long pythonExtension() + { + return this.pythonObject; + } + + public void finalize() + throws Throwable + { + pythonDecRef(); + } + + public native void pythonDecRef(); + public native ScoreDocComparator newComparator(IndexReader reader, + String fieldName); + public native Comparable getComparable(String termText); +} Propchange: lucene/pylucene/trunk/java/org/osafoundation/lucene/search/PythonSortComparator.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: lucene/pylucene/trunk/java/org/osafoundation/lucene/search/PythonSortComparator.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: lucene/pylucene/trunk/java/org/osafoundation/lucene/search/PythonSortComparatorSource.java URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/java/org/osafoundation/lucene/search/PythonSortComparatorSource.java?rev=732916&view=auto ============================================================================== --- lucene/pylucene/trunk/java/org/osafoundation/lucene/search/PythonSortComparatorSource.java (added) +++ lucene/pylucene/trunk/java/org/osafoundation/lucene/search/PythonSortComparatorSource.java Thu Jan 8 19:28:33 2009 @@ -0,0 +1,52 @@ +/* ==================================================================== + * Copyright (c) 2004-2008 Open Source Applications Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.osafoundation.lucene.search; + +import org.apache.lucene.index.IndexReader; +import org.apache.lucene.search.SortComparatorSource; +import org.apache.lucene.search.ScoreDocComparator; +import java.io.IOException; + + +public class PythonSortComparatorSource implements SortComparatorSource { + + private long pythonObject; + + public PythonSortComparatorSource() + { + } + + public void pythonExtension(long pythonObject) + { + this.pythonObject = pythonObject; + } + public long pythonExtension() + { + return this.pythonObject; + } + + public void finalize() + throws Throwable + { + pythonDecRef(); + } + + public native void pythonDecRef(); + public native ScoreDocComparator newComparator(IndexReader reader, + String fieldName); +} Propchange: lucene/pylucene/trunk/java/org/osafoundation/lucene/search/PythonSortComparatorSource.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: lucene/pylucene/trunk/java/org/osafoundation/lucene/search/PythonSortComparatorSource.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: lucene/pylucene/trunk/java/org/osafoundation/lucene/search/highlight/PythonFormatter.java URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/java/org/osafoundation/lucene/search/highlight/PythonFormatter.java?rev=732916&view=auto ============================================================================== --- lucene/pylucene/trunk/java/org/osafoundation/lucene/search/highlight/PythonFormatter.java (added) +++ lucene/pylucene/trunk/java/org/osafoundation/lucene/search/highlight/PythonFormatter.java Thu Jan 8 19:28:33 2009 @@ -0,0 +1,50 @@ +/* ==================================================================== + * Copyright (c) 2004-2008 Open Source Applications Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.osafoundation.lucene.search.highlight; + +import org.apache.lucene.search.highlight.Formatter; +import org.apache.lucene.search.highlight.TokenGroup; + + +public class PythonFormatter implements Formatter { + + private long pythonObject; + + public PythonFormatter() + { + } + + public void pythonExtension(long pythonObject) + { + this.pythonObject = pythonObject; + } + public long pythonExtension() + { + return this.pythonObject; + } + + public void finalize() + throws Throwable + { + pythonDecRef(); + } + + public native void pythonDecRef(); + public native String highlightTerm(String originalText, + TokenGroup tokenGroup); +} Propchange: lucene/pylucene/trunk/java/org/osafoundation/lucene/search/highlight/PythonFormatter.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: lucene/pylucene/trunk/java/org/osafoundation/lucene/search/highlight/PythonFormatter.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: lucene/pylucene/trunk/java/org/osafoundation/lucene/search/highlight/PythonFragmenter.java URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/java/org/osafoundation/lucene/search/highlight/PythonFragmenter.java?rev=732916&view=auto ============================================================================== --- lucene/pylucene/trunk/java/org/osafoundation/lucene/search/highlight/PythonFragmenter.java (added) +++ lucene/pylucene/trunk/java/org/osafoundation/lucene/search/highlight/PythonFragmenter.java Thu Jan 8 19:28:33 2009 @@ -0,0 +1,49 @@ +/* ==================================================================== + * Copyright (c) 2004-2008 Open Source Applications Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.osafoundation.lucene.search.highlight; + +import org.apache.lucene.search.highlight.Fragmenter; +import org.apache.lucene.analysis.Token; + +public class PythonFragmenter implements Fragmenter { + + private long pythonObject; + + public PythonFragmenter() + { + } + + public void pythonExtension(long pythonObject) + { + this.pythonObject = pythonObject; + } + public long pythonExtension() + { + return this.pythonObject; + } + + public void finalize() + throws Throwable + { + pythonDecRef(); + } + + public native void pythonDecRef(); + public native boolean isNewFragment(Token nextToken); + public native void start(String originalText); +} Propchange: lucene/pylucene/trunk/java/org/osafoundation/lucene/search/highlight/PythonFragmenter.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: lucene/pylucene/trunk/java/org/osafoundation/lucene/search/highlight/PythonFragmenter.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: lucene/pylucene/trunk/java/org/osafoundation/lucene/store/PythonDirectory.java URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/java/org/osafoundation/lucene/store/PythonDirectory.java?rev=732916&view=auto ============================================================================== --- lucene/pylucene/trunk/java/org/osafoundation/lucene/store/PythonDirectory.java (added) +++ lucene/pylucene/trunk/java/org/osafoundation/lucene/store/PythonDirectory.java Thu Jan 8 19:28:33 2009 @@ -0,0 +1,66 @@ +/* ==================================================================== + * Copyright (c) 2004-2008 Open Source Applications Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.osafoundation.lucene.store; + +import org.apache.lucene.store.Directory; +import org.apache.lucene.store.IndexInput; +import org.apache.lucene.store.IndexOutput; +import org.apache.lucene.store.Lock; + + +public class PythonDirectory extends Directory { + + private long pythonObject; + + public PythonDirectory() + { + } + + public void pythonExtension(long pythonObject) + { + this.pythonObject = pythonObject; + } + public long pythonExtension() + { + return this.pythonObject; + } + + public void finalize() + throws Throwable + { + pythonDecRef(); + } + + public native void pythonDecRef(); + public native void close(); + public native IndexOutput createOutput(String name); + public native void deleteFile(String name); + public native boolean fileExists(String name); + public native long fileLength(String name); + public native long fileModified(String name); + public native String[] list(); + public native Lock makeLock(String name); + public native IndexInput openInput(String name); + public native IndexInput openInput(String name, int bufferSize); + public native void touchFile(String name); + + /* no longer implemented, deprecated in Lucene 2.1 */ + public void renameFile(String from, String to) + { + } +} Propchange: lucene/pylucene/trunk/java/org/osafoundation/lucene/store/PythonDirectory.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: lucene/pylucene/trunk/java/org/osafoundation/lucene/store/PythonDirectory.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: lucene/pylucene/trunk/java/org/osafoundation/lucene/store/PythonIndexInput.java URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/java/org/osafoundation/lucene/store/PythonIndexInput.java?rev=732916&view=auto ============================================================================== --- lucene/pylucene/trunk/java/org/osafoundation/lucene/store/PythonIndexInput.java (added) +++ lucene/pylucene/trunk/java/org/osafoundation/lucene/store/PythonIndexInput.java Thu Jan 8 19:28:33 2009 @@ -0,0 +1,57 @@ +/* ==================================================================== + * Copyright (c) 2004-2008 Open Source Applications Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.osafoundation.lucene.store; + +import org.apache.lucene.store.BufferedIndexInput; + +public class PythonIndexInput extends BufferedIndexInput { + + private long pythonObject; + + public PythonIndexInput() + { + } + + public void pythonExtension(long pythonObject) + { + this.pythonObject = pythonObject; + } + public long pythonExtension() + { + return this.pythonObject; + } + + public void finalize() + throws Throwable + { + pythonDecRef(); + } + + public native Object clone(); + public native void close(); + public native void pythonDecRef(); + public native long length(); + public native byte[] readInternal(int length, long pos); + public native void seekInternal(long pos); + + protected void readInternal(byte[] b, int offset, int length) + { + byte[] data = readInternal(length, getFilePointer()); + System.arraycopy(data, 0, b, offset, data.length); + } +} Propchange: lucene/pylucene/trunk/java/org/osafoundation/lucene/store/PythonIndexInput.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: lucene/pylucene/trunk/java/org/osafoundation/lucene/store/PythonIndexInput.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: lucene/pylucene/trunk/java/org/osafoundation/lucene/store/PythonIndexOutput.java URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/java/org/osafoundation/lucene/store/PythonIndexOutput.java?rev=732916&view=auto ============================================================================== --- lucene/pylucene/trunk/java/org/osafoundation/lucene/store/PythonIndexOutput.java (added) +++ lucene/pylucene/trunk/java/org/osafoundation/lucene/store/PythonIndexOutput.java Thu Jan 8 19:28:33 2009 @@ -0,0 +1,66 @@ +/* ==================================================================== + * Copyright (c) 2004-2008 Open Source Applications Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.osafoundation.lucene.store; + +import java.io.IOException; +import org.apache.lucene.store.BufferedIndexOutput; + + +public class PythonIndexOutput extends BufferedIndexOutput { + + private long pythonObject; + + public PythonIndexOutput() + { + } + + public void pythonExtension(long pythonObject) + { + this.pythonObject = pythonObject; + } + public long pythonExtension() + { + return this.pythonObject; + } + + public void finalize() + throws Throwable + { + pythonDecRef(); + } + + public void seek(long pos) + throws IOException + { + super.seek(pos); + seekInternal(pos); + } + + public native void pythonDecRef(); + public native long length(); + public native void flushBuffer(byte[] data); + public native void seekInternal(long pos); + public native void close(); + + protected void flushBuffer(byte[] b, int offset, int len) + { + byte[] data = new byte[len]; + System.arraycopy(b, offset, data, 0, len); + flushBuffer(data); + } +} Propchange: lucene/pylucene/trunk/java/org/osafoundation/lucene/store/PythonIndexOutput.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: lucene/pylucene/trunk/java/org/osafoundation/lucene/store/PythonIndexOutput.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: lucene/pylucene/trunk/java/org/osafoundation/lucene/store/PythonLock.java URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/java/org/osafoundation/lucene/store/PythonLock.java?rev=732916&view=auto ============================================================================== --- lucene/pylucene/trunk/java/org/osafoundation/lucene/store/PythonLock.java (added) +++ lucene/pylucene/trunk/java/org/osafoundation/lucene/store/PythonLock.java Thu Jan 8 19:28:33 2009 @@ -0,0 +1,50 @@ +/* ==================================================================== + * Copyright (c) 2004-2008 Open Source Applications Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.osafoundation.lucene.store; + +import org.apache.lucene.store.Lock; + +public class PythonLock extends Lock { + + private long pythonObject; + + public PythonLock() + { + } + + public void pythonExtension(long pythonObject) + { + this.pythonObject = pythonObject; + } + public long pythonExtension() + { + return this.pythonObject; + } + + public void finalize() + throws Throwable + { + pythonDecRef(); + } + + public native void pythonDecRef(); + public native boolean isLocked(); + public native boolean obtain(); + public native boolean obtain(long lockWaitTimeout); + public native void release(); +} Propchange: lucene/pylucene/trunk/java/org/osafoundation/lucene/store/PythonLock.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: lucene/pylucene/trunk/java/org/osafoundation/lucene/store/PythonLock.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: lucene/pylucene/trunk/java/org/osafoundation/util/PythonComparable.java URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/java/org/osafoundation/util/PythonComparable.java?rev=732916&view=auto ============================================================================== --- lucene/pylucene/trunk/java/org/osafoundation/util/PythonComparable.java (added) +++ lucene/pylucene/trunk/java/org/osafoundation/util/PythonComparable.java Thu Jan 8 19:28:33 2009 @@ -0,0 +1,46 @@ +/* ==================================================================== + * Copyright (c) 2004-2008 Open Source Applications Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.osafoundation.util; + + +public class PythonComparable implements Comparable { + + private long pythonObject; + + public PythonComparable() + { + } + + public void pythonExtension(long pythonObject) + { + this.pythonObject = pythonObject; + } + public long pythonExtension() + { + return this.pythonObject; + } + + public void finalize() + throws Throwable + { + pythonDecRef(); + } + + public native void pythonDecRef(); + public native int compareTo(Object o); +} Propchange: lucene/pylucene/trunk/java/org/osafoundation/util/PythonComparable.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: lucene/pylucene/trunk/java/org/osafoundation/util/PythonComparable.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: lucene/pylucene/trunk/java/org/osafoundation/util/PythonIterator.java URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/java/org/osafoundation/util/PythonIterator.java?rev=732916&view=auto ============================================================================== --- lucene/pylucene/trunk/java/org/osafoundation/util/PythonIterator.java (added) +++ lucene/pylucene/trunk/java/org/osafoundation/util/PythonIterator.java Thu Jan 8 19:28:33 2009 @@ -0,0 +1,55 @@ +/* ==================================================================== + * Copyright (c) 2004-2008 Open Source Applications Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.osafoundation.util; + +import java.util.Iterator; + + +public class PythonIterator implements Iterator { + + private long pythonObject; + + public PythonIterator() + { + } + + public void pythonExtension(long pythonObject) + { + this.pythonObject = pythonObject; + } + public long pythonExtension() + { + return this.pythonObject; + } + + public void finalize() + throws Throwable + { + pythonDecRef(); + } + + public native void pythonDecRef(); + + public native boolean hasNext(); + public native Object next(); + + public void remove() + { + throw new UnsupportedOperationException(); + } +} Propchange: lucene/pylucene/trunk/java/org/osafoundation/util/PythonIterator.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: lucene/pylucene/trunk/java/org/osafoundation/util/PythonIterator.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: lucene/pylucene/trunk/java/org/osafoundation/util/PythonSet.java URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/java/org/osafoundation/util/PythonSet.java?rev=732916&view=auto ============================================================================== --- lucene/pylucene/trunk/java/org/osafoundation/util/PythonSet.java (added) +++ lucene/pylucene/trunk/java/org/osafoundation/util/PythonSet.java Thu Jan 8 19:28:33 2009 @@ -0,0 +1,77 @@ +/* ==================================================================== + * Copyright (c) 2004-2008 Open Source Applications Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.osafoundation.util; + +import java.util.Set; +import java.util.Collection; +import java.util.Iterator; +import java.lang.reflect.Array; + + +public class PythonSet implements Set { + + private long pythonObject; + + public PythonSet() + { + } + + public void pythonExtension(long pythonObject) + { + this.pythonObject = pythonObject; + } + public long pythonExtension() + { + return this.pythonObject; + } + + public void finalize() + throws Throwable + { + pythonDecRef(); + } + + public native void pythonDecRef(); + + public native boolean add(Object obj); + public native boolean addAll(Collection c); + public native void clear(); + public native boolean contains(Object obj); + public native boolean containsAll(Collection c); + public native boolean equals(Object obj); + public native boolean isEmpty(); + public native Iterator iterator(); + public native boolean remove(Object obj); + public native boolean removeAll(Collection c); + public native boolean retainAll(Collection c); + public native int size(); + public native Object[] toArray(); + + public Object[] toArray(Object[] a) + { + Object[] array = toArray(); + + if (a.length < array.length) + a = (Object[]) Array.newInstance(a.getClass().getComponentType(), + array.length); + + System.arraycopy(array, 0, a, 0, array.length); + + return a; + } +} Propchange: lucene/pylucene/trunk/java/org/osafoundation/util/PythonSet.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: lucene/pylucene/trunk/java/org/osafoundation/util/PythonSet.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: lucene/pylucene/trunk/jcc/CHANGES URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/CHANGES?rev=732916&view=auto ============================================================================== --- lucene/pylucene/trunk/jcc/CHANGES (added) +++ lucene/pylucene/trunk/jcc/CHANGES Thu Jan 8 19:28:33 2009 @@ -0,0 +1,91 @@ + +For bug , see http://bugzilla.osafoundation.org/show_bug.cgi?id= + +Version 2.1 -> +------------------ + - JCC now a subproject of the Apache PyLucene project + - + +Version 2.0 -> 2.1 +------------------ + - fixed bug with not checking missing module name when attempting build + - increased jcc's java stack to 512k + - added support for iPod/iPhone, with shared mode + - added missing cast to jweak in call to DeleteWeakGlobalRef() + - fixed local string ref leak in JArray (Aaron Lav) + - fixed local ref leak if ref for object already exists in table (Aaron Lav) + - fixed bug with error reporting from class methods (Aaron Lav) + - fixed bug with reporting python errors with RuntimeException when not shared + - removed bogus storage class from template specializations (Joseph Barillari) + +Version 1.9 -> 2.0 +------------------ + - fixed bug with failed findClass() import + - fixed bug 12127 + - added -ljvm to linux2 and sunos5 LFLAGS + - added support for using JCC in reverse (starting from Java VM) (shared only) + - using PythonException for reporting Python errors (shared only) + - inserted Apache 2.0 license copyright notices + - fixed bug with declaring array parameters in extension methods + - added support for --module to add individual python files to resulting egg + - JCC in reverse functional on Mac OS X and Linux + - fixed JCC in reverse threading issues + - JCC in reverse usable with Tomcat + - got python stacktrace into PythonException's message + - added 'self' property to get wrapped python object from extension wrapper + - added headless AWT workaround to JCC's own initVM() call + - added DEBUG_CFLAGS to setup.py to improve debug build support + - fixed uninitialized Class class bug (parseArgs) + - added errorName field to PythonException + - added support for excluding stack trace from PythonException + - arrays are now wrapped by JArray() objects instead of expanded into lists + - return by value in arrays now supported + - added support for nested arrays via JArray().cast_() + - included patch to setuptools to support shared mode on Linux + +Version 1.8 -> 1.9 +------------------ + - fixed code generation for clone() broken by finalization proxy work + - added 'union' to the list of reserved words + - fixed castCheck() to work with finalization proxies + - --compile no longer installs by default + - fixed bug in __init__.cpp #include statements for package-less classes + - fixed line ending bug on Windows + - fixed multiple JCC-built extensions in same process problem + - removed env argument from initVM() as it's redundant with the libjcc.dylib + - reimplemented env->setClassPath() in terms of system URLClassLoader hack + - added support for --include option + - added 'NULL' to list of reserved words + - added support for building shared libjcc library on Mac OS X and Linux + - fixed bug with generating wrappers for abstract Enumeration implementations + - added support for --install-dir and --use-distutils options + - copy jcc runtime sources into extension source tree before compiling + - added detection of invalid command line args + - fixed double-free bug when passing in vmargs + - added defines to enable building with MinGW (Bill Janssen) + - added support for --bdist + - added support for --compiler + - fixed crasher on Windows with virtual JObject.weaken$() + - fixed bug not checking return value from initVM() + - fixed bug with findClass() not catching C++ exception when class not found + - added missing code in parseArgs() to handle double[], float[] and long[] + +Version 1.7 -> 1.8 +------------------ + + - fixed bug using the wrong field modifiers for setter (Bill Janssen) + - added missing calls for generating wrappers for ancestors of Exception + - added missing call for generating wrappers for String + - added note about --classpath to README + +Version 1.6 -> 1.7 +------------------ + - fixed memory leak when calling inherited methods via callSuper() + - added support for building on Solaris with Sun Studio C++ (Solaris 11) + - fixed leak of local refs of jstring when converting to an array of String + - automated finalization of extensions via proxy for breaking ref cycle + - added Py_CLEAR and Py_VISIT macros for Python 2.3.5 compilation + +Earlier versions (changes included in PyLucene versions < 2.3) +-------------------------------------------------------------- + - see http://svn.osafoundation.org/pylucene/trunk/jcc/CHANGES Added: lucene/pylucene/trunk/jcc/DESCRIPTION URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/DESCRIPTION?rev=732916&view=auto ============================================================================== --- lucene/pylucene/trunk/jcc/DESCRIPTION (added) +++ lucene/pylucene/trunk/jcc/DESCRIPTION Thu Jan 8 19:28:33 2009 @@ -0,0 +1,47 @@ + +For changes since earlier releases, see: + http://svn.osafoundation.org/pylucene/trunk/jcc/jcc/CHANGES + +JCC is a C++ code generator for producing the glue code necessary to call +into Java classes from CPython via Java's Native Invocation Interface (JNI). + +JCC generates C++ wrapper classes that hide all the gory details of JNI +access as well Java memory and object reference management. + +JCC generates CPython types that make these C++ classes accessible from a +Python interpreter. JCC attempts to make these Python types pythonic by +detecting iterators and property accessors. Iterators and mappings may also +be declared to JCC. + +JCC has been built on Python 2.3, 2.4, 2.5 and 2.6 and has been used with +various Java Runtime Environments such as Sun Java 1.4, 1.5 and 1.6, Apple's +Java 1.4 and 1.5 on Mac OS X and open source Java OpenJDK 1.7 builds. + +JCC is known to work on Intel and PowerPC Mac OS X 10.3, 10.4 and 10.5, +Ubuntu Linux Dapper, Feisty and Gutsy, Sun Solaris Express, Windows 2000 and +Windows XP. + +JCC is written in C++ and Python. It uses Java's reflection API to do its +job and needs a Java Runtime Environment to be present to operate. + +JCC is built with distutils or setuptools:: + + python setup.py build + sudo python setup.py install + +Setuptools is required to build JCC on Python 2.3. + +Except for Mac OS X - where Apple's Java comes pre-installed in a known +framework location - JCC's setup.py file needs to be edited before building +JCC to specify the location of the Java Runtime Environment's header files +and libraries. + +The svn sources for JCC are available at: + http://svn.osafoundation.org/pylucene/trunk/jcc/jcc/ + +For more information about JCC see: + http://svn.osafoundation.org/pylucene/trunk/jcc/jcc/README + http://svn.osafoundation.org/pylucene/trunk/jcc/jcc/INSTALL + +JCC comes with an Apache 2.0 copyright license: + http://www.apache.org/licenses/LICENSE-2.0 Added: lucene/pylucene/trunk/jcc/INSTALL URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/INSTALL?rev=732916&view=auto ============================================================================== --- lucene/pylucene/trunk/jcc/INSTALL (added) +++ lucene/pylucene/trunk/jcc/INSTALL Thu Jan 8 19:28:33 2009 @@ -0,0 +1,155 @@ + + INSTALL file for JCC build + -------------------------- + + Contents + -------- + + - Building JCC + - Requirements + - Shared Mode (--shared) + - Notes for Mac OS X + - Notes for Linux + - Notes for Solaris + - Notes for Windows + - Notes for Python 2.3 + + + Building JCC + ------------ + + JCC is a Python extension written in Python and C++. it requires a Java + Runtime Environment to operate as it uses Java's reflection APIs to do + its work. It is built and installed via distutils. + + 1. Edit setup.py and review that values in the INCLUDE, CFLAGS, + DEBUG_CFLAGS, LFLAGS and JAVAC are correct for your system. These + values are also going to be compiled into JCC's config.py file and are + going to be used by JCC when invoking disutils or setuptools to compile + extensions its generating code for. + + 2. At the command line, enter: + + python setup.py build + sudo python setup.py install + + + Requirements + ------------ + + JCC requires a Java Development Kit to be present. It uses the Java Native + Invocation Interface and expects and the Java libraries to be + present at build and runtime. + + + Shared Mode (--shared) + ---------------------- + + JCC includes a small runtime that keeps track of the Java VM and of Java + objects escaping it. Because there can be only one Java VM embedded in a + given process at a time, the JCC runtime must be compiled as a shared + library when more than one JCC-built Python extension is going to be + imported into a given Python process. + + Shared mode depends on setuptools' capability of building plain shared + libraries (as opposed to shared libraries for Python extensions). + This shared library capability is a feature currently under development. + + Currently, shared mode is supported with setuptools 0.6c7 and above out of + the box on Mac OS X and Windows. On Linux, a patch to setuptools needs to + be applied first. This patch is included in the JCC source distribution in + the jcc/patches directory, patch.43. This patch was submitted to the + setuptools project via issue 43: http://bugs.python.org/setuptools/issue43 + + The 'shared mode disabled' error reported during the build of JCC's on + Linux contains the exact instructions on how to patch setuptools with + patch.43 on your system. + + Shared mode is also required when embedding Python in a Java VM as JCC's + runtime shared library is used by the JVM to load JCC and bootstrap the + Python VM via JNI. + + When shared mode is not enabled, not supported or distutils is used + instead of setuptools, static mode is used instead. The JCC runtime code + is statically linked with eacg JCC-built Python extension and only one + such extension can be used in a given Python process. + + As setuptools grows its shared library building capability it is expected + that more operating systems should be supported with shared mode in the + future. + + Shared mode can be forced off by building JCC with the NO_SHARED + environment variable set. + + + Notes for Mac OS X + ------------------ + + On Mac OS X, Java is installed by Apple's setup as a framework. + The values for INCLUDE and LFLAGS for 'darwin' should be correct and + ready to use. + + + Notes for Linux + --------------- + + JCC has been built and tested on a variety of Linux distributions, 32- and + 64-bit. Getting the java configuration correct is important and is done + differently for every distribution. + + For example: + + - on Ubuntu, to install Java 5, these commands may be used: + sudo apt-get install sun-java5-jdk + sudo update-java-alternatives -s java-1.5.0-sun + The samples flags for Linux in JCC's setup.py should be close to + correct. + + - on Gentoo, the java-config utility should be used to locate, and + possibly change, the default java installation. + The sample flags for Linux in JCC's setup.py should be changed to + reflect the root of the Java installation which may be obtained via: + java-config -O + + See above section about 'Shared Mode' for Linux support + + + Notes for Solaris + ----------------- + + At this time, JCC has been built and tested only on Solaris 11 with Sun + Studio C++ 12, Java 1.6 and Python 2.4. + + Because JCC is written in C++, Python's distutils must be nudged a bit to + invoke the correct compiler. Sun Studio's C compiler is called 'cc' while + its C++ compiler is called 'CC'. To build JCC, use the following shell + command to ensure that the C++ compiler is used: + + CC=CC python setup.py build + + Shared mode is not currently implemented for Solaris, setuptools needs to + be taught how to build plain shared libraries on Solaris first. + + + Notes for Windows + ----------------- + + At this time, JCC has been built and tested on Win2k and WinXP with a + variety of Python and Java versions. + + - Adding the Python directory to PATH is recommended. + - Adding the Java directories containing the necessary DLLs and to PATH is + a must. + - Adding the directory containing javac.exe to PATH is required for shared + mode (enabled by default if setuptools >= 0.6c7 is found to be installed). + + + Notes for Python 2.3 + -------------------- + + To use JCC with Python 2.3, setuptools is required: + + - download setuptools from http://python.org/pypi + - edit the downloaded setuptools egg file to use python2.3 instead of + python2.4 + - sudo sh setuptools-0.6c7-py2.4.egg Propchange: lucene/pylucene/trunk/jcc/INSTALL ------------------------------------------------------------------------------ svn:eol-style = native Propchange: lucene/pylucene/trunk/jcc/INSTALL ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: lucene/pylucene/trunk/jcc/LICENSE URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/LICENSE?rev=732916&view=auto ============================================================================== --- lucene/pylucene/trunk/jcc/LICENSE (added) +++ lucene/pylucene/trunk/jcc/LICENSE Thu Jan 8 19:28:33 2009 @@ -0,0 +1,12 @@ + +# 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. Added: lucene/pylucene/trunk/jcc/NOTICE URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/NOTICE?rev=732916&view=auto ============================================================================== --- lucene/pylucene/trunk/jcc/NOTICE (added) +++ lucene/pylucene/trunk/jcc/NOTICE Thu Jan 8 19:28:33 2009 @@ -0,0 +1,4 @@ + +Apache PyLucene (JCC) + Copyright 2009 The Apache Software Foundation + Copyright (c) 2007-2008 Open Source Applications Foundation Added: lucene/pylucene/trunk/jcc/README URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/README?rev=732916&view=auto ============================================================================== --- lucene/pylucene/trunk/jcc/README (added) +++ lucene/pylucene/trunk/jcc/README Thu Jan 8 19:28:33 2009 @@ -0,0 +1,611 @@ + + ******************************************************** + * =============== * + * IMPORTANT NOTE: * + * =============== * + * * + * Before calling any API into the Java VM, start it by * + * calling initVM(classpath, ...). * + * * + * More about this function below. * + * * + ******************************************************** + + README file for JCC + ------------------- + + Contents + -------- + + - Welcome + - Installing JCC + - Generating C++ and Python wrappers with JCC + - Classpath considerations + - Using distutils vs setuptools + - Distributing an egg + - JCC's runtime API functions + - Type casting and instance checks + - Handling arrays + - Exception reporting + - Writing Java class extensions in Python + - Pythonic protocols + + + Welcome + ------- + + Welcome to JCC, a code generator for producing Python extensions that + provide access to Java classes. + + For every target Java class, JCC generates a C++ wrapper class that hides + the gory details necessary for accessing methods and fields on instances + of the Java class from C++ via Java's Native Invocation Interface. + + JCC can also generate C++ wrappers that make it possible to access these + classes from Python. + + When generating Python wrappers, JCC produces a complete Python extension + via the distutils or setuptools packages that make it readily available to + the Python interpreter. + + JCC is a project maintained by the Open Source Applications Foundation. + + + Installing JCC + -------------- + + JCC is a Python extension written in Python and C++. It requires a Java + Runtime Environment (JRE) to operate as it uses Java's reflection APIs to + do its work. It is built and installed via distutils or setuptools. + + See INSTALL file for more information and operating system specific + notes. + + + Generating C++ and Python wrappers with JCC + ------------------------------------------- + + JCC started as a C++ code generator for hiding the gory details of + accessing methods and fields on Java classes via Java's Native Invocation + Interface [1]. These C++ wrappers make it possible to access a Java object + as if it was a regular C++ object very much like GCJ's CNI interface [2]. + + It then became apparent that JCC could also generate the C++ wrappers + for making these classes available to Python. Every class that gets thus + wrapped becomes a CPython type [3]. + + JCC generates wrappers for all public classes that are requested by name + on the command line or via the --jar command line argument. It generates + wrapper methods for all public methods and fields on these classes whose + types are found in one of the following ways: + + - the type is one of the requested classes + - the type is one of the requested classes' superclass or implemented + interfaces + - the type is available from one of the packages listed via the + --package command line argument + + JCC does not generate wrappers for methods or fields which don't satisfy + these requirements. Thus, JCC can avoid generating code for runaway + transitive closures of type dependencies. + + JCC generates property accessors for a property called 'field' when it + finds Java methods named set'Field'(value), get'Field'() or is'Field'(). + + The C++ wrappers are declared in a C++ namespace structure that mirrors + the Java classes' Java packages. The Python types are declared in a flat + namespace at the top level of the resulting Python extension module. + + JCC's command-line arguments are best illustrated via the PyLucene + example: + + > python -m jcc # run JCC to wrap + --jar lucene.jar # all public classes in the lucene jar file + --jar analyzers.jar # and the lucene analyzers contrib package + --jar snowball.jar # and the snowball contrib package + --jar highlighter.jar # and the highlighter contrib package + --jar regex.jar # and the regex search contrib package + --jar queries.jar # and the queries contrib package + --jar extensions.jar # and the Python extensions package + --package java.lang # including all dependencies found in the + # java.lang package + --package java.util # and the java.util package + --package java.io # and the java.io package + java.lang.System # and to explicitely wrap java.lang.System + java.lang.Runtime # as well as java.lang.Runtime + java.lang.Boolean # and java.lang.Boolean + java.lang.Byte # and java.lang.Byte + java.lang.Character # and java.lang.Character + java.lang.Integer # and java.lang.Integer + java.lang.Short # and java.lang.Short + java.lang.Long # and java.lang.Long + java.lang.Double # and java.lang.Double + java.lang.Float # and java.lang.Float + java.text.SimpleDateFormat + # and java.text.SimpleDateFormat + java.io.StringReader + # and java.io.StringReader + java.io.InputStreamReader + # and java.io.InputStreamReader + java.io.FileInputStream + # and java.io.FileInputStream + --exclude org.apache.lucene.queryParser.Token + # while explicitely not wrapping + # org.apache.lucene.queryParser.Token + --exclude org.apache.lucene.queryParser.TokenMgrError + # nor org.apache.lucene.queryParser.TokenMgrError + --exclude org.apache.lucene.queryParser.ParseException + # nor.apache.lucene.queryParser.ParseException + --python lucene # generating Python wrappers into a module + # called lucene + --version 2.4.0 # giving the Python extension egg version 2.4.0 + --mapping org.apache.lucene.document.Document + 'get:(Ljava/lang/String;)Ljava/lang/String;' + # asking for a Python mapping protocol wrapper + # for get access on the Document class by + # calling its get method + --mapping java.util.Properties + 'getProperty:(Ljava/lang/String;)Ljava/lang/String;' + # asking for a Python mapping protocol wrapper + # for get access on the Properties class by + # calling its getProperty method + --sequence org.apache.lucene.search.Hits + 'length:()I' + 'doc:(I)Lorg/apache/lucene/document/Document;' + # asking for a Python sequence protocol wrapper + # for length and get access on the Hits class by + # calling its length and doc methods + --files 2 # generating all C++ classes into about 2 .cpp + # files + --build # and finally compiling the generated C++ code + # into a Python egg via setuptools - when + # installed - or a regular Python extension via + # distutils or setuptools otherwise + --install # installing it into Python's site-packages + # directory. + + There are limits to both how many files can fit on the command line and + how large a C++ file the C++ compiler can handle. + By default, JCC generates one large C++ file containing the source code + for all wrapper classes. + + Using the --files command line argument, this behaviour can be tuned to + workaround various limits: + for example: + - to break up the large wrapper class file into about 2 files: + --files 2 + - to break up the large wrapper class file into about 10 files: + --files 10 + - to generate one C++ file per Java class wrapped: + --files separate + + The --prefix and --root arguments are passed through to distutils' setup(). + + [1] http://java.sun.com/j2se/1.5.0/docs/guide/jni/spec/invocation.html + [2] http://gcc.gnu.org/onlinedocs/gcj/About-CNI.html + [3] http://docs.python.org/ext/defining-new-types.html + + + Classpath considerations + ------------------------ + + When generating wrappers for Python, the JAR files passed to JCC via + --jar are copied into the resulting Python extension as resources and + added to the extension's CLASSPATH variable. + Classes or JAR files that are required by the classes contained in the + argument JAR files need to be made findable via JCC's --classpath command + line argument. At runtime, these need to be appended to the extension's + CLASSPATH variable before starting the VM with initVM(CLASSPATH). + + To have more jar files automatically copied into resulting python + extension and added to the classpath at build and runtime, use the + --include option. This option works like the --jar option except that + no wrappers are generated for the public classes contained in them unless + they're explicitely named on the command line. + + + Using distutils vs setuptools + ----------------------------- + + By default, when building a Python extension, if setuptools is found to be + installed, it is used over distutils. If you want to force the use of + distutils over setuptools, use the --use-distutils command line argument. + + + Distributing an egg + ------------------- + + The --bdist option can be used to ask JCC to invoke distutils with 'bdist' + or setuptools with 'bdist_egg'. If setuptools is used, the resulting egg + has to be installed with the easy_install installer [2] which is normally + part of a Python installation that includes setuptools. + + + JCC's runtime API functions + --------------------------- + + JCC includes a small runtime component that is compiled into any Python + extension it produces. + + This runtime component makes it possible to manage the Java VM from + Python. Because a Java VM can be configured with a myriad of options, it + is not automatically started when the resulting Python extension module is + loaded into the Python interpreter. + + Instead, the initVM() function must be called from the main thread before + using any of the wrapped classes. It takes the following keyword + arguments: + + - classpath + A string containing one or more directories or jar files for the + Java VM to search for classes. Every Python extension produced by + JCC exports a CLASSPATH variable that is hardcoded to the jar files + that it was produced from. A copy of each jar file is installed as a + resources files along with the extension when JCC is invoked with the + --install command line argument. + + example: + >>> import lucene + >>> lucene.initVM(classpath=lucene.CLASSPATH) + + - initialheap + The initial amount of Java heap to start the Java VM with. This + argument is a string that follows the same syntax as the similar + -Xms java command line argument. + + example: + >>> import lucene + >>> lucene.initVM(lucene.CLASSPATH, initialheap='32m') + >>> lucene.Runtime.getRuntime().totalMemory() + 33357824L + + - maxheap + The maximum amount of Java heap that could become available to the + Java VM. This argument is a string that follows the same syntax as + the similar -Xmx java command line argument. + + - maxstack + The maximum amount of stack space that available to the Java + VM. This argument is a string that follows the same syntax as + the similar -Xss java command line argument. + + - vmargs + A string of comma separated additional options to pass to the VM + startup rountine. These are passed through as-is. + + example: + >>> import lucene + >>> lucene.initVM(lucene.CLASSPATH, + vmargs='-Xcheck:jni,-verbose:jni,-verbose:gc') + + The initVM() and getVMEnv() functions return a JCCEnv object that has a few + utility methods on it: + + - attachCurrentThread(name, asDaemon) + Before a thread created in Python or elsewhere but not in the Java VM + can be used with the Java VM, this method needs to be invoked. + The two arguments it takes are optional and self-explanatory. + + - detachCurrentThread() + The opposite of attachCurrentThread(). This method should be used with + extreme caution as Python's and java VM's garbage collectors may + use a thread detached too early causing a system crash. The utility of + this method seems dubious at the moment. + + + findClass(className) + + There are several differences between JNI's findName() and Java's + Class.forName(): + - className is a '/' separated string of names + - the class loaders are different, findClass() may find classes + that Class.forName() won't. + + example: + >>> from lucene import * + >>> initVM(CLASSPATH) + >>> findClass('org/apache/lucene/document/Document') + + >>> Class.forName('org.apache.lucene.document.Document') + Traceback (most recent call last): + File "", line 1, in + lucene.JavaError: java.lang.ClassNotFoundException: + org/apache/lucene/document/Document + >>> Class.forName('java.lang.Object') + + + + Type casting and instance checks + -------------------------------- + + Many Java APIs are declared to return types that are less specific than + the types actually returned. In Java 1.5, this is worked around with + annotations. JCC does not heed annotations at the moment. A Java API + declared to return Object will wrap objects as such. + + In C++, casting the object into its actual type is supported via the + regular C casting operator. + + In Python each wrapped class has a class method called 'cast_' that + implements the same functionality. + + Similarly, each wrapped class has a class method called 'instance_' that + tests whether the wrapped java instance is of the given type. + + For example: + + if BooleanQuery.instance_(query): + booleanQuery = BooleanQuery.cast_(query) + + print booleanQuery.getClauses() + + + Handling arrays + --------------- + + Java arrays are wrapped with a C++ JArray template. The [] operator is + available for read access. This template, JArray, accomodates all java + primitive types, jstring, jobject and wrapper class arrays. + + Java arrays are returned to Python in a JArray wrapper instance that + implements the Python sequence protocol. It is possible to change array + elements but not to change an array's size. + + To convert a char or byte array to a Python string use a ''.join(array) + construct. + + Any Java method expecting an array can be called with the corresponding + sequence object from python. + + To instantiate a Java array from Python, use one of the following forms: + + >>> array = JArray('int')(size) + the resulting Java int array is initialized with zeroes + + >>> array = JArray('int')(sequence) + the sequence must only contain ints + the resulting Java int array contains the ints in the sequence + + Instead of 'int', you may also use one of 'object', 'string', 'bool', + 'byte', 'char', 'double', 'float', 'long' and 'short' to create an array + of the corresponding type. + + Because there is only one wrapper class for object arrays, the + JArray('object') type's constructor takes a second argument denoting the + class of the object elements. This argument is optional and defaults to + Object. + + As with the Object types, the JArray types also include a cast_ + method. This method becomes useful when the array returned to Python is + wrapped as a plain Object. This is the case, for example, with nested + arrays since there is no distinct Python type for every different java + object array class - all java object arrays are wrapped by + JArray('object'). + + For example: + - cast obj to an array of ints + >>> JArray('int').cast_(obj) + - cast obj to an array of Document + >>> JArray('object').cast_(obj, Document) + + In both cases, the java type of obj must be compatible with the array type + it is being cast to. + + - using nested array: + + >>> d = JArray('object')(1, Document) + >>> d[0] = Document() + >>> d + JArray[>] + >>> d[0] + > + >>> a = JArray('object')(2) + >>> a[0] = d + >>> a[1] = JArray('int')([0, 1, 2]) + >>> a + JArray[, ] + >>> a[0] + + >>> a[1] + + >>> JArray('object').cast_(a[0])[0] + > + >>> JArray('object').cast_(a[0], Document)[0] + > + >>> JArray('int').cast_(a[1]) + JArray[0, 1, 2] + >>> JArray('int').cast_(a[1])[0] + 0 + + To verify that a Java object is of a given array type, use the instance_() + method available on the array type. This is not the same as verifying that + it is assignable with elements of a given type. For example, using the + arrays created above: + + - is d array of Object ? are d's elements of type Object ? + >>> JArray('object').instance_(d) + True + + - can it receive Object instances ? + >>> JArray('object').assignable_(d) + False + + - is it array of Document ? are d's elements of type Document ? + >>> JArray('object').instance_(d, Document) + True + + - is it array of Class ? are d's elements of type Class ? + >>> JArray('object').instance_(d, Class) + False + + - can it receive Document instances ? + >>> JArray('object').assignable_(d, Document) + True + + + Exception reporting + ------------------- + + Exceptions that occur in the Java VM and that escape to C++ are reported + as a javaError C++ exception. Failure to handle the exception causes the + process to crash. + + Exceptions that occur in the Java VM and that escape to the Python VM are + reported with a JavaError python exception object. The getJavaException() + method can be called on JavaError objects to obtain the original java + exception object wrapped as any other Java object. This Java object can be + used to obtain a Java stack trace for the error, for example. + + Exceptions that occur in the Python VM and that escape to the Java VM, as + for example can happen in Python extensions (see topic below) are reported + to the Java VM as a RuntimeException or as a PythonException when using + shared mode. See INSTALL for more information about shared mode. + + + Writing Java class extensions in Python + --------------------------------------- + + JCC makes it relatively easy to extend a Java class from Python. This is + done via an intermediary class written in Java, that implements a special + method called 'pythonExtension()' and that declares a number of native + methods that are to be implemented by the actual Python extension. + + When JCC sees these special extension java classes it generates the C++ + code implementing the native methods they declare. These native methods + call the corresponding Python method implementations passing in parameters + and returning the result to the Java VM caller. + + For example, to implement a Lucene analyzer in Python, one would implement + first such an extension class in Java: + + package org.osafoundation.lucene.analysis; + + import org.apache.lucene.analysis.Analyzer; + import org.apache.lucene.analysis.TokenStream; + import java.io.Reader; + + public class PythonAnalyzer extends Analyzer { + private long pythonObject; + + public PythonAnalyzer() + { + } + + public void pythonExtension(long pythonObject) + { + this.pythonObject = pythonObject; + } + public long pythonExtension() + { + return this.pythonObject; + } + + public void finalize() + throws Throwable + { + pythonDecRef(); + } + + public native void pythonDecRef(); + public native TokenStream tokenStream(String fieldName, Reader reader); + } + + The pythonExtension() methods is what makes this class recognized as an + extension class by JCC. They should be included verbatim as above along + with the declaration of the pythonObject instance variable. + + The implementation of the native pythonDecRef() method is generated by JCC + and is necessary because it seems that finalize() cannot itself be native. + Since an extension class wraps the Python instance object it's going to be + calling methods on, its ref count needs to be decremented when this Java + wrapper class disappears. A declaration for pythonDecRef() and a finalize() + implementation should always be included verbatim as above. + + Really, the only non boilerplate user input is the constructor of the + class and the other native methods, tokenStream() in the example above. + + The corresponding Python class(es) are implemented as follows: + + class _analyzer(PythonAnalyzer): + def tokenStream(self, fieldName, reader): + class _tokenStream(PythonTokenStream): + def __init__(self): + super(_tokenStream, self).__init__() + self.TOKENS = ["1", "2", "3", "4", "5"] + self.INCREMENTS = [1, 2, 1, 0, 1] + self.i = 0 + def next(self): + if self.i == len(self.TOKENS): + return None + t = Token(self.TOKENS[self.i], self.i, self.i) + t.setPositionIncrement(self.INCREMENTS[self.i]) + self.i += 1 + return t + def reset(self): + pass + def close(self): + pass + return _tokenStream() + + When an __init__() is declared, super() must be called or else the Java + wrapper class will not know about the Python instance it needs to invoke. + + When a java extension class declares native methods for which there are + public or protected equivalents available on the parent class, JCC + generates code that makes it possible to call super() on these methods + from Python as well. + + There are a number of extension examples available in PyLucene's test + suite and samples. + + + Pythonic protocols + ------------------ + + When generating wrappers for Python, JCC attempts to detect which classes + can be made iterable: + + - When a class declares to implement java.util.Iterator or something + compatible with it, JCC makes it iterable from Python. + + - When a Java class declares a method called iterator() with no + arguments returning a type compatible with java.util.Iterator, this + class is made iterable from Python. + + - When a Java class declares a method called next() with no arguments + returning an object type, this class is made iterable. Its next() + method is assumed to terminate iteration by returning null. + + JCC generates a Python mapping get method for a class when requested to do + so via the --mapping command line option which takes two arguments, the + class to generate the mapping get for and the Java method to use. The + method is specified with its name followed by ':' and its Java + signature [1]. + + for example, System.getProperties()['java.class.path'] is made possible by: + + --mapping java.util.Properties + 'getProperty:(Ljava/lang/String;)Ljava/lang/String;' + # asking for a Python mapping protocol wrapper + # for get access on the Properties class by + # calling its getProperty method + + JCC generates Python sequence length and get methods for a class when + requested to do so via the --sequence command line option which takes + three arguments, the class to generate the sequence length and get for and + the two java methods to use. The methods are specified with their name + followed by ':' and their Java signature [1]. + + for example: + for i in xrange(len(hits)): + doc = hits[i] + ... + + is made possible by: + + --sequence org.apache.lucene.search.Hits + 'length:()I' + 'doc:(I)Lorg/apache/lucene/document/Document;' + + [1] http://java.sun.com/j2se/1.5.0/docs/guide/jni/spec/types.html#wp16432 + [2] http://peak.telecommunity.com/DevCenter/EasyInstall Propchange: lucene/pylucene/trunk/jcc/README ------------------------------------------------------------------------------ svn:eol-style = native Propchange: lucene/pylucene/trunk/jcc/README ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: lucene/pylucene/trunk/jcc/_jcc/boot.cpp URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/_jcc/boot.cpp?rev=732916&view=auto ============================================================================== --- lucene/pylucene/trunk/jcc/_jcc/boot.cpp (added) +++ lucene/pylucene/trunk/jcc/_jcc/boot.cpp Thu Jan 8 19:28:33 2009 @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2007-2008 Open Source Applications Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "java/lang/Class.h" +#include "java/lang/RuntimeException.h" +#include "macros.h" + +extern PyTypeObject JObjectType, JCCEnvType, ConstVariableDescriptorType; + +PyObject *initVM(PyObject *self, PyObject *args, PyObject *kwds); + +namespace java { + namespace lang { + void __install__(PyObject *m); + } +} + +PyObject *__initialize__(PyObject *module, PyObject *args, PyObject *kwds) +{ + PyObject *env = initVM(module, args, kwds); + + if (env == NULL) + return NULL; + + java::lang::Class::initializeClass(); + java::lang::RuntimeException::initializeClass(); + + return env; +} + +#include "jccfuncs.h" + +extern "C" { + + void init_jcc(void) + { + PyObject *m = Py_InitModule3("_jcc", jcc_funcs, "_jcc"); + + INSTALL_TYPE(JObject, m); + INSTALL_TYPE(JCCEnv, m); + INSTALL_TYPE(ConstVariableDescriptor, m); + java::lang::__install__(m); + } +} Propchange: lucene/pylucene/trunk/jcc/_jcc/boot.cpp ------------------------------------------------------------------------------ svn:eol-style = native Propchange: lucene/pylucene/trunk/jcc/_jcc/boot.cpp ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: lucene/pylucene/trunk/jcc/_jcc/java/lang/Boolean.cpp URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/_jcc/java/lang/Boolean.cpp?rev=732916&view=auto ============================================================================== --- lucene/pylucene/trunk/jcc/_jcc/java/lang/Boolean.cpp (added) +++ lucene/pylucene/trunk/jcc/_jcc/java/lang/Boolean.cpp Thu Jan 8 19:28:33 2009 @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2007-2008 Open Source Applications Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "JCCEnv.h" +#include "java/lang/Object.h" +#include "java/lang/Class.h" +#include "java/lang/Boolean.h" + +namespace java { + namespace lang { + + enum { + max_mid + }; + + Class *Boolean::class$ = NULL; + jmethodID *Boolean::_mids = NULL; + + Boolean *Boolean::TRUE = NULL; + Boolean *Boolean::FALSE = NULL; + + jclass Boolean::initializeClass() + { + if (!class$) + { + jclass cls = env->findClass("java/lang/Boolean"); + + _mids = new jmethodID[max_mid]; + class$ = (Class *) new JObject(cls); + + FALSE = new Boolean(env->getStaticObjectField(cls, "FALSE", "Ljava/lang/Boolean;")); + TRUE = new Boolean(env->getStaticObjectField(cls, "TRUE", "Ljava/lang/Boolean;")); + } + + return (jclass) class$->this$; + } + } +} + + +#include "structmember.h" +#include "functions.h" +#include "macros.h" + +namespace java { + namespace lang { + + static PyMethodDef t_Boolean__methods_[] = { + { NULL, NULL, 0, NULL } + }; + + DECLARE_TYPE(Boolean, t_Boolean, Object, java::lang::Boolean, + abstract_init, 0, 0, 0, 0, 0); + } +} Propchange: lucene/pylucene/trunk/jcc/_jcc/java/lang/Boolean.cpp ------------------------------------------------------------------------------ svn:eol-style = native Propchange: lucene/pylucene/trunk/jcc/_jcc/java/lang/Boolean.cpp ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: lucene/pylucene/trunk/jcc/_jcc/java/lang/Boolean.h URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/_jcc/java/lang/Boolean.h?rev=732916&view=auto ============================================================================== --- lucene/pylucene/trunk/jcc/_jcc/java/lang/Boolean.h (added) +++ lucene/pylucene/trunk/jcc/_jcc/java/lang/Boolean.h Thu Jan 8 19:28:33 2009 @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2007-2008 Open Source Applications Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _Boolean_H +#define _Boolean_H + +#include +#include "java/lang/Object.h" +#include "java/lang/Class.h" + +namespace java { + namespace lang { + + class Boolean : public Object { + public: + static Class *class$; + static jmethodID *_mids; + static jclass initializeClass(); + + explicit Boolean(jobject obj) : Object(obj) { + initializeClass(); + } + + static Boolean *TRUE; + static Boolean *FALSE; + }; + + extern PyTypeObject BooleanType; + + class t_Boolean { + public: + PyObject_HEAD + Boolean object; + static PyObject *wrap_Object(const Boolean& object); + static PyObject *wrap_jobject(const jobject& object); + }; + } +} + +#endif /* _Boolean_H */ Propchange: lucene/pylucene/trunk/jcc/_jcc/java/lang/Boolean.h ------------------------------------------------------------------------------ svn:eol-style = native Propchange: lucene/pylucene/trunk/jcc/_jcc/java/lang/Boolean.h ------------------------------------------------------------------------------ svn:mime-type = text/plain