Author: rob.stryker(a)jboss.com
Date: 2011-04-14 23:25:25 -0400 (Thu, 14 Apr 2011)
New Revision: 30584
Added:
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/DetypedDeployer.java
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/JBossDeploymentManager.java
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/JBossManagementService.java
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/JbossManagementUtil.java
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/operations/
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/operations/CommandFormatException.java
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/operations/CommandLineException.java
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/operations/DefaultOperationRequestAddress.java
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/operations/DefaultOperationRequestBuilder.java
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/operations/OperationFormatException.java
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/operations/OperationRequestAddress.java
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/operations/OperationRequestBuilder.java
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/operations/ValidatingOperationCallbackHandler.java
Modified:
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/.classpath
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/TypedDeployer.java
Log:
settling on API / still evolving
Modified: workspace/adietish/org.jboss.ide.eclipse.as7.deployment/.classpath
===================================================================
--- workspace/adietish/org.jboss.ide.eclipse.as7.deployment/.classpath 2011-04-14 22:31:32
UTC (rev 30583)
+++ workspace/adietish/org.jboss.ide.eclipse.as7.deployment/.classpath 2011-04-15 03:25:25
UTC (rev 30584)
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry exported="true" kind="lib"
path="jboss-threads-2.0.0.CR8.jar"
sourcepath="/home/adietish/jboss-workspaces/jboss-tools/jbosstools-src/jboss-threads-2.0.0.CR8-sources.jar"/>
- <classpathentry exported="true" kind="lib"
path="jboss-as-controller-client-7.0.0.Beta3-SNAPSHOT.jar"
sourcepath="/jboss-as-controller-client"/>
+ <classpathentry exported="true" kind="lib"
path="jboss-as-controller-client-7.0.0.Beta3-SNAPSHOT.jar"
sourcepath="/home/rob/.m2/repository/org/jboss/as/jboss-as-controller-client/7.0.0.Beta3-SNAPSHOT/jboss-as-controller-client-7.0.0.Beta3-SNAPSHOT-sources.jar"/>
<classpathentry exported="true" kind="lib"
path="jboss-as-protocol-7.0.0.Beta3-SNAPSHOT.jar"
sourcepath="/jboss-as-protocol"/>
<classpathentry exported="true" kind="lib"
path="jboss-dmr-1.0.0.Beta5.jar"
sourcepath="/home/adietish/jboss-workspaces/jboss-tools/jbosstools-src/jboss-dmr-1.0.0.Beta5-sources.jar"/>
<classpathentry exported="true" kind="lib"
path="jboss-logging-3.0.0.Beta3.jar"/>
Added:
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/DetypedDeployer.java
===================================================================
---
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/DetypedDeployer.java
(rev 0)
+++
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/DetypedDeployer.java 2011-04-15
03:25:25 UTC (rev 30584)
@@ -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.as7.deployment.internal;
+
+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:
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/JBossDeploymentManager.java
===================================================================
---
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/JBossDeploymentManager.java
(rev 0)
+++
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/JBossDeploymentManager.java 2011-04-15
03:25:25 UTC (rev 30584)
@@ -0,0 +1,35 @@
+package org.jboss.ide.eclipse.as7.deployment.internal;
+
+import java.io.File;
+import java.util.concurrent.Future;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.jboss.ide.eclipse.as7.deployment.IJBossDeploymentManager;
+
+public class JBossDeploymentManager implements IJBossDeploymentManager {
+
+ public Future asyncDeploy(String host, int port, String deploymentName,
+ File file, IProgressMonitor monitor) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Object syncDeploy(String host, int port, String deploymentName,
+ File file, IProgressMonitor monitor) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Future asyncUndeploy(String host, int port, String deploymentName,
+ boolean removeFile, IProgressMonitor monitor) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Object syncUndeploy(String host, int port, String deploymentName,
+ boolean removeFile, IProgressMonitor monitor) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Added:
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/JBossManagementService.java
===================================================================
---
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/JBossManagementService.java
(rev 0)
+++
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/JBossManagementService.java 2011-04-15
03:25:25 UTC (rev 30584)
@@ -0,0 +1,25 @@
+package org.jboss.ide.eclipse.as7.deployment.internal;
+
+import org.jboss.ide.eclipse.as7.deployment.IJBossDeploymentManager;
+import org.jboss.ide.eclipse.as7.deployment.IJBossManagementInterface;
+import org.jboss.ide.eclipse.as7.deployment.IJBossManagementService;
+
+public class JBossManagementService implements IJBossManagementService {
+
+ private IJBossDeploymentManager deploymentManager = null;
+ private IJBossManagementInterface manager = null;
+
+ @Override
+ public IJBossDeploymentManager getDeploymentManager() {
+ if( deploymentManager == null )
+ deploymentManager = new JBossDeploymentManager();
+ return deploymentManager;
+ }
+
+ @Override
+ public IJBossManagementInterface getManagementInterface() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Added:
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/JbossManagementUtil.java
===================================================================
---
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/JbossManagementUtil.java
(rev 0)
+++
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/JbossManagementUtil.java 2011-04-15
03:25:25 UTC (rev 30584)
@@ -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.as7.deployment.internal;
+
+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.as7.deployment.internal.operations.DefaultOperationRequestBuilder;
+import
org.jboss.ide.eclipse.as7.deployment.internal.operations.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);
+ }
+}
Modified:
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/TypedDeployer.java
===================================================================
---
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/TypedDeployer.java 2011-04-14
22:31:32 UTC (rev 30583)
+++
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/TypedDeployer.java 2011-04-15
03:25:25 UTC (rev 30584)
@@ -22,8 +22,10 @@
package org.jboss.ide.eclipse.as7.deployment.internal;
import java.io.File;
+import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.jboss.as.controller.client.ModelControllerClient;
import org.jboss.as.controller.client.helpers.standalone.DeploymentPlan;
import org.jboss.as.controller.client.helpers.standalone.InitialDeploymentPlanBuilder;
@@ -31,13 +33,35 @@
import org.jboss.as.protocol.StreamUtils;
/**
+ *
* @author André Dietisheim
*/
public class TypedDeployer {
- private static final long TIMEOUT = 15 * 1000;
-
- public static void undeploy(String name, String host, int port) throws DeployerException
{
+ public static void undeploySync(String name, String host, int port, IProgressMonitor
monitor) throws DeployerException {
+ Future f = undeploy(name, host, port);
+ syncWait(f, monitor);
+ }
+
+ public static void syncDeploy(String name, File file, String host, int port,
IProgressMonitor monitor) throws DeployerException {
+ Future f = deploy(name, file, host, port);
+ syncWait(f, monitor);
+ }
+
+ private static void syncWait(Future f, IProgressMonitor monitor) {
+ while(!f.isDone()) {
+ if( monitor.isCanceled()) {
+ f.cancel(true);
+ return;
+ }
+ try {
+ Thread.sleep(150);
+ } catch(InterruptedException ie) {
+ }
+ }
+ }
+
+ public static Future undeploy(String name, String host, int port) throws
DeployerException {
ModelControllerClient client = null;
try {
client = ModelControllerClient.Factory.create(host, port);
@@ -45,7 +69,7 @@
InitialDeploymentPlanBuilder builder = manager.newDeploymentPlan();
DeploymentPlan plan = builder.undeploy(name).andRemoveUndeployed().build();
- manager.execute(plan).get(TIMEOUT, TimeUnit.MILLISECONDS);
+ return manager.execute(plan);
} catch (Exception e) {
throw new DeployerException(e);
} finally {
@@ -53,46 +77,44 @@
}
}
- public static void deploy(File file, String host, int port) throws DeployerException {
- deploy(file.getName(), file, host, port);
+ public static Future deploy(File file, String host, int port) throws DeployerException
{
+ return 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);
- ServerDeploymentManager manager = ServerDeploymentManager.Factory.create(client);
- InitialDeploymentPlanBuilder builder = manager.newDeploymentPlan();
+ public static Future deploy(String name, File file, String host, int port) throws
DeployerException {
+ return internalDeploy(name, file, host, port, false);
+ }
- DeploymentPlan plan = builder.add(name, file).deploy(name).build();
- manager.execute(plan).get(TIMEOUT, TimeUnit.MILLISECONDS);
- } catch (Exception e) {
- throw new DeployerException(e);
- } finally {
- StreamUtils.safeClose(client);
- }
+ public static Future replace(File file, String host, int port) throws DeployerException
{
+ return replace(file.getName(), file, host, port);
}
- public static void replace(File file, String host, int port) throws DeployerException {
- replace(file.getName(), file, host, port);
+ public static Future replace(String name, File file, String host, int port) throws
DeployerException {
+ return internalDeploy(name, file, host, port, true);
}
- public static void replace(String name, File file, String host, int port) throws
DeployerException {
+ public static Future internalDeploy(String name, File file, String host, int port,
boolean replace) throws DeployerException {
ModelControllerClient client = null;
try {
client = ModelControllerClient.Factory.create(host, port);
ServerDeploymentManager manager = ServerDeploymentManager.Factory.create(client);
InitialDeploymentPlanBuilder builder = manager.newDeploymentPlan();
- DeploymentPlan plan = builder.replace(name, file).build();
- manager.execute(plan).get(TIMEOUT, TimeUnit.MILLISECONDS);
+ DeploymentPlan plan = null;
+ if( replace )
+ plan = builder.replace(name, file).build();
+ else
+ plan = builder.add(name, file).deploy(name).build();
+
+ return manager.execute(plan);
} catch (Exception e) {
throw new DeployerException(e);
} finally {
StreamUtils.safeClose(client);
}
}
-
+
+
//
// public static boolean isDeployed(String name, String host, int port)
// throws CancellationException, IOException {
Added:
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/operations/CommandFormatException.java
===================================================================
---
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/operations/CommandFormatException.java
(rev 0)
+++
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/operations/CommandFormatException.java 2011-04-15
03:25:25 UTC (rev 30584)
@@ -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.as7.deployment.internal.operations;
+
+/**
+ * @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:
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/operations/CommandLineException.java
===================================================================
---
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/operations/CommandLineException.java
(rev 0)
+++
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/operations/CommandLineException.java 2011-04-15
03:25:25 UTC (rev 30584)
@@ -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.as7.deployment.internal.operations;
+
+/**
+ * @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:
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/operations/DefaultOperationRequestAddress.java
===================================================================
---
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/operations/DefaultOperationRequestAddress.java
(rev 0)
+++
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/operations/DefaultOperationRequestAddress.java 2011-04-15
03:25:25 UTC (rev 30584)
@@ -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.as7.deployment.internal.operations;
+
+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:
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/operations/DefaultOperationRequestBuilder.java
===================================================================
---
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/operations/DefaultOperationRequestBuilder.java
(rev 0)
+++
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/operations/DefaultOperationRequestBuilder.java 2011-04-15
03:25:25 UTC (rev 30584)
@@ -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.as7.deployment.internal.operations;
+
+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.as7.deployment.internal.operations.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:
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/operations/OperationFormatException.java
===================================================================
---
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/operations/OperationFormatException.java
(rev 0)
+++
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/operations/OperationFormatException.java 2011-04-15
03:25:25 UTC (rev 30584)
@@ -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.as7.deployment.internal.operations;
+
+
+/**
+ *
+ * @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:
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/operations/OperationRequestAddress.java
===================================================================
---
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/operations/OperationRequestAddress.java
(rev 0)
+++
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/operations/OperationRequestAddress.java 2011-04-15
03:25:25 UTC (rev 30584)
@@ -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.as7.deployment.internal.operations;
+
+
+
+/**
+ * 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:
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/operations/OperationRequestBuilder.java
===================================================================
---
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/operations/OperationRequestBuilder.java
(rev 0)
+++
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/operations/OperationRequestBuilder.java 2011-04-15
03:25:25 UTC (rev 30584)
@@ -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.as7.deployment.internal.operations;
+
+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:
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/operations/ValidatingOperationCallbackHandler.java
===================================================================
---
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/operations/ValidatingOperationCallbackHandler.java
(rev 0)
+++
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/internal/operations/ValidatingOperationCallbackHandler.java 2011-04-15
03:25:25 UTC (rev 30584)
@@ -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.as7.deployment.internal.operations;
+
+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.");
+ }
+ }
+
+}