Coverage Report - org.apache.commons.scxml.model.CustomAction

Classes in this File Line Coverage Branch Coverage Complexity
CustomAction
90% 
100% 
3

 1  
 /*
 2  
  *
 3  
  *   Copyright 2006 The Apache Software Foundation.
 4  
  *
 5  
  *  Licensed under the Apache License, Version 2.0 (the "License");
 6  
  *  you may not use this file except in compliance with the License.
 7  
  *  You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  *  Unless required by applicable law or agreed to in writing, software
 12  
  *  distributed under the License is distributed on an "AS IS" BASIS,
 13  
  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  *  See the License for the specific language governing permissions and
 15  
  *  limitations under the License.
 16  
  *
 17  
  */
 18  
 package org.apache.commons.scxml.model;
 19  
 
 20  
 import org.apache.commons.logging.LogFactory;
 21  
 import org.apache.commons.scxml.SCXMLHelper;
 22  
 
 23  
 /**
 24  
  * A custom action is simply a tuple consisting of a namespace URI,
 25  
  * the local name for the custom action and the corresponding
 26  
  * {@link Action} class.
 27  
  *
 28  
  */
 29  
 public class CustomAction {
 30  
 
 31  
     /**
 32  
      * Error logged while attempting to define a custom action
 33  
      * in a null or empty namespace.
 34  
      */
 35  
     private static final String ERR_NO_NAMESPACE =
 36  
         "Cannot define a custom SCXML action with a null or empty namespace";
 37  
 
 38  
     /**
 39  
      * The SCXML namespace, to which custom actions may not be added.
 40  
      */
 41  
     private static final String NAMESPACE_SCXML =
 42  
         "http://www.w3.org/2005/07/scxml";
 43  
 
 44  
     /**
 45  
      * Error logged while attempting to define a custom action
 46  
      * with the SCXML namespace.
 47  
      */
 48  
     private static final String ERR_RESERVED_NAMESPACE =
 49  
         "Cannot define a custom SCXML action within the SCXML namespace '"
 50  
         + NAMESPACE_SCXML + "'";
 51  
 
 52  
     /**
 53  
      * Error logged while attempting to define a custom action
 54  
      * in a null or empty local name.
 55  
      */
 56  
     private static final String ERR_NO_LOCAL_NAME =
 57  
         "Cannot define a custom SCXML action with a null or empty local name";
 58  
 
 59  
     /**
 60  
      * Error logged while attempting to define a custom action
 61  
      * which does not extend {@link Action}.
 62  
      */
 63  
     private static final String ERR_NOT_AN_ACTION =
 64  
         "Custom SCXML action does not extend Action superclass";
 65  
 
 66  
     /**
 67  
      * The namespace this custom action belongs to.
 68  
      */
 69  
     private String namespaceURI;
 70  
 
 71  
     /**
 72  
      * The local name of the custom action.
 73  
      */
 74  
     private String localName;
 75  
 
 76  
     /**
 77  
      * The implementation of this custom action.
 78  
      */
 79  
     private Class actionClass;
 80  
 
 81  
     /**
 82  
      * The log for this custom action.
 83  
      */
 84  
     private org.apache.commons.logging.Log log;
 85  
 
 86  
     /**
 87  
      * Constructor, if the namespace or local name is null or empty,
 88  
      * or if the implementation is not an {@link Action}, an
 89  
      * {@link IllegalArgumentException} is thrown.
 90  
      *
 91  
      * @param namespaceURI The namespace URI for this custom action.
 92  
      * @param localName The local name for this custom action.
 93  
      * @param actionClass The {@link Action} subclass implementing this
 94  
      *                    custom action.
 95  
      */
 96  
     public CustomAction(final String namespaceURI, final String localName,
 97  9
             final Class actionClass) {
 98  11
         this.log = LogFactory.getLog(CustomAction.class);
 99  9
         if (SCXMLHelper.isStringEmpty(namespaceURI)) {
 100  2
             log.error(ERR_NO_NAMESPACE);
 101  2
             throw new IllegalArgumentException(ERR_NO_NAMESPACE);
 102  
         }
 103  7
         if (namespaceURI.trim().equalsIgnoreCase(NAMESPACE_SCXML)) {
 104  0
             log.error(ERR_RESERVED_NAMESPACE);
 105  0
             throw new IllegalArgumentException(ERR_RESERVED_NAMESPACE);
 106  
         }
 107  7
         if (SCXMLHelper.isStringEmpty(localName)) {
 108  2
             log.error(ERR_NO_LOCAL_NAME);
 109  2
             throw new IllegalArgumentException(ERR_NO_LOCAL_NAME);
 110  
         }
 111  5
         if (actionClass == null
 112  
                 || !SCXMLHelper.subtypeOf(actionClass, Action.class)) {
 113  1
             log.error(ERR_NOT_AN_ACTION);
 114  1
             throw new IllegalArgumentException(ERR_NOT_AN_ACTION);
 115  
         }
 116  4
         this.namespaceURI = namespaceURI;
 117  4
         this.localName = localName;
 118  4
         this.actionClass = actionClass;
 119  4
     }
 120  
 
 121  
     /**
 122  
      * Get this custom action's implementation.
 123  
      *
 124  
      * @return Returns the action class.
 125  
      */
 126  
     public Class getActionClass() {
 127  20
         return actionClass;
 128  
     }
 129  
 
 130  
     /**
 131  
      * Get the local name for this custom action.
 132  
      *
 133  
      * @return Returns the local name.
 134  
      */
 135  
     public String getLocalName() {
 136  20
         return localName;
 137  
     }
 138  
 
 139  
     /**
 140  
      * Get the namespace URI for this custom action.
 141  
      *
 142  
      * @return Returns the namespace URI.
 143  
      */
 144  
     public String getNamespaceURI() {
 145  20
         return namespaceURI;
 146  
     }
 147  
 
 148  
 }
 149