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: */
19: package org.apache.axis2.util;
20:
21: import org.apache.axis2.Constants;
22: import org.apache.axis2.description.AxisService;
23: import org.apache.axis2.description.AxisServiceGroup;
24:
25: import java.util.Iterator;
26:
27: public class SessionUtils {
28:
29: /**
30: * Walk through the list of services and use the minimum of the scopes as the scope for the whole service group
31: *
32: * @param axisServiceGroup
33: * @return scope for the service group
34: */
35: public static String calculateMaxScopeForServiceGroup(
36: AxisServiceGroup axisServiceGroup) {
37: Iterator servics = axisServiceGroup.getServices();
38: int maxScope = 1;
39: while (servics.hasNext()) {
40: AxisService axisService = (AxisService) servics.next();
41: int scopeIntValue = getScopeIntValue(axisService.getScope());
42: if (maxScope < scopeIntValue) {
43: maxScope = scopeIntValue;
44: }
45: }
46: return getScopeString(maxScope);
47: }
48:
49: /**
50: * convert scope into a numerical value
51: *
52: * @param scope
53: * @return integer
54: */
55: private static int getScopeIntValue(String scope) {
56: if (Constants.SCOPE_REQUEST.equals(scope)) {
57: return 1;
58: } else if (Constants.SCOPE_TRANSPORT_SESSION.equals(scope)) {
59: return 2;
60: } else if (Constants.SCOPE_SOAP_SESSION.equals(scope)) {
61: return 3;
62: } else if (Constants.SCOPE_APPLICATION.equals(scope)) {
63: return 4;
64: } else {
65: return 2;
66: }
67: }
68:
69: /**
70: * Get the actual scope string given the numerical value
71: *
72: * @param scope
73: * @return string
74: */
75: private static String getScopeString(int scope) {
76: switch (scope) {
77: case 1: {
78: return Constants.SCOPE_REQUEST;
79: }
80: case 2: {
81: return Constants.SCOPE_TRANSPORT_SESSION;
82: }
83: case 3: {
84: return Constants.SCOPE_SOAP_SESSION;
85: }
86: case 4: {
87: return Constants.SCOPE_APPLICATION;
88: }
89: default: {
90: return Constants.SCOPE_TRANSPORT_SESSION;
91: }
92: }
93: }
94: }
|