001 /** 002 * 003 * Copyright 2004 Protique Ltd 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 * 017 **/ 018 package org.codehaus.activesoap.handler.xstream; 019 020 import org.codehaus.activesoap.handler.DefaultHandlerRegistry; 021 import org.codehaus.activesoap.handler.DefaultHandlerRegistry; 022 import org.codehaus.activesoap.handler.DefaultHandlerRegistry; 023 024 import javax.xml.namespace.QName; 025 import java.lang.reflect.Method; 026 027 /** 028 * @version $Revision: 1.3 $ 029 */ 030 public class XStreamRegistry extends DefaultHandlerRegistry { 031 032 /** 033 * Allows simple services to be registered based on the types of their parameters. 034 * 035 * @param serviceClass 036 */ 037 public void registerService(Class serviceClass) throws IllegalAccessException, NoSuchFieldException { 038 Method[] methods = serviceClass.getMethods(); 039 for (int i = 0, size = methods.length; i < size; i++) { 040 Method method = methods[i]; 041 Class[] parameterTypes = method.getParameterTypes(); 042 if (parameterTypes.length == 1) { 043 registerServiceMethod(serviceClass, method, parameterTypes[0]); 044 } 045 } 046 } 047 048 protected void registerServiceMethod(Class serviceClass, Method method, Class parameterType) throws NoSuchFieldException, IllegalAccessException { 049 QName name = new QName(parameterType.getName()); 050 addHandler(name, new XStreamInvokeMethodHandler(serviceClass, method)); 051 } 052 }