craigmcc    01/08/13 14:17:40

  Added:       workflow/src/java/org/apache/commons/workflow/util
                        MapEntry.java ScopeSupport.java WorkflowUtils.java
  Log:
  Initial checkin of the workflow management system proposal.
  
  Revision  Changes    Path
  1.1                  
jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/util/MapEntry.java
  
  Index: MapEntry.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/util/MapEntry.java,v
 1.1 2001/08/13 21:17:40 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2001/08/13 21:17:40 $
   *
   * ====================================================================
   * 
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */ 
  
  package org.apache.commons.workflow.util;
  
  
  import java.util.Map;
  
  
  /**
   * General purpose implementation of the <strong>Map.Entry</strong>
   * interface for use in returning results from <code>entrySet()</code>
   * methods on <code>Map</code> implementations.
   *
   * @revision $Revision: 1.1 $ $Date: 2001/08/13 21:17:40 $
   * @author Craig R. McClanahan
   */
  
  public class MapEntry implements Map.Entry {
  
  
      // ----------------------------------------------------------- Constructors
  
  
      /**
       * Construct a new MapEntry based on the specified parameters.
       *
       * @param key Key for this entry
       * @param value Value for this entry
       */
      public MapEntry(Object key, Object value) {
  
          super();
          setKey(key);
          setValue(value);
  
      }
  
  
  
      // ------------------------------------------------------------- Properties
  
  
      /**
       * The key for this entry.
       */
      protected Object key = null;
  
      public Object getKey() {
          return (this.key);
      }
  
      public void setKey(Object key) {
          this.key = key;
      }
  
  
      /**
       * The value for for this entry.
       */
      protected Object value = null;
  
      public Object getValue() {
          return (this.value);
      }
  
      public Object setValue(Object value) {
          Object old = this.value;
          this.value = value;
          return (old);
      }
  
  
  }
  
  
  
  1.1                  
jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/util/ScopeSupport.java
  
  Index: ScopeSupport.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/util/ScopeSupport.java,v
 1.1 2001/08/13 21:17:40 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2001/08/13 21:17:40 $
   *
   * ====================================================================
   * 
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */ 
  
  package org.apache.commons.workflow.util;
  
  
  import java.util.Map;
  import org.apache.commons.workflow.Scope;
  import org.apache.commons.workflow.ScopeEvent;
  import org.apache.commons.workflow.ScopeListener;
  
  
  /**
   * <strong>ScopeSupport</strong> is a convenience class for managing the
   * firing of <code>ScopeEvents</code> to registered
   * <code>ScopeListeners</code>.
   *
   * @revision $Revision: 1.1 $ $Date: 2001/08/13 21:17:40 $
   * @author Craig R. McClanahan
   */
  
  public class ScopeSupport {
  
  
      // ----------------------------------------------------------- Constructors
  
  
      /**
       * Construct a new ScopeSupport object associated with the specified Scope.
       *
       * @param scope Scope for whom we will fire events
       */
      public ScopeSupport(Scope scope) {
  
          super();
          this.scope = scope;
  
      }
  
  
      // ----------------------------------------------------- Instance Variables
  
  
      /**
       * The set of registered <code>ScopeListener</code> event listeners.
       */
      protected ScopeListener listeners[] = new ScopeListener[0];
  
  
      /**
       * The <code>Scope</code> for whom we will fire events.
       */
      protected Scope scope = null;
  
  
      // ------------------------------------------------- Event Listener Methods
  
  
      /**
       * Add a listener that is notified each time beans are added,
       * replaced, or removed in this scope.
       *
       * @param listener The ScopeListener to be added
       */
      public void addScopeListener(ScopeListener listener) {
  
        synchronized (listeners) {
            ScopeListener results[] =
              new ScopeListener[listeners.length + 1];
            System.arraycopy(listeners, 0, results, 0, listeners.length);
            results[listeners.length] = listener;
            listeners = results;
        }
  
      }
  
  
      /**
       * Remove a listener that is notified each time beans are added,
       * replaced, or removed in this scope.
       *
       * @param listener The ScopeListener to be removed
       */
      public void removeScopeListener(ScopeListener listener) {
  
          synchronized (listeners) {
              int n = -1;
              for (int i = 0; i < listeners.length; i++) {
                  if (listeners[i] == listener) {
                      n = i;
                      break;
                  }
              }
              if (n < 0)
                  return;
              ScopeListener results[] =
                new ScopeListener[listeners.length - 1];
              int j = 0;
              for (int i = 0; i < listeners.length; i++) {
                  if (i != n)
                      results[j++] = listeners[i];
              }
              listeners = results;
          }
  
      }
  
  
      // --------------------------------------------------- Event Firing Methods
  
  
      /**
       * Fire a <code>beanAdded()</code> event to all registered listeners.
       *
       * @param key Key of the bean that was added
       * @param value Value of the bean that was added
       */
      public void fireBeanAdded(String key, Object value) {
  
          if (listeners.length == 0)
              return;
          ScopeEvent event = new ScopeEvent(scope, key, value);
          ScopeListener interested[] = null;
          synchronized (listeners) {
              interested = (ScopeListener[]) listeners.clone();
          }
          for (int i = 0; i < interested.length; i++)
              interested[i].beanAdded(event);
  
      }
  
  
      /**
       * Fire a <code>beanRemoved()</code> event to all registered listeners.
       *
       * @param key Key of the bean that was removed
       * @param value Value of the bean that was removed
       */
      public void fireBeanRemoved(String key, Object value) {
  
          if (listeners.length == 0)
              return;
          ScopeEvent event = new ScopeEvent(scope, key, value);
          ScopeListener interested[] = null;
          synchronized (listeners) {
              interested = (ScopeListener[]) listeners.clone();
          }
          for (int i = 0; i < interested.length; i++)
              interested[i].beanRemoved(event);
  
      }
  
  
      /**
       * Fire a <code>beanReplaced()</code> event to all registered listeners.
       *
       * @param key Key of the bean that was replaced
       * @param value Old value of the bean that was replaced
       */
      public void fireBeanReplaced(String key, Object value) {
  
          if (listeners.length == 0)
              return;
          ScopeEvent event = new ScopeEvent(scope, key, value);
          ScopeListener interested[] = null;
          synchronized (listeners) {
              interested = (ScopeListener[]) listeners.clone();
          }
          for (int i = 0; i < interested.length; i++)
              interested[i].beanReplaced(event);
  
      }
  
  
      /**
       * Fire a <code>scopeCleared()</code> event to all registered listeners.
       */
      public void fireScopeCleared() {
  
          if (listeners.length == 0)
              return;
          ScopeEvent event = new ScopeEvent(scope, null, null);
          ScopeListener interested[] = null;
          synchronized (listeners) {
              interested = (ScopeListener[]) listeners.clone();
          }
          for (int i = 0; i < interested.length; i++)
              interested[i].scopeCleared(event);
  
      }
  
  
  }
  
  
  
  1.1                  
jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/util/WorkflowUtils.java
  
  Index: WorkflowUtils.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/util/WorkflowUtils.java,v
 1.1 2001/08/13 21:17:40 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2001/08/13 21:17:40 $
   *
   * ====================================================================
   * 
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */ 
  
  package org.apache.commons.workflow.util;
  
  
  /**
   * General purpose static utility methods for the Workflow engine.
   *
   * @version $Revision: 1.1 $ $Date: 2001/08/13 21:17:40 $
   * @author Craig R. McClanahan
   */
  
  public class WorkflowUtils {
  
  
      /**
       * Parse the character encoding from the specified content type header.
       * If the content type is null, or there is no explicit character encoding,
       * <code>null</code> is returned.
       *
       * @param contentType a content type header
       */
      public static String parseCharacterEncoding(String contentType) {
  
          if (contentType == null)
              return (null);
          int start = contentType.indexOf("charset=");
          if (start < 0)
              return (null);
          String encoding = contentType.substring(start + 8);
          int end = encoding.indexOf(';');
          if (end >= 0)
              encoding = encoding.substring(0, end);
          encoding = encoding.trim();
          if ((encoding.length() > 2) && (encoding.startsWith("\""))
              && (encoding.endsWith("\"")))
              encoding = encoding.substring(1, encoding.length() - 1);
          return (encoding.trim());
  
      }
  
  
  }
  
  
  

Reply via email to