Method from org.exolab.castor.xml.MarshalFramework Detail: |
public CollectionHandler getCollectionHandler(Class clazz) {
CollectionHandler handler = null;
try {
handler = CollectionHandlers.getHandler(clazz);
}
catch (MappingException mx) {
//-- Not a collection, or no handler exists, return null.
}
return handler;
}
Returns the CollectionHandler associated with the
given collection, or null if no such handler exists. |
public InternalContext getInternalContext() {
return _internalContext;
}
|
public JavaNaming getJavaNaming() {
return _internalContext.getJavaNaming();
}
|
static final boolean hasFieldsAtLocation(String location,
XMLClassDescriptor classDesc) {
//-- check elements
XMLFieldDescriptor[] descriptors = classDesc.getElementDescriptors();
for (int i = 0; i < descriptors.length; i++) {
if (descriptors[i] == null) {
continue;
}
String tmpLocation = descriptors[i].getLocationPath();
if ((tmpLocation != null) && (tmpLocation.startsWith(location))) {
return true;
}
}
//-- check attributes
descriptors = classDesc.getAttributeDescriptors();
for (int i = 0; i < descriptors.length; i++) {
if (descriptors[i] == null) {
continue;
}
String tmpLocation = descriptors[i].getLocationPath();
if ((tmpLocation != null) && (tmpLocation.startsWith(location))) {
return true;
}
}
//-- check content/text
XMLFieldDescriptor content = classDesc.getContentDescriptor();
if (content != null) {
String tmpLocation = content.getLocationPath();
if ((tmpLocation != null) && (tmpLocation.startsWith(location))) {
return true;
}
}
return false;
}
Returns true if any of the fields associated with the given
XMLClassDescriptor are located at, or beneath, the given location. |
public static boolean isCollection(Class clazz) {
return CollectionHandlers.hasHandler(clazz);
}
Returns true if the given Class is a considered a
collection by the marshalling framework. |
static boolean isEnum(Class type) {
if (type == null) {
return false;
}
float javaVersion =
Float.valueOf(System.getProperty("java.specification.version")).floatValue();
if (javaVersion >= JDK_VERSION_1_5) {
try {
Boolean isEnum = ReflectionUtil.isEnumViaReflection(type);
return isEnum.booleanValue();
} catch (Exception e) {
// nothing to report; implies that there's no such method
}
}
// TODO: add code to cover 1.4 enum-stype classes as well.
return false;
}
Returns true if the given class should be treated as an enum type. This method
will return true for all Java 5 (or later) enums, and for enum-style
classes. |
static boolean isPrimitive(Class type) {
if (type == null) {
return false;
}
//-- java primitive
if (type.isPrimitive()) {
return true;
}
//-- we treat strings as primitives
if (type == String.class) {
return true;
}
//-- primtive wrapper classes
if ((type == Boolean.class) || (type == Character.class)) {
return true;
}
Class superClass = type.getSuperclass();
if (superClass == Number.class) {
return true;
}
if (superClass != null) {
return superClass.getName().equals("java.lang.Enum");
}
return false;
}
Returns true if the given class should be treated as a primitive
type. This method will return true for all Java primitive
types, the set of primitive object wrappers, as well
as Strings. |
public static boolean namespaceEquals(String ns1,
String ns2) {
if (ns1 == null) {
return ((ns2 == null) || (ns2.length() == 0));
}
if (ns2 == null) {
return (ns1.length() == 0);
}
return ns1.equals(ns2);
}
Compares the given namespaces (as strings) for equality.
null and empty values are considered equal. |
static boolean primitiveOrWrapperEquals(Class a,
Class b) {
if (!isPrimitive(a)) {
return false;
}
if (!isPrimitive(b)) {
return false;
}
if (a == b) {
return true;
}
//-- Boolean/boolean
if ((a == Boolean.class) || (a == Boolean.TYPE)) {
return ((b == Boolean.class) || (b == Boolean.TYPE));
}
//-- Byte/byte
else if ((a == Byte.class) || (a == Byte.TYPE)) {
return ((b == Byte.class) || (b == Byte.TYPE));
}
//-- Character/char
else if ((a == Character.class) || (a == Character.TYPE)) {
return ((b == Character.class) || (b == Character.TYPE));
}
//-- Double/double
else if ((a == Double.class) || (a == Double.TYPE)) {
return ((b == Double.class) || (b == Double.TYPE));
}
else if ((a == Float.class) || (a == Float.TYPE)) {
return ((b == Float.class) || (b == Float.TYPE));
}
//-- Integer/int
else if ((a == Integer.class) || (a == Integer.TYPE)) {
return ((b == Integer.class) || (b == Integer.TYPE));
}
//-- Long/long
else if ((a == Long.class) || (a == Long.TYPE)) {
return ((b == Long.class) || (b == Long.TYPE));
}
//-- Short/short
else if ((a == Short.class) || (a == Short.TYPE)) {
return ((b == Short.class) || (b == Short.TYPE));
}
return false;
}
Returns true if the given classes are both the same
primitive or primitive wrapper class. For exmaple, if
class "a" is an int (Integer.TYPE) and class "b" is
either an int or Integer.class then true will be
returned, otherwise false. |
protected InheritanceMatch[] searchInheritance(String name,
String namespace,
XMLClassDescriptor classDesc) throws MarshalException {
Iterator classDescriptorIterator = null;
try {
//-- A little required logic for finding Not-Yet-Loaded
//-- descriptors
String className = getJavaNaming().toJavaClassName(name);
//-- should use namespace-to-prefix mappings, but
//-- just create package for now.
Class clazz = classDesc.getJavaClass();
String pkg = null;
if (clazz != null) {
while (clazz.getDeclaringClass() != null) {
clazz = clazz.getDeclaringClass();
}
pkg = clazz.getName();
int idx = pkg.lastIndexOf('.');
if (idx >= 0) {
pkg = pkg.substring(0, idx + 1);
className = pkg + className;
}
}
getInternalContext().getXMLClassDescriptorResolver().resolve(
className, classDesc.getClass().getClassLoader());
//-- end Not-Yet-Loaded descriptor logic
//-- resolve all by XML name + namespace URI
classDescriptorIterator =
getInternalContext().getXMLClassDescriptorResolver().resolveAllByXMLName(
name, namespace, null);
}
catch (ResolverException rx) {
Throwable actual = rx.getCause();
if (actual instanceof MarshalException) {
throw (MarshalException) actual;
}
if (actual != null) {
throw new MarshalException(actual);
}
throw new MarshalException(rx);
}
Vector inheritanceList = null;
XMLFieldDescriptor descriptor = null;
XMLFieldDescriptor[] descriptors = classDesc.getElementDescriptors();
XMLClassDescriptor cdInherited = null;
if (classDescriptorIterator.hasNext()) {
while (classDescriptorIterator.hasNext() && (descriptor == null)) {
cdInherited = (XMLClassDescriptor) classDescriptorIterator.next();
Class subclass = cdInherited.getJavaClass();
for (int i = 0; i < descriptors.length; i++) {
if (descriptors[i] == null) {
continue;
}
//-- skip descriptors with special internal name
if (INTERNAL_XML_NAME.equals(descriptors[i].getXMLName())) {
continue;
}
//-- check for inheritence
Class superclass = descriptors[i].getFieldType();
// It is possible that the superclass is of type object if we use any node.
if (superclass.isAssignableFrom(subclass) && (superclass != Object.class)) {
descriptor = descriptors[i];
if (inheritanceList == null) {
inheritanceList = new Vector(3);
}
inheritanceList.addElement(new InheritanceMatch(descriptor, cdInherited));
}
}
}
//-- reset inherited class descriptor, if necessary
if (descriptor == null) {
cdInherited = null;
}
}
if (inheritanceList != null) {
InheritanceMatch[] result = new InheritanceMatch[inheritanceList.size()];
inheritanceList.toArray(result);
return result;
}
return NO_MATCH_ARRAY;
}
Search there is a field descriptor which can accept one of the class
descriptor which match the given name and namespace. |
public void setInternalContext(InternalContext internalContext) {
_internalContext = internalContext;
}
|