[jboss-cvs] JBossAS SVN: r88961 - projects/integration/branches/5_x/jboss-profileservice-spi/src/main/java/org/jboss/deployers/spi/management.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri May 15 16:57:16 EDT 2009


Author: scott.stark at jboss.org
Date: 2009-05-15 16:57:16 -0400 (Fri, 15 May 2009)
New Revision: 88961

Added:
   projects/integration/branches/5_x/jboss-profileservice-spi/src/main/java/org/jboss/deployers/spi/management/ContextStateMapper.java
Log:
JBAS-6927, add a mapControllerState method

Added: projects/integration/branches/5_x/jboss-profileservice-spi/src/main/java/org/jboss/deployers/spi/management/ContextStateMapper.java
===================================================================
--- projects/integration/branches/5_x/jboss-profileservice-spi/src/main/java/org/jboss/deployers/spi/management/ContextStateMapper.java	                        (rev 0)
+++ projects/integration/branches/5_x/jboss-profileservice-spi/src/main/java/org/jboss/deployers/spi/management/ContextStateMapper.java	2009-05-15 20:57:16 UTC (rev 88961)
@@ -0,0 +1,93 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, 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.deployers.spi.management;
+
+import java.util.Map;
+
+import org.jboss.dependency.spi.ControllerState;
+
+/**
+ * Basic state mapper.
+ * 
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class ContextStateMapper<T extends Enum<?>>
+{
+   
+   /** The state mappings. */
+   private Map<String, T> mappings;
+   
+   /** Installing state. */
+   private T installState;
+   
+   /** Uninstalling state. */
+   private T uninstallState;
+   
+   /** The unknown state. */
+   private T unknown;
+   
+   /** The error state. */
+   private T error;
+
+   public ContextStateMapper(Map<String, T> mappings,
+         T installState, T uninstallState, T error, T unknown)
+   {
+      this.mappings = mappings;
+      this.installState = installState;
+      this.uninstallState = uninstallState;
+      this.error = error;
+      this.unknown = unknown;
+   }
+   
+   public T getErrorState()
+   {
+      return this.error;
+   }
+   
+   public T map(ControllerState currentState, ControllerState toState)
+   {
+      // If the context is in the required state 
+      if(toState == null || currentState.equals(toState))
+         return getMapping(currentState);
+      // The error state
+      if(ControllerState.ERROR.equals(currentState))
+         return error;
+      // installing state
+      if(ControllerState.INSTALLED.equals(toState))
+         return installState;
+      // uninstalling state
+      if(ControllerState.NOT_INSTALLED.equals(toState))
+         return uninstallState;
+      // Fallback
+      return getMapping(currentState);
+   }
+   
+   protected T getMapping(ControllerState controllerState)
+   {
+      T state = unknown;
+      if(controllerState != null)
+       state = mappings.get(controllerState.getStateString());
+      return state;
+   }
+   
+}


Property changes on: projects/integration/branches/5_x/jboss-profileservice-spi/src/main/java/org/jboss/deployers/spi/management/ContextStateMapper.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision




More information about the jboss-cvs-commits mailing list