KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > serverconfig > cache > CacheServerConfigOptions


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.him.serverconfig.cache;
20
21 import java.awt.*;
22 import java.net.*;
23 import java.rmi.*;
24 import java.util.*;
25 import java.util.List JavaDoc;
26
27 import javax.swing.*;
28 import javax.xml.rpc.*;
29
30 import org.openharmonise.him.*;
31 import org.openharmonise.him.configuration.*;
32 import org.openharmonise.him.harmonise.*;
33 import org.openharmonise.him.serverconfig.*;
34 import org.openharmonise.vfs.servers.ServerList;
35
36
37 /**
38  * Panel for configuring the cache options of a Harmonise Information
39  * Server.
40  *
41  * @author Matthew Large
42  * @version $Revision: 1.1 $
43  *
44  */

45 public class CacheServerConfigOptions
46     extends AbstractServerConfigOptions
47     implements ApplyChangesListener{
48         
49         /**
50          * Description.
51          */

52         private JTextArea m_descriptionTextArea = null;
53         
54         /**
55          * Map of object name to {@link CacheSettings} objects.
56          */

57         private HashMap m_objectNameSettingsMap = new HashMap();
58         
59         /**
60          * Username for the current user.
61          */

62         private String JavaDoc m_sUsername = null;
63         
64         /**
65          * Password for the current user.
66          */

67         private String JavaDoc m_sPassword = null;
68
69         /**
70          * Constructs a new cache configuration options panel.
71          *
72          */

73         public CacheServerConfigOptions() {
74             super(null);
75             this.setup();
76         }
77
78         /**
79          * Constructs a new cache configuration options panel.
80          *
81          * @param dialog configuration dialog that this panel will be in.
82          */

83         public CacheServerConfigOptions(ServerConfigDialog dialog) {
84             super(dialog);
85             dialog.addApplyChangesListener(this);
86             this.setup();
87         }
88     
89         /**
90          * Initialises this component.
91          *
92          */

93         private void setup() {
94             BoxLayout layout = new BoxLayout(this, BoxLayout.PAGE_AXIS);
95             this.setLayout( layout );
96             
97             this.m_sUsername = ServerList.getInstance().getHarmoniseServer().getVFS().getAuthentication().getUsername();
98             this.m_sPassword = ServerList.getInstance().getHarmoniseServer().getVFS().getAuthentication().getPassword();
99
100             String JavaDoc fontName = "Dialog";
101             int fontSize = 11;
102             Font font = new Font(fontName, Font.PLAIN, fontSize);
103             
104             this.m_descriptionTextArea = new JTextArea("Set up server the Caches, alter total sizes.");
105             this.m_descriptionTextArea.setEditable(false);
106             this.m_descriptionTextArea.setBorder(BorderFactory.createEmptyBorder(5,10,5,5));
107             this.m_descriptionTextArea.setWrapStyleWord(true);
108             this.m_descriptionTextArea.setLineWrap(true);
109             this.m_descriptionTextArea.setOpaque(false);
110             this.m_descriptionTextArea.setPreferredSize(new Dimension(340, 20));
111             this.add(m_descriptionTextArea);
112             
113             ConfigSettingsClient service = new ConfigSettingsClient();
114             URL url = null;
115             try {
116                 URI uri = ServerList.getInstance().getHarmoniseServer().getURI();
117                 String JavaDoc sURL = uri.getScheme() + "://" + uri.getHost() + ":" + uri.getPort() + "/webdav/services/ConfigService";
118                 url = new URL(sURL);
119                 
120             } catch (MalformedURLException e) {
121                 e.printStackTrace();
122             }
123             
124             List JavaDoc aConfigProps = null;
125             try {
126                 aConfigProps = service.getAllProperties(url, this.m_sUsername, this.m_sPassword);
127             } catch (RemoteException e1) {
128                 e1.printStackTrace();
129             } catch (ServiceException e1) {
130                 e1.printStackTrace();
131             }
132             Iterator itor = aConfigProps.iterator();
133             while (itor.hasNext()) {
134                 ConfigProperty configProp = (ConfigProperty) itor.next();
135                 boolean bCacheSize = false;
136                 boolean bPageSize = false;
137                 if(configProp.getName().endsWith("_cache_size")) {
138                     bCacheSize=true;
139                 } else if(configProp.getName().endsWith("_cachepage_size")) {
140                     bPageSize=true;
141                 }
142                 
143                 if(bCacheSize || bPageSize) {
144                     String JavaDoc sObjName = configProp.getName().substring(0, configProp.getName().indexOf("_"));
145                     CacheSettings settings = (CacheSettings) this.m_objectNameSettingsMap.get(sObjName);
146                     if(settings==null) {
147                         settings = new CacheSettings(sObjName, this);
148                         this.add(settings);
149                         this.m_objectNameSettingsMap.put(sObjName, settings);
150                     }
151                     if(bCacheSize) {
152                         String JavaDoc sValue = null;
153                         sValue = configProp.getValue();
154                         if(sValue!=null) {
155                             settings.setCacheSize(sValue);
156                         }
157                     }
158                 }
159             }
160         }
161
162         /* (non-Javadoc)
163          * @see com.simulacramedia.contentmanager.configuration.ApplyChangesListener#applyChanges()
164          */

165         public boolean applyChanges() {
166             boolean bOk = true;
167             
168             ConfigSettingsClient service = new ConfigSettingsClient();
169             URL url = null;
170             try {
171                 URI uri = ServerList.getInstance().getHarmoniseServer().getURI();
172                 String JavaDoc sURL = uri.getScheme() + "://" + uri.getHost() + ":" + uri.getPort() + "/webdav/services/ConfigService";
173                 url = new URL(sURL);
174                 
175                 
176                 Iterator itor = this.m_objectNameSettingsMap.keySet().iterator();
177                 while (itor.hasNext()) {
178                     String JavaDoc sObjName = (String JavaDoc) itor.next();
179                     CacheSettings settings = (CacheSettings) this.m_objectNameSettingsMap.get(sObjName);
180                     if(settings.isCacheSizeChanged()) {
181                         service.setProperty(url, this.m_sUsername, this.m_sPassword, new ConfigProperty(sObjName + "_cache_size", settings.getCacheSize()));
182                         settings.setCacheSizeChanged(false);
183                     }
184                 }
185             } catch (MalformedURLException e) {
186                 e.printStackTrace();
187                 bOk = false;
188             } catch (RemoteException e) {
189                 e.printStackTrace();
190                 bOk = false;
191             } catch (ServiceException e) {
192                 e.printStackTrace();
193                 bOk = false;
194             }
195             
196             return bOk;
197         }
198
199         /* (non-Javadoc)
200          * @see com.simulacramedia.contentmanager.configuration.ApplyChangesListener#discardChanges()
201          */

202         public void discardChanges() {
203         }
204
205     }
206
Popular Tags