01: /*
02: * ObjectDescFactory.java
03: *
04: * Copyright (c) 2007 Sun Microsystems, Inc. All Rights Reserved.
05: *
06: * See the file "LICENSE.txt" for information on usage and redistribution
07: * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
08: */
09: package org.pnuts.lang;
10:
11: /*
12: * ObjectDescFactory.getDefault().create(className)
13: */
14: public abstract class ObjectDescFactory implements
15: ObjectDescFactoryConstants {
16:
17: static ObjectDescFactory defaultFactory = getDefaultObjectDescFactory();
18:
19: static ObjectDescFactory instantiateObjectDescFactory(
20: String className) {
21: try {
22: Class cls = Class.forName(className);
23: return (ObjectDescFactory) cls.newInstance();
24: } catch (Exception e) {
25: e.printStackTrace();
26: return null;
27: }
28: }
29:
30: static ObjectDescFactory getDefaultObjectDescFactory() {
31: String prop = System.getProperty(PROPERTY_OBJECT_DESC_FACTORY);
32: if (prop != null) {
33: return instantiateObjectDescFactory(prop);
34: }
35: return instantiateObjectDescFactory(DEFAULT_OBJECT_DESC_FACTORY_NAME);
36: }
37:
38: public static ObjectDescFactory getDefault() {
39: return defaultFactory;
40: }
41:
42: public abstract ObjectDesc create(Class cls);
43:
44: public ObjectDesc create(Class cls, Class stopClass) {
45: return create(cls);
46: }
47: }
|