Translate Java into Jython
November 21, 2006 10:29 PM Subscribe
Help me translate this Java into Jython(Python)...
I usually horse around in Python but my job is making me use some use some Java libraries thus my resorting to Jython.
I am trying to use the an API to access the Enterprise version of SourceForge. VA Software ships a JAR file that wraps their SOAP API. Here is an example code fragment (in Java) that does performs a login and then receives a session key:
import com.vasoftware.sf.soap43.webservices.ClientSoapStubFactory;
import com.vasoftware.sf.soap43.webservices.sfmain.ISourceForgeSoap;
import com.vasoftware.sf.soap43.webservices.sfmain.ProjectSoapList;
import com.vasoftware.sf.soap43.webservices.sfmain.ProjectSoapRow;
import java.rmi.RemoteException;
import java.io.IOException;
/**
* The SoapRunner class demonstrates how the SOAP APIs can be used
* to list, create or edit projects, trackers, artifacts, task groups,
* tasks etc.
*/
public class SoapRunner {
/** SourceForge Soap interface handle */
private ISourceForgeSoap mSfSoap;
/** Login user name */
private String mLoginUserName;
/** Session id */
private String mSessionId;
/** Soap server url */
private String mServerUrl;
/**
* Class consturctor.
*/
public SoapRunner(String serverUrl) {
mServerUrl = serverUrl;
mSfSoap = (ISourceForgeSoap) ClientSoapStubFactory.getSoapStub(ISourceForgeSoap.class, serverUrl);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
}
That last line is giving me grief.. My Java skills are weak.. and I can't figure out how that would map to Jython syntax.
Help!
PS.. don't ask me to access the SourceForge API via CPython. SOAP under CPython is brain dead.. :)
I usually horse around in Python but my job is making me use some use some Java libraries thus my resorting to Jython.
I am trying to use the an API to access the Enterprise version of SourceForge. VA Software ships a JAR file that wraps their SOAP API. Here is an example code fragment (in Java) that does performs a login and then receives a session key:
import com.vasoftware.sf.soap43.webservices.ClientSoapStubFactory;
import com.vasoftware.sf.soap43.webservices.sfmain.ISourceForgeSoap;
import com.vasoftware.sf.soap43.webservices.sfmain.ProjectSoapList;
import com.vasoftware.sf.soap43.webservices.sfmain.ProjectSoapRow;
import java.rmi.RemoteException;
import java.io.IOException;
/**
* The SoapRunner class demonstrates how the SOAP APIs can be used
* to list, create or edit projects, trackers, artifacts, task groups,
* tasks etc.
*/
public class SoapRunner {
/** SourceForge Soap interface handle */
private ISourceForgeSoap mSfSoap;
/** Login user name */
private String mLoginUserName;
/** Session id */
private String mSessionId;
/** Soap server url */
private String mServerUrl;
/**
* Class consturctor.
*/
public SoapRunner(String serverUrl) {
mServerUrl = serverUrl;
mSfSoap = (ISourceForgeSoap) ClientSoapStubFactory.getSoapStub(ISourceForgeSoap.class, serverUrl);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
}
That last line is giving me grief.. My Java skills are weak.. and I can't figure out how that would map to Jython syntax.
Help!
PS.. don't ask me to access the SourceForge API via CPython. SOAP under CPython is brain dead.. :)
Erm.
So. The static method takes the Class instance and the url, and returns an object of dynamic type ISourceForgeSoap, which is assigned to the member variable mSfSoap. While the dynamic or runtime type is ISourceForgeSoap, the static* or compile time type is some base type, so it's necessary to cast the returned reference.
* I'm using a different meaning of static here than I was above, in case that's not clear.
More questions? Ask.
posted by orthogonality at 10:51 PM on November 21, 2006
So. The static method takes the Class instance and the url, and returns an object of dynamic type ISourceForgeSoap, which is assigned to the member variable mSfSoap. While the dynamic or runtime type is ISourceForgeSoap, the static* or compile time type is some base type, so it's necessary to cast the returned reference.
* I'm using a different meaning of static here than I was above, in case that's not clear.
More questions? Ask.
posted by orthogonality at 10:51 PM on November 21, 2006
Response by poster: Well.. reading your explanation gets me closer. It seems like you have to go through hoops in Java to do stuff Python does auto-magically.. But I am still not sure how to 'port' the code still.. I'm going to keep thinking about it....
posted by tucsongal at 10:56 PM on November 21, 2006
posted by tucsongal at 10:56 PM on November 21, 2006
Looking at the JPython FAQ, it seems that ISourceForgeSoap.class is represented by a Python instance of the Python type JavaClass.
posted by orthogonality at 11:12 PM on November 21, 2006
posted by orthogonality at 11:12 PM on November 21, 2006
This thread is closed to new comments.
Piece by piece:
mSfSoap =
The declaration above tells us that mSfSoap is a Java reference variable (in C terms, a pointer) of type ISourceForgeSoap ; this reference will be assigned the result of the expression to its right
mSfSoap = (ISourceForgeSoap)
The parenthesized type name is a cast
ClientSoapStubFactory
ClientSoapStubFactory is a class imported in the first line of the example code
.getSoapStub(
is a (static) method of that class
getSoapStub(ISourceForgeSoap.class, serverUrl);
that method is called with two arguments, the ISourceForgeSoap.class (see below) and the url, a String
ISourceForgeSoap.class
In Java, all types (both primitives and classes derived from Object) have a "static member" of type Class named class, that is that instance's type's Class. If you had an actual instance, this would be the same Class instance you'd get by calling instance.getClass().
posted by orthogonality at 10:46 PM on November 21, 2006