Back to index

wims  3.65+svn20090927
Factory.java
Go to the documentation of this file.
00001 /*
00002 $Id: Factory.java,v 1.2 2003/02/18 11:48:48 sander Exp $
00003 */
00004 
00005 
00006 package fr.ove.utils;
00007 
00014 public class Factory implements java.io.Serializable {
00019     public static Object getClassInstance(String className) {
00020         Object newClass = null;
00021         
00022        try {
00023               Class c = Class.forName(className);
00024               
00025               try {
00026                      newClass = c.newInstance();
00027               }
00028               catch (InstantiationException e ) {
00029                      System.out.println(className + " cannot be instantiated");
00030                      return null;
00031               }
00032               catch (IllegalAccessException e ) {
00033                      System.out.println(className + " impossible to access default constructor");
00034                      return null;
00035               }
00036               catch (NoClassDefFoundError e ) {
00037                      System.out.println("No definition of " + className + " can be found");
00038               }
00039 
00040         }
00041         catch (ClassNotFoundException e) {
00042               System.out.println("Class " + className + " not found");
00043                      return null;
00044         }
00045 
00046         return newClass;
00047     }
00048 }