Skip to main content
summaryrefslogtreecommitdiffstats
blob: 4e4db767392dd0e1da56d2b39a6aaacc6ca1bb5c (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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*******************************************************************************
 * Copyright (c) 2001, 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
 *******************************************************************************/
package org.eclipse.jst.j2ee.model.internal.validation;



import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.emf.common.command.Command;
import org.eclipse.jst.j2ee.client.ApplicationClient;
import org.eclipse.jst.j2ee.commonarchivecore.internal.ApplicationClientFile;
import org.eclipse.jst.j2ee.commonarchivecore.internal.ValidateXmlCommand;
import org.eclipse.wst.validation.internal.core.Message;
import org.eclipse.wst.validation.internal.core.ValidationException;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
import org.eclipse.wst.validation.internal.provisional.core.IValidationContext;



/**
 * Validates the applicatin-client.xml
 */
public class ApplicationClientValidator extends J2EEValidator implements ApplicationClientMessageConstants {
	protected ApplicationClientFile appClientFile;
	protected ApplicationClient appClientDD;
	
	/**
 	 * ApplicationClientValidator constructor comment.
 	 */
	public ApplicationClientValidator() {
		super();
	}// ApplicationClientValidator
	
	/**
 	 * <p>Answer the id of the resource bundle which is
 	 * used by the receiver.</p>
 	 */
	@Override
	public String getBaseName() {
		return APLICATIONCLIENT_CATEGORY;
	}// getBaseName
	
	/**
	 *  XML Validator now handles validation of Deployment Descriptor
	 * 
	 * @throws ValidationException
	 */
	public void validate() throws ValidationException {
	  validateMainClassInManifest();
	}// validate

	protected void validateMainClassInManifest() {

		if (appClientFile != null && appClientFile.getManifest() != null) {
			String mainClass = appClientFile.getManifest().getMainClass();
			if (mainClass == null || mainClass.length() == 0) {
				Object target = getManifestTarget();
				addError(getBaseName(), APPCLIENT_MAIN_CLASS_ERROR_, new String[0], target);
			}
		}
	}	
	
	protected Object getManifestTarget() {
		return null;
	}
	/**
	 * Does the validation.
	 * 
	 * @throws ValidationException
	 */
	@Override
	public void validate(IValidationContext inHelper, IReporter inReporter)
	  throws ValidationException {
		
		validateInJob(inHelper, inReporter);
	}// validate
	/**
	 * Creates the validate xml command.
	 * 
	 * @return Command
	 */	
	public Command createValidateXMLCommand() {
		Command cmd = new ValidateXmlCommand(appClientFile);
		return cmd;
	}// createValidateXMLCommand
	
	/**
	 * Gets the appClientFile.
	 * 
	 * @return ApplicationClientFile
	 */
	public ApplicationClientFile getAppClientFile() {
		return appClientFile;
	}// getAppClientFile

	/**
	 * Sets the appClientFile.
	 * 
	 * @param ApplicatonClientFile appClientFile - The appClientFile to set
	 */
	public void setAppClientFile(ApplicationClientFile appClientFile) {
		this.appClientFile = appClientFile;
	}// setAppClientFile

	/**
	 * Gets the appClientDD.
	 * 
	 * @return ApplicationClient
	 */
	public ApplicationClient getAppClientDD() {
		return appClientDD;
	}// getAppClientDD

	/**
	 * Sets the appClientDD.
	 * 
	 * @param ApplicationClient appClientDD - The appClientDD to set
	 */
	public void setAppClientDD(ApplicationClient appClientDD) {
		this.appClientDD = appClientDD;
	}// setAppClientDD

	public ISchedulingRule getSchedulingRule(IValidationContext helper) {
		return null;
	}
	
	@Override
	public IStatus validateInJob(IValidationContext inHelper, IReporter inReporter) 
	 		throws ValidationException {

		try {
			super.validateInJob(inHelper, inReporter);
			_reporter.removeAllMessages(this, null); 
			
			setAppClientFile( (ApplicationClientFile) inHelper.loadModel(APPCLIENT_MODEL_NAME) );
			if ( appClientFile != null ) {
				setAppClientDD( appClientFile.getDeploymentDescriptor() );
				validate();
			} else {
				IMessage errorMsg = new Message(getBaseName(), IMessage.HIGH_SEVERITY, ERROR_APPCLIENT_INVALID_APPCLIENT_FILE);
				throw new ValidationException(errorMsg);
			}// if
		} catch (ValidationException ex) {
			throw ex;
		} catch (Exception e) {
			IMessage errorMsg = new Message(getBaseName(), IMessage.HIGH_SEVERITY, ERROR_APPCLIENT_VALIDATION_FAILED);
			throw new ValidationException(errorMsg, e);
		}// try 
		return status;
	}
	
	@Override
	public void cleanup(IReporter reporter) {
		appClientDD = null;
		appClientFile = null;
		super.cleanup(reporter);
	}	
}// ApplicationClientValidator

Back to the top