|
|||||||||||||||||||
| 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 | |||||||||||||||
| SimpleMetadataStrategy.java | 100% | 88.5% | 66.7% | 87.2% |
|
||||||||||||||
| 1 |
/**
|
|
| 2 |
*
|
|
| 3 |
* Copyright 2005 LogicBlaze, Inc.
|
|
| 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.logicblaze.lingo;
|
|
| 19 |
|
|
| 20 |
import java.lang.reflect.Method;
|
|
| 21 |
import java.rmi.Remote;
|
|
| 22 |
import java.util.EventListener;
|
|
| 23 |
import java.util.HashSet;
|
|
| 24 |
import java.util.Iterator;
|
|
| 25 |
import java.util.Set;
|
|
| 26 |
|
|
| 27 |
/**
|
|
| 28 |
* A simple metadata strategy which uses POJO naming conventions. One way methods are enabled by
|
|
| 29 |
* default for all void methods which do not throw checked exceptions.
|
|
| 30 |
* <p/>
|
|
| 31 |
* Also any object which implements the {@link Remote} interface or the {@link EventListener}
|
|
| 32 |
* are assumed to be remote and so a remote proxy is used to allow remote notifications and asynchronous
|
|
| 33 |
* messaging.
|
|
| 34 |
*
|
|
| 35 |
* @version $Revision: 1.1 $
|
|
| 36 |
*/
|
|
| 37 |
public class SimpleMetadataStrategy implements MetadataStrategy { |
|
| 38 |
private boolean oneWayForVoidMethods; |
|
| 39 |
private Set remoteTypes;
|
|
| 40 |
|
|
| 41 | 27 |
public SimpleMetadataStrategy() {
|
| 42 |
} |
|
| 43 |
|
|
| 44 | 53 |
public SimpleMetadataStrategy(boolean oneWayForVoidMethods) { |
| 45 | 53 |
this.oneWayForVoidMethods = oneWayForVoidMethods;
|
| 46 |
} |
|
| 47 |
|
|
| 48 | 66 |
public MethodMetadata getMethodMetadata(Method method) {
|
| 49 | 66 |
boolean oneway = false; |
| 50 | 66 |
if (oneWayForVoidMethods) {
|
| 51 | 24 |
oneway = method.getReturnType().equals(void.class) && method.getExceptionTypes().length == 0; |
| 52 |
} |
|
| 53 | 66 |
boolean[] remoteParams = null; |
| 54 | 66 |
Class[] parameterTypes = method.getParameterTypes(); |
| 55 | 66 |
int size = parameterTypes.length;
|
| 56 | 66 |
if (size > 0) {
|
| 57 | 32 |
remoteParams = new boolean[size]; |
| 58 | 32 |
for (int i = 0; i < size; i++) { |
| 59 | 38 |
remoteParams[i] = isRemoteParameter(method, parameterTypes[i], i); |
| 60 |
} |
|
| 61 |
} |
|
| 62 | 66 |
return new MethodMetadata(oneway, remoteParams); |
| 63 |
} |
|
| 64 |
|
|
| 65 | 0 |
public boolean isOneWayForVoidMethods() { |
| 66 | 0 |
return oneWayForVoidMethods;
|
| 67 |
} |
|
| 68 |
|
|
| 69 | 0 |
public void setOneWayForVoidMethods(boolean oneWayForVoidMethods) { |
| 70 | 0 |
this.oneWayForVoidMethods = oneWayForVoidMethods;
|
| 71 |
} |
|
| 72 |
|
|
| 73 | 38 |
public Set getRemoteTypes() {
|
| 74 | 38 |
if (remoteTypes == null) { |
| 75 | 24 |
remoteTypes = new HashSet();
|
| 76 | 24 |
populateDefaultRemoteTypes(remoteTypes); |
| 77 |
} |
|
| 78 | 38 |
return remoteTypes;
|
| 79 |
} |
|
| 80 |
|
|
| 81 |
|
|
| 82 | 0 |
public void setRemoteTypes(Set remoteTypes) { |
| 83 | 0 |
this.remoteTypes = remoteTypes;
|
| 84 |
} |
|
| 85 |
|
|
| 86 | 38 |
protected boolean isRemoteParameter(Method method, Class parameterType, int index) { |
| 87 | 38 |
for (Iterator iter = getRemoteTypes().iterator(); iter.hasNext();) {
|
| 88 | 75 |
Class type = (Class) iter.next(); |
| 89 | 75 |
if (type.isAssignableFrom(parameterType)) {
|
| 90 | 4 |
return true; |
| 91 |
} |
|
| 92 |
} |
|
| 93 | 34 |
return false; |
| 94 |
} |
|
| 95 |
|
|
| 96 | 24 |
protected void populateDefaultRemoteTypes(Set remoteTypes) { |
| 97 | 24 |
remoteTypes.add(Remote.class);
|
| 98 | 24 |
remoteTypes.add(EventListener.class);
|
| 99 |
} |
|
| 100 |
} |
|
| 101 |
|
|
||||||||||