Forums Register Login

runtime bytecode generation

+Pie Number of slices to send: Send
I have a requirement to create a composite key from JMS message properties; the properties that need to be used for key is in a XML configuration file. At run time I have to read this configuration file and then create the composite key from the incoming JMS message. I can do this various ways. But I am looking for bytecode generation at runtime; can any one help or point me in right direction


Thanks
Raees
[ October 07, 2007: Message edited by: RAEES UZHUNNAN ]
+Pie Number of slices to send: Send
The Javassist library (on SourceForge, part of the JBoss project) is very useful for generating classes at runtime.
[ October 08, 2007: Message edited by: Ulf Dittmer ]
+Pie Number of slices to send: Send
I'm curious about what happens next. You create a key object of a dynamically created class and ... who uses it and how? The class cannot be known by any other part of the system at compile time, right?
+Pie Number of slices to send: Send
The usual way would be for the dynamically generated class to implement some pre-known interface to which a newly created object can then be cast.
+Pie Number of slices to send: Send
Yes , he is correct !. The idea is to populate key data and validation logic at runtime as per the configuration !. For achieving this we will define and interface like below (eg

interface BaseKey
{
string getKey()
boolean validateKey()
}

and then provide the specialization based on client selection of the key attributes from the configuration file at runtime. The psedo code for new generated class will be like the below

Class NewKey implements BaseKey
{
Int a;
Int b;
Int c;
NewKey(a,b,c);

String getKey()
{
Return ��+a+b+c;
}
Boolean validateKey()
{// validation logic here
Return true;
}
}

Raees
[ October 08, 2007: Message edited by: RAEES UZHUNNAN ]
+Pie Number of slices to send: Send
Cool. Sounds fun enough.

Edit: I was on the run out the door before. This particular example seems simple enough to do with a generic class that concatenates some fields or creates an ordered list of name-value-pairs. Seems like any metadata that you use to generate code in the class - like the validate - could just as well be interpreted at runtime in the generic class.

Is an on-the-fly class really worth the trouble?
[ October 08, 2007: Message edited by: Stan James ]
+Pie Number of slices to send: Send
Can you pls put an example
+Pie Number of slices to send: Send
I agree with generics approach; but not for complex ideas like below;
Even though I did not mention much about the validate function before; bulk of my code generation is going to benefit there. For example;

if I have a configuration like below ( again this is pseudo ); I wan to implement the code in the fly and this rules can change based on client deployment

<Key>
<Item>
<Name>a</Name>
<Validation>
<startlimit>0< startlimit >
<endlimit>10<endlimit>
</ Validation >
</Item>
<Item>
<Name>b</Name>
<Validation>
<Enum>
10,20,30
</Enum>
</ Validation >
</Item>
<Item>
<Name>c</Name>
<Validation>
<Length>
8
</ Length >
</ Validation >
</Item>
</Key>
no wonder he is so sad, he hasn't seen this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 958 times.
Similar Threads
Hibernate Criteria and composite key
hibernate: id generator for column in composite key
How to use generators in Composite-id
Difference between runtime reflection, runtime bytecode generation and .....
Websphere 6.1.0.3 trail version --> Default JMS server problemm
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 20:33:56.