Skip to main content
summaryrefslogtreecommitdiffstats
blob: 972a1afd39d90b6725ddf566859d374f4ad72c81 (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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
/***************************************************************************************************
 * Copyright (c) 2003, 2004 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
 **************************************************************************************************/
/*
 * Created on Oct 27, 2003
 * 
 * To change the template for this generated file go to Window>Preferences>Java>Code
 * Generation>Code and Comments
 */
package org.eclipse.jst.j2ee.application.internal.operations;


import java.lang.reflect.InvocationTargetException;

import org.eclipse.core.runtime.IPath;
import org.eclipse.jem.util.logger.proxy.Logger;
import org.eclipse.jst.j2ee.common.XMLResource;
import org.eclipse.jst.j2ee.internal.J2EEVersionConstants;
import org.eclipse.jst.j2ee.internal.earcreation.IEARNatureConstants;
import org.eclipse.jst.j2ee.internal.plugin.J2EEPlugin;
import org.eclipse.jst.j2ee.internal.servertarget.ServerTargetDataModel;
import org.eclipse.wst.common.frameworks.internal.operations.ProjectCreationDataModel;
import org.eclipse.wst.common.frameworks.internal.operations.WTPOperation;
import org.eclipse.wst.common.frameworks.internal.operations.WTPOperationDataModelEvent;
import org.eclipse.wst.common.frameworks.internal.operations.WTPPropertyDescriptor;
import org.eclipse.wst.common.internal.emfworkbench.operation.EditModelOperationDataModel;

/**
 * This dataModel is used for to create Enterprise Applications.
 * 
 * This class (and all its fields and methods) is likely to change during the WTP 1.0 milestones as
 * the new project structures are adopted. Use at your own risk.
 * 
 * @since WTP 1.0
 */
public final class EnterpriseApplicationCreationDataModelOld extends J2EEArtifactCreationDataModelOld {
	/**
	 * An optional dataModel propertyName for an Integer type. It is used to specify the J2EE
	 * Version for the new Enterprise Application. The default value is computed based on the
	 * highest J2EE version specified in the J2EE Properties.
	 * 
	 * @since WTP 1.0
	 */
	public static final String APPLICATION_VERSION = "J2EEApplicationCreationDataModel.APPLICATION_VERSION"; //$NON-NLS-1$

	/*
	 * A List containing IProjects
	 */
	public static final String MODULE_LIST = AddArchiveProjectsToEARDataModel.MODULE_LIST;
	/*
	 * UI only, type Boolean, default false.
	 */
	public static final String UI_SHOW_FIRST_PAGE_ONLY = "J2EEApplicationCreationDataModel.UI_SHOW_FIRST_PAGE_ONLY"; //$NON-NLS-1$

	private static final String NESTED_MODEL_ADD_ARCHIVE_TO_EAR = "J2EEApplicationCreationDataModel.NESTED_MODEL_ADD_ARCHIVE_TO_EAR"; //$NON-NLS-1$
	private AddArchiveProjectsToEARDataModel addModulesToEARDataModel;

	/**
	 * Creates an Enterprise Application project with the specified name and version in the
	 * specified location.
	 * 
	 * @param projectName
	 *            The name of the Enterprise Application project to create.
	 * @param projectLocation
	 *            Sets the local file system location for the described project. The path must be
	 *            either an absolute file system path, or a relative path whose first segment is the
	 *            name of a defined workspace path variable. If <code>null</code> is specified,
	 *            the default location is used.
	 * @param applicationVersion
	 *            Sets the J2EE Version for the descibed project. The version must be one of
	 *            <code>J2EEVersionConstants.J2EE_1_2_ID</code>,
	 *            <code>J2EEVersionConstants.J2EE_1_3_ID</code>, or
	 *            <code>J2EEVersionConstants.J2EE_1_4_ID</code>.
	 * @since WTP 1.0
	 */
	public static void createProject(String projectName, IPath projectLocation, int applicationVersion) {
		EnterpriseApplicationCreationDataModelOld dataModel = new EnterpriseApplicationCreationDataModelOld();
		dataModel.setProperty(PROJECT_NAME, projectName);
		if (null != projectLocation) {
			dataModel.setProperty(PROJECT_LOCATION, projectLocation.toOSString());
		}
		dataModel.setIntProperty(APPLICATION_VERSION, applicationVersion);
		try {
			dataModel.getDefaultOperation().run(null);
		} catch (InvocationTargetException e) {
			Logger.getLogger().logError(e);
		} catch (InterruptedException e) {
			Logger.getLogger().logError(e);
		}
	}


	public WTPOperation getDefaultOperation() {
		return new EnterpriseApplicationCreationOperationOld(this);
	}

	protected void init() {
		super.init();
		setProperty(EDIT_MODEL_ID, IEARNatureConstants.EDIT_MODEL_ID);
		getServerTargetDataModel().setIntProperty(ServerTargetDataModel.DEPLOYMENT_TYPE_ID, XMLResource.APPLICATION_TYPE);
		getProjectDataModel().setProperty(ProjectCreationDataModel.PROJECT_NATURES, new String[]{IEARNatureConstants.NATURE_ID});
		setProperty(APPLICATION_VERSION, getDefaultProperty(APPLICATION_VERSION));
		//set it so it pushes it down to ServerTargeting
	}

	protected void initValidBaseProperties() {
		super.initValidBaseProperties();
		addValidBaseProperty(APPLICATION_VERSION);
		addValidBaseProperty(UI_SHOW_FIRST_PAGE_ONLY);
	}

	protected void initNestedModels() {
		super.initNestedModels();
		addModulesToEARDataModel = new AddArchiveProjectsToEARDataModel();
		addNestedModel(NESTED_MODEL_ADD_ARCHIVE_TO_EAR, addModulesToEARDataModel);
	}

	protected Object getDefaultProperty(String propertyName) {
		if (propertyName.equals(APPLICATION_VERSION)) {
			return getDefaultJ2EEVersion();
		} else if (propertyName.equals(UI_SHOW_FIRST_PAGE_ONLY)) {
			return Boolean.FALSE;
		}
		return super.getDefaultProperty(propertyName);
	}

	/*
	 * @return Returns the default J2EE spec level based on the Global J2EE Preference
	 */
	private Object getDefaultJ2EEVersion() {
		int highestJ2EEPref = J2EEPlugin.getDefault().getJ2EEPreferences().getHighestJ2EEVersionID();
		switch (highestJ2EEPref) {
			case (J2EEVersionConstants.J2EE_1_4_ID) :
				return new Integer(J2EEVersionConstants.J2EE_1_4_ID);
			case (J2EEVersionConstants.J2EE_1_3_ID) :
				return new Integer(J2EEVersionConstants.J2EE_1_3_ID);
			case (J2EEVersionConstants.J2EE_1_2_ID) :
				return new Integer(J2EEVersionConstants.J2EE_1_2_ID);
			default :
				return new Integer(J2EEVersionConstants.J2EE_1_4_TEXT);
		}
	}

	/**
	 * Returns the String representation of <code>J2EEVersionConstants.J2EE_1_2_ID</code>,
	 * <code>J2EEVersionConstants.J2EE_1_3_ID</code>, or
	 * <code>J2EEVersionConstants.J2EE_1_4_ID</code>.
	 * 
	 * @param applicationVersion
	 * @return The String representation of <code>applicationVersion</code>
	 */
	public final static String getVersionString(int applicationVersion) {
		switch (applicationVersion) {
			case J2EEVersionConstants.J2EE_1_2_ID :
				return J2EEVersionConstants.VERSION_1_2_TEXT;
			case J2EEVersionConstants.J2EE_1_3_ID :
				return J2EEVersionConstants.VERSION_1_3_TEXT;
			case J2EEVersionConstants.J2EE_1_4_ID :
			default :
				return J2EEVersionConstants.VERSION_1_4_TEXT;
		}
	}

	protected WTPPropertyDescriptor[] doGetValidPropertyDescriptors(String propertyName) {
		if (propertyName.equals(APPLICATION_VERSION)) {
			return getValidJ2EEVersionDescriptors();
		}
		return super.doGetValidPropertyDescriptors(propertyName);
	}

	protected WTPPropertyDescriptor doGetPropertyDescriptor(String propertyName) {
		if (propertyName.equals(APPLICATION_VERSION)) {
			int version = getIntProperty(APPLICATION_VERSION);
			WTPPropertyDescriptor descriptor = null;
			switch (version) {
				case (J2EEVersionConstants.J2EE_1_2_ID) :
					descriptor = new WTPPropertyDescriptor(new Integer(J2EEVersionConstants.J2EE_1_2_ID), J2EEVersionConstants.VERSION_1_2_TEXT);
					break;
				case (J2EEVersionConstants.J2EE_1_3_ID) :
					descriptor = new WTPPropertyDescriptor(new Integer(J2EEVersionConstants.J2EE_1_3_ID), J2EEVersionConstants.VERSION_1_3_TEXT);
					break;
				case (J2EEVersionConstants.J2EE_1_4_ID) :
				default :
					descriptor = new WTPPropertyDescriptor(new Integer(J2EEVersionConstants.J2EE_1_4_ID), J2EEVersionConstants.VERSION_1_4_TEXT);
					break;

			}
			return descriptor;
		}
		return super.doGetPropertyDescriptor(propertyName);
	}

	/**
	 * @return Return a String[] of the valid J2EE versions for the selected J2EE Preference Level.
	 */
	protected WTPPropertyDescriptor[] getValidJ2EEVersionDescriptors() {
		int highestJ2EEPref = J2EEPlugin.getDefault().getJ2EEPreferences().getHighestJ2EEVersionID();
		WTPPropertyDescriptor[] descriptors = null;
		switch (highestJ2EEPref) {
			case (J2EEVersionConstants.J2EE_1_2_ID) :
				descriptors = new WTPPropertyDescriptor[1];
				descriptors[0] = new WTPPropertyDescriptor(new Integer(J2EEVersionConstants.J2EE_1_2_ID), J2EEVersionConstants.VERSION_1_2_TEXT);
				break;
			case (J2EEVersionConstants.J2EE_1_3_ID) :
				descriptors = new WTPPropertyDescriptor[2];
				descriptors[0] = new WTPPropertyDescriptor(new Integer(J2EEVersionConstants.J2EE_1_2_ID), J2EEVersionConstants.VERSION_1_2_TEXT);
				descriptors[1] = new WTPPropertyDescriptor(new Integer(J2EEVersionConstants.J2EE_1_3_ID), J2EEVersionConstants.VERSION_1_3_TEXT);
				break;
			case (J2EEVersionConstants.J2EE_1_4_ID) :
			default :
				descriptors = new WTPPropertyDescriptor[3];
				descriptors[0] = new WTPPropertyDescriptor(new Integer(J2EEVersionConstants.J2EE_1_2_ID), J2EEVersionConstants.VERSION_1_2_TEXT);
				descriptors[1] = new WTPPropertyDescriptor(new Integer(J2EEVersionConstants.J2EE_1_3_ID), J2EEVersionConstants.VERSION_1_3_TEXT);
				descriptors[2] = new WTPPropertyDescriptor(new Integer(J2EEVersionConstants.J2EE_1_4_ID), J2EEVersionConstants.VERSION_1_4_TEXT);
		}
		return descriptors;
	}

	protected boolean doSetProperty(String propertyName, Object propertyValue) {
		super.doSetProperty(propertyName, propertyValue);
		if (EditModelOperationDataModel.PROJECT_NAME.equals(propertyName)) {
			addModulesToEARDataModel.setProperty(AddArchiveProjectsToEARDataModel.PROJECT_NAME, propertyValue);
		} else if (propertyName.equals(APPLICATION_VERSION)) {
			getServerTargetDataModel().setProperty(ServerTargetDataModel.J2EE_VERSION_ID, propertyValue);
		} else if (MODULE_LIST.equals(propertyName)) {
			addModulesToEARDataModel.setProperty(AddArchiveProjectsToEARDataModel.MODULE_LIST, propertyValue);
		}
		return true;
	}

	public AddArchiveProjectsToEARDataModel getAddModulesToEARDataModel() {
		return addModulesToEARDataModel;
	}

	public void propertyChanged(WTPOperationDataModelEvent event) {
		if (event.getFlag() == WTPOperationDataModelEvent.PROPERTY_CHG) {
			if (AddArchiveProjectsToEARDataModel.PROJECT_NAME.equals(event.getPropertyName())) {
				setProperty(PROJECT_NAME, event.getProperty());
				return;
			}
		}
		super.propertyChanged(event);
	}

	public void enableValidation() {
		super.enableValidation();
	}

	public void disableValidation() {
		super.disableValidation();
	}
}

Back to the top