01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: * $Header:$
18: */
19: package org.apache.beehive.netui.pageflow.scoping.internal;
20:
21: import org.apache.beehive.netui.pageflow.scoping.ScopedServletUtils;
22:
23: /**
24: * Base class for wrapper objects that keep their own scoped attributes, ignoring the attributes
25: * of the wrapped objects.
26: */
27: public class ScopedAttributeContainer extends AttributeContainer {
28: private Object _scopeKey;
29:
30: public ScopedAttributeContainer(Object scopeKey) {
31: _scopeKey = scopeKey;
32: }
33:
34: public final String getScopedName(String baseName) {
35: return ScopedServletUtils.getScopedName(baseName, _scopeKey);
36: }
37:
38: public boolean isInScope(String keyName) {
39: return isInScope(keyName, _scopeKey);
40: }
41:
42: public static boolean isInScope(String keyName, Object scopeKey) {
43: return keyName.startsWith(scopeKey.toString());
44: }
45:
46: public String removeScope(String keyName) {
47: return removeScope(keyName, _scopeKey);
48: }
49:
50: public static String removeScope(String keyName, Object scopeKey) {
51: assert keyName.startsWith(scopeKey.toString()) : keyName;
52: return keyName.substring(scopeKey.toString().length());
53: }
54:
55: public final Object getScopeKey() {
56: return _scopeKey;
57: }
58:
59: public void renameScope(Object newScopeKey) {
60: _scopeKey = newScopeKey;
61: }
62: }
|