1 24 25 package org.objectweb.cjdbc.controller.loadbalancer.policies.createtable; 26 27 import java.util.HashMap ; 28 import java.util.Iterator ; 29 30 import org.objectweb.cjdbc.common.xml.DatabasesXmlTags; 31 import org.objectweb.cjdbc.common.xml.XmlComponent; 32 33 39 public class CreateTablePolicy implements XmlComponent 40 { 41 42 public static final int RANDOM = 0; 43 44 45 public static final int ROUND_ROBIN = 1; 46 47 48 public static final int ALL = 2; 49 50 51 private HashMap ruleList = new HashMap (); 52 53 59 public void addRule(CreateTableRule rule) 60 { 61 ruleList.put(rule.getTableName(), rule); 62 } 63 64 69 public HashMap getRuleList() 70 { 71 return ruleList; 72 } 73 74 81 public CreateTableRule getTableRule(String tableName) 82 { 83 return (CreateTableRule) ruleList.get(tableName); 84 } 85 86 92 public CreateTableRule getDefaultRule() 93 { 94 return (CreateTableRule) ruleList.get(null); 95 } 96 97 103 public static final String getXmlValue(int policy) 104 { 105 switch (policy) 106 { 107 case RANDOM : 108 return DatabasesXmlTags.VAL_random; 109 case ROUND_ROBIN : 110 return DatabasesXmlTags.VAL_roundRobin; 111 case ALL : 112 return DatabasesXmlTags.VAL_all; 113 default : 114 return ""; 115 } 116 } 117 118 124 public String getXml() 125 { 126 StringBuffer info = new StringBuffer (); 127 for (Iterator iterator = ruleList.keySet().iterator(); iterator.hasNext();) 128 info.append(((CreateTableRule) ruleList.get(iterator.next())).getXml()); 129 return info.toString(); 130 } 131 132 } 133 | Popular Tags |