1 package org.apache.ojb.odmg.collections; 2 3 import org.odmg.DList; 4 import org.odmg.DBag; 5 import org.odmg.DSet; 6 import org.odmg.DArray; 7 import org.odmg.DMap; 8 import org.apache.ojb.broker.util.factory.ConfigurableFactory; 9 import org.apache.ojb.broker.PBKey; 10 11 25 public class DCollectionFactory 26 { 27 private static final DCollectionFactory singleton = new DCollectionFactory(); 28 29 private DCollectionFactory() 30 { 31 } 32 33 public static DCollectionFactory getInstance() 34 { 35 return singleton; 36 } 37 38 public DList createDList() 39 { 40 return (DList) DListFactory.singleton.createCollectionOrMap(); 41 } 42 43 public DList createDList(PBKey key) 44 { 45 return (DList) DListFactory.singleton.createCollectionOrMap(key); 46 } 47 48 public DBag createDBag() 49 { 50 return (DBag) DBagFactory.singleton.createCollectionOrMap(); 51 } 52 53 public DBag createDBag(PBKey key) 54 { 55 return (DBag) DBagFactory.singleton.createCollectionOrMap(key); 56 } 57 58 public DSet createDSet() 59 { 60 return (DSet) DSetFactory.singleton.createCollectionOrMap(); 61 } 62 63 public DSet createDSet(PBKey key) 64 { 65 return (DSet) DSetFactory.singleton.createCollectionOrMap(key); 66 } 67 68 public DArray createDArray() 69 { 70 return (DArray) DArrayFactory.singleton.createCollectionOrMap(); 71 } 72 73 public DArray createDArray(PBKey key) 74 { 75 return (DArray) DArrayFactory.singleton.createCollectionOrMap(key); 76 } 77 78 public DMap createDMap() 79 { 80 return (DMap) DMapFactory.singleton.createCollectionOrMap(); 81 } 82 83 public DMap createDMap(PBKey key) 84 { 85 return (DMap) DMapFactory.singleton.createCollectionOrMap(key); 86 } 87 88 92 abstract static class BaseFactory extends ConfigurableFactory 93 { 94 Object createCollectionOrMap() 95 { 96 return this.createNewInstance(); 97 } 98 99 Object createCollectionOrMap(PBKey key) 100 { 101 return createNewInstance(PBKey.class, key); 102 } 103 } 104 105 static final class DListFactory extends BaseFactory 106 { 107 static final BaseFactory singleton = new DListFactory(); 108 protected String getConfigurationKey() 109 { 110 return "DListClass"; 111 } 112 } 113 114 static final class DArrayFactory extends BaseFactory 115 { 116 static final BaseFactory singleton = new DArrayFactory(); 117 protected String getConfigurationKey() 118 { 119 return "DArrayClass"; 120 } 121 } 122 123 static final class DBagFactory extends BaseFactory 124 { 125 static final BaseFactory singleton = new DBagFactory(); 126 protected String getConfigurationKey() 127 { 128 return "DBagClass"; 129 } 130 } 131 132 static final class DSetFactory extends BaseFactory 133 { 134 static final BaseFactory singleton = new DSetFactory(); 135 protected String getConfigurationKey() 136 { 137 return "DSetClass"; 138 } 139 } 140 141 static final class DMapFactory extends BaseFactory 142 { 143 static final BaseFactory singleton = new DMapFactory(); 144 protected String getConfigurationKey() 145 { 146 return "DMapClass"; 147 } 148 } 149 } 150 | Popular Tags |