Skip to main content
summaryrefslogtreecommitdiffstats
blob: 3862baa60f1e8e4d5f4e80c653ba04df6f335524 (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
/*******************************************************************************
 * Copyright (c) 2001, 2005 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
 *******************************************************************************/
package org.eclipse.jst.j2ee.model.internal.validation;
import java.util.List;

import org.eclipse.jem.java.JavaClass;
import org.eclipse.jem.java.JavaHelpers;
import org.eclipse.jem.java.Method;
import org.eclipse.jst.j2ee.ejb.EnterpriseBean;
import org.eclipse.jst.j2ee.ejb.Entity;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;


public abstract class ABMPHomeVRule extends AEntityHomeVRule {

	public final void validateMatchingReturnTypeMatches(IEJBValidationContext vc, EnterpriseBean bean, JavaClass clazz, Method homeMethod, Method beanMethod, List[] methodsExtendedLists) {
		long methodType = MethodUtility.getUtility().getMethodTypeId(bean, clazz, homeMethod, methodsExtendedLists, this);
		if((methodType & FIND) != FIND) {
			super.validateMatchingReturnTypeMatches(vc, bean, clazz, homeMethod, beanMethod, methodsExtendedLists);
		}
		else {
			JavaHelpers homeRetType = homeMethod.getReturnType();
			JavaHelpers beanRetType = beanMethod.getReturnType();
			if (!ValidationRuleUtility.isAssignableFrom(homeRetType, beanRetType)) {
				// emit the error only if it's a multi-finder. Single-finders are supposed to have different return types on the home & bean class.
				boolean homeRetTypeIsRemote = ValidationRuleUtility.isAssignableFrom(homeRetType, bean.getRemoteInterface());
				boolean homeRetTypeIsLocal =  ValidationRuleUtility.isAssignableFrom(homeRetType, bean.getLocalInterface());
				boolean beanRetTypeIsKey = ValidationRuleUtility.isAssignableFrom(beanRetType, ((Entity)bean).getPrimaryKey());
				if(!((homeRetTypeIsRemote || homeRetTypeIsLocal) && beanRetTypeIsKey)) {
					String retTypeName = null;
					if(beanRetTypeIsKey) {
						if((isRemote() & IEJBType.REMOTE) == IEJBType.REMOTE) {
							retTypeName = (bean.getRemoteInterface() == null) ? IEJBValidatorConstants.NULL_REMOTE : bean.getRemoteInterface().getJavaName();
						}
						else {
							retTypeName = (bean.getLocalInterface() == null) ? IEJBValidatorConstants.NULL_LOCAL : bean.getLocalInterface().getJavaName();
						}
					}
					else {
						retTypeName = (beanRetType == null) ? "?" : beanRetType.getJavaName(); //$NON-NLS-1$
					}
					IMessage message = MessageUtility.getUtility().getMessage(vc, IMessagePrefixEjb20Constants.CHKJ2479, IEJBValidationContext.ERROR, bean, clazz, homeMethod, new String[] { retTypeName}, this);
					vc.addMessage(message);
				}
			}
		}
	}

}

Back to the top