blob: f10a66d72dcddde261e648dcc9f02446dfa16280 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.tuscany.sca.binding.ejb.java2idl;
import java.lang.reflect.Method;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.ArrayList;
/**
* IDL Operation.
*/
public class OperationType extends IDLType {
/**
* The Method that this OperationType is mapping.
*/
private Method method;
/**
* The mapped exceptions of this operation.
*/
private ExceptionType[] mappedExceptions;
/**
* The parameters of this operation.
*/
private ParameterType[] parameters;
OperationType(Method method) {
super(method.getName());
this.method = method;
// Check if valid return type, IF it is a remote interface.
Class retCls = method.getReturnType();
if (retCls.isInterface() && Remote.class.isAssignableFrom(retCls))
IDLUtil.isValidRMIIIOP(retCls);
// Analyze exceptions
Class[] ex = method.getExceptionTypes();
boolean gotRemoteException = false;
ArrayList a = new ArrayList();
for (int i = 0; i < ex.length; ++i) {
if (ex[i].isAssignableFrom(java.rmi.RemoteException.class))
gotRemoteException = true;
if (Exception.class.isAssignableFrom(ex[i]) && !RuntimeException.class.isAssignableFrom(ex[i])
&& !RemoteException.class.isAssignableFrom(ex[i]))
a.add(ExceptionType.getExceptionType(ex[i])); // map this
}
if (!gotRemoteException && Remote.class.isAssignableFrom(method.getDeclaringClass()))
throw new IDLViolationException(
"All interface methods must throw java.rmi.RemoteException, " + "or a superclass of java.rmi.RemoteException, but method "
+ getJavaName()
+ " of interface "
+ method.getDeclaringClass().getName()
+ " does not.", "1.2.3");
mappedExceptions = new ExceptionType[a.size()];
mappedExceptions = (ExceptionType[])a.toArray(mappedExceptions);
// Analyze parameters
Class[] params = method.getParameterTypes();
parameters = new ParameterType[params.length];
for (int i = 0; i < params.length; ++i) {
parameters[i] = new ParameterType("param" + (i + 1), params[i]);
}
}
/**
* Return my Java return type.
*/
public Class getReturnType() {
return method.getReturnType();
}
/**
* Return my mapped Method.
*/
public Method getMethod() {
return method;
}
/**
* Return my mapped exceptions.
*/
public ExceptionType[] getMappedExceptions() {
return (ExceptionType[])mappedExceptions.clone();
}
/**
* Return my parameters.
*/
public ParameterType[] getParameters() {
return (ParameterType[])parameters.clone();
}
}
|