Coverage Report - org.mule.api.transport.PropertyScope
 
Classes in this File Line Coverage Branch Coverage Complexity
PropertyScope
0%
0/37
0%
0/26
0
PropertyScope$ScopeComparator
0%
0/6
0%
0/6
0
 
 1  
 /*
 2  
  * $Id: PropertyScope.java 19191 2010-08-25 21:05:23Z tcarlson $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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 associate a message property with a lifetime.  A scope may be very 
 17  
  * brief such as {@link #INVOCATION} which only lasts until a service has been invoked or longer 
 18  
  * running such as {@link #SESSION}.
 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  0
     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  0
     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  0
     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 mechanism where a session is
 50  
      * encoded on the message with an expiry time associated with it.
 51  
      */
 52  0
     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  0
     public static final PropertyScope APPLICATION = new PropertyScope(APPLICATION_NAME, 4);
 59  
 
 60  
     /**
 61  
      * An array of all scopes defined here
 62  
      */
 63  0
     public static final PropertyScope[] ALL_SCOPES = new PropertyScope[]{INVOCATION, INBOUND, OUTBOUND, SESSION, APPLICATION};
 64  
 
 65  
     private String scope;
 66  
     private int order;
 67  
 
 68  
     private PropertyScope(String scope, int order)
 69  0
     {
 70  0
         this.scope = scope;
 71  0
         this.order = order;
 72  0
     }
 73  
 
 74  
     public static PropertyScope get(String name)
 75  
     {
 76  0
         if (INVOCATION.getScopeName().equals(name))
 77  
         {
 78  0
             return INVOCATION;
 79  
         }
 80  0
         else if (INBOUND.getScopeName().equals(name))
 81  
         {
 82  0
             return INBOUND;
 83  
         }
 84  0
         else if (OUTBOUND.getScopeName().equals(name))
 85  
         {
 86  0
             return OUTBOUND;
 87  
         }
 88  0
         else if (SESSION.getScopeName().equals(name))
 89  
         {
 90  0
             return SESSION;
 91  
         }
 92  0
         else if (APPLICATION.getScopeName().equals(name))
 93  
         {
 94  0
             return APPLICATION;
 95  
         }
 96  
         else
 97  
         {
 98  0
             return null;
 99  
         }
 100  
     }
 101  
     
 102  
     public String getScopeName()
 103  
     {
 104  0
         return scope;
 105  
     }
 106  
 
 107  
     public int getOrder()
 108  
     {
 109  0
         return order;
 110  
     }
 111  
 
 112  
     @Override
 113  
     public String toString()
 114  
     {
 115  0
         return getScopeName();
 116  
     }
 117  
 
 118  
     @Override
 119  
     public boolean equals(Object o)
 120  
     {
 121  0
         if (this == o)
 122  
         {
 123  0
             return true;
 124  
         }
 125  0
         if (o == null || getClass() != o.getClass())
 126  
         {
 127  0
             return false;
 128  
         }
 129  
 
 130  0
         PropertyScope that = (PropertyScope) o;
 131  
 
 132  0
         if (order != that.order)
 133  
         {
 134  0
             return false;
 135  
         }
 136  0
         if (scope != null ? !scope.equals(that.scope) : that.scope != null)
 137  
         {
 138  0
             return false;
 139  
         }
 140  
 
 141  0
         return true;
 142  
     }
 143  
 
 144  
     @Override
 145  
     public int hashCode()
 146  
     {
 147  
         int result;
 148  0
         result = (scope != null ? scope.hashCode() : 0);
 149  0
         result = 31 * result + order;
 150  0
         return result;
 151  
     }
 152  
 
 153  
     /**
 154  
      * Used for comparing {@link PropertyScope} instances in a map. The {@link PropertyScope#getOrder()}
 155  
      * property is used to determine the order in the map
 156  
      */
 157  0
     public static class ScopeComparator implements Comparator<PropertyScope>, Serializable
 158  
     {
 159  
         private static final long serialVersionUID = -3346258000312580166L;
 160  
 
 161  
         public int compare(PropertyScope o, PropertyScope o1)
 162  
         {
 163  0
             if (o == o1)
 164  
             {
 165  0
                 return 0;
 166  
             }
 167  0
             if (o.equals(o1))
 168  
             {
 169  0
                 return 0;
 170  
             }
 171  0
             return (o.getOrder() < o1.getOrder() ? -1 : 1);
 172  
         }
 173  
     }
 174  
 }
 175