|
|||||||||||||||||||
| 30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| XMLBeansRegistry.java | 75% | 81.2% | 75% | 78.6% |
|
||||||||||||||
| 1 |
/**
|
|
| 2 |
*
|
|
| 3 |
* Copyright 2004 Protique Ltd
|
|
| 4 |
*
|
|
| 5 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
| 6 |
* you may not use this file except in compliance with the License.
|
|
| 7 |
* You may obtain a copy of the License at
|
|
| 8 |
*
|
|
| 9 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
| 10 |
*
|
|
| 11 |
* Unless required by applicable law or agreed to in writing, software
|
|
| 12 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
| 13 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
| 14 |
* See the License for the specific language governing permissions and
|
|
| 15 |
* limitations under the License.
|
|
| 16 |
*
|
|
| 17 |
**/
|
|
| 18 |
package org.codehaus.activesoap.handler.xmlbeans;
|
|
| 19 |
|
|
| 20 |
import org.apache.xmlbeans.SchemaType;
|
|
| 21 |
import org.apache.xmlbeans.XmlObject;
|
|
| 22 |
import org.codehaus.activesoap.handler.DefaultHandlerRegistry;
|
|
| 23 |
import org.codehaus.activesoap.handler.DefaultHandlerRegistry;
|
|
| 24 |
import org.codehaus.activesoap.handler.DefaultHandlerRegistry;
|
|
| 25 |
|
|
| 26 |
import javax.xml.namespace.QName;
|
|
| 27 |
import java.lang.reflect.Field;
|
|
| 28 |
import java.lang.reflect.Method;
|
|
| 29 |
|
|
| 30 |
/**
|
|
| 31 |
* @version $Revision: 1.6 $
|
|
| 32 |
*/
|
|
| 33 |
public class XMLBeansRegistry extends DefaultHandlerRegistry { |
|
| 34 |
|
|
| 35 |
/**
|
|
| 36 |
* Allows simple services to be registered so that they can automatically handle
|
|
| 37 |
* requests of the correct schema type.
|
|
| 38 |
*
|
|
| 39 |
* @param instance
|
|
| 40 |
*/
|
|
| 41 | 0 |
public void registerService(Object instance) throws IllegalAccessException, NoSuchFieldException { |
| 42 | 0 |
if (instance == null) { |
| 43 | 0 |
throw new IllegalArgumentException("instance should not be null"); |
| 44 |
} |
|
| 45 | 0 |
registerService(instance.getClass(), instance); |
| 46 |
} |
|
| 47 |
|
|
| 48 |
/**
|
|
| 49 |
* Allows simple services to be registered so that they can automatically handle
|
|
| 50 |
* requests of the correct schema type.
|
|
| 51 |
*
|
|
| 52 |
* @param serviceClass
|
|
| 53 |
*/
|
|
| 54 | 8 |
public void registerService(Class serviceClass) throws IllegalAccessException, NoSuchFieldException { |
| 55 | 8 |
registerService(serviceClass, null);
|
| 56 |
} |
|
| 57 |
|
|
| 58 | 8 |
protected void registerService(Class serviceClass, Object instance) throws NoSuchFieldException, IllegalAccessException { |
| 59 | 8 |
Method[] methods = serviceClass.getMethods(); |
| 60 | 8 |
for (int i = 0, size = methods.length; i < size; i++) { |
| 61 | 80 |
Method method = methods[i]; |
| 62 | 80 |
Class[] parameterTypes = method.getParameterTypes(); |
| 63 | 80 |
if (parameterTypes.length == 1) {
|
| 64 | 24 |
Class parameterType = parameterTypes[0]; |
| 65 | 24 |
if (XmlObject.class.isAssignableFrom(parameterType)) { |
| 66 | 8 |
registerServiceMethod(serviceClass, instance, method, parameterType); |
| 67 |
} |
|
| 68 |
} |
|
| 69 |
} |
|
| 70 |
} |
|
| 71 |
|
|
| 72 | 8 |
protected void registerServiceMethod(Class serviceClass, Object instance, Method method, Class parameterType) throws NoSuchFieldException, IllegalAccessException { |
| 73 |
// lets access to the SchemaType
|
|
| 74 | 8 |
Field field = parameterType.getField("type");
|
| 75 | 8 |
SchemaType type = (SchemaType) field.get(null);
|
| 76 | 8 |
QName name = type.getDocumentElementName(); |
| 77 | 8 |
addHandler(name, new XMLBeanInvokeMethodHandler(serviceClass, instance, method));
|
| 78 |
} |
|
| 79 |
} |
|
| 80 |
|
|
||||||||||