001: /**
002: * Copyright 2006 Webmedia Group Ltd.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: **/package org.araneaframework.http.util;
016:
017: import org.araneaframework.Environment;
018: import org.araneaframework.framework.FlowContext;
019: import org.araneaframework.framework.LocalizationContext;
020: import org.araneaframework.framework.MessageContext;
021: import org.araneaframework.framework.SystemFormContext;
022: import org.araneaframework.framework.ThreadContext;
023: import org.araneaframework.framework.TopServiceContext;
024: import org.araneaframework.http.UpdateRegionContext;
025:
026: /**
027: * Utility class that provides shortcuts for accessing some {@link Environment} entries.
028: *
029: * @author Alar Kvell (alar@araneaframework.org)
030: * @since 1.1
031: */
032: public abstract class EnvironmentUtil {
033: public static Object getTopServiceId(Environment env) {
034: TopServiceContext topServiceContext = (TopServiceContext) env
035: .getEntry(TopServiceContext.class);
036: if (topServiceContext == null)
037: return null;
038: return topServiceContext.getCurrentId();
039: }
040:
041: public static Object getThreadServiceId(Environment env) {
042: ThreadContext threadContext = (ThreadContext) env
043: .getEntry(ThreadContext.class);
044: if (threadContext == null)
045: return null;
046: return threadContext.getCurrentId();
047: }
048:
049: public static Object requireTopServiceId(Environment env) {
050: TopServiceContext topServiceContext = (TopServiceContext) env
051: .requireEntry(TopServiceContext.class);
052: return topServiceContext.getCurrentId();
053: }
054:
055: public static Object requireThreadServiceId(Environment env) {
056: ThreadContext threadContext = (ThreadContext) env
057: .requireEntry(ThreadContext.class);
058: return threadContext.getCurrentId();
059: }
060:
061: // THESE ARE NOT CONNECTED TO SYSTEM FORM
062: public static LocalizationContext getLocalizationContext(
063: Environment env) {
064: return (LocalizationContext) env
065: .getEntry(LocalizationContext.class);
066: }
067:
068: public static LocalizationContext requireLocalizationContext(
069: Environment env) {
070: return (LocalizationContext) env
071: .requireEntry(LocalizationContext.class);
072: }
073:
074: public static FlowContext getFlowContext(Environment env) {
075: return (FlowContext) env.getEntry(FlowContext.class);
076: }
077:
078: public static FlowContext requireFlowContext(Environment env) {
079: return (FlowContext) env.requireEntry(FlowContext.class);
080: }
081:
082: public static MessageContext getMessageContext(Environment env) {
083: return (MessageContext) env.getEntry(MessageContext.class);
084: }
085:
086: public static MessageContext requireMessageContext(Environment env) {
087: return (MessageContext) env.requireEntry(MessageContext.class);
088: }
089:
090: public static SystemFormContext getSystemFormContext(Environment env) {
091: return (SystemFormContext) env
092: .getEntry(SystemFormContext.class);
093: }
094:
095: public static SystemFormContext requireSystemFormContext(
096: Environment env) {
097: return (SystemFormContext) env
098: .requireEntry(SystemFormContext.class);
099: }
100:
101: public static UpdateRegionContext getUpdateRegionContext(
102: Environment env) {
103: return (UpdateRegionContext) env
104: .getEntry(UpdateRegionContext.class);
105: }
106:
107: public static UpdateRegionContext requireUpdateRegionContext(
108: Environment env) {
109: return (UpdateRegionContext) env
110: .requireEntry(UpdateRegionContext.class);
111: }
112: }
|