001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019: package org.openharmonise.him.serverconfig.cache;
020:
021: import java.awt.*;
022: import java.net.*;
023: import java.rmi.*;
024: import java.util.*;
025: import java.util.List;
026:
027: import javax.swing.*;
028: import javax.xml.rpc.*;
029:
030: import org.openharmonise.him.*;
031: import org.openharmonise.him.configuration.*;
032: import org.openharmonise.him.harmonise.*;
033: import org.openharmonise.him.serverconfig.*;
034: import org.openharmonise.vfs.servers.ServerList;
035:
036: /**
037: * Panel for configuring the cache options of a Harmonise Information
038: * Server.
039: *
040: * @author Matthew Large
041: * @version $Revision: 1.1 $
042: *
043: */
044: public class CacheServerConfigOptions extends
045: AbstractServerConfigOptions implements ApplyChangesListener {
046:
047: /**
048: * Description.
049: */
050: private JTextArea m_descriptionTextArea = null;
051:
052: /**
053: * Map of object name to {@link CacheSettings} objects.
054: */
055: private HashMap m_objectNameSettingsMap = new HashMap();
056:
057: /**
058: * Username for the current user.
059: */
060: private String m_sUsername = null;
061:
062: /**
063: * Password for the current user.
064: */
065: private String m_sPassword = null;
066:
067: /**
068: * Constructs a new cache configuration options panel.
069: *
070: */
071: public CacheServerConfigOptions() {
072: super (null);
073: this .setup();
074: }
075:
076: /**
077: * Constructs a new cache configuration options panel.
078: *
079: * @param dialog configuration dialog that this panel will be in.
080: */
081: public CacheServerConfigOptions(ServerConfigDialog dialog) {
082: super (dialog);
083: dialog.addApplyChangesListener(this );
084: this .setup();
085: }
086:
087: /**
088: * Initialises this component.
089: *
090: */
091: private void setup() {
092: BoxLayout layout = new BoxLayout(this , BoxLayout.PAGE_AXIS);
093: this .setLayout(layout);
094:
095: this .m_sUsername = ServerList.getInstance()
096: .getHarmoniseServer().getVFS().getAuthentication()
097: .getUsername();
098: this .m_sPassword = ServerList.getInstance()
099: .getHarmoniseServer().getVFS().getAuthentication()
100: .getPassword();
101:
102: String fontName = "Dialog";
103: int fontSize = 11;
104: Font font = new Font(fontName, Font.PLAIN, fontSize);
105:
106: this .m_descriptionTextArea = new JTextArea(
107: "Set up server the Caches, alter total sizes.");
108: this .m_descriptionTextArea.setEditable(false);
109: this .m_descriptionTextArea.setBorder(BorderFactory
110: .createEmptyBorder(5, 10, 5, 5));
111: this .m_descriptionTextArea.setWrapStyleWord(true);
112: this .m_descriptionTextArea.setLineWrap(true);
113: this .m_descriptionTextArea.setOpaque(false);
114: this .m_descriptionTextArea.setPreferredSize(new Dimension(340,
115: 20));
116: this .add(m_descriptionTextArea);
117:
118: ConfigSettingsClient service = new ConfigSettingsClient();
119: URL url = null;
120: try {
121: URI uri = ServerList.getInstance().getHarmoniseServer()
122: .getURI();
123: String sURL = uri.getScheme() + "://" + uri.getHost() + ":"
124: + uri.getPort() + "/webdav/services/ConfigService";
125: url = new URL(sURL);
126:
127: } catch (MalformedURLException e) {
128: e.printStackTrace();
129: }
130:
131: List aConfigProps = null;
132: try {
133: aConfigProps = service.getAllProperties(url,
134: this .m_sUsername, this .m_sPassword);
135: } catch (RemoteException e1) {
136: e1.printStackTrace();
137: } catch (ServiceException e1) {
138: e1.printStackTrace();
139: }
140: Iterator itor = aConfigProps.iterator();
141: while (itor.hasNext()) {
142: ConfigProperty configProp = (ConfigProperty) itor.next();
143: boolean bCacheSize = false;
144: boolean bPageSize = false;
145: if (configProp.getName().endsWith("_cache_size")) {
146: bCacheSize = true;
147: } else if (configProp.getName().endsWith("_cachepage_size")) {
148: bPageSize = true;
149: }
150:
151: if (bCacheSize || bPageSize) {
152: String sObjName = configProp.getName().substring(0,
153: configProp.getName().indexOf("_"));
154: CacheSettings settings = (CacheSettings) this .m_objectNameSettingsMap
155: .get(sObjName);
156: if (settings == null) {
157: settings = new CacheSettings(sObjName, this );
158: this .add(settings);
159: this .m_objectNameSettingsMap
160: .put(sObjName, settings);
161: }
162: if (bCacheSize) {
163: String sValue = null;
164: sValue = configProp.getValue();
165: if (sValue != null) {
166: settings.setCacheSize(sValue);
167: }
168: }
169: }
170: }
171: }
172:
173: /* (non-Javadoc)
174: * @see com.simulacramedia.contentmanager.configuration.ApplyChangesListener#applyChanges()
175: */
176: public boolean applyChanges() {
177: boolean bOk = true;
178:
179: ConfigSettingsClient service = new ConfigSettingsClient();
180: URL url = null;
181: try {
182: URI uri = ServerList.getInstance().getHarmoniseServer()
183: .getURI();
184: String sURL = uri.getScheme() + "://" + uri.getHost() + ":"
185: + uri.getPort() + "/webdav/services/ConfigService";
186: url = new URL(sURL);
187:
188: Iterator itor = this .m_objectNameSettingsMap.keySet()
189: .iterator();
190: while (itor.hasNext()) {
191: String sObjName = (String) itor.next();
192: CacheSettings settings = (CacheSettings) this .m_objectNameSettingsMap
193: .get(sObjName);
194: if (settings.isCacheSizeChanged()) {
195: service.setProperty(url, this .m_sUsername,
196: this .m_sPassword, new ConfigProperty(
197: sObjName + "_cache_size", settings
198: .getCacheSize()));
199: settings.setCacheSizeChanged(false);
200: }
201: }
202: } catch (MalformedURLException e) {
203: e.printStackTrace();
204: bOk = false;
205: } catch (RemoteException e) {
206: e.printStackTrace();
207: bOk = false;
208: } catch (ServiceException e) {
209: e.printStackTrace();
210: bOk = false;
211: }
212:
213: return bOk;
214: }
215:
216: /* (non-Javadoc)
217: * @see com.simulacramedia.contentmanager.configuration.ApplyChangesListener#discardChanges()
218: */
219: public void discardChanges() {
220: }
221:
222: }
|