You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by John Colvin <jc...@openconnect.ie> on 2001/09/21 10:15:51 UTC

Get static instance of Peer dynamically

Hi
Is there a way that I can get a static instance of a peer class by using Class.forName() or a class loader. I am writing an application that contructs simple forms for updating databases dynamically by reading the database Map, TableMap and ColumnMaps an generating the forms on the fly.

When I come to do a select/update/delete I would like to load a static instance by constructing a string for the class name and then load this class statically.

ie from this :

String class name = "com.mywebsite.application. " + tablename + "Peer";

I know how to get an instance but I want the class as a static as the peer methods are static and I would like to call them.


Rgrds
John



---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.281 / Virus Database: 149 - Release Date: 9/18/2001

Re: Get static instance of Peer dynamically

Posted by John Colvin <jc...@openconnect.ie>.
Hi
I found out through some investigation, you were correct, you use the method
Method.invoke, if you do not pass in an object as the first parameter it
calls the method as static.

Thanks
John Colvin
----- Original Message -----
From: "John McNally" <jm...@collab.net>
To: <tu...@jakarta.apache.org>
Sent: Friday, September 21, 2001 4:33 PM
Subject: Re: Get static instance of Peer dynamically


> I am not an expert using reflection but I think you will need to get an
> instance to pass to the Method.invoke command whether the method is
> static or not.  Is there some other way to invoke the method?  It seems
> like there should be so that you could use reflection on an abstract
> class.  It is not required in the case of Peers however since nothing
> prevents you from getting an instance of the class.  You should be able
> to invoke the method regardless of it being static.
>
> john mcnally
>
> John Colvin wrote:
> >
> > Hi
> > Is there a way that I can get a static instance of a peer class by using
Class.forName() or a class loader. I am writing an application that
contructs simple forms for updating databases dynamically by reading the
database Map, TableMap and ColumnMaps an generating the forms on the fly.
> >
> > When I come to do a select/update/delete I would like to load a static
instance by constructing a string for the class name and then load this
class statically.
> >
> > ie from this :
> >
> > String class name = "com.mywebsite.application. " + tablename + "Peer";
> >
> > I know how to get an instance but I want the class as a static as the
peer methods are static and I would like to call them.
> >
> > Rgrds
> > John
> >
> > ---
> > Outgoing mail is certified Virus Free.
> > Checked by AVG anti-virus system (http://www.grisoft.com).
> > Version: 6.0.281 / Virus Database: 149 - Release Date: 9/18/2001
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-user-help@jakarta.apache.org
>


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.281 / Virus Database: 149 - Release Date: 9/18/2001


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: Get static instance of Peer dynamically

Posted by John McNally <jm...@collab.net>.
Ok.  I was just reading the javadoc and interpreting "member" to mean
"non-static".  I have not tried reflection on a static method to know
exactly what's required.

john mcnally

Age Mooy wrote:
> 
> I think that's only necessary if you want a non-public method. I don't exactly know in which cases the
> SecurityManager allows you to get or invoke non-public Method objects
> 
> Age
> 
> > I think you may have to use
> >
> > Method method = peerClass.getDeclaredMethod("doSelect", types).
> >
> > john mcnally
> >
> > Age Mooy wrote:
> > >
> > > Static methods can be invoked with a null object reference.
> > > It would look something like this:
> > >
> > > String className = "com.mywebsite.application. " + tablename + "Peer";
> > >
> > > Class[] types = new Class[] {Criteria.class};
> > > Object[] parameters = new Object[] {new Criteria()};
> > >
> > > Class peerClass = Class.forName(className);
> > > Method select = peerClass.getMethod("doSelect", types);
> > >
> > > List results = (List) m.invoke(null, parameters);
> > >
> > > Untested of course but it should be close.
> > > Age
> > >
> > > > -----Original Message-----
> > > > From: jmcnally@mx3.home.nl [mailto:jmcnally@mx3.home.nl]On Behalf Of
> > > > John McNally
> > > > Sent: Friday, September 21, 2001 17:33
> > > > To: turbine-user@jakarta.apache.org
> > > > Subject: Re: Get static instance of Peer dynamically
> > > >
> > > >
> > > > I am not an expert using reflection but I think you will need to get an
> > > > instance to pass to the Method.invoke command whether the method is
> > > > static or not.  Is there some other way to invoke the method?  It seems
> > > > like there should be so that you could use reflection on an abstract
> > > > class.  It is not required in the case of Peers however since nothing
> > > > prevents you from getting an instance of the class.  You should be able
> > > > to invoke the method regardless of it being static.
> > > >
> > > > john mcnally
> > > >
> > > > John Colvin wrote:
> > > > >
> > > > > Hi
> > > > > Is there a way that I can get a static instance of a peer class by using Class.forName() or a
> > > > class loader. I am writing an application that contructs simple forms for updating databases
> > > > dynamically by reading the database Map, TableMap and ColumnMaps an generating the forms on the fly.
> > > > >
> > > > > When I come to do a select/update/delete I would like to load a static instance by constructing a
> > > > string for the class name and then load this class statically.
> > > > >
> > > > > ie from this :
> > > > >
> > > > > String class name = "com.mywebsite.application. " + tablename + "Peer";
> > > > >
> > > > > I know how to get an instance but I want the class as a static as the peer methods are static and
> > > > I would like to call them.
> > > > >
> > > > > Rgrds
> > > > > John
> > > > >
> > > > > ---
> > > > > Outgoing mail is certified Virus Free.
> > > > > Checked by AVG anti-virus system (http://www.grisoft.com).
> > > > > Version: 6.0.281 / Virus Database: 149 - Release Date: 9/18/2001
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> > > > For additional commands, e-mail: turbine-user-help@jakarta.apache.org
> > > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: turbine-user-help@jakarta.apache.org
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: turbine-user-help@jakarta.apache.org
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-user-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


RE: Get static instance of Peer dynamically

Posted by Age Mooy <am...@home.nl>.
I think that's only necessary if you want a non-public method. I don't exactly know in which cases the
SecurityManager allows you to get or invoke non-public Method objects

Age

> I think you may have to use
>
> Method method = peerClass.getDeclaredMethod("doSelect", types).
>
> john mcnally
>
> Age Mooy wrote:
> >
> > Static methods can be invoked with a null object reference.
> > It would look something like this:
> >
> > String className = "com.mywebsite.application. " + tablename + "Peer";
> >
> > Class[] types = new Class[] {Criteria.class};
> > Object[] parameters = new Object[] {new Criteria()};
> >
> > Class peerClass = Class.forName(className);
> > Method select = peerClass.getMethod("doSelect", types);
> >
> > List results = (List) m.invoke(null, parameters);
> >
> > Untested of course but it should be close.
> > Age
> >
> > > -----Original Message-----
> > > From: jmcnally@mx3.home.nl [mailto:jmcnally@mx3.home.nl]On Behalf Of
> > > John McNally
> > > Sent: Friday, September 21, 2001 17:33
> > > To: turbine-user@jakarta.apache.org
> > > Subject: Re: Get static instance of Peer dynamically
> > >
> > >
> > > I am not an expert using reflection but I think you will need to get an
> > > instance to pass to the Method.invoke command whether the method is
> > > static or not.  Is there some other way to invoke the method?  It seems
> > > like there should be so that you could use reflection on an abstract
> > > class.  It is not required in the case of Peers however since nothing
> > > prevents you from getting an instance of the class.  You should be able
> > > to invoke the method regardless of it being static.
> > >
> > > john mcnally
> > >
> > > John Colvin wrote:
> > > >
> > > > Hi
> > > > Is there a way that I can get a static instance of a peer class by using Class.forName() or a
> > > class loader. I am writing an application that contructs simple forms for updating databases
> > > dynamically by reading the database Map, TableMap and ColumnMaps an generating the forms on the fly.
> > > >
> > > > When I come to do a select/update/delete I would like to load a static instance by constructing a
> > > string for the class name and then load this class statically.
> > > >
> > > > ie from this :
> > > >
> > > > String class name = "com.mywebsite.application. " + tablename + "Peer";
> > > >
> > > > I know how to get an instance but I want the class as a static as the peer methods are static and
> > > I would like to call them.
> > > >
> > > > Rgrds
> > > > John
> > > >
> > > > ---
> > > > Outgoing mail is certified Virus Free.
> > > > Checked by AVG anti-virus system (http://www.grisoft.com).
> > > > Version: 6.0.281 / Virus Database: 149 - Release Date: 9/18/2001
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: turbine-user-help@jakarta.apache.org
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: turbine-user-help@jakarta.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: Get static instance of Peer dynamically

Posted by John McNally <jm...@collab.net>.
I think you may have to use 

Method method = peerClass.getDeclaredMethod("doSelect", types).

john mcnally

Age Mooy wrote:
> 
> Static methods can be invoked with a null object reference.
> It would look something like this:
> 
> String className = "com.mywebsite.application. " + tablename + "Peer";
> 
> Class[] types = new Class[] {Criteria.class};
> Object[] parameters = new Object[] {new Criteria()};
> 
> Class peerClass = Class.forName(className);
> Method select = peerClass.getMethod("doSelect", types);
> 
> List results = (List) m.invoke(null, parameters);
> 
> Untested of course but it should be close.
> Age
> 
> > -----Original Message-----
> > From: jmcnally@mx3.home.nl [mailto:jmcnally@mx3.home.nl]On Behalf Of
> > John McNally
> > Sent: Friday, September 21, 2001 17:33
> > To: turbine-user@jakarta.apache.org
> > Subject: Re: Get static instance of Peer dynamically
> >
> >
> > I am not an expert using reflection but I think you will need to get an
> > instance to pass to the Method.invoke command whether the method is
> > static or not.  Is there some other way to invoke the method?  It seems
> > like there should be so that you could use reflection on an abstract
> > class.  It is not required in the case of Peers however since nothing
> > prevents you from getting an instance of the class.  You should be able
> > to invoke the method regardless of it being static.
> >
> > john mcnally
> >
> > John Colvin wrote:
> > >
> > > Hi
> > > Is there a way that I can get a static instance of a peer class by using Class.forName() or a
> > class loader. I am writing an application that contructs simple forms for updating databases
> > dynamically by reading the database Map, TableMap and ColumnMaps an generating the forms on the fly.
> > >
> > > When I come to do a select/update/delete I would like to load a static instance by constructing a
> > string for the class name and then load this class statically.
> > >
> > > ie from this :
> > >
> > > String class name = "com.mywebsite.application. " + tablename + "Peer";
> > >
> > > I know how to get an instance but I want the class as a static as the peer methods are static and
> > I would like to call them.
> > >
> > > Rgrds
> > > John
> > >
> > > ---
> > > Outgoing mail is certified Virus Free.
> > > Checked by AVG anti-virus system (http://www.grisoft.com).
> > > Version: 6.0.281 / Virus Database: 149 - Release Date: 9/18/2001
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: turbine-user-help@jakarta.apache.org
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-user-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: Mac doesn't upload properly

Posted by Kurt Schrader <ks...@engin.umich.edu>.
On Friday, September 21, 2001, at 12:42 PM, Gareth Coltman wrote:

> Here is my form header:
>
> <cut>
>
> Look right to you?

Yep.

> Its never actually getting to my code as you can see from my stack 
> trace. It seems to think that the stream ends unexpectedly.....

It must be a browser problem.  IE 5 must not be doing whatever it needs 
to in order to correctly send the file from the browser to Turbine.  I'm 
not sure what the workaround would be for this other than to use another 
browser.

-Kurt

RE: Mac doesn't upload properly

Posted by Gareth Coltman <ga...@majorband.co.uk>.
Mac Edition Version 5.

Here is my form header:

<form onSubmit="return validForm(this)" enctype="multipart/form-data" name="details_form"  id="details_form" method=post>
	<input type="hidden" name="action" value="myaction">
...

</form>

Look right to you?

Its never actually getting to my code as you can see from my stack trace. It seems to think that the stream ends unexpectedly.....

Please help!


> -----Original Message-----
> From: Kurt Schrader [mailto:kschrade@engin.umich.edu]
> Sent: Friday, September 21, 2001 17:33
> To: turbine-user@jakarta.apache.org
> Subject: Re: Mac doesn't upload properly
> 
> 
> 
> On Friday, September 21, 2001, at 12:07 PM, Gareth Coltman wrote:
> 
> > When a user tries to upload on a Mac (my Imac runs Explorer), the 
> > following error occurs:
> > <cut>
> 
> I use the upload service from my Mac and I've never seen an 
> error like 
> this.  Perhaps the version of Explorer you're using has a bug in its 
> Multipart upload code.  What version are you using?
> 
> -Kurt
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-user-help@jakarta.apache.org
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: Mac doesn't upload properly

Posted by Kurt Schrader <ks...@engin.umich.edu>.
On Friday, September 21, 2001, at 12:07 PM, Gareth Coltman wrote:

> When a user tries to upload on a Mac (my Imac runs Explorer), the 
> following error occurs:
> <cut>

I use the upload service from my Mac and I've never seen an error like 
this.  Perhaps the version of Explorer you're using has a bug in its 
Multipart upload code.  What version are you using?

-Kurt

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Mac doesn't upload properly

Posted by Gareth Coltman <ga...@majorband.co.uk>.
I am using the Turbine upload service, and it is working great on Explorer and Navigator... except

When a user tries to upload on a Mac (my Imac runs Explorer), the following error occurs:

        Exception:  org.apache.turbine.util.TurbineException: File upload failed: Processing of multipart/form-data request failed:
Stream ended unexpectedly
        Stack Trace follows:
        org.apache.turbine.util.upload.MultipartStream$MalformedStreamException: Stream ended unexpectedly
        at org.apache.turbine.util.upload.MultipartStream.readBoundary(MultipartStream.java:301)
        at org.apache.turbine.services.upload.TurbineUploadService.parseRequest(TurbineUploadService.java:245)
rethrown as org.apache.turbine.util.TurbineException: Processing of multipart/form-data request failed: Stream ended unexpectedly
        at org.apache.turbine.services.upload.TurbineUploadService.parseRequest(TurbineUploadService.java:250)
        at org.apache.turbine.services.upload.TurbineUpload.parseRequest(TurbineUpload.java:178)
        at org.apache.turbine.util.parser.DefaultParameterParser.setRequest(DefaultParameterParser.java:189)
rethrown as org.apache.turbine.util.TurbineException: File upload failed: Processing of multipart/form-data request failed: Stream
ended unexpectedly
        at org.apache.turbine.util.parser.DefaultParameterParser.setRequest(DefaultParameterParser.java:193)
        at org.apache.turbine.services.rundata.DefaultTurbineRunData.getParameters(DefaultTurbineRunData.java:502)
        at org.apache.turbine.Turbine.doGet(Turbine.java:278)
        at org.apache.turbine.Turbine.doPost(Turbine.java:537)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)
        at org.apache.tomcat.core.Handler.service(Handler.java:286)
        at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
        at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:797)
        at org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
        at org.apache.tomcat.service.connector.Ajp12ConnectionHandler.processConnection(Ajp12ConnectionHandler.java:166)
        at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
        at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
        at java.lang.Thread.run(Thread.java:484)

Any ideas????


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


RE: Get static instance of Peer dynamically

Posted by Age Mooy <am...@home.nl>.
Static methods can be invoked with a null object reference. 
It would look something like this:

String className = "com.mywebsite.application. " + tablename + "Peer";

Class[] types = new Class[] {Criteria.class};
Object[] parameters = new Object[] {new Criteria()};

Class peerClass = Class.forName(className);
Method select = peerClass.getMethod("doSelect", types);

List results = (List) m.invoke(null, parameters);

Untested of course but it should be close.
Age

> -----Original Message-----
> From: jmcnally@mx3.home.nl [mailto:jmcnally@mx3.home.nl]On Behalf Of
> John McNally
> Sent: Friday, September 21, 2001 17:33
> To: turbine-user@jakarta.apache.org
> Subject: Re: Get static instance of Peer dynamically
> 
> 
> I am not an expert using reflection but I think you will need to get an
> instance to pass to the Method.invoke command whether the method is
> static or not.  Is there some other way to invoke the method?  It seems
> like there should be so that you could use reflection on an abstract
> class.  It is not required in the case of Peers however since nothing
> prevents you from getting an instance of the class.  You should be able
> to invoke the method regardless of it being static.
> 
> john mcnally
> 
> John Colvin wrote:
> > 
> > Hi
> > Is there a way that I can get a static instance of a peer class by using Class.forName() or a 
> class loader. I am writing an application that contructs simple forms for updating databases 
> dynamically by reading the database Map, TableMap and ColumnMaps an generating the forms on the fly.
> > 
> > When I come to do a select/update/delete I would like to load a static instance by constructing a 
> string for the class name and then load this class statically.
> > 
> > ie from this :
> > 
> > String class name = "com.mywebsite.application. " + tablename + "Peer";
> > 
> > I know how to get an instance but I want the class as a static as the peer methods are static and 
> I would like to call them.
> > 
> > Rgrds
> > John
> > 
> > ---
> > Outgoing mail is certified Virus Free.
> > Checked by AVG anti-virus system (http://www.grisoft.com).
> > Version: 6.0.281 / Virus Database: 149 - Release Date: 9/18/2001
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-user-help@jakarta.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: Get static instance of Peer dynamically

Posted by John McNally <jm...@collab.net>.
I am not an expert using reflection but I think you will need to get an
instance to pass to the Method.invoke command whether the method is
static or not.  Is there some other way to invoke the method?  It seems
like there should be so that you could use reflection on an abstract
class.  It is not required in the case of Peers however since nothing
prevents you from getting an instance of the class.  You should be able
to invoke the method regardless of it being static.

john mcnally

John Colvin wrote:
> 
> Hi
> Is there a way that I can get a static instance of a peer class by using Class.forName() or a class loader. I am writing an application that contructs simple forms for updating databases dynamically by reading the database Map, TableMap and ColumnMaps an generating the forms on the fly.
> 
> When I come to do a select/update/delete I would like to load a static instance by constructing a string for the class name and then load this class statically.
> 
> ie from this :
> 
> String class name = "com.mywebsite.application. " + tablename + "Peer";
> 
> I know how to get an instance but I want the class as a static as the peer methods are static and I would like to call them.
> 
> Rgrds
> John
> 
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.281 / Virus Database: 149 - Release Date: 9/18/2001

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org