~ubuntu-branches/ubuntu/raring/libjboss-remoting-java/raring

« back to all changes in this revision

Viewing changes to src/main/org/jboss/remoting/Version.java

  • Committer: Package Import Robot
  • Author(s): Torsten Werner
  • Date: 2011-09-09 14:01:03 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: package-import@ubuntu.com-20110909140103-hqokx61534tas9rg
Tags: 2.5.3.SP1-1
* Newer but not newest upstream release. Do not build samples.
* Change debian/watch to upstream's svn repo.
* Add patch to fix compile error caused by tomcat update.
  (Closes: #628303)
* Switch to source format 3.0.
* Switch to debhelper level 7.
* Remove useless Depends.
* Update Standards-Version: 3.9.2.
* Update README.source.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
23
package org.jboss.remoting;
 
24
 
 
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;
 
30
 
 
31
import org.jboss.remoting.util.SecurityUtility;
 
32
 
 
33
/**
 
34
 * @author <a href="mailto:tom.elrod@jboss.com">Tom Elrod</a>
 
35
 */
 
36
public class Version
 
37
{
 
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;
 
42
 
 
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;
 
47
 
 
48
 
 
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";
 
54
 
 
55
   // have a static block to load the user defined version to use
 
56
   static
 
57
   {
 
58
      try
 
59
      {
 
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});
 
66
      }
 
67
      catch (Throwable t)
 
68
      {
 
69
         // ignore
 
70
      }
 
71
      
 
72
      boolean precompatibleFlag = false;
 
73
      String  precompatible = getSystemProperty(PRE_2_0_COMPATIBLE);
 
74
 
 
75
      if(precompatible != null && precompatible.length() > 0)
 
76
      {
 
77
         precompatibleFlag = Boolean.valueOf(precompatible).booleanValue();
 
78
      }
 
79
      // if is precompatible, no need to look for custom version, as there is only 1 precompatible version
 
80
      if(precompatibleFlag)
 
81
      {
 
82
         defaultByteVersion = 1;
 
83
         performVersioning = false;
 
84
      }
 
85
      else
 
86
      {
 
87
         String userDefinedVersion = getSystemProperty(REMOTING_VERSION_TO_USE);
 
88
         
 
89
         if(userDefinedVersion != null && userDefinedVersion.length() > 0)
 
90
         {
 
91
            byte userByteVersion = new Byte(userDefinedVersion).byteValue();
 
92
            if(userByteVersion > 0)
 
93
            {
 
94
               defaultByteVersion = userByteVersion;
 
95
               if(defaultByteVersion < 2)
 
96
               {
 
97
                  performVersioning = false;
 
98
               }
 
99
            }
 
100
            else
 
101
            {
 
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);
 
104
            }
 
105
         }
 
106
         else
 
107
         {
 
108
            setSystemProperty(REMOTING_VERSION_TO_USE, new Byte(defaultByteVersion).toString());
 
109
         }
 
110
      }
 
111
   }
 
112
 
 
113
   public static void main(String arg[])
 
114
   {
 
115
      System.out.println("JBossRemoting Version " + VERSION);
 
116
   }
 
117
 
 
118
   public static int getDefaultVersion()
 
119
   {
 
120
      return defaultByteVersion;
 
121
   }
 
122
 
 
123
   public static boolean performVersioning()
 
124
   {
 
125
      return performVersioning;
 
126
   }
 
127
   
 
128
   public static boolean performVersioning(int version)
 
129
   {
 
130
      return version >= 2;
 
131
   }
 
132
   
 
133
   public static boolean isValidVersion(int version)
 
134
   {
 
135
      return version == VERSION_1 || version == VERSION_2 || version == VERSION_2_2;
 
136
   }
 
137
   
 
138
   static private String getSystemProperty(final String name)
 
139
   {
 
140
      if (SecurityUtility.skipAccessControl())
 
141
         return System.getProperty(name);
 
142
      
 
143
      String value = null;
 
144
      try
 
145
      {
 
146
         value = (String)AccessController.doPrivileged( new PrivilegedExceptionAction()
 
147
         {
 
148
            public Object run() throws Exception
 
149
            {
 
150
               return System.getProperty(name);
 
151
            }
 
152
         });
 
153
      }
 
154
      catch (PrivilegedActionException e)
 
155
      {
 
156
         throw (RuntimeException) e.getCause();
 
157
      }
 
158
      
 
159
      return value;
 
160
   }
 
161
   
 
162
   static private void setSystemProperty(final String name, final String value)
 
163
   {
 
164
      if (SecurityUtility.skipAccessControl())
 
165
      {
 
166
         System.setProperty(name, value);
 
167
         return;
 
168
      }
 
169
      
 
170
      try
 
171
      {
 
172
         AccessController.doPrivileged( new PrivilegedExceptionAction()
 
173
         {
 
174
            public Object run() throws Exception
 
175
            {
 
176
               return System.setProperty(name, value);
 
177
            }
 
178
         });
 
179
      }
 
180
      catch (PrivilegedActionException e)
 
181
      {
 
182
         throw (RuntimeException) e.getCause();
 
183
      }
 
184
   }
 
185
   
 
186
   static private ClassLoader getClassLoader()
 
187
   {
 
188
      if (SecurityUtility.skipAccessControl())
 
189
      {
 
190
         return Version.class.getClassLoader();
 
191
      }
 
192
 
 
193
      return (ClassLoader)AccessController.doPrivileged( new PrivilegedAction()
 
194
      {
 
195
         public Object run()
 
196
         {
 
197
            return Version.class.getClassLoader();
 
198
         }
 
199
      });
 
200
   }
 
201
}
 
 
b'\\ No newline at end of file'