1 18 19 20 package org.apache.struts.config; 21 22 23 import java.io.Serializable ; 24 import java.util.HashMap ; 25 import java.util.Iterator ; 26 import java.util.Map ; 27 import org.apache.struts.Globals; 28 29 30 42 43 public class DataSourceConfig implements Serializable { 44 45 46 47 49 50 53 protected boolean configured = false; 54 55 56 58 59 63 protected String key = Globals.DATA_SOURCE_KEY; 64 65 public String getKey() { 66 return (this.key); 67 } 68 69 public void setKey(String key) { 70 if (configured) { 71 throw new IllegalStateException ("Configuration is frozen"); 72 } 73 this.key = key; 74 } 75 76 77 80 protected HashMap properties = new HashMap (); 81 82 public Map getProperties() { 83 return (this.properties); 84 } 85 86 87 91 protected String type; 92 93 public String getType() { 94 return (this.type); 95 } 96 97 public void setType(String type) { 98 if (configured) { 99 throw new IllegalStateException ("Configuration is frozen"); 100 } 101 this.type = type; 102 } 103 104 105 107 108 114 public void addProperty(String name, String value) { 115 116 if (configured) { 117 throw new IllegalStateException ("Configuration is frozen"); 118 } 119 properties.put(name, value); 120 121 } 122 123 124 127 public void freeze() { 128 129 configured = true; 130 131 } 132 133 134 137 public String toString() { 138 139 StringBuffer sb = new StringBuffer ("DataSourceConfig["); 140 sb.append("key="); 141 sb.append(key); 142 sb.append(",type="); 143 sb.append(type); 144 Iterator names = properties.keySet().iterator(); 145 while (names.hasNext()) { 146 String name = (String ) names.next(); 147 String value = (String ) properties.get(name); 148 sb.append(','); 149 sb.append(name); 150 sb.append('='); 151 sb.append(value); 152 } 153 sb.append("]"); 154 return (sb.toString()); 155 156 } 157 158 159 } 160 | Popular Tags |