KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cruisecontrol > distributed > util > ReggieUtil


1 /****************************************************************************
2 * CruiseControl, a Continuous Integration Toolkit
3 * Copyright (c) 2001, ThoughtWorks, Inc.
4 * 651 W Washington Ave. Suite 600
5 * Chicago, IL 60661 USA
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * + Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * + Redistributions in binary form must reproduce the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer in the documentation and/or other materials provided
18 * with the distribution.
19 *
20 * + Neither the name of ThoughtWorks, Inc., CruiseControl, nor the
21 * names of its contributors may be used to endorse or promote
22 * products derived from this software without specific prior
23 * written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
29 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 ****************************************************************************/

37
38 package net.sourceforge.cruisecontrol.distributed.util;
39
40 import java.rmi.RMISecurityManager JavaDoc;
41 import java.util.ArrayList JavaDoc;
42 import java.util.StringTokenizer JavaDoc;
43 import java.util.List JavaDoc;
44
45 import net.jini.core.entry.Entry;
46 import net.sourceforge.cruisecontrol.distributed.PropertyEntry;
47
48 import org.apache.log4j.Logger;
49
50 public final class ReggieUtil {
51
52     private ReggieUtil() { }
53
54     private static final Logger LOG = Logger.getLogger(ReggieUtil.class);
55
56     /**
57      * converts an entries search string ento a list of entries. An example
58      * entries search string: "hostname=gandalf;os.name=Windows XP"
59      *
60      * @param searchString
61      * @return entriesList
62      */

63     public static Entry[] convertStringEntries(final String JavaDoc searchString) {
64         searchString.replace(',', ';');
65         final StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(searchString.trim(), ";");
66         final List JavaDoc entriesList = new ArrayList JavaDoc();
67         while (tokenizer.hasMoreElements()) {
68             final String JavaDoc token = tokenizer.nextToken();
69             final PropertyEntry entry = new PropertyEntry();
70             entry.name = token.substring(0, token.indexOf("=")).trim();
71             entry.value = token.substring(token.indexOf("=") + 1).trim();
72             entriesList.add(entry);
73         }
74
75         LOG.debug("Entry List: " + entriesList);
76         
77         final Entry[] arrEntries;
78         if (entriesList.size() == 0) {
79             arrEntries = null;
80         } else {
81             arrEntries = (Entry[]) entriesList.toArray(new Entry[entriesList.size()]);
82         }
83         return arrEntries;
84     }
85
86     /**
87      * Install the RMISecurityManager if not already installed.
88      */

89     public static void setupRMISecurityManager() {
90         final SecurityManager JavaDoc origSecurityManager = System.getSecurityManager();
91         if (origSecurityManager == null) {
92             System.setSecurityManager(new RMISecurityManager JavaDoc());
93         } else if (origSecurityManager.getClass().getName().indexOf("JavaWebStart") > -1) {
94             // do nothing, we're running under webstart
95
} else if (!(origSecurityManager instanceof RMISecurityManager JavaDoc)) {
96             final String JavaDoc msg = "Unexpected Security Manager. origSecurityManager: "
97                     + origSecurityManager;
98             LOG.error(msg);
99             throw new IllegalStateException JavaDoc(msg);
100         }
101     }
102 }
103
Popular Tags