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 * Adds meta-data capabilities to Axis's ServiceDesc class.
17 *
18 * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
19 * @since May 5, 2003
20 */
21 public class IvoryServiceDesc
22 extends ServiceDesc
23 {
24 private boolean loadingServiceDesc = false;
25
26 /***
27 * Load the meta data for the class being exposed as a service and take
28 * apropriate action.
29 */
30 public void loadMetaData()
31 {
32 for ( Iterator itr = getOperations().iterator(); itr.hasNext(); )
33 {
34 OperationDesc operation = ( OperationDesc ) itr.next();
35
36 customizeOperation( operation );
37
38 if ( !isValidOperation( operation ) ||
39 hideOperation( operation ) )
40 {
41 itr.remove();
42 }
43 }
44 }
45
46 /***
47 * Whether or an Operation on the services should not be exposed.
48 *
49 * @param operation
50 * @return
51 */
52 protected boolean hideOperation(OperationDesc operation)
53 {
54 Method method = operation.getMethod();
55
56 return Attributes.hasAttribute( method, NonWebMethod.class );
57 }
58
59 protected void customizeOperation( OperationDesc operation )
60 {
61 for( Iterator itr = operation.getParameters().iterator(); itr.hasNext(); )
62 {
63 ParameterDesc parameter = (ParameterDesc) itr.next();
64
65 customizeParameter( operation, parameter );
66 }
67
68 customizeParameter( operation, operation.getReturnParamDesc() );
69 }
70
71 protected void customizeParameter( OperationDesc operation,
72 ParameterDesc parameter )
73 {
74 Method method = operation.getMethod();
75
76 String name = parameter.getName();
77
78 if ( name == null &&
79 Attributes.hasReturnAttributeType( method, ParameterType.class ) )
80 {
81 Collection allAttrs = Attributes.getReturnAttributes(method);
82
83 for ( Iterator itr = allAttrs.iterator(); itr.hasNext(); )
84 {
85 Object attr = itr.next();
86 if ( attr instanceof ParameterType )
87 {
88 changeParameterType( parameter, (ParameterType) attr );
89 }
90 }
91 }
92 else if (Attributes.hasReturnAttributeType( method, ParameterType.class ))
93 {
94 // parameters are named "in0", "in1" and so on.
95 // get everything after "in"
96 int num = new Integer(name.substring( 2 )).intValue();
97 Collection allAttrs = Attributes.getParameterAttributes(method, num);
98
99 for ( Iterator itr = allAttrs.iterator(); itr.hasNext(); )
100 {
101 Object attr = itr.next();
102 if ( attr instanceof ParameterType )
103 {
104 changeParameterType( parameter, (ParameterType) attr );
105 }
106 }
107 }
108 }
109
110 /***
111 * @param parameter
112 * @param type
113 */
114 private void changeParameterType(ParameterDesc parameter, ParameterType type)
115 {
116 String clazz = type.getParameterType().getName();
117
118 log.debug( "Changing parameter type to " + clazz );
119
120 parameter.setJavaType( type.getParameterType() );
121 }
122
123 protected boolean isValidOperation( OperationDesc operation )
124 {
125 for( Iterator itr = operation.getParameters().iterator(); itr.hasNext(); )
126 {
127 ParameterDesc parameter = (ParameterDesc) itr.next();
128
129 if ( !isValidParameter( parameter ) )
130 return false;
131 }
132
133 return isValidParameter( operation.getReturnParamDesc() );
134 }
135
136 /***
137 * Checks whether or not Axis will work with this parameter. The only
138 * criterion is that it not be a List or inherit from the List type.
139 *
140 * @param parameter
141 * @return
142 */
143 protected boolean isValidParameter( ParameterDesc parameter )
144 {
145 if ( parameter.getJavaType().equals( java.util.List.class.getClass() )
146 || List.class.isAssignableFrom( parameter.getJavaType() ) )
147 {
148 return false;
149 }
150
151 return true;
152 }
153 }
This page was automatically generated by Maven