1 2 57 package org.objectstyle.cayenne.modeler.dialog.datadomain; 58 59 import java.util.HashMap ; 60 import java.util.Map ; 61 62 import org.objectstyle.cayenne.access.DataRowStore; 63 import org.objectstyle.cayenne.event.JavaGroupsBridgeFactory; 64 import org.scopemvc.core.Selector; 65 66 69 public class JGroupsConfigModel extends CacheSyncConfigModel { 70 private static final String [] storedProperties = 71 new String [] { 72 DataRowStore.EVENT_BRIDGE_FACTORY_PROPERTY, 73 JavaGroupsBridgeFactory.MCAST_ADDRESS_PROPERTY, 74 JavaGroupsBridgeFactory.MCAST_PORT_PROPERTY, 75 JavaGroupsBridgeFactory.JGROUPS_CONFIG_URL_PROPERTY }; 76 77 private static Map selectors; 78 private static Map defaults; 79 80 public static final Selector USING_CONFIG_FILE_SELECTOR = 81 Selector.fromString("usingConfigFile"); 82 public static final Selector USING_DEFAULT_CONFIG_SELECTOR = 83 Selector.fromString("usingDefaultConfig"); 84 85 public static final Selector MCAST_ADDRESS_SELECTOR = 86 Selector.fromString("mcastAddress"); 87 public static final Selector MCAST_PORT_SELECTOR = Selector.fromString("mcastPort"); 88 public static final Selector JGROUPS_CONFIG_URL_SELECTOR = 89 Selector.fromString("jgroupsConfigURL"); 90 91 static { 92 selectors = new HashMap (5); 93 selectors.put( 94 JavaGroupsBridgeFactory.JGROUPS_CONFIG_URL_PROPERTY, 95 JGROUPS_CONFIG_URL_SELECTOR); 96 selectors.put( 97 JavaGroupsBridgeFactory.MCAST_ADDRESS_PROPERTY, 98 MCAST_ADDRESS_SELECTOR); 99 selectors.put(JavaGroupsBridgeFactory.MCAST_PORT_PROPERTY, MCAST_PORT_SELECTOR); 100 101 defaults = new HashMap (4); 102 defaults.put( 103 JavaGroupsBridgeFactory.MCAST_ADDRESS_PROPERTY, 104 JavaGroupsBridgeFactory.MCAST_ADDRESS_DEFAULT); 105 defaults.put( 106 JavaGroupsBridgeFactory.MCAST_PORT_PROPERTY, 107 JavaGroupsBridgeFactory.MCAST_PORT_DEFAULT); 108 } 109 110 protected boolean usingConfigFile; 111 112 public void setMap(Map map) { 113 super.setMap(map); 114 usingConfigFile = (map != null && getJgroupsConfigURL() != null); 115 } 116 117 public Selector selectorForKey(String key) { 118 return (Selector) selectors.get(key); 119 } 120 121 public String defaultForKey(String key) { 122 return (String ) defaults.get(key); 123 } 124 125 public boolean isUsingConfigFile() { 126 return usingConfigFile; 127 } 128 129 public String [] supportedProperties() { 130 return storedProperties; 131 } 132 133 public void setUsingConfigFile(boolean b) { 134 this.usingConfigFile = b; 135 136 if (b) { 137 setMcastAddress(null); 138 setMcastPort(null); 139 } 140 else { 141 setJgroupsConfigURL(null); 142 } 143 } 144 145 public boolean isUsingDefaultConfig() { 146 return !isUsingConfigFile(); 147 } 148 149 public void setUsingDefaultConfig(boolean flag) { 150 setUsingConfigFile(!flag); 151 } 152 153 public String getJgroupsConfigURL() { 154 return getProperty(JavaGroupsBridgeFactory.JGROUPS_CONFIG_URL_PROPERTY); 155 } 156 157 public void setJgroupsConfigURL(String jgroupsConfigURL) { 158 setProperty( 159 JavaGroupsBridgeFactory.JGROUPS_CONFIG_URL_PROPERTY, 160 jgroupsConfigURL); 161 } 162 163 public String getMcastAddress() { 164 return getProperty(JavaGroupsBridgeFactory.MCAST_ADDRESS_PROPERTY); 165 } 166 167 public void setMcastAddress(String multicastAddress) { 168 setProperty(JavaGroupsBridgeFactory.MCAST_ADDRESS_PROPERTY, multicastAddress); 169 } 170 171 public String getMcastPort() { 172 return getProperty(JavaGroupsBridgeFactory.MCAST_PORT_PROPERTY); 173 } 174 175 public void setMcastPort(String multicastPort) { 176 setProperty(JavaGroupsBridgeFactory.MCAST_PORT_PROPERTY, multicastPort); 177 } 178 } 179 | Popular Tags |