1
2
3
4
5
6
7 package org.mule.api.transport;
8
9 import java.io.Serializable;
10 import java.util.Comparator;
11
12
13
14
15
16
17 public final class PropertyScope implements Serializable
18 {
19 private static final long serialVersionUID = -4792653762048974018L;
20
21 public static final String INVOCATION_NAME = "invocation";
22 public static final String INBOUND_NAME = "inbound";
23 public static final String OUTBOUND_NAME = "outbound";
24 public static final String SESSION_NAME = "session";
25 public static final String APPLICATION_NAME = "application";
26
27
28
29
30
31 public static final PropertyScope INVOCATION = new PropertyScope(INVOCATION_NAME, 0);
32
33
34
35
36 public static final PropertyScope INBOUND = new PropertyScope(INBOUND_NAME, 1);
37
38
39
40
41
42 public static final PropertyScope OUTBOUND = new PropertyScope(OUTBOUND_NAME, 2);
43
44
45
46
47
48
49 public static final PropertyScope SESSION = new PropertyScope(SESSION_NAME, 3);
50
51
52
53
54
55 public static final PropertyScope APPLICATION = new PropertyScope(APPLICATION_NAME, 4);
56
57
58
59
60 public static final PropertyScope[] ALL_SCOPES = new PropertyScope[]{INVOCATION, INBOUND, OUTBOUND, SESSION, APPLICATION};
61
62 private String scope;
63 private int order;
64
65 private PropertyScope(String scope, int order)
66 {
67 this.scope = scope;
68 this.order = order;
69 }
70
71 public static PropertyScope get(String name)
72 {
73 if (INVOCATION.getScopeName().equals(name))
74 {
75 return INVOCATION;
76 }
77 else if (INBOUND.getScopeName().equals(name))
78 {
79 return INBOUND;
80 }
81 else if (OUTBOUND.getScopeName().equals(name))
82 {
83 return OUTBOUND;
84 }
85 else if (SESSION.getScopeName().equals(name))
86 {
87 return SESSION;
88 }
89 else if (APPLICATION.getScopeName().equals(name))
90 {
91 return APPLICATION;
92 }
93 else
94 {
95 return null;
96 }
97 }
98
99 public String getScopeName()
100 {
101 return scope;
102 }
103
104 public int getOrder()
105 {
106 return order;
107 }
108
109 @Override
110 public String toString()
111 {
112 return getScopeName();
113 }
114
115 @Override
116 public boolean equals(Object o)
117 {
118 if (this == o)
119 {
120 return true;
121 }
122 if (o == null || getClass() != o.getClass())
123 {
124 return false;
125 }
126
127 PropertyScope that = (PropertyScope) o;
128
129 if (order != that.order)
130 {
131 return false;
132 }
133 if (scope != null ? !scope.equals(that.scope) : that.scope != null)
134 {
135 return false;
136 }
137
138 return true;
139 }
140
141 @Override
142 public int hashCode()
143 {
144 int result;
145 result = (scope != null ? scope.hashCode() : 0);
146 result = 31 * result + order;
147 return result;
148 }
149
150
151
152
153
154 public static class ScopeComparator implements Comparator<PropertyScope>, Serializable
155 {
156 private static final long serialVersionUID = -3346258000312580166L;
157
158 public int compare(PropertyScope o, PropertyScope o1)
159 {
160 if (o == o1)
161 {
162 return 0;
163 }
164 if (o.equals(o1))
165 {
166 return 0;
167 }
168 return (o.getOrder() < o1.getOrder() ? -1 : 1);
169 }
170 }
171 }
172