01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.service.invoker;
19:
20: import java.beans.PropertyEditorSupport;
21:
22: /**
23: * This class is responsible for converting string to ScopePolicy object.
24: * <p>
25: *
26: * @author Ben Yu Feb 12, 2006 12:40:31 AM
27: */
28: public class ScopePolicyEditor extends PropertyEditorSupport {
29: /**
30: * To get the default scope policy when no policy is specified. This
31: * implementation uses "application" as default.
32: */
33: public static ScopePolicy getDefaultScope() {
34: return ApplicationScopePolicy.instance();
35: }
36:
37: /**
38: * Convert a policy name to ScopePolicy object.
39: *
40: * @param policy the policy name.
41: * @return the ScopePolicy object.
42: */
43: public static ScopePolicy toScopePolicy(String policy) {
44: if (policy == null) {
45: return getDefaultScope();
46: }
47:
48: policy = policy.trim();
49:
50: if (policy.length() == 0) {
51: return getDefaultScope();
52: } else if ("application".equals(policy)) {
53: return ApplicationScopePolicy.instance();
54: } else if ("session".equals(policy)) {
55: return SessionScopePolicy.instance();
56: } else if ("request".equals(policy)) {
57: return RequestScopePolicy.instance();
58: } else {
59: throw new IllegalArgumentException("Scope " + policy
60: + " is invalid.");
61: }
62: }
63:
64: public void setAsText(String text) {
65: setValue(toScopePolicy(text));
66: }
67: }
|