01: package org.xdev.base.core;
02:
03: /**
04: * <p>Title: Reliant B2B Engine</p>
05: * <p>Description: XML Driven B2B Framework</p>
06: * <p>Copyright: Copyright (c) 2002</p>
07: * <p>Company: Reliant Energy</p>
08: * @author Artem D. Yegorov
09: * @version 1.0
10: */
11: import java.util.*;
12:
13: import org.xdev.base.core.object.*;
14:
15: public class ObjectFactory implements GenericFactory {
16: private HashMap stubs = new HashMap();
17: private static HashMap factories = new HashMap();
18: private static ObjectFactory f = null;
19:
20: private ObjectFactory() {
21: }
22:
23: public static ObjectFactory getInstance(Object key) {
24: ObjectFactory factory = (ObjectFactory) factories.get(key);
25: if (factory == null) {
26: factory = new ObjectFactory();
27: factories.put(key, factory);
28: }
29:
30: return factory;
31: }
32:
33: public static ObjectFactory getInstance() {
34: if (f == null) {
35: f = new ObjectFactory();
36: }
37:
38: return f;
39: }
40:
41: public Object newInstance(String type, String id) throws Exception {
42: GenericObjectStub stub = (GenericObjectStub) this .stubs
43: .get(type + id);
44: Object object = null;
45: if (stub != null) {
46: object = stub.newInstance();
47: stub = null;
48: }
49:
50: return object;
51: }
52:
53: public Object newInstance(String id) throws Exception {
54: return this .newInstance("", id);
55: }
56:
57: public void addStub(String type, String id, GenericObjectStub stub) {
58: this .stubs.put(type + id, stub);
59: }
60:
61: public void addStub(String id, GenericObjectStub stub) {
62: this .addStub("", id, stub);
63: }
64:
65: public synchronized void reset() {
66: this .stubs = new HashMap();
67: }
68:
69: }
|