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.
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.
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.
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.
23
package org.jboss.remoting;
25
import java.lang.reflect.Method;
26
import java.security.AccessController;
27
import java.security.PrivilegedAction;
28
import java.security.PrivilegedActionException;
29
import java.security.PrivilegedExceptionAction;
31
import org.jboss.remoting.util.SecurityUtility;
34
* @author <a href="mailto:tom.elrod@jboss.com">Tom Elrod</a>
38
// possible remoting versions
39
public static final byte VERSION_1 = 1;
40
public static final byte VERSION_2 = 2;
41
public static final byte VERSION_2_2 = 22;
43
public static final String VERSION = "2.5.3.SP1 (Flounder)";
44
private static final byte byteVersion = VERSION_2_2;
45
private static byte defaultByteVersion = byteVersion;
46
private static boolean performVersioning = true;
49
public static final String PRE_2_0_COMPATIBLE = "jboss.remoting.pre_2_0_compatible";
50
//TODO: -TME Is this the best system property key to use? May want to use something that
51
// is more decscriptive that is user defined version. However, may want to make available
52
// to users via system property the version of remoting?
53
public static final String REMOTING_VERSION_TO_USE = "jboss.remoting.version";
55
// have a static block to load the user defined version to use
60
ClassLoader cl = getClassLoader();
61
Class c = cl.loadClass("org.jboss.logging.Logger");
62
Method getLogger = c.getMethod("getLogger", new Class[]{String.class});
63
Object logger = getLogger.invoke(null, new Object[] {"org.jboss.remoting"});
64
Method debug = c.getMethod("debug", new Class[]{Object.class});
65
debug.invoke(logger, new Object[]{"Remoting version: " + VERSION});
72
boolean precompatibleFlag = false;
73
String precompatible = getSystemProperty(PRE_2_0_COMPATIBLE);
75
if(precompatible != null && precompatible.length() > 0)
77
precompatibleFlag = Boolean.valueOf(precompatible).booleanValue();
79
// if is precompatible, no need to look for custom version, as there is only 1 precompatible version
82
defaultByteVersion = 1;
83
performVersioning = false;
87
String userDefinedVersion = getSystemProperty(REMOTING_VERSION_TO_USE);
89
if(userDefinedVersion != null && userDefinedVersion.length() > 0)
91
byte userByteVersion = new Byte(userDefinedVersion).byteValue();
92
if(userByteVersion > 0)
94
defaultByteVersion = userByteVersion;
95
if(defaultByteVersion < 2)
97
performVersioning = false;
102
System.err.println("Can not set remoting version to value less than 1. " +
103
"System property value set for '" + REMOTING_VERSION_TO_USE + "' was " + userDefinedVersion);
108
setSystemProperty(REMOTING_VERSION_TO_USE, new Byte(defaultByteVersion).toString());
113
public static void main(String arg[])
115
System.out.println("JBossRemoting Version " + VERSION);
118
public static int getDefaultVersion()
120
return defaultByteVersion;
123
public static boolean performVersioning()
125
return performVersioning;
128
public static boolean performVersioning(int version)
133
public static boolean isValidVersion(int version)
135
return version == VERSION_1 || version == VERSION_2 || version == VERSION_2_2;
138
static private String getSystemProperty(final String name)
140
if (SecurityUtility.skipAccessControl())
141
return System.getProperty(name);
146
value = (String)AccessController.doPrivileged( new PrivilegedExceptionAction()
148
public Object run() throws Exception
150
return System.getProperty(name);
154
catch (PrivilegedActionException e)
156
throw (RuntimeException) e.getCause();
162
static private void setSystemProperty(final String name, final String value)
164
if (SecurityUtility.skipAccessControl())
166
System.setProperty(name, value);
172
AccessController.doPrivileged( new PrivilegedExceptionAction()
174
public Object run() throws Exception
176
return System.setProperty(name, value);
180
catch (PrivilegedActionException e)
182
throw (RuntimeException) e.getCause();
186
static private ClassLoader getClassLoader()
188
if (SecurityUtility.skipAccessControl())
190
return Version.class.getClassLoader();
193
return (ClassLoader)AccessController.doPrivileged( new PrivilegedAction()
197
return Version.class.getClassLoader();
b'\\ No newline at end of file'