-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: dynamic classes
PostPosted: Fri Apr 01, 2005 3:59 am 
Beginner
Beginner

Joined: Wed Feb 23, 2005 10:37 am
Posts: 29
Hi,
I have a question regarding dynamic class loading.
I have a mapping class which has a field (interface) and in database column we have saved factory implementation classname. It needs to be loaded dynamically from the fully-qualified classname stored in db:

Code:
class foo{
int id;
Runnable impl;
}


The impl classname is stored in db and the implementation is hidden. Would appreciate if anybody can give a hint on how to map the foo.hbm.xml this component.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 01, 2005 4:04 am 
Beginner
Beginner

Joined: Wed Feb 23, 2005 10:37 am
Posts: 29
one way of doing it is as following:
Code:
class foo{
int id;
Runnable impl;
String ImplClassName;

public void setImplClassName(String implClassName){
this.ImplClassName=implClassName;
this.impl=(Runnable)Class.forName(this.ImplClassName).newInstance();
}

public String getImplClassName(){
return ImplClassName;
}


But I was wondering if there was any prettier solution for cases like this.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.