1 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 ; 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 45 public class CacheServerConfigOptions 46 extends AbstractServerConfigOptions 47 implements ApplyChangesListener{ 48 49 52 private JTextArea m_descriptionTextArea = null; 53 54 57 private HashMap m_objectNameSettingsMap = new HashMap(); 58 59 62 private String m_sUsername = null; 63 64 67 private String m_sPassword = null; 68 69 73 public CacheServerConfigOptions() { 74 super(null); 75 this.setup(); 76 } 77 78 83 public CacheServerConfigOptions(ServerConfigDialog dialog) { 84 super(dialog); 85 dialog.addApplyChangesListener(this); 86 this.setup(); 87 } 88 89 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 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 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 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 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 sValue = null; 153 sValue = configProp.getValue(); 154 if(sValue!=null) { 155 settings.setCacheSize(sValue); 156 } 157 } 158 } 159 } 160 } 161 162 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 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 sObjName = (String ) 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 202 public void discardChanges() { 203 } 204 205 } 206 | Popular Tags |