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