You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hivemind.apache.org by "David J. M. Karlsen" <da...@davidkarlsen.com> on 2005/05/24 18:17:55 UTC

ClassFabUtils.getInstanceClass

Hi list!

I'm trying to make an interceptor the same way as HM's 
LoggingInterceptorFactory, but I have some problems with the following code:

private void createInfrastructure(InterceptorStack stack, ClassFab 
classFab){
	Class topClass = ClassFabUtils.getInstanceClass(stack.peek(), 
stack.getServiceInterface());
	classFab.addField("_delegate", topClass);
	classFab.addConstructor(new Class[]{ topClass }, null, "{_delegate = 
$1;}");
}


the debugger tells me topClass is: Class ($PooledProxy_1040f7af339_32) 
which is the pooled instance of my real underlying class.

The function fails at line two, with this message:

Unable to process content of element construct/service: Unable to lookup 
$PooledProxy_1040f7af339_32: $PooledProxy_1040f7af339_32 
(DefaultErrorHandler.java:37)

I guess that this is beacuse topClass is no real class - but a dynamic 
one - but the same should be true for the LoggingInterceptor - so I 
cannot understand why this is a problem for my class ??



-- 
David J. M. Karlsen - +47 90 68 22 43
http://www.davidkarlsen.com
http://mp3.davidkarlsen.com

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


Re: ClassFabUtils.getInstanceClass

Posted by "David J. M. Karlsen" <da...@davidkarlsen.com>.
James Carman wrote:

Because the software has to be ultra-stable! (Production quality)

> Why not use HM 1.1 now and let us know if you come across any bugs?  That's
> what the beta is for.
>>
>>
>>>>I'm trying to make an interceptor the same way as HM's
>>>>LoggingInterceptorFactory, but I have some problems with the 
>>>>following code:
>>>>
>>>>private void createInfrastructure(InterceptorStack stack, ClassFab
>>>>classFab){
>>>>       Class topClass = ClassFabUtils.getInstanceClass(stack.peek(),
>>>>stack.getServiceInterface());
>>>>       classFab.addField("_delegate", topClass);
>>>>       classFab.addConstructor(new Class[]{ topClass }, null, 
>>>>"{_delegate =
>>>>$1;}");
>>>>}
>>>>
>>>>
>>>>the debugger tells me topClass is: Class ($PooledProxy_1040f7af339_32)
>>>>which is the pooled instance of my real underlying class.
>>>>
>>>>The function fails at line two, with this message:
>>>>
>>>>Unable to process content of element construct/service: Unable to 
>>>>lookup
>>>>$PooledProxy_1040f7af339_32: $PooledProxy_1040f7af339_32
>>>>(DefaultErrorHandler.java:37)
>>>>
>>>>I guess that this is beacuse topClass is no real class - but a dynamic
>>>>one - but the same should be true for the LoggingInterceptor - so I
>>>>cannot understand why this is a problem for my class ??
>>>>  
>>>
>>I posted a mail earlier with the same problem - and Knut's response:
>>
>>"
>>
>>The problem is a class loader issue. You're creating your own
>>ClassFactory instance, which in turn uses its own Javassist ClassPool,
>>which can't find the PooledProxy class HiveMind created using its own
>>ClassPool. You'll have to use HiveMind's ClassFactory.
>>
>>For this you should define a setFactory(ClassFactory) method on your
>>interceptor factory and then add a line like this to the <construct>
>>of your interceptor factory service:
>>
>><set-service property="factory" service-id="hivemind.ClassFactory"/>
>>
>>"
>>
>>fixed the problem.
>>
>>But I've fallen into a new one - on some methods I get this:
>>
>>"
>>Unable to create class $Interceptor_1041511b5ba_38: (class: 
>>$Interceptor_1041511b5ba_38, method: defaultIntValueOf signature: 
>>(Ljava/lang/String;Ljava/lang/Object;I)I) Expecting to find 
>>object/array on stack
>>"
>>
>>which I posted on the same mail thread.
> 
> 
> 
> A good old reply-to-myself:
> 
> I din't check for the correct return types (it failed on returning 
> primitives).
> Now I check signature.getResulttype() and change the bodybuilder 
> accordingly.
> If javassist dini't have the bug the code could be the same for all 
> return types - I'm looking forward to HM 1.1! :-)


-- 
David J. M. Karlsen - +47 90 68 22 43
http://www.davidkarlsen.com
http://mp3.davidkarlsen.com

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


RE: ClassFabUtils.getInstanceClass

Posted by James Carman <ja...@carmanconsulting.com>.
Why not use HM 1.1 now and let us know if you come across any bugs?  That's
what the beta is for.

-----Original Message-----
From: David J. M. Karlsen [mailto:david@davidkarlsen.com] 
Sent: Thursday, May 26, 2005 5:29 PM
To: hivemind-dev@jakarta.apache.org
Subject: Re: ClassFabUtils.getInstanceClass

David J. M. Karlsen wrote:

> Hi list!
>
>>>
>>> I'm trying to make an interceptor the same way as HM's
>>> LoggingInterceptorFactory, but I have some problems with the 
>>> following code:
>>>
>>> private void createInfrastructure(InterceptorStack stack, ClassFab
>>> classFab){
>>>        Class topClass = ClassFabUtils.getInstanceClass(stack.peek(),
>>> stack.getServiceInterface());
>>>        classFab.addField("_delegate", topClass);
>>>        classFab.addConstructor(new Class[]{ topClass }, null, 
>>> "{_delegate =
>>> $1;}");
>>> }
>>>
>>>
>>> the debugger tells me topClass is: Class ($PooledProxy_1040f7af339_32)
>>> which is the pooled instance of my real underlying class.
>>>
>>> The function fails at line two, with this message:
>>>
>>> Unable to process content of element construct/service: Unable to 
>>> lookup
>>> $PooledProxy_1040f7af339_32: $PooledProxy_1040f7af339_32
>>> (DefaultErrorHandler.java:37)
>>>
>>> I guess that this is beacuse topClass is no real class - but a dynamic
>>> one - but the same should be true for the LoggingInterceptor - so I
>>> cannot understand why this is a problem for my class ??
>>>   
>>
> I posted a mail earlier with the same problem - and Knut's response:
>
> "
>
> The problem is a class loader issue. You're creating your own
> ClassFactory instance, which in turn uses its own Javassist ClassPool,
> which can't find the PooledProxy class HiveMind created using its own
> ClassPool. You'll have to use HiveMind's ClassFactory.
>
> For this you should define a setFactory(ClassFactory) method on your
> interceptor factory and then add a line like this to the <construct>
> of your interceptor factory service:
>
> <set-service property="factory" service-id="hivemind.ClassFactory"/>
>
> "
>
> fixed the problem.
>
> But I've fallen into a new one - on some methods I get this:
>
> "
> Unable to create class $Interceptor_1041511b5ba_38: (class: 
> $Interceptor_1041511b5ba_38, method: defaultIntValueOf signature: 
> (Ljava/lang/String;Ljava/lang/Object;I)I) Expecting to find 
> object/array on stack
> "
>
> which I posted on the same mail thread.


A good old reply-to-myself:

I din't check for the correct return types (it failed on returning 
primitives).
Now I check signature.getResulttype() and change the bodybuilder 
accordingly.
If javassist dini't have the bug the code could be the same for all 
return types - I'm looking forward to HM 1.1! :-)


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


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


Re: ClassFabUtils.getInstanceClass

Posted by "David J. M. Karlsen" <da...@davidkarlsen.com>.
David J. M. Karlsen wrote:

> Hi list!
>
>>>
>>> I'm trying to make an interceptor the same way as HM's
>>> LoggingInterceptorFactory, but I have some problems with the 
>>> following code:
>>>
>>> private void createInfrastructure(InterceptorStack stack, ClassFab
>>> classFab){
>>>        Class topClass = ClassFabUtils.getInstanceClass(stack.peek(),
>>> stack.getServiceInterface());
>>>        classFab.addField("_delegate", topClass);
>>>        classFab.addConstructor(new Class[]{ topClass }, null, 
>>> "{_delegate =
>>> $1;}");
>>> }
>>>
>>>
>>> the debugger tells me topClass is: Class ($PooledProxy_1040f7af339_32)
>>> which is the pooled instance of my real underlying class.
>>>
>>> The function fails at line two, with this message:
>>>
>>> Unable to process content of element construct/service: Unable to 
>>> lookup
>>> $PooledProxy_1040f7af339_32: $PooledProxy_1040f7af339_32
>>> (DefaultErrorHandler.java:37)
>>>
>>> I guess that this is beacuse topClass is no real class - but a dynamic
>>> one - but the same should be true for the LoggingInterceptor - so I
>>> cannot understand why this is a problem for my class ??
>>>   
>>
> I posted a mail earlier with the same problem - and Knut's response:
>
> "
>
> The problem is a class loader issue. You're creating your own
> ClassFactory instance, which in turn uses its own Javassist ClassPool,
> which can't find the PooledProxy class HiveMind created using its own
> ClassPool. You'll have to use HiveMind's ClassFactory.
>
> For this you should define a setFactory(ClassFactory) method on your
> interceptor factory and then add a line like this to the <construct>
> of your interceptor factory service:
>
> <set-service property="factory" service-id="hivemind.ClassFactory"/>
>
> "
>
> fixed the problem.
>
> But I've fallen into a new one - on some methods I get this:
>
> "
> Unable to create class $Interceptor_1041511b5ba_38: (class: 
> $Interceptor_1041511b5ba_38, method: defaultIntValueOf signature: 
> (Ljava/lang/String;Ljava/lang/Object;I)I) Expecting to find 
> object/array on stack
> "
>
> which I posted on the same mail thread.


A good old reply-to-myself:

I din't check for the correct return types (it failed on returning 
primitives).
Now I check signature.getResulttype() and change the bodybuilder 
accordingly.
If javassist dini't have the bug the code could be the same for all 
return types - I'm looking forward to HM 1.1! :-)


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


Re: ClassFabUtils.getInstanceClass

Posted by "David J. M. Karlsen" <da...@davidkarlsen.com>.
Howard Lewis Ship wrote:

>Are you using anything interesting, like loading modules from
>different class loaders?
>
>On 5/24/05, David J. M. Karlsen <da...@davidkarlsen.com> wrote:
>  
>
>>Hi list!
>>
>>I'm trying to make an interceptor the same way as HM's
>>LoggingInterceptorFactory, but I have some problems with the following code:
>>
>>private void createInfrastructure(InterceptorStack stack, ClassFab
>>classFab){
>>        Class topClass = ClassFabUtils.getInstanceClass(stack.peek(),
>>stack.getServiceInterface());
>>        classFab.addField("_delegate", topClass);
>>        classFab.addConstructor(new Class[]{ topClass }, null, "{_delegate =
>>$1;}");
>>}
>>
>>
>>the debugger tells me topClass is: Class ($PooledProxy_1040f7af339_32)
>>which is the pooled instance of my real underlying class.
>>
>>The function fails at line two, with this message:
>>
>>Unable to process content of element construct/service: Unable to lookup
>>$PooledProxy_1040f7af339_32: $PooledProxy_1040f7af339_32
>>(DefaultErrorHandler.java:37)
>>
>>I guess that this is beacuse topClass is no real class - but a dynamic
>>one - but the same should be true for the LoggingInterceptor - so I
>>cannot understand why this is a problem for my class ??
>>    
>>
I posted a mail earlier with the same problem - and Knut's response:

"

The problem is a class loader issue. You're creating your own
ClassFactory instance, which in turn uses its own Javassist ClassPool,
which can't find the PooledProxy class HiveMind created using its own
ClassPool. You'll have to use HiveMind's ClassFactory.

For this you should define a setFactory(ClassFactory) method on your
interceptor factory and then add a line like this to the <construct>
of your interceptor factory service:

 <set-service property="factory" service-id="hivemind.ClassFactory"/>

"

fixed the problem.

But I've fallen into a new one - on some methods I get this:

"
Unable to create class $Interceptor_1041511b5ba_38: (class: 
$Interceptor_1041511b5ba_38, method: defaultIntValueOf signature: 
(Ljava/lang/String;Ljava/lang/Object;I)I) Expecting to find object/array 
on stack
"

which I posted on the same mail thread.



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


Re: ClassFabUtils.getInstanceClass

Posted by Howard Lewis Ship <hl...@gmail.com>.
Are you using anything interesting, like loading modules from
different class loaders?

On 5/24/05, David J. M. Karlsen <da...@davidkarlsen.com> wrote:
> Hi list!
> 
> I'm trying to make an interceptor the same way as HM's
> LoggingInterceptorFactory, but I have some problems with the following code:
> 
> private void createInfrastructure(InterceptorStack stack, ClassFab
> classFab){
>         Class topClass = ClassFabUtils.getInstanceClass(stack.peek(),
> stack.getServiceInterface());
>         classFab.addField("_delegate", topClass);
>         classFab.addConstructor(new Class[]{ topClass }, null, "{_delegate =
> $1;}");
> }
> 
> 
> the debugger tells me topClass is: Class ($PooledProxy_1040f7af339_32)
> which is the pooled instance of my real underlying class.
> 
> The function fails at line two, with this message:
> 
> Unable to process content of element construct/service: Unable to lookup
> $PooledProxy_1040f7af339_32: $PooledProxy_1040f7af339_32
> (DefaultErrorHandler.java:37)
> 
> I guess that this is beacuse topClass is no real class - but a dynamic
> one - but the same should be true for the LoggingInterceptor - so I
> cannot understand why this is a problem for my class ??
> 
> 
> 
> --
> David J. M. Karlsen - +47 90 68 22 43
> http://www.davidkarlsen.com
> http://mp3.davidkarlsen.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: hivemind-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: hivemind-dev-help@jakarta.apache.org
> 
> 


-- 
Howard M. Lewis Ship
Independent J2EE / Open-Source Java Consultant
Creator, Jakarta Tapestry
Creator, Jakarta HiveMind

Professional Tapestry training, mentoring, support
and project work.  http://howardlewisship.com

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