[jbosstools-commits] JBoss Tools SVN: r30608 - in trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7: deployment and 1 other directories.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Fri Apr 15 16:39:54 EDT 2011


Author: rob.stryker at jboss.com
Date: 2011-04-15 16:39:54 -0400 (Fri, 15 Apr 2011)
New Revision: 30608

Added:
   trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/
   trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/Deployable.java
   trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/DeployerException.java
   trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/DeploymentManager.java
   trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/DetypedDeployer.java
   trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/JBossDeploymentManager.java
   trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/JBossManagementService.java
   trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/JbossManagementUtil.java
   trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/TypedDeployer.java
   trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/internal/
   trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/internal/CommandFormatException.java
   trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/internal/CommandLineException.java
   trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/internal/DefaultOperationRequestAddress.java
   trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/internal/DefaultOperationRequestBuilder.java
   trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/internal/OperationFormatException.java
   trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/internal/OperationRequestAddress.java
   trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/internal/OperationRequestBuilder.java
   trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/internal/ValidatingOperationCallbackHandler.java
Log:
as7 management support - initial impl

Added: trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/Deployable.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/Deployable.java	                        (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/Deployable.java	2011-04-15 20:39:54 UTC (rev 30608)
@@ -0,0 +1,95 @@
+package org.jboss.ide.eclipse.as.management.as7.deployment;
+
+import java.io.File;
+import java.text.MessageFormat;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.jboss.as.controller.client.helpers.standalone.DeploymentAction;
+import org.jboss.as.controller.client.helpers.standalone.ServerDeploymentActionResult;
+import org.jboss.as.controller.client.helpers.standalone.ServerDeploymentPlanResult;
+import org.jboss.ide.eclipse.as.management.as7.Activator;
+
+public class Deployable {
+
+	private String name;
+	private File file;
+	private Future<ServerDeploymentPlanResult> resultFuture;
+	private long timeout;
+	private DeploymentAction action;
+
+	protected Deployable(String name, File file, long timeout) {
+		this.name = name;
+		this.file = file;
+		this.timeout = timeout;
+	}
+
+	protected void setDeploymentAction(DeploymentAction action) {
+		this.action = action;
+	}
+
+	protected void setResultFuture(Future<ServerDeploymentPlanResult> resultFuture) {
+		this.resultFuture = resultFuture;
+	}
+
+	public File getFile() {
+		return file;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public IStatus getStatus() throws DeployerException {
+		if (resultFuture == null
+				|| action == null) {
+			return null;
+		}
+		try {
+			ServerDeploymentPlanResult result = resultFuture.get(timeout, TimeUnit.MILLISECONDS);
+			ServerDeploymentActionResult actionResult = result.getDeploymentActionResult(action.getId());
+			return createStatus(action, actionResult);
+		} catch (Exception e) {
+			throw new DeployerException(e);
+		}
+	}
+
+	private IStatus createStatus(DeploymentAction action, ServerDeploymentActionResult actionResult) {
+		if (actionResult == null) {
+			return null;
+		}
+
+		IStatus status = null;
+		switch (actionResult.getResult()) {
+		case NOT_EXECUTED:
+			status = createStatus(IStatus.ERROR, "The operation {0} was not executed on unit {1}", action
+					.getType().name(), getName());
+			break;
+		case EXECUTED:
+			status = Status.OK_STATUS;
+			break;
+		case FAILED:
+			status = createStatus(IStatus.ERROR, "The operation {0} failed for unit {1}", action.getType()
+					.name(), getName());
+			break;
+		case ROLLED_BACK:
+			status = createStatus(IStatus.ERROR, "The operation {0} for unit {1} was rolled back", action
+					.getType().name(), getName());
+			break;
+		case CONFIGURATION_MODIFIED_REQUIRES_RESTART:
+			status = createStatus(
+					IStatus.WARNING,
+					"The operation {0} was not executed on unit {1}. The server configuration was changed though and the server needs to be restarted",
+					action.getType().name(), getName());
+			break;
+		}
+		return status;
+	}
+
+	private IStatus createStatus(int severity, String messagePattern, Object... messageArguments) {
+		return new Status(severity, Activator.getContext().getBundle().getSymbolicName(), MessageFormat.format(
+				messagePattern, messageArguments));
+	}
+}
\ No newline at end of file

Added: trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/DeployerException.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/DeployerException.java	                        (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/DeployerException.java	2011-04-15 20:39:54 UTC (rev 30608)
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat Inc..
+ * 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:
+ *     Red Hat Incorporated - initial API and implementation
+ *******************************************************************************/
+package org.jboss.ide.eclipse.as.management.as7.deployment;
+
+/**
+ * @author André Dietisheim
+ */
+public class DeployerException extends Exception {
+
+	private static final long serialVersionUID = 1L;
+
+	public DeployerException(String message, Throwable cause) {
+		super(message, cause);
+	}
+
+	public DeployerException(Throwable cause) {
+		super(cause);
+	}
+
+	public DeployerException(String message) {
+		super(message);
+	}
+
+}

Added: trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/DeploymentManager.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/DeploymentManager.java	                        (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/DeploymentManager.java	2011-04-15 20:39:54 UTC (rev 30608)
@@ -0,0 +1,169 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ide.eclipse.as.management.as7.deployment;
+
+import static org.jboss.as.protocol.StreamUtils.safeClose;
+
+import java.io.File;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+import org.jboss.as.controller.client.ModelControllerClient;
+import org.jboss.as.controller.client.helpers.standalone.DeploymentPlanBuilder;
+import org.jboss.as.controller.client.helpers.standalone.ServerDeploymentManager;
+
+/**
+ * Used to deploy/undeploy deployments to a running <b>standalone</b>
+ * application server
+ * 
+ * @author <a href="adietish at redhat.com">André Dietisheim</a>
+ */
+public class DeploymentManager {
+
+	public static final long DEFAULT_TIMEOUT = 15000;
+
+	private final List<IDeploymentPlanBuilderOperation> deployments = new ArrayList<IDeploymentPlanBuilderOperation>();
+	private final ModelControllerClient client;
+	private final ServerDeploymentManager manager;
+	private long timeout = DEFAULT_TIMEOUT;
+
+	public DeploymentManager(String host, int port) throws UnknownHostException {
+		client = ModelControllerClient.Factory.create(host, port);
+		manager = ServerDeploymentManager.Factory.create(client);
+	}
+
+	public synchronized DeploymentManager deploy(File file) {
+		deployments.add(new DeployOperation(file));
+		return this;
+	}
+
+	public synchronized DeploymentManager deploy(String name, File file) {
+		deployments.add(new DeployOperation(name, file));
+		return this;
+	}
+
+	public synchronized DeploymentManager undeploy(String name) {
+		deployments.add(new UndeployOperation(name));
+		return this;
+	}
+
+	public synchronized DeploymentManager undeploy(File file) {
+		deployments.add(new UndeployOperation(file));
+		return this;
+	}
+
+	public synchronized void execute() throws DeployerException {
+		try {
+			DeploymentPlanBuilder builder = manager.newDeploymentPlan();
+			for (IDeploymentPlanBuilderOperation deployment : deployments) {
+				builder = deployment.addTo(builder);
+			}
+			manager.execute(builder.build()).get(timeout, TimeUnit.MILLISECONDS);
+		} catch (Exception e) {
+			throw new DeployerException(e);
+		}
+	}
+
+	public void setTimeout(long timeout) {
+		this.timeout = timeout;
+	}
+
+	public void dispose() {
+		safeClose(client);
+	}
+
+	private static class DeployOperation extends FileOperation {
+
+		private DeployOperation(File file) {
+			super(file);
+		}
+
+		private DeployOperation(String name, File file) {
+			super(name, file);
+		}
+
+		public synchronized DeploymentPlanBuilder addTo(DeploymentPlanBuilder builder) throws Exception {
+			String name = getName();
+			return builder.add(name, getFile()).deploy(name);
+		}		
+	}
+	
+	private static class UndeployOperation extends FileOperation {
+
+		private UndeployOperation(File file) {
+			super(file);
+		}
+
+		private UndeployOperation(String name) {
+			super(name, null);
+		}
+
+		public synchronized DeploymentPlanBuilder addTo(DeploymentPlanBuilder builder) throws Exception {
+			String name = getName();
+			return builder.undeploy(name).undeploy(name);
+		}
+	}
+	
+	private abstract static class FileOperation extends NamedOperation {
+
+		private File file;
+
+		private FileOperation(File file) {
+			this(null, file);
+		}
+
+		private FileOperation(String name, File file) {
+			super(name);
+			this.file = file;
+		}
+
+		protected File getFile() {
+			return file;
+		}
+
+		protected String getName() {
+			if (name != null) {
+				return name;
+			} else {
+				return file.getName();
+			}
+		}
+
+	}
+
+	private abstract static class NamedOperation implements IDeploymentPlanBuilderOperation {
+
+		protected String name;
+
+		private NamedOperation(String name) {
+			this.name = name;
+		}
+	}
+
+	private interface IDeploymentPlanBuilderOperation {
+
+		public DeploymentPlanBuilder addTo(DeploymentPlanBuilder builder) throws Exception;
+
+	}
+}

Added: trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/DetypedDeployer.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/DetypedDeployer.java	                        (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/DetypedDeployer.java	2011-04-15 20:39:54 UTC (rev 30608)
@@ -0,0 +1,143 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ide.eclipse.as.management.as7.deployment;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.net.UnknownHostException;
+import java.util.List;
+import java.util.concurrent.CancellationException;
+
+import org.jboss.as.controller.client.ModelControllerClient;
+import org.jboss.as.controller.client.Operation;
+import org.jboss.as.controller.client.OperationBuilder;
+import org.jboss.as.protocol.StreamUtils;
+import org.jboss.dmr.ModelNode;
+
+/**
+ * @author André Dietisheim
+ */
+public class DetypedDeployer {
+
+	public static void undeploy(String name, String host, int port) throws DeployerException {
+		ModelControllerClient client = null;
+		try {
+			client = ModelControllerClient.Factory.create(host, port);
+			// undeploy
+			ModelNode request = new ModelNode();
+			request.get("operation").set("undeploy");
+			request.get("address").add("deployment", name);
+			ModelNode result = client.execute(request);
+			throwOnFailure(result);
+
+			// remove
+			request = new ModelNode();
+			request.get("operation").set("remove");
+			request.get("address").add("deployment", name);
+			result = client.execute(request);
+		} catch (Exception e) {
+			throw new DeployerException(e);
+		} finally {
+			StreamUtils.safeClose(client);
+		}
+	}
+
+	public static void deploy(File file, String host, int port) throws DeployerException {
+		deploy(file.getName(), file, host, port);
+	}
+
+	public static void deploy(String name, File file, String host, int port) throws DeployerException {
+		ModelControllerClient client = null;
+		try {
+			client = ModelControllerClient.Factory.create(host, port);
+
+			ModelNode request = new ModelNode();
+			request.get("operation").set("add");
+			request.get("address").add("deployment", name);
+			request.get("enabled").set(true);
+
+			OperationBuilder builder = OperationBuilder.Factory.create(request);
+			builder.addInputStream(new BufferedInputStream(new FileInputStream(file)));
+			Operation operation = builder.build();
+			request.get("input-stream-index").set(0);
+
+			ModelNode result = client.execute(operation);
+			System.out.println(result);
+
+			throwOnFailure(result);
+		} catch (Exception e) {
+			throw new DeployerException(e);
+		} finally {
+			StreamUtils.safeClose(client);
+		}
+	}
+
+	public static void replace(String name, File file, String host, int port) throws DeployerException {
+		ModelControllerClient client = null;
+		try {
+			client = ModelControllerClient.Factory.create(host, port);
+
+			ModelNode request = new ModelNode();
+			request.get("operation").set("full-replace-deployment");
+			request.get("name").set(name);
+
+			OperationBuilder builder = OperationBuilder.Factory.create(request);
+			builder.addInputStream(new BufferedInputStream(new FileInputStream(file)));
+			Operation operation = builder.build();
+			request.get("input-stream-index").set(0);
+
+			ModelNode result = client.execute(operation);
+
+			throwOnFailure(result);
+		} catch (Exception e) {
+			throw new DeployerException(e);
+		} finally {
+			StreamUtils.safeClose(client);
+		}
+	}
+
+	public static boolean isDeployed(String name, String host, int port) throws CancellationException, IOException {
+		ModelControllerClient client = ModelControllerClient.Factory.create(host, port);
+		try {
+			return JbossManagementUtil.isDeployed(name, client);
+		} finally {
+			StreamUtils.safeClose(client);
+		}
+	}
+
+	public static List<String> getDeployments(String host, int port) throws UnknownHostException {
+		ModelControllerClient client = ModelControllerClient.Factory.create(host, port);
+		return JbossManagementUtil.getDeployments(client);
+	}
+
+	private static void throwOnFailure(ModelNode result) throws DeployerException {
+		if (!JbossManagementUtil.isSuccess(result)) {
+			throw new DeployerException(JbossManagementUtil.getFailureDescription(result));
+		}
+	}
+
+	private DetypedDeployer() {
+		// inhibit instantiation
+	}
+}

Added: trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/JBossDeploymentManager.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/JBossDeploymentManager.java	                        (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/JBossDeploymentManager.java	2011-04-15 20:39:54 UTC (rev 30608)
@@ -0,0 +1,35 @@
+package org.jboss.ide.eclipse.as.management.as7.deployment;
+
+import java.io.File;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.jboss.ide.eclipse.as.core.server.internal.v7.IJBoss7DeploymentManager;
+import org.jboss.ide.eclipse.as.management.as7.deployment.TypedDeployer.DeploymentResult;
+
+public class JBossDeploymentManager implements IJBoss7DeploymentManager {
+
+	public DeploymentResult deployAsync(String host, int port, String deploymentName,
+			File file, IProgressMonitor monitor) throws Exception {
+		TypedDeployer deployer = new TypedDeployer(host, port);
+		return deployer.deploy(deploymentName, file);
+	}
+
+	public DeploymentResult deploySync(String host, int port, String deploymentName,
+			File file, IProgressMonitor monitor) throws Exception {
+		TypedDeployer deployer = new TypedDeployer(host, port);
+		return deployer.deploySync(deploymentName, file, monitor);
+	}
+
+	public DeploymentResult undeployAsync(String host, int port, String deploymentName,
+			boolean removeFile, IProgressMonitor monitor) throws Exception  {
+		TypedDeployer deployer = new TypedDeployer(host, port);
+		return deployer.undeploy(deploymentName);
+	}
+
+	public DeploymentResult syncUndeploy(String host, int port, String deploymentName,
+			boolean removeFile, IProgressMonitor monitor) throws Exception {
+		TypedDeployer deployer = new TypedDeployer(host, port);
+		return deployer.undeploySync(deploymentName, monitor);
+	}
+
+}

Added: trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/JBossManagementService.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/JBossManagementService.java	                        (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/JBossManagementService.java	2011-04-15 20:39:54 UTC (rev 30608)
@@ -0,0 +1,24 @@
+package org.jboss.ide.eclipse.as.management.as7.deployment;
+
+import org.jboss.ide.eclipse.as.core.server.internal.v7.IJBoss7DeploymentManager;
+import org.jboss.ide.eclipse.as.core.server.internal.v7.IJBoss7ManagementInterface;
+import org.jboss.ide.eclipse.as.core.server.internal.v7.IJBoss7ManagementService;
+
+
+public class JBossManagementService implements IJBoss7ManagementService {
+
+	private IJBoss7DeploymentManager deploymentManager = null;
+	private IJBoss7ManagementInterface manager = null;
+	
+	public IJBoss7DeploymentManager getDeploymentManager() {
+		if( deploymentManager == null )
+			deploymentManager = new JBossDeploymentManager();
+		return deploymentManager;
+	}
+
+	public IJBoss7ManagementInterface getManagementInterface() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+}

Added: trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/JbossManagementUtil.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/JbossManagementUtil.java	                        (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/JbossManagementUtil.java	2011-04-15 20:39:54 UTC (rev 30608)
@@ -0,0 +1,166 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ide.eclipse.as.management.as7.deployment;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.jboss.as.controller.client.ModelControllerClient;
+import org.jboss.dmr.ModelNode;
+import org.jboss.dmr.Property;
+import org.jboss.ide.eclipse.as.management.as7.internal.DefaultOperationRequestBuilder;
+import org.jboss.ide.eclipse.as.management.as7.internal.OperationFormatException;
+
+/**
+ *
+ * @author Alexey Loubyansky
+ */
+public class JbossManagementUtil {
+
+    public static boolean isSuccess(ModelNode operationResult) {
+        if(operationResult != null) {
+            ModelNode outcome = operationResult.get("outcome");
+            return outcome != null && outcome.asString().equals("success");
+        }
+        return false;
+    }
+
+    public static String getFailureDescription(ModelNode operationResult) {
+        if(operationResult == null) {
+            return null;
+        }
+
+        ModelNode descr = operationResult.get("failure-description");
+        if(descr == null) {
+            return null;
+        }
+
+        return descr.asString();
+    }
+
+    public static List<String> getList(ModelNode operationResult) {
+        if(!operationResult.hasDefined("result"))
+            return Collections.emptyList();
+
+        List<ModelNode> nodeList = operationResult.get("result").asList();
+        if(nodeList.isEmpty())
+            return Collections.emptyList();
+
+        List<String> list = new ArrayList<String>(nodeList.size());
+        for(ModelNode node : nodeList) {
+            list.add(node.asString());
+        }
+        return list;
+    }
+
+    public static byte[] getHash(ModelNode operationResult) {
+        if(!operationResult.hasDefined("result"))
+            return null;
+        return operationResult.get("result").asBytes();
+    }
+
+    public static List<String> getRequestPropertyNames(ModelNode operationResult) {
+        if(!operationResult.hasDefined("result"))
+            return Collections.emptyList();
+
+        ModelNode result = operationResult.get("result");
+        if(!result.hasDefined("request-properties"))
+            return Collections.emptyList();
+
+        List<Property> nodeList = result.get("request-properties").asPropertyList();
+        if(nodeList.isEmpty())
+            return Collections.emptyList();
+
+        List<String> list = new ArrayList<String>(nodeList.size());
+        for(Property node : nodeList) {
+            list.add(node.getName());
+        }
+        return list;
+    }
+
+    public static boolean isDeployed(String name, ModelControllerClient client) {
+        return getDeployments(client).contains(name);
+    }
+
+    public static List<String> getDeployments(ModelControllerClient client) {
+
+        DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder();
+        final ModelNode request;
+        try {
+            builder.operationName("read-children-names");
+            builder.addProperty("child-type", "deployment");
+            request = builder.buildRequest();
+        } catch (OperationFormatException e) {
+            throw new IllegalStateException("Failed to build operation", e);
+        }
+
+        try {
+            ModelNode outcome = client.execute(request);
+            if (isSuccess(outcome)) {
+                return getList(outcome);
+            }
+        } catch (Exception e) {
+        }
+
+        return Collections.emptyList();
+    }
+
+    public static List<String> getJmsResources(ModelControllerClient client, String type) {
+
+        DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder();
+        final ModelNode request;
+        try {
+            builder.addNode("subsystem", "jms");
+            builder.operationName("read-children-names");
+            builder.addProperty("child-type", type);
+            request = builder.buildRequest();
+        } catch (OperationFormatException e) {
+            throw new IllegalStateException("Failed to build operation", e);
+        }
+
+        try {
+            ModelNode outcome = client.execute(request);
+            if (isSuccess(outcome)) {
+                return getList(outcome);
+            }
+        } catch (Exception e) {
+        }
+
+        return Collections.emptyList();
+    }
+
+    public static boolean isTopic(ModelControllerClient client, String name) {
+        List<String> topics = getJmsResources(client, "topic");
+        return topics.contains(name);
+    }
+
+    public static boolean isQueue(ModelControllerClient client, String name) {
+        List<String> queues = getJmsResources(client, "queue");
+        return queues.contains(name);
+    }
+
+    public static boolean isConnectionFactory(ModelControllerClient client, String name) {
+        List<String> cf = getJmsResources(client, "connection-factory");
+        return cf.contains(name);
+    }
+}

Added: trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/TypedDeployer.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/TypedDeployer.java	                        (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/deployment/TypedDeployer.java	2011-04-15 20:39:54 UTC (rev 30608)
@@ -0,0 +1,202 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ide.eclipse.as.management.as7.deployment;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.UnknownHostException;
+import java.text.MessageFormat;
+import java.util.concurrent.Future;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.jboss.as.controller.client.ModelControllerClient;
+import org.jboss.as.controller.client.helpers.standalone.DeploymentAction;
+import org.jboss.as.controller.client.helpers.standalone.DeploymentPlanBuilder;
+import org.jboss.as.controller.client.helpers.standalone.ServerDeploymentActionResult;
+import org.jboss.as.controller.client.helpers.standalone.ServerDeploymentManager;
+import org.jboss.as.controller.client.helpers.standalone.ServerDeploymentPlanResult;
+import org.jboss.as.protocol.StreamUtils;
+import org.jboss.ide.eclipse.as.management.as7.Activator;
+
+/**
+ * 
+ * @author André Dietisheim
+ */
+public class TypedDeployer {
+
+	private ModelControllerClient client;
+	private ServerDeploymentManager manager;
+
+	public TypedDeployer(String host, int port) throws UnknownHostException {
+		this.client = ModelControllerClient.Factory.create(host, port);
+		this.manager = ServerDeploymentManager.Factory.create(client);
+	}
+
+	public DeploymentResult undeploySync(String name, IProgressMonitor monitor) throws DeployerException {
+		DeploymentResult result = undeploy(name);
+		result.getStatus();
+		return result;
+	}
+
+	public DeploymentResult deploySync(String name, File file, IProgressMonitor monitor) throws DeployerException {
+		DeploymentResult result = deploy(name, file);
+		result.getStatus();
+		return result;
+	}
+
+	public DeploymentResult undeploy(String name) throws DeployerException {
+		try {
+			DeploymentPlanBuilder builder = manager.newDeploymentPlan();
+			builder = builder.undeploy(name).andRemoveUndeployed();
+			return new DeploymentResult(builder.getLastAction(), manager.execute(builder.build()));
+		} catch (Exception e) {
+			throw new DeployerException(e);
+		}
+	}
+
+	public DeploymentResult deploy(File file) throws DeployerException {
+		return deploy(file.getName(), file);
+	}
+
+	public DeploymentResult deploy(String name, File file) throws DeployerException {
+		try {
+			return execute(manager.newDeploymentPlan().add(name, file).andDeploy());
+		} catch (IOException e) {
+			throw new DeployerException(e);
+		}
+	}
+
+	public DeploymentResult replace(File file) throws DeployerException {
+		return replace(file.getName(), file);
+	}
+
+	public DeploymentResult replace(String name, File file) throws DeployerException {
+		try {
+			return execute(manager.newDeploymentPlan().replace(name, file));
+		} catch (IOException e) {
+			throw new DeployerException(e);
+		}
+	}
+
+	private DeploymentResult execute(DeploymentPlanBuilder builder) throws DeployerException {
+		try {
+			DeploymentAction action = builder.getLastAction();
+			Future<ServerDeploymentPlanResult> planResult = manager.execute(builder.build());
+			return new DeploymentResult(action, planResult);
+		} catch (Exception e) {
+			throw new DeployerException(e);
+		}
+	}
+
+	//
+	// public static boolean isDeployed(String name, String host, int port)
+	// throws CancellationException, IOException {
+	// ModelControllerClient client = ModelControllerClient.Factory.create(host,
+	// port);
+	// try {
+	// return Util.isDeployed(name, client);
+	// } finally {
+	// StreamUtils.safeClose(client);
+	// }
+	// }
+	//
+	// public static List<String> getDeployments(String host, int port) throws
+	// UnknownHostException {
+	// ModelControllerClient client = ModelControllerClient.Factory.create(host,
+	// port);
+	// return Util.getDeployments(client);
+	// }
+	//
+	// private static void throwOnFailure(ModelNode result) throws
+	// DeployerException {
+	// if (!Util.isSuccess(result)) {
+	// throw new DeployerException(Util.getFailureDescription(result));
+	// }
+	// }
+
+	public void dispose() {
+		StreamUtils.safeClose(client);
+	}
+
+	public static class DeploymentResult {
+
+		private Future<ServerDeploymentPlanResult> planResult;
+		private DeploymentAction action;
+
+		public DeploymentResult(DeploymentAction action, Future<ServerDeploymentPlanResult> planResult) {
+			Assert.isNotNull(action);
+			this.action = action;
+			Assert.isNotNull(planResult);
+			this.planResult = planResult;
+		}
+
+		public IStatus getStatus() throws DeployerException {
+			try {
+				ServerDeploymentActionResult actionResult = planResult.get().getDeploymentActionResult(action.getId());
+				return createStatus(action.getDeploymentUnitUniqueName(), action.getType().name(), actionResult);
+			} catch (Exception e) {
+				throw new DeployerException(e);
+			}
+		}
+
+		private IStatus createStatus(String deploymentName, String actionName, ServerDeploymentActionResult actionResult) {
+			if (actionResult == null) {
+				return null;
+			}
+
+			IStatus status = null;
+			switch (actionResult.getResult()) {
+			case NOT_EXECUTED:
+				status = createStatus(IStatus.ERROR, "The operation {0} was not executed on unit {1}",
+						actionName, deploymentName);
+				break;
+			case EXECUTED:
+				status = Status.OK_STATUS;
+				break;
+			case FAILED:
+				status = createStatus(IStatus.ERROR, "The operation {0} failed for unit {1}",
+						actionName, deploymentName);
+				break;
+			case ROLLED_BACK:
+				status = createStatus(IStatus.ERROR, "The operation {0} for unit {1} was rolled back",
+						actionName, deploymentName);
+				break;
+			case CONFIGURATION_MODIFIED_REQUIRES_RESTART:
+				status = createStatus(
+						IStatus.WARNING,
+						"The operation {0} was not executed on unit {1}. The server configuration was changed though and the server needs to be restarted",
+						actionName, deploymentName);
+				break;
+			}
+			return status;
+		}
+
+		private IStatus createStatus(int severity, String messagePattern, Object... messageArguments) {
+			return new Status(severity, Activator.getContext().getBundle().getSymbolicName(), MessageFormat.format(
+					messagePattern, messageArguments));
+		}
+	}
+
+}

Added: trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/internal/CommandFormatException.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/internal/CommandFormatException.java	                        (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/internal/CommandFormatException.java	2011-04-15 20:39:54 UTC (rev 30608)
@@ -0,0 +1,53 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ide.eclipse.as.management.as7.internal;
+
+/**
+ * @author Alexey Loubyansky
+ *
+ */
+public class CommandFormatException extends CommandLineException {
+
+    private static final long serialVersionUID = -5802389813870206943L;
+
+    /**
+     * @param message
+     * @param cause
+     */
+    public CommandFormatException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    /**
+     * @param message
+     */
+    public CommandFormatException(String message) {
+        super(message);
+    }
+
+    /**
+     * @param cause
+     */
+    public CommandFormatException(Throwable cause) {
+        super(cause);
+    }
+}

Added: trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/internal/CommandLineException.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/internal/CommandLineException.java	                        (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/internal/CommandLineException.java	2011-04-15 20:39:54 UTC (rev 30608)
@@ -0,0 +1,43 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ide.eclipse.as.management.as7.internal;
+
+/**
+ * @author Alexey Loubyansky
+ *
+ */
+public class CommandLineException extends Exception {
+
+    private static final long serialVersionUID = 423938082439473323L;
+
+    public CommandLineException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public CommandLineException(String message) {
+        super(message);
+    }
+
+    public CommandLineException(Throwable cause) {
+        super(cause);
+    }
+}

Added: trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/internal/DefaultOperationRequestAddress.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/internal/DefaultOperationRequestAddress.java	                        (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/internal/DefaultOperationRequestAddress.java	2011-04-15 20:39:54 UTC (rev 30608)
@@ -0,0 +1,258 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ide.eclipse.as.management.as7.internal;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * This implementation is not thread-safe.
+ *
+ * @author Alexey Loubyansky
+ */
+public class DefaultOperationRequestAddress implements OperationRequestAddress {
+
+    private final List<NodeImpl> nodes = new ArrayList<NodeImpl>();
+
+    public DefaultOperationRequestAddress() {
+    }
+
+    /**
+     * Creates a prefix and initializes it to the value of the argument.
+     * @param initial  the initial value
+     */
+    public DefaultOperationRequestAddress(OperationRequestAddress initial) {
+        if(!initial.isEmpty()) {
+            for(Node node : initial) {
+                toNode(node.getType(), node.getName());
+            }
+        }
+    }
+
+    @Override
+    public void toNodeType(String nodeType) {
+
+        nodes.add(new NodeImpl(nodeType, null));
+    }
+
+    @Override
+    public void toNode(String nodeName) {
+
+        if(nodes.isEmpty())
+            throw new IllegalStateException("The prefix should end with the node type before going to a specific node name.");
+
+        nodes.get(nodes.size() - 1).name = nodeName;
+    }
+
+    @Override
+    public void toNode(String nodeType, String nodeName) {
+
+        if(endsOnType()) {
+            throw new IllegalStateException("The prefix ends on a type. A node name must be specified before this method can be invoked.");
+        }
+        nodes.add(new NodeImpl(nodeType, nodeName));
+    }
+
+    @Override
+    public String toNodeType() {
+
+        if(nodes.isEmpty()) {
+            return null;
+        }
+        String name = nodes.get(nodes.size() - 1).name;
+        nodes.get(nodes.size() - 1).name = null;
+        return name;
+    }
+
+    @Override
+    public Node toParentNode() {
+
+        if(nodes.isEmpty()) {
+            return null;
+        }
+        return nodes.remove(nodes.size() - 1);
+    }
+
+    @Override
+    public void reset() {
+        nodes.clear();
+    }
+
+    @Override
+    public boolean endsOnType() {
+        if(nodes.isEmpty()) {
+            return false;
+        }
+
+        NodeImpl node = nodes.get(nodes.size() - 1);
+        return node.name == null;
+    }
+
+    @Override
+    public boolean isEmpty() {
+        return nodes.isEmpty();
+    }
+
+    @Override
+    public Iterator<Node> iterator() {
+
+        final Node[] array = nodes.toArray(new Node[nodes.size()]);
+        return new Iterator<Node>() {
+
+            int i = 0;
+
+            @Override
+            public boolean hasNext() {
+                return i < array.length;
+            }
+
+            @Override
+            public Node next() {
+                return array[i++];
+            }
+
+            @Override
+            public void remove() {
+                throw new UnsupportedOperationException();
+            }
+
+        };
+    }
+
+    @Override
+    public String getNodeType() {
+
+        if(nodes.isEmpty()) {
+            return null;
+        }
+        return nodes.get(nodes.size() - 1).type;
+    }
+
+    @Override
+    public String getNodeName() {
+
+        if(nodes.isEmpty()) {
+            return null;
+        }
+        return nodes.get(nodes.size() - 1).name;
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((nodes == null) ? 0 : nodes.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (!(obj instanceof OperationRequestAddress))
+            return false;
+
+        OperationRequestAddress other = (OperationRequestAddress) obj;
+
+        if(isEmpty() != other.isEmpty())
+            return false;
+
+        Iterator<Node> thisIterator = iterator();
+        Iterator<Node> otherIterator = other.iterator();
+        boolean result = true;
+        while(result) {
+            if(!thisIterator.next().equals(otherIterator.next())) {
+                result = false;
+            } else {
+                if (!thisIterator.hasNext()) {
+                    if (otherIterator.hasNext()) {
+                        result = false;
+                    }
+                    break;
+                }
+                if (!otherIterator.hasNext()) {
+                    if (thisIterator.hasNext()) {
+                        result = false;
+                    }
+                    break;
+                }
+            }
+        }
+        return result;
+    }
+
+    private static final class NodeImpl implements Node {
+
+        String type;
+        String name;
+
+        NodeImpl(String type, String name) {
+            this.type = type;
+            this.name = name;
+        }
+
+        @Override
+        public String getType() {
+            return type;
+        }
+        @Override
+        public String getName() {
+            return name;
+        }
+
+        @Override
+        public int hashCode() {
+            final int prime = 31;
+            int result = 1;
+            result = prime * result + ((name == null) ? 0 : name.hashCode());
+            result = prime * result + ((type == null) ? 0 : type.hashCode());
+            return result;
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            if (this == obj)
+                return true;
+            if (obj == null)
+                return false;
+
+            if(!(obj instanceof Node))
+                return false;
+
+            Node other = (Node) obj;
+            if (name == null) {
+                if (other.getName() != null)
+                    return false;
+            } else if (!name.equals(other.getName()))
+                return false;
+            if (type == null) {
+                if (other.getType() != null)
+                    return false;
+            } else if (!type.equals(other.getType()))
+                return false;
+            return true;
+        }
+    }
+}

Added: trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/internal/DefaultOperationRequestBuilder.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/internal/DefaultOperationRequestBuilder.java	                        (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/internal/DefaultOperationRequestBuilder.java	2011-04-15 20:39:54 UTC (rev 30608)
@@ -0,0 +1,234 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ide.eclipse.as.management.as7.internal;
+
+import java.io.IOException;
+import java.util.Iterator;
+
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.UnsupportedCallbackException;
+
+import org.jboss.dmr.ModelNode;
+import org.jboss.ide.eclipse.as.management.as7.internal.OperationRequestAddress.Node;
+
+/**
+ *
+ * @author Alexey Loubyansky
+ */
+public class DefaultOperationRequestBuilder  extends ValidatingOperationCallbackHandler implements OperationRequestBuilder {
+
+    private ModelNode request = new ModelNode();
+    private OperationRequestAddress prefix;
+
+    public DefaultOperationRequestBuilder() {
+        this.prefix = new DefaultOperationRequestAddress();
+    }
+
+    public DefaultOperationRequestBuilder(OperationRequestAddress prefix) {
+        if(prefix == null) {
+            throw new IllegalArgumentException("Prefix can't be null");
+        }
+        this.prefix = new DefaultOperationRequestAddress(prefix);
+    }
+
+    /* (non-Javadoc)
+     * @see org.jboss.as.cli.operation.OperationParser.CallbackHandler#rootNode()
+     */
+    public void rootNode() {
+        prefix.reset();
+    }
+
+    /* (non-Javadoc)
+     * @see org.jboss.as.cli.operation.OperationParser.CallbackHandler#parentNode()
+     */
+    public void parentNode() {
+        prefix.toParentNode();
+    }
+
+    /* (non-Javadoc)
+     * @see org.jboss.as.cli.operation.OperationParser.CallbackHandler#nodeType()
+     */
+    public void nodeType() {
+        prefix.toNodeType();
+    }
+
+    /* (non-Javadoc)
+     * @see org.jboss.as.cli.operation.OperationParser.CallbackHandler#nodeTypeNameSeparator(int)
+     */
+    public void nodeTypeNameSeparator(int index) {
+    }
+
+    /* (non-Javadoc)
+     * @see org.jboss.as.cli.operation.OperationParser.CallbackHandler#nodeSeparator(int)
+     */
+    public void nodeSeparator(int index) {
+    }
+
+    /* (non-Javadoc)
+     * @see org.jboss.as.cli.operation.OperationParser.CallbackHandler#addressOperationSeparator(int)
+     */
+    public void addressOperationSeparator(int index) {
+    }
+
+    /* (non-Javadoc)
+     * @see org.jboss.as.cli.operation.OperationParser.CallbackHandler#operationName(java.lang.String)
+     */
+    @Override
+    public void validatedOperationName(String operationName) {
+        this.setOperationName(operationName);
+    }
+
+    /* (non-Javadoc)
+     * @see org.jboss.as.cli.operation.OperationParser.CallbackHandler#propertyListStart(int)
+     */
+    public void propertyListStart(int index) {
+    }
+
+    /* (non-Javadoc)
+     * @see org.jboss.as.cli.operation.OperationParser.CallbackHandler#propertyNameValueSeparator(int)
+     */
+    public void propertyNameValueSeparator(int index) {
+    }
+
+    /* (non-Javadoc)
+     * @see org.jboss.as.cli.operation.OperationParser.CallbackHandler#propertySeparator(int)
+     */
+    public void propertySeparator(int index) {
+    }
+
+    /* (non-Javadoc)
+     * @see org.jboss.as.cli.operation.OperationParser.CallbackHandler#propertyListEnd(int)
+     */
+    public void propertyListEnd(int index) {
+    }
+
+    @Override
+    protected void validatedNodeType(String nodeType)
+            throws OperationFormatException {
+        this.addNodeType(nodeType);
+    }
+
+    @Override
+    protected void validatedNodeName(String nodeName)
+            throws OperationFormatException {
+        this.addNodeName(nodeName);
+    }
+
+    @Override
+    protected void validatedPropertyName(String propertyName)
+            throws OperationFormatException {
+        throw new OperationFormatException("Property '" + propertyName + "' is missing the value.");
+    }
+
+    @Override
+    protected void validatedProperty(String name, String value,
+            int nameValueSeparatorIndex) throws OperationFormatException {
+        this.addProperty(name, value);
+    }
+
+    public void nodeTypeOrName(String typeOrName)
+            throws OperationFormatException {
+
+        if(prefix.endsOnType()) {
+            this.addNodeName(typeOrName);
+        } else {
+            this.addNodeType(typeOrName);
+        }
+    }
+
+    /**
+     * Makes sure that the operation name and the address have been set and returns a ModelNode
+     * representing the operation request.
+     */
+    public ModelNode buildRequest() throws OperationFormatException {
+
+        ModelNode address = request.get("address");
+        if(prefix.isEmpty()) {
+            address.setEmptyList();
+        } else {
+            Iterator<Node> iterator = prefix.iterator();
+            while (iterator.hasNext()) {
+                OperationRequestAddress.Node node = iterator.next();
+                if (node.getName() != null) {
+                    address.add(node.getType(), node.getName());
+                } else if (iterator.hasNext()) {
+                    throw new OperationFormatException(
+                            "The node name is not specified for type '"
+                                    + node.getType() + "'");
+                }
+            }
+        }
+
+        if(!request.hasDefined("operation")) {
+            throw new OperationFormatException("The operation name is missing or the format of the operation request is wrong.");
+        }
+
+        return request;
+    }
+
+    @Override
+    public void setOperationName(String name) {
+        request.get("operation").set(name);
+    }
+
+    @Override
+    public void addNode(String type, String name) {
+        prefix.toNode(type, name);
+    }
+
+    @Override
+    public void addNodeType(String type) {
+        prefix.toNodeType(type);
+    }
+
+    @Override
+    public void addNodeName(String name) {
+        prefix.toNode(name);
+    }
+
+    @Override
+    public void addProperty(String name, String value) {
+
+        if(name == null || name.trim().isEmpty())
+            throw new IllegalArgumentException("The argument name is not specified: '" + name + "'");
+        if(value == null || value.trim().isEmpty())
+            throw new IllegalArgumentException("The argument value is not specified: '" + value + "'");
+        ModelNode toSet = null;
+        try {
+            toSet = ModelNode.fromString(value);
+        } catch (Exception e) {
+            // just use the string
+            toSet = new ModelNode().set(value);
+        }
+        request.get(name).set(toSet);
+    }
+
+    public ModelNode getModelNode() {
+        return request;
+    }
+
+	public void handle(Callback[] callbacks) throws IOException,
+			UnsupportedCallbackException {
+		// TODO Auto-generated method stub
+		
+	}
+}

Added: trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/internal/OperationFormatException.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/internal/OperationFormatException.java	                        (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/internal/OperationFormatException.java	2011-04-15 20:39:54 UTC (rev 30608)
@@ -0,0 +1,61 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ide.eclipse.as.management.as7.internal;
+
+
+/**
+ *
+ * @author Alexey Loubyansky
+ */
+public class OperationFormatException extends CommandFormatException {
+
+    /**
+     *
+     */
+    private static final long serialVersionUID = -3481664048439674648L;
+
+    /**
+     * @param message
+     * @param cause
+     */
+    public OperationFormatException(String message, Throwable cause) {
+        super(message, cause);
+        // TODO Auto-generated constructor stub
+    }
+
+    /**
+     * @param message
+     */
+    public OperationFormatException(String message) {
+        super(message);
+        // TODO Auto-generated constructor stub
+    }
+
+    /**
+     * @param cause
+     */
+    public OperationFormatException(Throwable cause) {
+        super(cause);
+        // TODO Auto-generated constructor stub
+    }
+
+}

Added: trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/internal/OperationRequestAddress.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/internal/OperationRequestAddress.java	                        (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/internal/OperationRequestAddress.java	2011-04-15 20:39:54 UTC (rev 30608)
@@ -0,0 +1,110 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ide.eclipse.as.management.as7.internal;
+
+
+
+/**
+ * An instance of this interface represents a prefix for the operation request address part.
+ *
+ * @author Alexey Loubyansky
+ */
+public interface OperationRequestAddress extends Iterable<OperationRequestAddress.Node> {
+
+    /**
+     * Appends the node type to the prefix.
+     * Note, the current prefix must end on the node name before this method
+     * is invoked.
+     *
+     * @param nodeType  the node type to append to the prefix.
+     */
+    void toNodeType(String nodeType);
+
+    /**
+     * Appends the node name to the prefix.
+     * Note, the current prefix must end on the node type before this method
+     * is invoked.
+     *
+     * @param nodeName the node name to append to the prefix.
+     */
+    void toNode(String nodeName);
+
+    /**
+     * Appends the node to the prefix.
+     * Note, the current prefix must end on the node (i.e. node name) before
+     * this method is invoked.
+     *
+     * @param nodeType  the node type of the node to append to the prefix
+     * @param nodeName  the node name of the node to append to the prefix
+     */
+    void toNode(String nodeType, String nodeName);
+
+    /**
+     * Sets the current prefix to the node type of the current node,
+     * i.e. the node name is removed from the end of the prefix.
+     * @return the node name the prefix ended on
+     */
+    String toNodeType();
+
+    /**
+     * Removes the last node in the prefix, i.e. moves the value a node up.
+     * @return the node the prefix ended on
+     */
+    Node toParentNode();
+
+    /**
+     * Resets the prefix, i.e. this will make the prefix empty.
+     */
+    void reset();
+
+    /**
+     * Checks whether the prefix ends on a node type or a node name.
+     * @return  true if the prefix ends on a node type, otherwise false.
+     */
+    boolean endsOnType();
+
+    /**
+     * Checks whether the prefix is empty.
+     * @return  true if the prefix is empty, otherwise false.
+     */
+    boolean isEmpty();
+
+    /**
+     * Returns the node type of the last node.
+     * @return the node type of the last node or null if the prefix is empty.
+     */
+    String getNodeType();
+
+    /**
+     * Returns the node name of the last node.
+     * @return  the node name of the last node or null if the prefix ends
+     * on a type or is empty.
+     */
+    String getNodeName();
+
+    interface Node {
+
+        String getType();
+
+        String getName();
+    }
+}

Added: trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/internal/OperationRequestBuilder.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/internal/OperationRequestBuilder.java	                        (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/internal/OperationRequestBuilder.java	2011-04-15 20:39:54 UTC (rev 30608)
@@ -0,0 +1,77 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ide.eclipse.as.management.as7.internal;
+
+import org.jboss.dmr.ModelNode;
+
+/**
+ * TODO this is not used for now...
+ *
+ * @author Alexey Loubyansky
+ */
+public interface OperationRequestBuilder {
+
+    /**
+     * Sets the name operation to be invoked.
+     *
+     * @param name the name of the operation to invoke.
+     */
+    void setOperationName(String name);
+
+    /**
+     * The address is specified as a path to the target node. Each element of the path is a node
+     * and is identified by its type and name.
+     *
+     * @param type the type of the node
+     * @param name the name of the node
+     */
+    void addNode(String type, String name);
+
+    /**
+     * This method is supposed to be invoked from applying the prefix with ends on a node type.
+     * @param type  the type of the node.
+     */
+    void addNodeType(String type);
+
+    /**
+     * This method assumes there is a non-empty prefix which ends on a node type.
+     * Otherwise, this method will result in an exception.
+     * @param name the name of the node for the type specified by the prefix.
+     */
+    void addNodeName(String name);
+
+    /**
+     * Adds an argument.
+     *
+     * @param name the name of the argument
+     * @param value the value of the argument
+     */
+    void addProperty(String name, String value);
+
+    /**
+     * Builds the operation request based on the collected operation name, address and arguments.
+     *
+     * @return an instance of ModelNode representing the operation request
+     * @throws OperationFormatException
+     */
+    ModelNode buildRequest() throws OperationFormatException;
+}

Added: trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/internal/ValidatingOperationCallbackHandler.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/internal/ValidatingOperationCallbackHandler.java	                        (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/management/as7/internal/ValidatingOperationCallbackHandler.java	2011-04-15 20:39:54 UTC (rev 30608)
@@ -0,0 +1,131 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ide.eclipse.as.management.as7.internal;
+
+import java.util.regex.Pattern;
+
+import javax.security.auth.callback.CallbackHandler;
+
+/**
+ *
+ * @author Alexey Loubyansky
+ */
+public abstract class ValidatingOperationCallbackHandler implements CallbackHandler {
+
+    private static final Pattern ALPHANUMERICS_PATTERN = Pattern.compile("[_a-zA-Z](?:[-_a-zA-Z0-9]*[_a-zA-Z0-9])?");
+    private static final Pattern NODE_NAME_PATTERN = Pattern.compile("\\*|[^*\\p{Space}\\p{Cntrl}]+");
+
+
+    protected String operationStr;
+
+    public void start(String operationString) {
+        this.operationStr = operationString;
+    }
+
+    /* (non-Javadoc)
+     * @see org.jboss.as.cli.operation.OperationParser.CallbackHandler#nodeType(java.lang.String)
+     */
+    public void nodeType(String nodeType) throws OperationFormatException {
+
+        assertValidType(nodeType);
+        validatedNodeType(nodeType);
+    }
+
+    protected abstract void validatedNodeType(String nodeType) throws OperationFormatException;
+
+    /* (non-Javadoc)
+     * @see org.jboss.as.cli.operation.OperationParser.CallbackHandler#nodeName(java.lang.String)
+     */
+    public void nodeName(String nodeName) throws OperationFormatException {
+
+        assertValidNodeName(nodeName);
+        validatedNodeName(nodeName);
+    }
+
+    protected abstract void validatedNodeName(String nodeName) throws OperationFormatException;
+
+    /* (non-Javadoc)
+     * @see org.jboss.as.cli.operation.OperationParser.CallbackHandler#operationName(java.lang.String)
+     */
+    public void operationName(String operationName)
+            throws OperationFormatException {
+
+        if (operationName == null || !ALPHANUMERICS_PATTERN.matcher(operationName).matches()) {
+            throw new OperationFormatException("'" + operationName + "' is not a valid operation name.");
+        }
+
+        validatedOperationName(operationName);
+    }
+
+    protected abstract void validatedOperationName(String operationName) throws OperationFormatException;
+
+    /* (non-Javadoc)
+     * @see org.jboss.as.cli.operation.OperationParser.CallbackHandler#propertyName(java.lang.String)
+     */
+    public void propertyName(String propertyName)
+            throws OperationFormatException {
+
+        assertValidParameterName(propertyName);
+        validatedPropertyName(propertyName);
+    }
+
+    protected abstract void validatedPropertyName(String propertyName) throws OperationFormatException;
+
+    /* (non-Javadoc)
+     * @see org.jboss.as.cli.operation.OperationParser.CallbackHandler#property(java.lang.String, java.lang.String, int)
+     */
+    public void property(String name, String value, int nameValueSeparatorIndex)
+            throws OperationFormatException {
+
+        assertValidParameterName(name);
+
+        if (value.isEmpty()) {
+            throw new OperationFormatException("Parameter '" + value + "' is missing value.");
+        }
+
+        validatedProperty(name, value, nameValueSeparatorIndex);
+    }
+
+    protected abstract void validatedProperty(String name, String value, int nameValueSeparatorIndex) throws OperationFormatException;
+
+    protected void assertValidType(String nodeType)
+            throws OperationFormatException {
+        if (nodeType == null || !ALPHANUMERICS_PATTERN.matcher(nodeType).matches()) {
+            throw new OperationFormatException("'" + nodeType + "' is not a valid node type name.");
+        }
+    }
+
+    protected void assertValidNodeName(String nodeName)
+            throws OperationFormatException {
+        if (nodeName == null || !NODE_NAME_PATTERN.matcher(nodeName).matches()) {
+            throw new OperationFormatException("'" + nodeName + "' is not a valid node name.");
+        }
+    }
+
+    protected void assertValidParameterName(String name)
+            throws OperationFormatException {
+        if (name == null || !ALPHANUMERICS_PATTERN.matcher(name).matches()) {
+            throw new OperationFormatException("'" + name + "' is not a valid parameter name.");
+        }
+    }
+
+}



More information about the jbosstools-commits mailing list