1
|
|
package org.codehaus.ivory;
|
2
|
|
|
3
|
|
import java.lang.reflect.Method;
|
4
|
|
import java.util.Collection;
|
5
|
|
import java.util.Iterator;
|
6
|
|
import java.util.List;
|
7
|
|
|
8
|
|
import org.apache.axis.description.OperationDesc;
|
9
|
|
import org.apache.axis.description.ParameterDesc;
|
10
|
|
import org.apache.axis.description.ServiceDesc;
|
11
|
|
import org.apache.commons.attributes.Attributes;
|
12
|
|
import org.codehaus.ivory.attributes.NonWebMethod;
|
13
|
|
import org.codehaus.ivory.attributes.ParameterType;
|
14
|
|
|
15
|
|
|
16
|
|
|
17
|
|
|
18
|
|
|
19
|
|
|
20
|
|
|
21
|
|
public class IvoryServiceDesc
|
22
|
|
extends ServiceDesc
|
23
|
|
{
|
24
|
|
private boolean loadingServiceDesc = false;
|
25
|
|
|
26
|
|
|
27
|
|
|
28
|
|
|
29
|
|
|
30
|
5
|
public void loadMetaData()
|
31
|
|
{
|
32
|
5
|
for ( Iterator itr = getOperations().iterator(); itr.hasNext(); )
|
33
|
|
{
|
34
|
10
|
OperationDesc operation = ( OperationDesc ) itr.next();
|
35
|
|
|
36
|
10
|
customizeOperation( operation );
|
37
|
|
|
38
|
10
|
if ( !isValidOperation( operation ) ||
|
39
|
|
hideOperation( operation ) )
|
40
|
|
{
|
41
|
0
|
itr.remove();
|
42
|
|
}
|
43
|
|
}
|
44
|
|
}
|
45
|
|
|
46
|
|
|
47
|
|
|
48
|
|
|
49
|
|
|
50
|
|
|
51
|
|
|
52
|
10
|
protected boolean hideOperation(OperationDesc operation)
|
53
|
|
{
|
54
|
10
|
Method method = operation.getMethod();
|
55
|
|
|
56
|
10
|
return Attributes.hasAttribute( method, NonWebMethod.class );
|
57
|
|
}
|
58
|
|
|
59
|
10
|
protected void customizeOperation( OperationDesc operation )
|
60
|
|
{
|
61
|
10
|
for( Iterator itr = operation.getParameters().iterator(); itr.hasNext(); )
|
62
|
|
{
|
63
|
4
|
ParameterDesc parameter = (ParameterDesc) itr.next();
|
64
|
|
|
65
|
4
|
customizeParameter( operation, parameter );
|
66
|
|
}
|
67
|
|
|
68
|
10
|
customizeParameter( operation, operation.getReturnParamDesc() );
|
69
|
|
}
|
70
|
|
|
71
|
14
|
protected void customizeParameter( OperationDesc operation,
|
72
|
|
ParameterDesc parameter )
|
73
|
|
{
|
74
|
14
|
Method method = operation.getMethod();
|
75
|
|
|
76
|
14
|
String name = parameter.getName();
|
77
|
|
|
78
|
14
|
if ( name == null &&
|
79
|
|
Attributes.hasReturnAttributeType( method, ParameterType.class ) )
|
80
|
|
{
|
81
|
1
|
Collection allAttrs = Attributes.getReturnAttributes(method);
|
82
|
|
|
83
|
1
|
for ( Iterator itr = allAttrs.iterator(); itr.hasNext(); )
|
84
|
|
{
|
85
|
1
|
Object attr = itr.next();
|
86
|
1
|
if ( attr instanceof ParameterType )
|
87
|
|
{
|
88
|
1
|
changeParameterType( parameter, (ParameterType) attr );
|
89
|
|
}
|
90
|
|
}
|
91
|
|
}
|
92
|
13
|
else if (Attributes.hasReturnAttributeType( method, ParameterType.class ))
|
93
|
|
{
|
94
|
|
|
95
|
|
|
96
|
0
|
int num = new Integer(name.substring( 2 )).intValue();
|
97
|
0
|
Collection allAttrs = Attributes.getParameterAttributes(method, num);
|
98
|
|
|
99
|
0
|
for ( Iterator itr = allAttrs.iterator(); itr.hasNext(); )
|
100
|
|
{
|
101
|
0
|
Object attr = itr.next();
|
102
|
0
|
if ( attr instanceof ParameterType )
|
103
|
|
{
|
104
|
0
|
changeParameterType( parameter, (ParameterType) attr );
|
105
|
|
}
|
106
|
|
}
|
107
|
|
}
|
108
|
|
}
|
109
|
|
|
110
|
|
|
111
|
|
|
112
|
|
|
113
|
|
|
114
|
1
|
private void changeParameterType(ParameterDesc parameter, ParameterType type)
|
115
|
|
{
|
116
|
1
|
String clazz = type.getParameterType().getName();
|
117
|
|
|
118
|
1
|
log.debug( "Changing parameter type to " + clazz );
|
119
|
|
|
120
|
1
|
parameter.setJavaType( type.getParameterType() );
|
121
|
|
}
|
122
|
|
|
123
|
10
|
protected boolean isValidOperation( OperationDesc operation )
|
124
|
|
{
|
125
|
10
|
for( Iterator itr = operation.getParameters().iterator(); itr.hasNext(); )
|
126
|
|
{
|
127
|
4
|
ParameterDesc parameter = (ParameterDesc) itr.next();
|
128
|
|
|
129
|
4
|
if ( !isValidParameter( parameter ) )
|
130
|
0
|
return false;
|
131
|
|
}
|
132
|
|
|
133
|
10
|
return isValidParameter( operation.getReturnParamDesc() );
|
134
|
|
}
|
135
|
|
|
136
|
|
|
137
|
|
|
138
|
|
|
139
|
|
|
140
|
|
|
141
|
|
|
142
|
|
|
143
|
14
|
protected boolean isValidParameter( ParameterDesc parameter )
|
144
|
|
{
|
145
|
14
|
if ( parameter.getJavaType().equals( java.util.List.class.getClass() )
|
146
|
|
|| List.class.isAssignableFrom( parameter.getJavaType() ) )
|
147
|
|
{
|
148
|
0
|
return false;
|
149
|
|
}
|
150
|
|
|
151
|
14
|
return true;
|
152
|
|
}
|
153
|
|
}
|
154
|
|
|