001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.runtime.net.rpc; 020 021import javax.xml.namespace.QName; 022import javax.xml.rpc.encoding.TypeMapping; 023import javax.xml.rpc.encoding.TypeMappingRegistry; 024 025import lucee.runtime.net.rpc.server.StringDeserializerFactory; 026import lucee.runtime.net.rpc.server.StringSerializerFactory; 027 028import org.apache.axis.encoding.ser.ArrayDeserializerFactory; 029import org.apache.axis.encoding.ser.ArraySerializerFactory; 030import org.apache.axis.encoding.ser.BeanDeserializerFactory; 031import org.apache.axis.encoding.ser.BeanSerializerFactory; 032import org.apache.axis.server.AxisServer; 033 034import coldfusion.xml.rpc.QueryBean; 035 036public class TypeMappingUtil { 037 038 public static void registerDefaults(TypeMappingRegistry tmr) { 039 TypeMapping tm = tmr.getDefaultTypeMapping(); 040 if(!tm.isRegistered(QueryBean.class, RPCConstants.QUERY_QNAME)) 041 tm.register(QueryBean.class, 042 RPCConstants.QUERY_QNAME, 043 new BeanSerializerFactory(QueryBean.class,RPCConstants.QUERY_QNAME), 044 new BeanDeserializerFactory(QueryBean.class,RPCConstants.QUERY_QNAME)); 045 046 //Adding custom string serialization for non printable characters. 047 tm.register(String.class, 048 RPCConstants.STRING_QNAME, 049 new StringSerializerFactory(String.class, RPCConstants.STRING_QNAME), 050 new StringDeserializerFactory(String.class, RPCConstants.STRING_QNAME)); 051 052 053 } 054 055 public static void registerBeanTypeMapping(javax.xml.rpc.encoding.TypeMapping tm, Class clazz, QName qName) { 056 if(tm.isRegistered(clazz, qName)) return; 057 058 if(clazz.isArray()) { 059 QName ct=AxisCaster.toComponentType(qName,null); 060 if(ct!=null) { 061 tm.register( 062 clazz, 063 qName, 064 new ArraySerializerFactory(clazz, ct), 065 new ArrayDeserializerFactory(ct)); 066 return; 067 } 068 } 069 070 tm.register( 071 clazz, 072 qName, 073 new BeanSerializerFactory(clazz, qName), 074 new BeanDeserializerFactory(clazz, qName)); 075 076 077 } 078 079 public static org.apache.axis.encoding.TypeMapping getServerTypeMapping(AxisServer axisServer) { 080 org.apache.axis.encoding.TypeMappingRegistry reg = axisServer.getTypeMappingRegistry(); 081 return reg.getOrMakeTypeMapping("http://schemas.xmlsoap.org/soap/encoding/"); 082 083 } 084 public static org.apache.axis.encoding.TypeMapping getServerTypeMapping(TypeMappingRegistry reg) { 085 //org.apache.axis.encoding.TypeMappingRegistry reg = axisServer.getTypeMappingRegistry(); 086 return ((org.apache.axis.encoding.TypeMappingRegistry)reg).getOrMakeTypeMapping("http://schemas.xmlsoap.org/soap/encoding/"); 087 088 } 089 090}