001: /****************************************************************************
002: * CruiseControl, a Continuous Integration Toolkit
003: * Copyright (c) 2001, ThoughtWorks, Inc.
004: * 200 E. Randolph, 25th Floor
005: * Chicago, IL 60601 USA
006: * All rights reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * + Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * + Redistributions in binary form must reproduce the above
016: * copyright notice, this list of conditions and the following
017: * disclaimer in the documentation and/or other materials provided
018: * with the distribution.
019: *
020: * + Neither the name of ThoughtWorks, Inc., CruiseControl, nor the
021: * names of its contributors may be used to endorse or promote
022: * products derived from this software without specific prior
023: * written permission.
024: *
025: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
026: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
027: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
028: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
029: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
030: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
031: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
032: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
033: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
034: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
035: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
036: ****************************************************************************/package net.sourceforge.cruisecontrol.distributed.core;
037:
038: import java.rmi.RMISecurityManager;
039: import java.util.ArrayList;
040: import java.util.StringTokenizer;
041: import java.util.List;
042:
043: import net.jini.core.entry.Entry;
044: import net.sourceforge.cruisecontrol.distributed.PropertyEntry;
045:
046: import org.apache.log4j.Logger;
047:
048: public final class ReggieUtil {
049:
050: private ReggieUtil() {
051: }
052:
053: private static final Logger LOG = Logger
054: .getLogger(ReggieUtil.class);
055:
056: /**
057: * converts an entries search string into a list of entries. An example
058: * entries search string: "hostname=gandalf;os.name=Windows XP"
059: *
060: * @param searchString this semicolon delimited list of search entries
061: * @return entriesList an array of entry objects
062: */
063: public static Entry[] convertStringEntries(final String searchString) {
064: final StringTokenizer tokenizer = new StringTokenizer(
065: searchString.trim(), ";");
066: final List entriesList = new ArrayList();
067: while (tokenizer.hasMoreElements()) {
068: final String token = tokenizer.nextToken();
069: final PropertyEntry entry = new PropertyEntry();
070: entry.name = token.substring(0, token.indexOf("=")).trim();
071: entry.value = token.substring(token.indexOf("=") + 1)
072: .trim();
073: entriesList.add(entry);
074: }
075:
076: LOG.debug("Entry List: " + entriesList);
077:
078: final Entry[] arrEntries;
079: if (entriesList.size() == 0) {
080: arrEntries = null;
081: } else {
082: arrEntries = (Entry[]) entriesList
083: .toArray(new Entry[entriesList.size()]);
084: }
085: return arrEntries;
086: }
087:
088: /**
089: * Install the RMISecurityManager if not already installed.
090: */
091: public static void setupRMISecurityManager() {
092: final SecurityManager origSecurityManager = System
093: .getSecurityManager();
094: if (origSecurityManager == null) {
095: System.setSecurityManager(new RMISecurityManager());
096: } else if (origSecurityManager.getClass().getName().indexOf(
097: "JavaWebStart") > -1) {
098: // do nothing, we're running under webstart
099: } else if (!(origSecurityManager instanceof RMISecurityManager)) {
100: final String msg = "Unexpected Security Manager. origSecurityManager: "
101: + origSecurityManager;
102: LOG.error(msg);
103: throw new IllegalStateException(msg);
104: }
105: }
106: }
|