KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectstyle > cayenne > modeler > dialog > datadomain > JGroupsConfigModel


1
2 /* ====================================================================
3  *
4  * The ObjectStyle Group Software License, version 1.1
5  * ObjectStyle Group - http://objectstyle.org/
6  *
7  * Copyright (c) 2002-2005, Andrei (Andrus) Adamchik and individual authors
8  * of the software. All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  *
14  * 1. Redistributions of source code must retain the above copyright
15  * notice, this list of conditions and the following disclaimer.
16  *
17  * 2. Redistributions in binary form must reproduce the above copyright
18  * notice, this list of conditions and the following disclaimer in
19  * the documentation and/or other materials provided with the
20  * distribution.
21  *
22  * 3. The end-user documentation included with the redistribution, if any,
23  * must include the following acknowlegement:
24  * "This product includes software developed by independent contributors
25  * and hosted on ObjectStyle Group web site (http://objectstyle.org/)."
26  * Alternately, this acknowlegement may appear in the software itself,
27  * if and wherever such third-party acknowlegements normally appear.
28  *
29  * 4. The names "ObjectStyle Group" and "Cayenne" must not be used to endorse
30  * or promote products derived from this software without prior written
31  * permission. For written permission, email
32  * "andrus at objectstyle dot org".
33  *
34  * 5. Products derived from this software may not be called "ObjectStyle"
35  * or "Cayenne", nor may "ObjectStyle" or "Cayenne" appear in their
36  * names without prior written permission.
37  *
38  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
39  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
40  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
41  * DISCLAIMED. IN NO EVENT SHALL THE OBJECTSTYLE GROUP OR
42  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
44  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
45  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
46  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
47  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
48  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
49  * SUCH DAMAGE.
50  * ====================================================================
51  *
52  * This software consists of voluntary contributions made by many
53  * individuals and hosted on ObjectStyle Group web site. For more
54  * information on the ObjectStyle Group, please see
55  * <http://objectstyle.org/>.
56  */

57 package org.objectstyle.cayenne.modeler.dialog.datadomain;
58
59 import java.util.HashMap JavaDoc;
60 import java.util.Map JavaDoc;
61
62 import org.objectstyle.cayenne.access.DataRowStore;
63 import org.objectstyle.cayenne.event.JavaGroupsBridgeFactory;
64 import org.scopemvc.core.Selector;
65
66 /**
67  * @author Andrei Adamchik
68  */

69 public class JGroupsConfigModel extends CacheSyncConfigModel {
70     private static final String JavaDoc[] storedProperties =
71         new String JavaDoc[] {
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 JavaDoc selectors;
78     private static Map JavaDoc 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 JavaDoc(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 JavaDoc(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 JavaDoc map) {
113         super.setMap(map);
114         usingConfigFile = (map != null && getJgroupsConfigURL() != null);
115     }
116
117     public Selector selectorForKey(String JavaDoc key) {
118         return (Selector) selectors.get(key);
119     }
120
121     public String JavaDoc defaultForKey(String JavaDoc key) {
122         return (String JavaDoc) defaults.get(key);
123     }
124
125     public boolean isUsingConfigFile() {
126         return usingConfigFile;
127     }
128
129     public String JavaDoc[] 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 JavaDoc getJgroupsConfigURL() {
154         return getProperty(JavaGroupsBridgeFactory.JGROUPS_CONFIG_URL_PROPERTY);
155     }
156
157     public void setJgroupsConfigURL(String JavaDoc jgroupsConfigURL) {
158         setProperty(
159             JavaGroupsBridgeFactory.JGROUPS_CONFIG_URL_PROPERTY,
160             jgroupsConfigURL);
161     }
162
163     public String JavaDoc getMcastAddress() {
164         return getProperty(JavaGroupsBridgeFactory.MCAST_ADDRESS_PROPERTY);
165     }
166
167     public void setMcastAddress(String JavaDoc multicastAddress) {
168         setProperty(JavaGroupsBridgeFactory.MCAST_ADDRESS_PROPERTY, multicastAddress);
169     }
170
171     public String JavaDoc getMcastPort() {
172         return getProperty(JavaGroupsBridgeFactory.MCAST_PORT_PROPERTY);
173     }
174
175     public void setMcastPort(String JavaDoc multicastPort) {
176         setProperty(JavaGroupsBridgeFactory.MCAST_PORT_PROPERTY, multicastPort);
177     }
178 }
179
Popular Tags