mirror of https://github.com/apache/activemq.git
Applied patch in AMQ-1515 Thx David.
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@602565 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6f0dcac677
commit
27c87d20f3
|
@ -28,7 +28,6 @@ import org.apache.activemq.command.DataStructure;
|
|||
import org.apache.activemq.command.WireFormatInfo;
|
||||
import org.apache.activemq.util.ByteSequence;
|
||||
import org.apache.activemq.util.ByteSequenceData;
|
||||
import org.apache.activemq.util.ClassLoading;
|
||||
import org.apache.activemq.util.DataByteArrayInputStream;
|
||||
import org.apache.activemq.util.DataByteArrayOutputStream;
|
||||
import org.apache.activemq.wireformat.WireFormat;
|
||||
|
@ -326,7 +325,7 @@ public final class OpenWireFormat implements WireFormat {
|
|||
String mfName = "org.apache.activemq.openwire.v" + version + ".MarshallerFactory";
|
||||
Class mfClass;
|
||||
try {
|
||||
mfClass = ClassLoading.loadClass(mfName, getClass().getClassLoader());
|
||||
mfClass = Class.forName(mfName, false, getClass().getClassLoader());
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw (IllegalArgumentException)new IllegalArgumentException("Invalid version: " + version
|
||||
+ ", could not load " + mfName)
|
||||
|
|
|
@ -26,7 +26,6 @@ import org.apache.activemq.openwire.BooleanStream;
|
|||
import org.apache.activemq.openwire.DataStreamMarshaller;
|
||||
import org.apache.activemq.openwire.OpenWireFormat;
|
||||
import org.apache.activemq.util.ByteSequence;
|
||||
import org.apache.activemq.util.ClassLoading;
|
||||
|
||||
public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller {
|
||||
|
||||
|
@ -228,7 +227,7 @@ public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller {
|
|||
|
||||
private Throwable createThrowable(String className, String message) {
|
||||
try {
|
||||
Class clazz = ClassLoading.loadClass(className, BaseDataStreamMarshaller.class.getClassLoader());
|
||||
Class clazz = Class.forName(className, false, BaseDataStreamMarshaller.class.getClassLoader());
|
||||
Constructor constructor = clazz.getConstructor(new Class[] {String.class});
|
||||
return (Throwable)constructor.newInstance(new Object[] {message});
|
||||
} catch (Throwable e) {
|
||||
|
|
|
@ -26,7 +26,6 @@ import org.apache.activemq.openwire.BooleanStream;
|
|||
import org.apache.activemq.openwire.DataStreamMarshaller;
|
||||
import org.apache.activemq.openwire.OpenWireFormat;
|
||||
import org.apache.activemq.util.ByteSequence;
|
||||
import org.apache.activemq.util.ClassLoading;
|
||||
|
||||
public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller {
|
||||
|
||||
|
@ -228,7 +227,7 @@ public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller {
|
|||
|
||||
private Throwable createThrowable(String className, String message) {
|
||||
try {
|
||||
Class clazz = ClassLoading.loadClass(className, BaseDataStreamMarshaller.class.getClassLoader());
|
||||
Class clazz = Class.forName(className, false, BaseDataStreamMarshaller.class.getClassLoader());
|
||||
Constructor constructor = clazz.getConstructor(new Class[] {String.class});
|
||||
return (Throwable)constructor.newInstance(new Object[] {message});
|
||||
} catch (Throwable e) {
|
||||
|
|
|
@ -26,7 +26,6 @@ import org.apache.activemq.openwire.BooleanStream;
|
|||
import org.apache.activemq.openwire.DataStreamMarshaller;
|
||||
import org.apache.activemq.openwire.OpenWireFormat;
|
||||
import org.apache.activemq.util.ByteSequence;
|
||||
import org.apache.activemq.util.ClassLoading;
|
||||
|
||||
public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller {
|
||||
|
||||
|
@ -228,7 +227,7 @@ public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller {
|
|||
|
||||
private Throwable createThrowable(String className, String message) {
|
||||
try {
|
||||
Class clazz = ClassLoading.loadClass(className, BaseDataStreamMarshaller.class.getClassLoader());
|
||||
Class clazz = Class.forName(className, false, BaseDataStreamMarshaller.class.getClassLoader());
|
||||
Constructor constructor = clazz.getConstructor(new Class[] {String.class});
|
||||
return (Throwable)constructor.newInstance(new Object[] {message});
|
||||
} catch (Throwable e) {
|
||||
|
@ -291,7 +290,7 @@ public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller {
|
|||
dataIn.readFully(data);
|
||||
// Yes deprecated, but we know what we are doing.
|
||||
// This allows us to create a String from a ASCII byte array. (no UTF-8 decoding)
|
||||
return new String(data, 0);
|
||||
return new String(data, 0);
|
||||
} else {
|
||||
return dataIn.readUTF();
|
||||
}
|
||||
|
|
|
@ -1,244 +0,0 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.activemq.util;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Utilities for loading classes.
|
||||
*
|
||||
* @version $Rev: 109957 $ $Date$
|
||||
*/
|
||||
public final class ClassLoading {
|
||||
|
||||
/**
|
||||
* Primitive type name -> class map.
|
||||
*/
|
||||
private static final Map<String, Class> PRIMITIVES = new HashMap<String, Class>();
|
||||
/**
|
||||
* VM primitive type primitive type -> name
|
||||
*/
|
||||
private static final Map<Class, String> VM_PRIMITIVES_REVERSE = new HashMap<Class, String>();
|
||||
/**
|
||||
* VM primitive type name -> primitive type
|
||||
*/
|
||||
private static final Map<String, Class> VM_PRIMITIVES = new HashMap<String, Class>();
|
||||
/**
|
||||
* Map of primitive types to their wrapper classes
|
||||
*/
|
||||
private static final Map<Class, Class> PRIMITIVE_WRAPPERS = new HashMap<Class, Class>();
|
||||
|
||||
private ClassLoading() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a class for the given name. <p/>
|
||||
* <p>
|
||||
* Handles loading primitive types as well as VM class and array syntax.
|
||||
*
|
||||
* @param className
|
||||
* The name of the Class to be loaded.
|
||||
* @param classLoader
|
||||
* The class loader to load the Class object from.
|
||||
* @return The Class object for the given name.
|
||||
* @throws ClassNotFoundException
|
||||
* Failed to load Class object.
|
||||
*/
|
||||
public static Class loadClass(final String className, final ClassLoader classLoader) throws ClassNotFoundException {
|
||||
if (className == null) {
|
||||
throw new IllegalArgumentException("className is null");
|
||||
}
|
||||
|
||||
// First just try to load
|
||||
try {
|
||||
return load(className, classLoader);
|
||||
} catch (ClassNotFoundException ignore) {
|
||||
// handle special cases below
|
||||
}
|
||||
|
||||
Class type = null;
|
||||
|
||||
// Check if it is a primitive type
|
||||
type = getPrimitiveType(className);
|
||||
if (type != null) {
|
||||
return type;
|
||||
}
|
||||
|
||||
// Check if it is a vm primitive
|
||||
type = getVMPrimitiveType(className);
|
||||
if (type != null) {
|
||||
return type;
|
||||
}
|
||||
|
||||
// Handle VM class syntax (Lclassname;)
|
||||
if (className.charAt(0) == 'L' && className.charAt(className.length() - 1) == ';') {
|
||||
String name = className.substring(1, className.length() - 1);
|
||||
return load(name, classLoader);
|
||||
}
|
||||
|
||||
// Handle VM array syntax ([type)
|
||||
if (className.charAt(0) == '[') {
|
||||
int arrayDimension = className.lastIndexOf('[') + 1;
|
||||
String componentClassName = className.substring(arrayDimension, className.length());
|
||||
type = loadClass(componentClassName, classLoader);
|
||||
|
||||
int dim[] = new int[arrayDimension];
|
||||
java.util.Arrays.fill(dim, 0);
|
||||
return Array.newInstance(type, dim).getClass();
|
||||
}
|
||||
|
||||
// Handle user friendly type[] syntax
|
||||
if (className.endsWith("[]")) {
|
||||
// get the base component class name and the arrayDimensions
|
||||
int arrayDimension = 0;
|
||||
String componentClassName = className;
|
||||
while (componentClassName.endsWith("[]")) {
|
||||
componentClassName = componentClassName.substring(0, componentClassName.length() - 2);
|
||||
arrayDimension++;
|
||||
}
|
||||
|
||||
// load the base type
|
||||
type = loadClass(componentClassName, classLoader);
|
||||
|
||||
// return the array type
|
||||
int[] dim = new int[arrayDimension];
|
||||
java.util.Arrays.fill(dim, 0);
|
||||
return Array.newInstance(type, dim).getClass();
|
||||
}
|
||||
|
||||
// Else we can not load (give up)
|
||||
throw new ClassNotFoundException(className);
|
||||
}
|
||||
|
||||
private static Class load(final String className, final ClassLoader classLoader) throws ClassNotFoundException {
|
||||
if (classLoader == null) {
|
||||
return Class.forName(className);
|
||||
} else {
|
||||
return classLoader.loadClass(className);
|
||||
}
|
||||
}
|
||||
|
||||
public static String getClassName(Class clazz) {
|
||||
StringBuffer rc = new StringBuffer();
|
||||
while (clazz.isArray()) {
|
||||
rc.append('[');
|
||||
clazz = clazz.getComponentType();
|
||||
}
|
||||
if (!clazz.isPrimitive()) {
|
||||
rc.append('L');
|
||||
rc.append(clazz.getName());
|
||||
rc.append(';');
|
||||
} else {
|
||||
rc.append(VM_PRIMITIVES_REVERSE.get(clazz));
|
||||
}
|
||||
return rc.toString();
|
||||
}
|
||||
|
||||
/** Setup the primitives map. */
|
||||
static {
|
||||
PRIMITIVES.put("boolean", Boolean.TYPE);
|
||||
PRIMITIVES.put("byte", Byte.TYPE);
|
||||
PRIMITIVES.put("char", Character.TYPE);
|
||||
PRIMITIVES.put("short", Short.TYPE);
|
||||
PRIMITIVES.put("int", Integer.TYPE);
|
||||
PRIMITIVES.put("long", Long.TYPE);
|
||||
PRIMITIVES.put("float", Float.TYPE);
|
||||
PRIMITIVES.put("double", Double.TYPE);
|
||||
PRIMITIVES.put("void", Void.TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the primitive type for the given primitive name.
|
||||
*
|
||||
* @param name
|
||||
* Primitive type name (boolean, byte, int, ...)
|
||||
* @return Primitive type or null.
|
||||
*/
|
||||
private static Class getPrimitiveType(final String name) {
|
||||
return PRIMITIVES.get(name);
|
||||
}
|
||||
|
||||
|
||||
/** Setup the vm primitives map. */
|
||||
static {
|
||||
VM_PRIMITIVES.put("B", byte.class);
|
||||
VM_PRIMITIVES.put("C", char.class);
|
||||
VM_PRIMITIVES.put("D", double.class);
|
||||
VM_PRIMITIVES.put("F", float.class);
|
||||
VM_PRIMITIVES.put("I", int.class);
|
||||
VM_PRIMITIVES.put("J", long.class);
|
||||
VM_PRIMITIVES.put("S", short.class);
|
||||
VM_PRIMITIVES.put("Z", boolean.class);
|
||||
VM_PRIMITIVES.put("V", void.class);
|
||||
}
|
||||
|
||||
|
||||
/** Setup the vm primitives reverse map. */
|
||||
static {
|
||||
VM_PRIMITIVES_REVERSE.put(byte.class, "B");
|
||||
VM_PRIMITIVES_REVERSE.put(char.class, "C");
|
||||
VM_PRIMITIVES_REVERSE.put(double.class, "D");
|
||||
VM_PRIMITIVES_REVERSE.put(float.class, "F");
|
||||
VM_PRIMITIVES_REVERSE.put(int.class, "I");
|
||||
VM_PRIMITIVES_REVERSE.put(long.class, "J");
|
||||
VM_PRIMITIVES_REVERSE.put(short.class, "S");
|
||||
VM_PRIMITIVES_REVERSE.put(boolean.class, "Z");
|
||||
VM_PRIMITIVES_REVERSE.put(void.class, "V");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the primitive type for the given VM primitive name. <p/>
|
||||
* <p>
|
||||
* Mapping:
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* B - byte
|
||||
* C - char
|
||||
* D - double
|
||||
* F - float
|
||||
* I - int
|
||||
* J - long
|
||||
* S - short
|
||||
* Z - boolean
|
||||
* V - void
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @param name
|
||||
* VM primitive type name (B, C, J, ...)
|
||||
* @return Primitive type or null.
|
||||
*/
|
||||
private static Class getVMPrimitiveType(final String name) {
|
||||
return VM_PRIMITIVES.get(name);
|
||||
}
|
||||
|
||||
/** Setup the wrapper map. */
|
||||
static {
|
||||
PRIMITIVE_WRAPPERS.put(Boolean.TYPE, Boolean.class);
|
||||
PRIMITIVE_WRAPPERS.put(Byte.TYPE, Byte.class);
|
||||
PRIMITIVE_WRAPPERS.put(Character.TYPE, Character.class);
|
||||
PRIMITIVE_WRAPPERS.put(Double.TYPE, Double.class);
|
||||
PRIMITIVE_WRAPPERS.put(Float.TYPE, Float.class);
|
||||
PRIMITIVE_WRAPPERS.put(Integer.TYPE, Integer.class);
|
||||
PRIMITIVE_WRAPPERS.put(Long.TYPE, Long.class);
|
||||
PRIMITIVE_WRAPPERS.put(Short.TYPE, Short.class);
|
||||
PRIMITIVE_WRAPPERS.put(Void.TYPE, Void.class);
|
||||
}
|
||||
}
|
|
@ -51,9 +51,9 @@ public class ClassLoadingAwareObjectInputStream extends ObjectInputStream {
|
|||
|
||||
private Class load(String className, ClassLoader cl) throws ClassNotFoundException {
|
||||
try {
|
||||
return ClassLoading.loadClass(className, cl);
|
||||
return Class.forName(className, false, cl);
|
||||
} catch (ClassNotFoundException e) {
|
||||
return ClassLoading.loadClass(className, FALLBACK_CLASS_LOADER);
|
||||
return Class.forName(className, false, FALLBACK_CLASS_LOADER);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue