Skip to main content
summaryrefslogtreecommitdiffstats
blob: c66cf7a51a5fabec7f5ae2568cdf7ca64092fa43 (plain) (blame)
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*******************************************************************************
 * Copyright (c) 2006 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * IBM Corporation - initial API and implementation
 * yyyymmdd bug      Email and other contact information
 * -------- -------- -----------------------------------------------------------
 * 20060419   132905 cbrealey@ca.ibm.com - Chris Brealey          
 *******************************************************************************/
package org.eclipse.jst.ws.internal.conformance.rules;

import java.util.Stack;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jst.ws.internal.WSPluginMessages;
import org.eclipse.jst.ws.internal.conformance.IJavaWebServiceRuleEngine;
import org.eclipse.jst.ws.internal.conformance.JDTResolver;
import org.eclipse.jst.ws.internal.conformance.JavaWebServiceRule;
import org.eclipse.osgi.util.NLS;

/**
 * This rule verifies that the methods of a service class
 * uses only JAX-RPC supported types.
 */
public class JAXRPCRule0005 extends JavaWebServiceRule
{
	/**
	 * Creates a new instance of this rule.
	 */
	public JAXRPCRule0005 ()
	{
		id_ = 5;
		namespace_ = "http://www.eclipse.org/webtools/org.eclipse.jst.ws/jaxrpc/1.1";
		name_ = null;
		description_ = null;
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.jst.ws.internal.conformance.JavaWebServiceRule#init(org.eclipse.jst.ws.internal.conformance.IJavaWebServiceRuleEngine)
	 */
	public void init ( IJavaWebServiceRuleEngine engine )
	{
		super.init(engine);
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.jst.ws.internal.conformance.JavaWebServiceRule#visitClass(org.eclipse.jdt.core.IType, java.util.Stack)
	 */
	public void visitClass ( IType jdtClass, Stack peanutTrail )
	{
		//
		// An empty peanut trail implies this is the root
		// class, aka. JAX-RPC service class. Put aside
		// the class name in case visitMethod() needs it.
		//
		if (peanutTrail.size() == 0)
		{
			serviceClassName_ = jdtClass.getFullyQualifiedName();
		}
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jst.ws.internal.conformance.JavaWebServiceRule#visitMethod(org.eclipse.jdt.core.IMethod, java.util.Stack)
	 */
	public void visitMethod ( IMethod jdtMethod, Stack peanutTrail )
	{
		//
		// A peanut trail of length one implies this is a method
		// belonging to the root class, aka. JAX-RPC service class.
		//
		if (peanutTrail.size() == 1)
		{
			try
			{
				String methodName = jdtMethod.getElementName();
				//
				// Check the method return type for compliance.
				// Any Java primitive or standard ("java." or "javax.") type
				// that is not supported by JAX-RPC will get flagged.
				// Any non-primitive or non-standard type is presumed to be a
				// potential value type and is bypassed since the rule engine
				// will navigate into the potential value type's class.
				//
				JDTResolver resolver = engine_.getJDTResolver();
				String returnTypeName = resolver.getReturnTypeName(jdtMethod);
				if ((resolver.isPrimitiveType(returnTypeName) || resolver.isStandardType(returnTypeName)) && !resolver.isJAXRPCStandardType(returnTypeName))
				{
					String message = NLS.bind(WSPluginMessages.MSG_JAXRPC11_RULE_0005,new String[] {methodName,serviceClassName_,returnTypeName});
					statusList_.add(new Status(IStatus.WARNING,"org.eclipse.jst.ws",0,message,null));
				}
				//
				// Check the method parameter types for compliance.
				// Same comment as above, only applied to the method's parameters.
				//
				String[] parameterTypeNames = resolver.getParameterTypeNames(jdtMethod);
				for (int p=0; p<parameterTypeNames.length; p++)
				{
					if ((resolver.isPrimitiveType(parameterTypeNames[p]) || resolver.isStandardType(parameterTypeNames[p])) && !resolver.isJAXRPCStandardType(parameterTypeNames[p]))
					{
						String message = NLS.bind(WSPluginMessages.MSG_JAXRPC11_RULE_0005,new String[] {methodName,serviceClassName_,parameterTypeNames[p]});
						statusList_.add(new Status(IStatus.WARNING,"org.eclipse.jst.ws",0,message,null));
					}
				}
			}
			catch (JavaModelException e)
			{
				// Do nothing.
			}
		}
	}
	
	private String serviceClassName_;
}

Back to the top