You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by bu...@apache.org on 2003/06/01 02:16:26 UTC
DO NOT REPLY [Bug 20388] New: -
[Collections]GenericFactory -> Factory implementation for general use of Factory with lazyList
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=20388>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND
INSERTED IN THE BUG DATABASE.
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=20388
[Collections]GenericFactory -> Factory implementation for general use of Factory with lazyList
Summary: [Collections]GenericFactory -> Factory implementation
for general use of Factory with lazyList
Product: Commons
Version: unspecified
Platform: All
OS/Version: All
Status: NEW
Severity: Enhancement
Priority: Other
Component: Collections
AssignedTo: commons-dev@jakarta.apache.org
ReportedBy: mail@phase.ws
The following is a class that I wrote that implements the Factory interface of
the Collections package. It is a good generic class when using the lazyList. It
cuts down on the amount of code you have to write. I submitted this a long
while back and for some reason it did not go through. It really should. If
there is a class that already accomplishes this, then please let me know. But,
I haven't been able to find it. Also, if the Factory Interface exists within
the Collections package then why not have an implementation. Anyways, the class
is called GenericFactory and it's easy to use. Here is the syntax.
List myList;
this.myList =
ListUtils.lazyList(
new ArrayList(),
new GenericFactory("com.foo.myClass"));
Simple Huh?
Here is the class code.
--- code start ---
package org.apache.commons.collections;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* @author Brandon Goodin
*
*/
public class GenericFactory implements Factory
{
private static final Log log = LogFactory.getLog(GenericFactory.class);
private String className;
private Object object;
public GenericFactory(String className)
{
this.className = className;
}
public Object create()
{
try {
object = null;
Class classDefinition = Class.forName(className);
object = classDefinition.newInstance();
}
catch(InstantiationException ex){
log.error(ex.getMessage(),ex.fillInStackTrace());
}
catch(IllegalAccessException ex) {
log.error(ex.getMessage(),ex.fillInStackTrace());
} catch(ClassNotFoundException ex) {
log.error(ex.getMessage(),ex.fillInStackTrace());
}
return object;
}
}
--- code stop ---
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org