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