KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > system > server > ServerConfigUtil


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.system.server;
23
24 import java.net.InetAddress JavaDoc;
25 import java.net.UnknownHostException JavaDoc;
26
27 /**
28  * Utilities for accessing server configuration
29  *
30  * @author <a HREF="mailto:adrian@jboss.org">Adrian Brock</a>
31  * @version <tt>$Revision: 57108 $</tt>
32  */

33 public class ServerConfigUtil
34 {
35    private static final String JavaDoc ANY = "0.0.0.0";
36    
37    /**
38     * Retrieve the default bind address for the server
39     *
40     * @return the default bind adress
41     */

42    public static String JavaDoc getDefaultBindAddress()
43    {
44       return System.getProperty(ServerConfig.SERVER_BIND_ADDRESS);
45    }
46
47    /**
48     * Retrieve the default bind address, but only if it is specific
49     *
50     * @return the specific bind address
51     */

52    public static String JavaDoc getSpecificBindAddress()
53    {
54       String JavaDoc address = System.getProperty(ServerConfig.SERVER_BIND_ADDRESS);
55       if (address == null || address.equals(ANY))
56          return null;
57       return address;
58    }
59
60    /**
61     * Fix the remote inet address.
62     *
63     * If we pass the address to the client we don't want to
64     * tell it to connect to 0.0.0.0, use our host name instead
65     * @param address the passed address
66     * @return the fixed address
67     */

68    public static InetAddress JavaDoc fixRemoteAddress(InetAddress JavaDoc address)
69    {
70       try
71       {
72          if (address == null || InetAddress.getByName(ANY).equals(address))
73             return InetAddress.getLocalHost();
74       }
75       catch (UnknownHostException JavaDoc ignored)
76       {
77       }
78       return address;
79    }
80
81    /**
82     * Fix the remote address.
83     *
84     * If we pass the address to the client we don't want to
85     * tell it to connect to 0.0.0.0, use our host name instead
86     * @param address the passed address
87     * @return the fixed address
88     */

89    public static String JavaDoc fixRemoteAddress(String JavaDoc address)
90    {
91       try
92       {
93          if (address == null || ANY.equals(address))
94             return InetAddress.getLocalHost().getHostName();
95       }
96       catch (UnknownHostException JavaDoc ignored)
97       {
98       }
99       return address;
100    }
101
102    /**
103     * Get the default partition name
104     *
105     * @return the default partition name
106     */

107    public static String JavaDoc getDefaultPartitionName()
108    {
109       return System.getProperty(ServerConfig.PARTITION_NAME_PROPERTY, ServerConfig.DEFAULT_PARITION_NAME);
110    }
111
112    /**
113     * Whether to load native directories
114     *
115     * @return true when loading native directories
116     */

117    public static boolean isLoadNative()
118    {
119       return Boolean.getBoolean(ServerConfig.NATIVE_LOAD_PROPERTY);
120    }
121
122    /**
123     * Utility to get a shortened url relative to the server home if possible
124     *
125     * @param longUrl
126     * @return the short url
127     */

128    public static String JavaDoc shortUrlFromServerHome(String JavaDoc longUrl)
129    {
130       String JavaDoc serverHomeUrl = System.getProperty(org.jboss.system.server.ServerConfig.SERVER_HOME_URL);
131
132       if (longUrl == null || serverHomeUrl == null)
133           return longUrl;
134
135       if (longUrl.startsWith(serverHomeUrl))
136         return ".../" + longUrl.substring(serverHomeUrl.length());
137       else
138       {
139          String JavaDoc jarServerHomeUrl = "jar:" + serverHomeUrl;
140          if (longUrl.startsWith(jarServerHomeUrl))
141             return ".../" + longUrl.substring(jarServerHomeUrl.length());
142          else
143             return longUrl;
144       }
145    }
146 }
147
Popular Tags