| /******************************************************************************* |
| * Copyright (c) 2003, 2004, 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.applicationclient.internal.creation; |
| |
| import java.lang.reflect.InvocationTargetException; |
| |
| import org.eclipse.core.commands.ExecutionException; |
| import org.eclipse.core.resources.IContainer; |
| import org.eclipse.core.resources.IFile; |
| import org.eclipse.core.resources.IResource; |
| import org.eclipse.core.runtime.CoreException; |
| import org.eclipse.core.runtime.IAdaptable; |
| import org.eclipse.core.runtime.IPath; |
| import org.eclipse.core.runtime.IProgressMonitor; |
| import org.eclipse.core.runtime.IStatus; |
| import org.eclipse.core.runtime.Path; |
| import org.eclipse.jem.util.logger.proxy.Logger; |
| import org.eclipse.jst.j2ee.application.internal.operations.J2EEComponentCreationOperation; |
| import org.eclipse.jst.j2ee.application.internal.operations.UpdateManifestDataModelProperties; |
| import org.eclipse.jst.j2ee.application.internal.operations.UpdateManifestDataModelProvider; |
| import org.eclipse.jst.j2ee.applicationclient.componentcore.util.AppClientArtifactEdit; |
| import org.eclipse.jst.j2ee.datamodel.properties.IAppClientComponentCreationDataModelProperties; |
| import org.eclipse.jst.j2ee.internal.J2EEConstants; |
| import org.eclipse.jst.j2ee.internal.common.J2EEVersionUtil; |
| import org.eclipse.jst.j2ee.internal.common.operations.INewJavaClassDataModelProperties; |
| import org.eclipse.jst.j2ee.internal.common.operations.NewJavaClassDataModelProvider; |
| import org.eclipse.wst.common.componentcore.ComponentCore; |
| import org.eclipse.wst.common.componentcore.internal.operation.IArtifactEditOperationDataModelProperties; |
| import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; |
| import org.eclipse.wst.common.componentcore.resources.IVirtualFolder; |
| import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory; |
| import org.eclipse.wst.common.frameworks.datamodel.IDataModel; |
| |
| |
| public class AppClientComponentCreationOperation extends J2EEComponentCreationOperation implements IAppClientComponentCreationDataModelProperties { |
| |
| public AppClientComponentCreationOperation(IDataModel model) { |
| super(model); |
| } |
| |
| protected void createAndLinkJ2EEComponentsForMultipleComponents() throws CoreException { |
| IVirtualComponent component = ComponentCore.createComponent(getProject(), getModuleDeployName()); |
| component.create(0, null); |
| //create and link appClientModule Source Folder |
| IVirtualFolder rootFolder = component.getRootFolder(); |
| IVirtualFolder appClientModuleFolder = rootFolder.getFolder(new Path("/")); //$NON-NLS-1$ |
| appClientModuleFolder.createLink(new Path( "/" + model.getStringProperty(JAVASOURCE_FOLDER)), 0, null); //$NON-NLS-1$ //$NON-NLS-2$ |
| |
| //create and link META-INF folder |
| IVirtualFolder metaInfFolder = appClientModuleFolder.getFolder(J2EEConstants.META_INF); |
| metaInfFolder.create(IResource.FORCE, null); |
| } |
| |
| protected void createAndLinkJ2EEComponentsForSingleComponent() throws CoreException { |
| IVirtualComponent component = ComponentCore.createComponent(getProject(), getModuleDeployName()); |
| component.create(0, null); |
| //create and link appClientModule Source Folder |
| IVirtualFolder rootFolder = component.getRootFolder(); |
| IVirtualFolder appClientModuleFolder = rootFolder.getFolder(new Path("/")); //$NON-NLS-1$ |
| appClientModuleFolder.createLink(new Path( "/" + model.getStringProperty(JAVASOURCE_FOLDER)), 0, null); //$NON-NLS-1$ //$NON-NLS-2$ |
| |
| //create and link META-INF folder |
| IVirtualFolder metaInfFolder = appClientModuleFolder.getFolder(J2EEConstants.META_INF); |
| metaInfFolder.create(IResource.FORCE, null); |
| } |
| |
| protected void createDeploymentDescriptor(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException { |
| AppClientArtifactEdit artifactEdit = null; |
| try { |
| artifactEdit = AppClientArtifactEdit.getAppClientArtifactEditForWrite(getProject()); |
| Integer version = (Integer)model.getProperty(COMPONENT_VERSION); |
| artifactEdit.createModelRoot(version.intValue()); |
| artifactEdit.save(monitor); |
| } catch(Exception e){ |
| Logger.getLogger().logError(e); |
| } finally { |
| if (artifactEdit != null) |
| artifactEdit.dispose(); |
| } |
| } |
| |
| protected String getVersion() { |
| int version = model.getIntProperty(COMPONENT_VERSION); |
| return J2EEVersionUtil.getJ2EETextVersion(version); |
| } |
| |
| public IStatus execute(IProgressMonitor monitor, IAdaptable info) { |
| try { |
| super.execute(monitor ); |
| |
| if (model.getBooleanProperty(CREATE_DEFAULT_MAIN_CLASS)) { |
| IDataModel mainClassDataModel = DataModelFactory.createDataModel(NewJavaClassDataModelProvider.class); |
| mainClassDataModel.setProperty(IArtifactEditOperationDataModelProperties.PROJECT_NAME, getProject().getName()); |
| mainClassDataModel.setProperty(IArtifactEditOperationDataModelProperties.COMPONENT_NAME, getComponentName()); |
| mainClassDataModel.setProperty(INewJavaClassDataModelProperties.CLASS_NAME, "Main"); //$NON-NLS-1$ |
| mainClassDataModel.setBooleanProperty(INewJavaClassDataModelProperties.MAIN_METHOD, true); |
| String projRelativeSourcePath = IPath.SEPARATOR + getProject().getName() + IPath.SEPARATOR + model.getStringProperty(JAVASOURCE_FOLDER); |
| mainClassDataModel.setProperty(INewJavaClassDataModelProperties.SOURCE_FOLDER, projRelativeSourcePath); |
| // mainClassDataModel.setProperty(NewJavaClassDataModel.JAVA_PACKAGE, "appclient");//$NON-NLS-1$ |
| mainClassDataModel.getDefaultOperation().execute(monitor,null); |
| |
| createManifestEntryForMainClass(monitor); |
| } |
| } catch (Exception e) { |
| Logger.getLogger().log(e.getMessage()); |
| } |
| return OK_STATUS; |
| } |
| |
| protected void createManifestEntryForMainClass(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException { |
| String manifestFolder = model.getStringProperty(MANIFEST_FOLDER); |
| IContainer container = getProject().getFolder(manifestFolder); |
| IFile file = container.getFile(new Path(J2EEConstants.MANIFEST_SHORT_NAME)); |
| |
| if (model.getBooleanProperty(CREATE_DEFAULT_MAIN_CLASS)) { |
| IDataModel dm = DataModelFactory.createDataModel(UpdateManifestDataModelProvider.class); |
| dm.setProperty(UpdateManifestDataModelProperties.PROJECT_NAME, getProject().getName()); |
| dm.setBooleanProperty(UpdateManifestDataModelProperties.MERGE, false); |
| dm.setProperty(UpdateManifestDataModelProperties.MANIFEST_FILE, file); |
| dm.setProperty(UpdateManifestDataModelProperties.MAIN_CLASS, "Main"); //$NON-NLS-1$ |
| try { |
| dm.getDefaultOperation().execute(monitor,null); |
| } catch (Exception e) { |
| //Ignore |
| } |
| } |
| } |
| public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { |
| // TODO Auto-generated method stub |
| return null; |
| } |
| |
| public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { |
| // TODO Auto-generated method stub |
| return null; |
| } |
| |
| } |