Author: sppatel
Date: Thu Oct 13 11:33:08 2005
New Revision: 320865
URL: http://svn.apache.org/viewcvs?rev=320865&view=rev
Log:
add initial drop of importdeploymentplanoperation
Added:
geronimo/devtools/trunk/modules/eclipse-plugin/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/operations/ImportDeploymentPlanOperation.java
Added: geronimo/devtools/trunk/modules/eclipse-plugin/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/operations/ImportDeploymentPlanOperation.java
URL: http://svn.apache.org/viewcvs/geronimo/devtools/trunk/modules/eclipse-plugin/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/operations/ImportDeploymentPlanOperation.java?rev=320865&view=auto
==============================================================================
--- geronimo/devtools/trunk/modules/eclipse-plugin/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/operations/ImportDeploymentPlanOperation.java
(added)
+++ geronimo/devtools/trunk/modules/eclipse-plugin/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/operations/ImportDeploymentPlanOperation.java
Thu Oct 13 11:33:08 2005
@@ -0,0 +1,201 @@
+/**
+ * Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.geronimo.core.operations;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+
+import org.apache.geronimo.core.internal.GeronimoUtils;
+import org.apache.geronimo.deployment.xmlbeans.XmlBeansUtil;
+import org.apache.geronimo.schema.SchemaConversionUtils;
+import org.apache.geronimo.xbeans.geronimo.web.GerWebAppType;
+import org.apache.xmlbeans.XmlException;
+import org.apache.xmlbeans.XmlObject;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.wst.common.componentcore.ComponentCore;
+import org.eclipse.wst.common.componentcore.datamodel.properties.IComponentCreationDataModelProperties;
+import org.eclipse.wst.common.componentcore.internal.util.IModuleConstants;
+import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
+import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelOperation;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
+import org.eclipse.wst.common.frameworks.datamodel.properties.IFlexibleProjectCreationDataModelProperties;
+import org.eclipse.wst.server.core.IRuntime;
+import org.eclipse.wst.server.core.ServerCore;
+
+public class ImportDeploymentPlanOperation extends AbstractDataModelOperation
+ implements IExportDeploymentPlanDataModelProperties {
+
+ /**
+ *
+ */
+ public ImportDeploymentPlanOperation() {
+ super();
+ }
+
+ /**
+ * @param model
+ */
+ public ImportDeploymentPlanOperation(IDataModel model) {
+ super(model);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor,
+ * org.eclipse.core.runtime.IAdaptable)
+ */
+ public IStatus execute(IProgressMonitor monitor, IAdaptable info)
+ throws ExecutionException {
+
+ if (!isGeronimoRuntimeTarget())
+ return Status.OK_STATUS;
+
+ IVirtualComponent comp = ComponentCore.createComponent(getProject(),
+ getComponentName());
+
+ try {
+ if (comp.getComponentTypeId().equals(
+ IModuleConstants.JST_WEB_MODULE)) {
+ importWebDeploymentPlan(GeronimoUtils
+ .getWebDeploymentPlanFile(comp));
+ } else if (comp.getComponentTypeId().equals(
+ IModuleConstants.JST_EJB_MODULE)) {
+ importEjbDeploymentPlan(GeronimoUtils
+ .getOpenEjbDeploymentPlanFile(comp));
+ } else if (comp.getComponentTypeId().equals(
+ IModuleConstants.JST_EAR_MODULE)) {
+ importEarDeploymentPlan(GeronimoUtils
+ .getApplicationDeploymentPlanFile(comp));
+ } else if (comp.getComponentTypeId().equals(
+ IModuleConstants.JST_CONNECTOR_MODULE)) {
+ importConnectorDeploymentPlan(GeronimoUtils
+ .getConnectorDeploymentPlanFile(comp));
+ }
+ } catch (XmlException e) {
+ e.printStackTrace();
+ }
+
+ return Status.OK_STATUS;
+ }
+
+ public void importWebDeploymentPlan(IFile dpFile) throws XmlException {
+
+ XmlObject plan = getXmlObject(dpFile);
+
+ if (plan != null) {
+ SchemaConversionUtils.fixGeronimoSchema(plan, "web-app",
+ GerWebAppType.type);
+ save(plan, dpFile);
+ }
+ }
+
+ public void importEarDeploymentPlan(IFile dpFile) throws XmlException {
+ }
+
+ public void importEjbDeploymentPlan(IFile dpFile) throws XmlException {
+
+ }
+
+ public void importConnectorDeploymentPlan(IFile dpFile) throws XmlException {
+
+ }
+
+ private XmlObject getXmlObject(IFile dpFile) {
+
+ if (dpFile.exists()) {
+ try {
+ return XmlBeansUtil
+ .parse(dpFile.getLocation().toFile().toURL());
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (XmlException e) {
+ e.printStackTrace();
+ }
+ }
+
+ return null;
+ }
+
+ private void save(XmlObject object, IFile file) {
+ try {
+ object.save(file.getLocation().toFile());
+ file.refreshLocal(IFile.DEPTH_ONE, null);
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor,
+ * org.eclipse.core.runtime.IAdaptable)
+ */
+ public IStatus redo(IProgressMonitor monitor, IAdaptable info)
+ throws ExecutionException {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor,
+ * org.eclipse.core.runtime.IAdaptable)
+ */
+ public IStatus undo(IProgressMonitor monitor, IAdaptable info)
+ throws ExecutionException {
+ return null;
+ }
+
+ public boolean isGeronimoRuntimeTarget() {
+
+ IRuntime runtime = ServerCore.getProjectProperties(getProject())
+ .getRuntimeTarget();
+ return runtime.getName().startsWith("Apache Geronimo");
+
+ }
+
+ public String getComponentName() {
+ return model.getProperty(
+ IComponentCreationDataModelProperties.COMPONENT_NAME)
+ .toString();
+ }
+
+ public IProject getProject() {
+ String projectName = model.getProperty(
+ IFlexibleProjectCreationDataModelProperties.PROJECT_NAME)
+ .toString();
+ if (projectName != null) {
+ return ResourcesPlugin.getWorkspace().getRoot().getProject(
+ projectName);
+ }
+ return null;
+ }
+
+}
|