KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > dav > server > webservice > ConfigSettingsService


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.dav.server.webservice;
20
21 import java.rmi.*;
22 import java.util.*;
23 import java.util.logging.*;
24
25 import org.openharmonise.rm.config.*;
26
27 /**
28  * This class provides configuration operations for config properties.
29  *
30  * @author Michael Bell
31  * @version $Revision: 1.1 $
32  *
33  */

34 public class ConfigSettingsService {
35
36     /**
37      * Logger for this class.
38      */

39     private static final Logger m_logger = Logger.getLogger(ConfigSettingsService.class.getName());
40     
41     /**
42      * Construct a new <code>ConfigSettingsService</code>.
43      */

44     public ConfigSettingsService() {
45         super();
46     }
47     
48     /**
49      * Return an array of all config properties.
50      *
51      * @param username the user name
52      * @param password the password
53      * @return an array of all config properties
54      * @throws RemoteException
55      */

56     public static ConfigProperty[] getAllProperties(String JavaDoc username, String JavaDoc password) throws RemoteException {
57         ConfigProperty[] props = null;
58         
59         try {
60             authenticateSuperUser(username, password);
61             
62             List propNames = ConfigSettings.getPropertyNameArray();
63             
64             props = new ConfigProperty[propNames.size()];
65             
66             for(int i=0;i<propNames.size();i++) {
67                 String JavaDoc sName = (String JavaDoc) propNames.get(i);
68                 String JavaDoc sVal = ConfigSettings.getProperty(sName);
69                 props[i] = new ConfigProperty(sName,sVal);
70                 System.out.println(props[i]);
71             }
72             
73             System.out.println(props.toString());
74             
75         } catch (ConfigException e) {
76             m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
77         }
78         
79         return props;
80     }
81     
82     /**
83      * Get the specified properties.
84      *
85      * @param username the user name
86      * @param password the user password
87      * @param propNames the names of the properties to return
88      * @return an array of config properties
89      * @throws RemoteException
90      */

91     public static ConfigProperty[] getProperties(String JavaDoc username, String JavaDoc password, String JavaDoc[] propNames) throws RemoteException {
92         ConfigProperty[] props = null;
93         
94         try {
95             authenticateSuperUser(username, password);
96             
97             props = new ConfigProperty[propNames.length];
98             
99             for(int i=0;i<propNames.length;i++) {
100                 String JavaDoc sName = (String JavaDoc) propNames[i];
101                 String JavaDoc sVal = ConfigSettings.getProperty(sName);
102                 props[i] = new ConfigProperty(sName,sVal);
103                 System.out.println(props[i]);
104             }
105             
106             System.out.println(props.toString());
107             
108         } catch (ConfigException e) {
109             m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
110         }
111         
112         return props;
113     }
114     
115     /**
116      * Set the values of the given config properties.
117      *
118      * @param username the user name
119      * @param password the user password
120      * @param props the properties to set
121      * @throws ConfigException
122      * @throws RemoteException
123      */

124     public static void setProperties(String JavaDoc username, String JavaDoc password, ConfigProperty[] props) throws ConfigException, RemoteException {
125         
126         authenticateSuperUser(username, password);
127         
128         for(int i=0;i<props.length;i++) {
129             
130             try {
131                 ConfigSettings.setProperty(props[i].getName(), props[i].getValue());
132             } catch (ConfigException e) {
133                 m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
134             }
135         }
136         
137     }
138     
139     /**
140      * Add the given properties.
141      *
142      * @param username the user name
143      * @param password the user password
144      * @param props the properties to add
145      * @throws ConfigException
146      * @throws RemoteException
147      */

148     public static void addProperties(String JavaDoc username, String JavaDoc password, ConfigProperty[] props) throws ConfigException, RemoteException {
149         
150         
151         authenticateSuperUser(username, password);
152         
153         for(int i=0;i<props.length;i++) {
154             
155             try {
156                 ConfigSettings.insertProperty(props[i].getName(), props[i].getValue());
157             } catch (ConfigException e) {
158                 m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
159             }
160             
161         }
162         
163     }
164     
165     /**
166      * Removes the specified configuration properties from
167      * this Harmonise installation.
168      *
169      * @param username the user name
170      * @param password the user password
171      * @param propNames the properties to remove
172      * @throws ConfigException
173      * @throws RemoteException
174      */

175     public static void removeProperties(String JavaDoc username, String JavaDoc password, String JavaDoc[] propNames) throws ConfigException, RemoteException {
176         
177         authenticateSuperUser(username, password);
178         
179         for(int i=0;i<propNames.length;i++) {
180             
181             try {
182                 ConfigSettings.removeProperty(propNames[i]);
183             } catch (ConfigException e) {
184                 m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
185             }
186             
187         }
188         
189     }
190
191     /**
192      * Authenticate that the user with the specified user name and
193      * password is a super user.
194      *
195      * @param username the user name
196      * @param password the user password
197      * @throws ConfigException
198      * @throws RemoteException
199      */

200     static private void authenticateSuperUser(String JavaDoc username, String JavaDoc password) throws ConfigException, RemoteException {
201         if(UserConfigService.isSuperUser(username, password) == false) {
202             throw new ConfigException("Forbidden: User is not super user");
203         }
204     }
205 }
206
Popular Tags