Coverage Report - org.mule.api.transport.PropertyScope
 
Classes in this File Line Coverage Branch Coverage Complexity
PropertyScope
62%
16/26
25%
4/16
2.714
PropertyScope$ScopeComparator
83%
5/6
83%
5/6
2.714
 
 1  
 /*
 2  
  * $Id: PropertyScope.java 12370 2008-07-17 13:11:17Z tcarlson $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 package org.mule.api.transport;
 11  
 
 12  
 import java.io.Serializable;
 13  
 import java.util.Comparator;
 14  
 
 15  
 /**
 16  
  * A PropertyScope is used to assoaciate a message property with a lifetime. Some scopes may be very brief such as
 17  
  * {@link #INVOCATION} scope which only lasts until a service has been invoke or a longer running scope such as {@link #SESSION}
 18  
  *
 19  
  */
 20  
 public final class PropertyScope implements Serializable
 21  
 {
 22  
     private static final long serialVersionUID = -4792653762048974018L;
 23  
     
 24  
     public static final String INVOCATION_NAME = "invocation";
 25  
     public static final String INBOUND_NAME = "inbound";
 26  
     public static final String OUTBOUND_NAME = "outbound";
 27  
     public static final String SESSION_NAME = "session";
 28  
     public static final String APPLICATION_NAME = "application";
 29  
 
 30  
     /**
 31  
      * This scope is defined from the point that a Message is created until a service has processed the
 32  
      * message. Properties set on endpoints will be found in this scope
 33  
      */
 34  2
     public static final PropertyScope INVOCATION = new PropertyScope(INVOCATION_NAME, 0);
 35  
 
 36  
     /**
 37  
      * This scope holds all inbound headers when a message is received. This scope is read only
 38  
      */
 39  2
     public static final PropertyScope INBOUND = new PropertyScope(INBOUND_NAME, 1);
 40  
 
 41  
     /**
 42  
      * This is the default scope when writing properties to a message. All properties written in this scope
 43  
      * will be attached to the outbound message (or response message)
 44  
      */
 45  2
     public static final PropertyScope OUTBOUND = new PropertyScope(OUTBOUND_NAME, 2);
 46  
 
 47  
     /**
 48  
      * Defines the scope for any properties set on the session. Mule utilises the underlying transport for controlling the
 49  
      * session where possible i.e. HttpSession. But Mule will fallback to an internal session mechanisim where a session is
 50  
      * encoded on the message with an expiry time associated with it.
 51  
      */
 52  2
     public static final PropertyScope SESSION = new PropertyScope(SESSION_NAME, 3);
 53  
 
 54  
     /**
 55  
      * This provides access to properties in the registry. By default this scope is not enabled since
 56  
      * it will most likely have a performance impact. This is a read-only scope
 57  
      */
 58  2
     public static final PropertyScope APPLICATION = new PropertyScope(APPLICATION_NAME, 4);
 59  
 
 60  
     /**
 61  
      * An array of all scopes defined here
 62  
      */
 63  2
     public static final PropertyScope[] ALL_SCOPES = new PropertyScope[]{INVOCATION, INBOUND, OUTBOUND, SESSION, APPLICATION};
 64  
 
 65  
     private String scope;
 66  
     private int order;
 67  
 
 68  
     public PropertyScope(String scope, int order)
 69  10
     {
 70  10
         this.scope = scope;
 71  10
         this.order = order;
 72  10
     }
 73  
 
 74  
     public String getScope()
 75  
     {
 76  0
         return scope;
 77  
     }
 78  
 
 79  
     public int getOrder()
 80  
     {
 81  12516
         return order;
 82  
     }
 83  
 
 84  
     public String toString()
 85  
     {
 86  0
         return getScope();
 87  
     }
 88  
 
 89  
     public boolean equals(Object o)
 90  
     {
 91  6506
         if (this == o)
 92  
         {
 93  0
             return true;
 94  
         }
 95  6506
         if (o == null || getClass() != o.getClass())
 96  
         {
 97  0
             return false;
 98  
         }
 99  
 
 100  6506
         PropertyScope that = (PropertyScope) o;
 101  
 
 102  6506
         if (order != that.order)
 103  
         {
 104  6506
             return false;
 105  
         }
 106  0
         if (scope != null ? !scope.equals(that.scope) : that.scope != null)
 107  
         {
 108  0
             return false;
 109  
         }
 110  
 
 111  0
         return true;
 112  
     }
 113  
 
 114  
     public int hashCode()
 115  
     {
 116  
         int result;
 117  0
         result = (scope != null ? scope.hashCode() : 0);
 118  0
         result = 31 * result + order;
 119  0
         return result;
 120  
     }
 121  
 
 122  
     /**
 123  
      * Used for comparing {@link PropertyScope} instances in a map. The {@link PropertyScope#getOrder()}
 124  
      * property is used to determine the order in the map
 125  
      */
 126  1032
     public static class ScopeComparator implements Comparator, Serializable
 127  
     {
 128  
         private static final long serialVersionUID = -3346258000312580166L;
 129  
 
 130  
         public int compare(Object o, Object o1)
 131  
         {
 132  7282
             if (o == o1)
 133  
             {
 134  1024
                 return 0;
 135  
             }
 136  6258
             if (o.equals(o1))
 137  
             {
 138  0
                 return 0;
 139  
             }
 140  6258
             return (((PropertyScope) o).getOrder() < ((PropertyScope) o1).getOrder() ? -1 : 1);
 141  
         }
 142  
     }
 143  
 }
 144