blob: 869cbd9d5209b57a86645fa6dd444f5fb12016ca [file] [log] [blame]
/*******************************************************************************
* 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 Nov 6, 2003
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package org.eclipse.jst.j2ee.internal.jca.operations;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.InvocationTargetException;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.jst.j2ee.application.operations.J2EEModuleCreationDataModel;
import org.eclipse.jst.j2ee.application.operations.J2EEModuleCreationOperation;
import org.eclipse.jst.j2ee.commonarchivecore.internal.helpers.ArchiveConstants;
import org.eclipse.jst.j2ee.commonarchivecore.internal.util.ArchiveUtil;
import org.eclipse.jst.j2ee.internal.J2EEVersionConstants;
import org.eclipse.jst.j2ee.internal.project.IConnectorNatureConstants;
import org.eclipse.jst.j2ee.jca.Connector;
import org.eclipse.wst.common.internal.emfworkbench.operation.EditModelOperation;
import com.ibm.wtp.common.logger.proxy.Logger;
import com.ibm.wtp.emf.workbench.WorkbenchByteArrayOutputStream;
public class ConnectorModuleCreationOperation extends J2EEModuleCreationOperation {
public ConnectorModuleCreationOperation(ConnectorModuleCreationDataModel dataModel) {
super(dataModel);
}
protected void createDeploymentDescriptor(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
EditModelOperation op = new EditModelOperation((J2EEModuleCreationDataModel) operationDataModel) {
protected void execute(IProgressMonitor aMonitor) throws CoreException, InvocationTargetException, InterruptedException {
ConnectorEditModel model = (ConnectorEditModel) editModel;
IFolder metainf = model.getConnectorNature().getEMFRoot().getFolder(new Path(ArchiveConstants.META_INF));
if (!metainf.exists()) {
metainf.create(true, true, null);
}
IFile aFile = model.getConnectorNature().getEMFRoot().getFile(new Path(ArchiveConstants.RAR_DD_URI));
OutputStream out = new WorkbenchByteArrayOutputStream(aFile);
String template = model.getJ2EENature().getModuleVersion() == J2EEVersionConstants.JCA_1_0_ID ? IConnectorNatureConstants.CONNECTOR_XML_TEMPLATE_10 : IConnectorNatureConstants.CONNECTOR_XML_TEMPLATE_15;
InputStream in = getClass().getResourceAsStream(template);
if (in != null & out != null) {
try {
ArchiveUtil.copy(in, out);
} catch (IOException ioe) {
Logger.getLogger().logError(ioe);
} finally {
try {
if (null != out) {
out.close();
}
if (null != in) {
in.close();
}
} catch (IOException ioe) {
Logger.getLogger().logError(ioe);
}
}
Resource resource = model.getResource(URI.createURI(ArchiveConstants.RAR_DD_URI));
if (null != resource) {
resource.unload();
}
Connector connector = model.getConnector();
if (connector != null) {
IProject project = model.getProject();
if (project != null)
connector.setDisplayName(project.getName());
}
} else {
//without a template
model.makeDeploymentDescriptorWithRoot();
} // if
}
};
op.doRun(monitor);
}
}