Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2006-2008 Web Cohesion
*
* Licensed 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.codehaus.enunciate.modules.amf;
import javax.activation.DataHandler;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.namespace.QName;
import java.lang.reflect.*;
import java.net.URI;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
/**
* Introspector used to lookup AMF mappers.
*
* @author Ryan Heaton
*/
public class AMFMapperIntrospector {
private static final Map MAPPERS = new HashMap();
static {
AMFMapperIntrospector.MAPPERS.put(DataHandler.class, new DataHandlerAMFMapper());
AMFMapperIntrospector.MAPPERS.put(QName.class, new QNameAMFMapper());
AMFMapperIntrospector.MAPPERS.put(URI.class, new URIAMFMapper());
AMFMapperIntrospector.MAPPERS.put(UUID.class, new UUIDAMFMapper());
AMFMapperIntrospector.MAPPERS.put(XMLGregorianCalendar.class, new XMLGregorianCalendarAMFMapper());
}
public static AMFMapper getAMFMapper(Type jaxbType) {
return getAMFMapper(null, jaxbType);
}
public static AMFMapper getAMFMapper(Class realType, Type jaxbType) {
return getAMFMapper(realType, jaxbType, null, null);
}
public static AMFMapper getAMFMapper(Type jaxbType, XmlJavaTypeAdapter adapterInfo, XmlElement elementInfo) {
return getAMFMapper(null, jaxbType, adapterInfo, elementInfo);
}
public static AMFMapper getAMFMapper(Class realType, Type jaxbType, XmlJavaTypeAdapter adapterInfo, XmlElement elementInfo) {
if ((realType != null) && (!realType.isArray()) && (!realType.isPrimitive()) && (realType.getPackage() != null)) {
//first check the real type. if a mapper exists, use it, otherwise use the type defined in the signature.
if (MAPPERS.containsKey(realType)) {
return MAPPERS.get(realType);
}
try {
loadCustomMapperClass(realType);
jaxbType = realType;
}
catch (Throwable e) {
//fall through.
}
}
if (jaxbType == null) {
jaxbType = Object.class;
}
Class specifiedType = ((elementInfo != null) && (elementInfo.type() != null) && (elementInfo.type() != XmlElement.DEFAULT.class)) ? elementInfo.type() : null;
AMFMapper mapper;
if (MAPPERS.containsKey(jaxbType)) {
mapper = MAPPERS.get(jaxbType);
}
else {
if (jaxbType instanceof ParameterizedType) {
Type rawType = ((ParameterizedType) jaxbType).getRawType();
if (rawType instanceof Class) {
if (Map.class.isAssignableFrom((Class) rawType)) {
Type keyType = Object.class;
Type valueType = Object.class;
Type[] typeArgs = ((ParameterizedType) jaxbType).getActualTypeArguments();
if ((typeArgs != null) && (typeArgs.length == 2)) {
keyType = typeArgs[0];
valueType = typeArgs[1];
}
mapper = new MapAMFMapper((Class