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.server;
020
021import java.lang.reflect.Method;
022
023import javax.xml.rpc.encoding.TypeMapping;
024
025import lucee.runtime.Component;
026import lucee.runtime.PageContext;
027import lucee.runtime.exp.PageException;
028import lucee.runtime.net.rpc.AxisCaster;
029
030import org.apache.axis.MessageContext;
031import org.apache.axis.providers.java.RPCProvider;
032
033public final class ComponentProvider extends RPCProvider {
034
035        public static final String PAGE_CONTEXT = PageContext.class.getName();
036        public static final String COMPONENT = Component.class.getName();
037
038        @Override
039        protected Object invokeMethod(MessageContext mc, Method method, Object trg, Object[] args) throws Exception {
040                PageContext pc=(PageContext) mc.getProperty(Constants.PAGE_CONTEXT);
041                Component c= (Component) mc.getProperty(Constants.COMPONENT);
042
043                RPCServer server = RPCServer.getInstance(pc.getId(),pc.getServletContext());
044                TypeMapping tm =mc.getTypeMapping();//TypeMappingUtil.getServerTypeMapping(server.getEngine().getTypeMappingRegistry());
045                
046                return AxisCaster.toAxisType(tm,c.call(pc,method.getName(),toLuceeType(pc,args)),null);
047        }
048
049        private Object[] toLuceeType(PageContext pc,Object[] args) throws PageException {
050                Object[] trgs=new Object[args.length];
051                for(int i=0;i<trgs.length;i++) {
052                        trgs[i]=AxisCaster.toLuceeType(pc,args[i]);
053                }
054                return trgs;
055        }
056}