You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by mr...@apache.org on 2005/08/26 07:46:58 UTC
svn commit: r240168 [10/30] - in /struts/sandbox/trunk/ti: ./
core/src/java/org/apache/ti/ core/src/java/org/apache/ti/config/
core/src/java/org/apache/ti/config/mapper/
core/src/java/org/apache/ti/core/ core/src/java/org/apache/ti/core/factory/
core/s...
Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/action/ActionInterceptor.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/action/ActionInterceptor.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/action/ActionInterceptor.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/action/ActionInterceptor.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,165 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.interceptor.action;
+
+import org.apache.ti.pageflow.interceptor.AbstractInterceptor;
+import org.apache.ti.pageflow.interceptor.InterceptorChain;
+import org.apache.ti.pageflow.interceptor.InterceptorContext;
+import org.apache.ti.pageflow.interceptor.InterceptorException;
+
+
+/**
+ * Base class for Page Flow action interceptors. These are configured in /WEB-INF/beehive-netui-config.xml like this:
+ * <pre>
+ * <netui-config xmlns="http://beehive.apache.org/netui/2004/server/config">
+ * ...
+ * <p/>
+ * <pageflow-action-interceptors>
+ * <global>
+ * <before-action>
+ * <action-interceptor>
+ * <interceptor-class>test.BeforeActionInterceptor1</interceptor-class>
+ * </action-interceptor>
+ * <action-interceptor>
+ * <interceptor-class>test.BeforeActionInterceptor2</interceptor-class>
+ * </action-interceptor>
+ * ...
+ * </before-action>
+ * <after-action>
+ * <action-interceptor>
+ * <interceptor-class>test.AfterActionInterceptor1</interceptor-class>
+ * </action-interceptor>
+ * <action-interceptor>
+ * <interceptor-class>test.AfterActionInterceptor2</interceptor-class>
+ * </action-interceptor>
+ * </after-action>
+ * </global>
+ * </pageflow-action-interceptors>
+ * <p/>
+ * ...
+ * </netui-config>
+ * <p/>
+ * </pre>
+ * <p/>
+ * Note that a registered ActionInterceptor is created and cached as a single instance per application.
+ * It should not hold any per-request or per-session state.
+ */
+public abstract class ActionInterceptor
+ extends AbstractInterceptor {
+
+ /**
+ * Callback invoked before the action is processed. During this method, {@link #setOverrideForward} may be called
+ * to:
+ * <ul>
+ * <li>change the destination URI and thus prevent the action from running, or,</li>
+ * <li>set the destination URI to <code>null</code> (no forwarding) and thus prevent the action from running, or,</li>
+ * <li>
+ * "inject" an entire nested page flow to run before the action is invoked. If the override forward URI
+ * is a nested page flow, then it will run until it raises one of its return actions. At that point,
+ * {@link #afterNestedIntercept} is called on <i>this interceptor</i>, which can again choose to override
+ * the forward or allow the original action to run.
+ * </li>
+ * </ul>
+ * <p/>
+ * {@link InterceptorChain#continueChain} is called to invoke the rest of the
+ * interceptor chain, anywhere within this method (e.g., at the end, or within a try/finally).
+ *
+ * @param context the current ActionInterceptorContext.
+ * @param chain the interceptor chain. Calling <code>continueChain</code> on this runs the rest of the interceptors.
+ */
+ public abstract void preAction(ActionInterceptorContext context, InterceptorChain chain)
+ throws InterceptorException;
+
+ /**
+ * Callback invoked before the action is processed. {@link #preAction} may be used instead.
+ */
+ public void preInvoke(InterceptorContext context, InterceptorChain chain) throws InterceptorException {
+ preAction((ActionInterceptorContext) context, chain);
+ }
+
+ /**
+ * Callback invoked after the action is processed. During this method, {@link #setOverrideForward} may be called
+ * to:
+ * <ul>
+ * <li>change the destination URI and thus override the one returned from the action, or,</li>
+ * <li>set the destination URI to <code>null</code> (no forwarding).</li>
+ * </ul>
+ * <p/>
+ * {@link InterceptorChain#continueChain} is called to invoke the rest of the
+ * interceptor chain, anywhere within this method (e.g., at the end, or within a try/finally).
+ *
+ * @param context the current ActionInterceptorContext.
+ * @param chain the interceptor chain. Calling <code>continueChain</code> on this runs the rest of the interceptors.
+ */
+ public abstract void postAction(ActionInterceptorContext context, InterceptorChain chain)
+ throws InterceptorException;
+
+ /**
+ * Callback invoked after the action is processed. {@link #postAction} may be used instead.
+ */
+ public void postInvoke(InterceptorContext context, InterceptorChain chain) throws InterceptorException {
+ postAction((ActionInterceptorContext) context, chain);
+ }
+
+ /**
+ * Callback invoked after a nested page flow has been "injected" by {@link #preAction}, and before the original
+ * action has run. During this method, {@link #setOverrideForward} may be called to:
+ * <p/>
+ * <ul>
+ * <li>change the destination URI that was returned by the action, or,</li>
+ * <li>set the destination URI to <code>null</code> (no forwarding).</li>
+ * </ul>
+ * <p/>
+ * {@link InterceptorChain#continueChain} is called to invoke the rest of the
+ * interceptor chain, anywhere within this method (e.g., at the end, or within a try/finally).
+ *
+ * @param context an extension of {@link ActionInterceptorContext} which contains the return action from the
+ * injected nested page flow.
+ * @throws InterceptorException
+ */
+ public abstract void afterNestedIntercept(AfterNestedInterceptContext context)
+ throws InterceptorException;
+
+ /**
+ * Override the forward, either before or after the target action is run. See {@link #preAction} and
+ * {@link #postAction} for information on how this is used.
+ *
+ * @param forward an InterceptorForward that will override the target action's forward; or <code>null</code> to
+ * cancel navigation.
+ * @param context the current ActionInterceptorContext.
+ */
+ protected void setOverrideForward(InterceptorForward forward, ActionInterceptorContext context) {
+ context.setOverrideForward(forward, this);
+ }
+
+ /**
+ * Optional method that "wraps" the target action invocation. This is mainly useful for surrounding an action
+ * (and the rest of the interceptor chain) with try/catch/finally. This default implementation simply <i>returns</i>
+ * <code>continueChain</code> on the passed-in InterceptorChain, which allows the rest of the interceptors
+ * <i>and</i> the action to run.
+ *
+ * @param context the current ActionInterceptorContext.
+ * @param chain the interceptor chain. This chain is different from the ones passed to {@link #preAction} and
+ * {@link #postAction} in that the action invocation itself is included in it.
+ * @return the forward returned by the action.
+ */
+ public Object wrapAction(ActionInterceptorContext context, InterceptorChain chain)
+ throws InterceptorException {
+ return chain.continueChain();
+ }
+}
Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/action/ActionInterceptorContext.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/action/ActionInterceptorContext.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/action/ActionInterceptorContext.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/action/ActionInterceptorContext.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,232 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.interceptor.action;
+
+import org.apache.ti.pageflow.Forward;
+import org.apache.ti.pageflow.PageFlowController;
+import org.apache.ti.pageflow.interceptor.action.internal.OriginalForward;
+import org.apache.ti.pageflow.interceptor.request.RequestInterceptorContext;
+import org.apache.ti.pageflow.internal.InternalConstants;
+import org.apache.ti.pageflow.xwork.PageFlowActionContext;
+import org.apache.ti.schema.config.PageflowActionInterceptors;
+import org.apache.ti.util.config.ConfigUtil;
+import org.apache.ti.util.internal.concurrent.InternalConcurrentHashMap;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+
+/**
+ * Context passed to {@link ActionInterceptor} methods.
+ */
+public class ActionInterceptorContext
+ extends RequestInterceptorContext {
+
+ private static final String ACTIVE_INTERCEPTOR_CONTEXT_ATTR = InternalConstants.ATTR_PREFIX + "interceptorContext";
+ private static final String CACHE_ATTR = InternalConstants.ATTR_PREFIX + "actionInterceptorConfig";
+
+ private PageFlowController _pageFlow;
+ private InterceptorForward _originalForward;
+ private String _actionName;
+
+
+ public ActionInterceptorContext(PageFlowController controller, InterceptorForward originalForward, String actionName) {
+ super();
+ _pageFlow = controller;
+ _originalForward = originalForward;
+ _actionName = actionName;
+ }
+
+ /**
+ * Get the page flow on which the action is being raised.
+ */
+ public PageFlowController getPageFlow() {
+ return _pageFlow;
+ }
+
+ /**
+ * Get a wrapper for the original URI from the action that was intercepted. This value will be <code>null</code>
+ * if the interceptor was run before the action, or if the action itself returned <code>null</code>.
+ */
+ public InterceptorForward getOriginalForward() {
+ return _originalForward;
+ }
+
+ /**
+ * Get the name of the action being raised.
+ */
+ public String getActionName() {
+ return _actionName;
+ }
+
+ /**
+ * Set an {@link InterceptorForward} that changes the destination URI of the intercepted action. If the
+ * InterceptorForward points to a nested page flow, then {@link ActionInterceptor#afterNestedIntercept} will be
+ * called before the nested page flow returns to the original page flow.
+ */
+ public void setOverrideForward(InterceptorForward fwd, ActionInterceptor interceptor) {
+ setResultOverride(fwd, interceptor);
+
+ //
+ // If there was no original forward (i.e., this is happening before the action was invoked), create a
+ // pseudo-forward out of the original request.
+ //
+ if (_originalForward == null) _originalForward = new OriginalForward();
+
+ //
+ // Store this context in the request.
+ //
+ PageFlowActionContext actionContext = PageFlowActionContext.get();
+ actionContext.getRequestScope().put(ACTIVE_INTERCEPTOR_CONTEXT_ATTR, this);
+ }
+
+ public ActionInterceptor getOverridingActionInterceptor() {
+ return (ActionInterceptor) super.getOverridingInterceptor();
+ }
+
+ public InterceptorForward getInterceptorForward() {
+ return (InterceptorForward) getResultOverride();
+ }
+
+ public boolean hasInterceptorForward() {
+ return hasResultOverride();
+ }
+
+ public static ActionInterceptorContext getActiveContext(boolean consume) {
+ PageFlowActionContext actionContext = PageFlowActionContext.get();
+ Map requestScope = actionContext.getRequestScope();
+ ActionInterceptorContext context =
+ (ActionInterceptorContext) requestScope.get(ACTIVE_INTERCEPTOR_CONTEXT_ATTR);
+ if (consume) requestScope.remove(ACTIVE_INTERCEPTOR_CONTEXT_ATTR);
+ return context;
+ }
+
+
+ public List/*< Interceptor >*/ getActionInterceptors() {
+ PageFlowActionContext actionContext = PageFlowActionContext.get();
+ InternalConcurrentHashMap/*< String, HashMap< String, ArrayList< Interceptor > > >*/ cache =
+ (InternalConcurrentHashMap) actionContext.getApplication().get(CACHE_ATTR);
+
+ if (cache == null) {
+ //
+ // Don't have to synchronize here. If by some chance two initial requests come in at the same time,
+ // one of the caches will get overwritten in the ServletContext, but it will just get recreated the
+ // next time.
+ //
+ cache = new InternalConcurrentHashMap/*< String, HashMap< String, ArrayList< Interceptor > > >*/();
+ actionContext.getApplication().put(CACHE_ATTR, cache);
+ }
+
+ String namespace = getPageFlow().getNamespace();
+ String actionName = getActionName();
+ HashMap/*< String, ArrayList< Interceptor > >*/ cacheByPageFlow = (HashMap) cache.get(namespace);
+ if (cacheByPageFlow != null) {
+ List/*< Interceptor >*/ interceptors = (List) cacheByPageFlow.get(actionName);
+ if (interceptors != null) return interceptors;
+ }
+
+ //
+ // We didn't find it in the cache -- build it.
+ //
+ if (cacheByPageFlow == null) cacheByPageFlow = new HashMap/*< String, ArrayList< Interceptor > >*/();
+ PageflowActionInterceptors config = ConfigUtil.getConfig().getPageflowActionInterceptors();
+ ArrayList/*< Interceptor >*/ interceptorsList = new ArrayList/*< Interceptor >*/();
+
+ if (config == null) {
+ cacheByPageFlow.put(actionName, interceptorsList);
+ cache.put(namespace, cacheByPageFlow);
+ return interceptorsList;
+ }
+
+ //
+ // Global interceptors.
+ //
+ PageflowActionInterceptors.Global globalInterceptors = config.getGlobal();
+
+ if (globalInterceptors != null) {
+ addInterceptors(globalInterceptors.getActionInterceptorArray(), interceptorsList, ActionInterceptor.class);
+ addSimpleInterceptors(globalInterceptors.getSimpleActionInterceptorArray(), interceptorsList);
+ }
+
+ //
+ // Per-pageflow and per-action interceptors.
+ //
+ String pageFlowURI = getPageFlow().getPath();
+ PageflowActionInterceptors.PerPageflow[] perPageFlowInterceptorsConfig = config.getPerPageflowArray();
+
+ if (perPageFlowInterceptorsConfig != null) {
+ for (int i = 0; i < perPageFlowInterceptorsConfig.length; i++) {
+ PageflowActionInterceptors.PerPageflow ppfi = perPageFlowInterceptorsConfig[i];
+
+ if (ppfi != null && pageFlowURI.equals(ppfi.getPageflowUri())) {
+ //
+ // This is a matching page flow -- add per-pageflow interceptors.
+ //
+ addInterceptors(perPageFlowInterceptorsConfig[i].getActionInterceptorArray(), interceptorsList,
+ ActionInterceptor.class);
+ addSimpleInterceptors(perPageFlowInterceptorsConfig[i].getSimpleActionInterceptorArray(),
+ interceptorsList);
+
+ PageflowActionInterceptors.PerPageflow.PerAction[] perActionConfigs =
+ perPageFlowInterceptorsConfig[i].getPerActionArray();
+
+ if (perActionConfigs != null) {
+ for (int j = 0; j < perActionConfigs.length; j++) {
+ PageflowActionInterceptors.PerPageflow.PerAction perActionConfig = perActionConfigs[j];
+
+ if (perActionConfig != null && actionName.equals(perActionConfig.getActionName())) {
+ //
+ // This is a matching action -- add per-action interceptors.
+ //
+ addInterceptors(perActionConfig.getActionInterceptorArray(), interceptorsList,
+ ActionInterceptor.class);
+ addSimpleInterceptors(perActionConfig.getSimpleActionInterceptorArray(),
+ interceptorsList);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ cacheByPageFlow.put(actionName, interceptorsList);
+ cache.put(namespace, cacheByPageFlow);
+ return interceptorsList;
+ }
+
+ private static void addSimpleInterceptors(org.apache.ti.schema.config.SimpleActionInterceptor[] configBeans,
+ List/*< Interceptor >*/ interceptorsList) {
+ for (int i = 0; i < configBeans.length; i++) {
+ org.apache.ti.schema.config.SimpleActionInterceptor configBean = configBeans[i];
+ String path = configBean.getInterceptPath();
+ boolean afterAction = configBean.getAfterAction();
+ SimpleActionInterceptorConfig config = new SimpleActionInterceptorConfig(path, afterAction);
+ interceptorsList.add(new SimpleActionInterceptor(config));
+ }
+ }
+
+ public void setOriginalForward(Forward origFwd) {
+ _originalForward = origFwd != null ? new InterceptorForward(origFwd) : null;
+ }
+
+ public static void init(Map appScope) {
+ // TODO: move some of the lazy-load logic in getActionInterceptors into here.
+ }
+}
Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/action/AfterNestedInterceptContext.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/action/AfterNestedInterceptContext.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/action/AfterNestedInterceptContext.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/action/AfterNestedInterceptContext.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.interceptor.action;
+
+import org.apache.ti.pageflow.PageFlowController;
+
+/**
+ * Context passed to {@link ActionInterceptor#afterNestedIntercept}.
+ */
+public class AfterNestedInterceptContext
+ extends ActionInterceptorContext {
+
+ private String _returnAction;
+
+ public AfterNestedInterceptContext(PageFlowController controller,
+ InterceptorForward originalForward, String actionName,
+ String returnAction) {
+ super(controller, originalForward, actionName);
+ _returnAction = returnAction;
+ }
+
+ /**
+ * Get the return action from the nested page flow that intercepted the original page flow's action.
+ */
+ public String getReturnAction() {
+ return _returnAction;
+ }
+}
Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/action/InterceptorForward.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/action/InterceptorForward.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/action/InterceptorForward.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/action/InterceptorForward.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,91 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.interceptor.action;
+
+import org.apache.ti.pageflow.Forward;
+
+import java.net.URI;
+
+
+/**
+ * forward returned from an {@link ActionInterceptor} to alter the destination URI of a page flow action.
+ */
+public class InterceptorForward extends Forward {
+
+ protected InterceptorForward(Forward originalForward) {
+ super(originalForward);
+ }
+
+ protected InterceptorForward() {
+ super();
+ }
+
+ /**
+ * Construct from a webapp-relative path.
+ *
+ * @param path the webapp-relative destination path.
+ */
+ public InterceptorForward(String path) {
+ super(path);
+ }
+
+ /**
+ * Construct from a URI.
+ *
+ * @param path the webapp-relative destination path.
+ * @param redirect if <code>true</code>, the controller will redirect to the given path; otherwise, a server forward
+ * will be performed.
+ */
+ /* TODO: re-add this
+ public InterceptorForward(String path, boolean redirect) {
+ super(path, redirect);
+ }
+ */
+
+ /**
+ * Construct from a URI.
+ *
+ * @param uri the URI pointed to by this forward. This is assumed to be <strong>webapp-relative</strong>
+ * (i.e., it does not include the webapp context path), unless {@link #setExternalRedirect} is called.
+ */
+ public InterceptorForward(URI uri) {
+ super(null, uri);
+ }
+
+ /**
+ * Construct from a URI.
+ *
+ * @param uri the URI pointed to by this forward. This is assumed to be <strong>webapp-relative</strong>
+ * (i.e., it does not include the webapp context path), unless {@link #setExternalRedirect} is called.
+ * @param redirect if <code>true</code>, the controller will redirect to the given URI; otherwise, a server forward
+ * will be performed.
+ */
+ // TODO: re-add the ability to set redirect programmatically on a Forward; also setExternalRedirect
+ /*
+ public InterceptorForward( URI uri, boolean redirect )
+ {
+ super( uri, redirect );
+ }
+ */
+
+ /**
+ * @exclude
+ */
+ public void rehydrateRequest() {
+ }
+}
Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/action/SimpleActionInterceptor.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/action/SimpleActionInterceptor.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/action/SimpleActionInterceptor.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/action/SimpleActionInterceptor.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.interceptor.action;
+
+import org.apache.ti.pageflow.interceptor.InterceptorChain;
+import org.apache.ti.pageflow.interceptor.InterceptorException;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+class SimpleActionInterceptor
+ extends ActionInterceptor {
+
+ public SimpleActionInterceptor(SimpleActionInterceptorConfig config) {
+ init(config);
+ }
+
+ public void preAction(ActionInterceptorContext context, InterceptorChain chain)
+ throws InterceptorException {
+ if (!getActionInterceptorConfig().isAfterAction()) doit(context, chain);
+ }
+
+ public void postAction(ActionInterceptorContext context, InterceptorChain chain)
+ throws InterceptorException {
+ if (getActionInterceptorConfig().isAfterAction()) doit(context, chain);
+ }
+
+ private void doit(ActionInterceptorContext context, InterceptorChain chain)
+ throws InterceptorException {
+ try {
+ String path = getActionInterceptorConfig().getPath();
+ setOverrideForward(new InterceptorForward(new URI(path)), context);
+ chain.continueChain();
+ } catch (URISyntaxException e) {
+ throw new InterceptorException(e);
+ }
+ }
+
+ public void afterNestedIntercept(AfterNestedInterceptContext context) throws InterceptorException {
+ }
+
+ public SimpleActionInterceptorConfig getActionInterceptorConfig() {
+ return (SimpleActionInterceptorConfig) super.getConfig();
+ }
+}
Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/action/SimpleActionInterceptorConfig.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/action/SimpleActionInterceptorConfig.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/action/SimpleActionInterceptorConfig.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/action/SimpleActionInterceptorConfig.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.interceptor.action;
+
+import org.apache.ti.pageflow.interceptor.InterceptorConfig;
+
+class SimpleActionInterceptorConfig
+ extends InterceptorConfig {
+
+ private String _path;
+ private boolean _afterAction;
+
+ public SimpleActionInterceptorConfig(String path, boolean afterAction) {
+ super(SimpleActionInterceptor.class.getName());
+ _path = path;
+ _afterAction = afterAction;
+ }
+
+ public String getPath() {
+ return _path;
+ }
+
+ public boolean isAfterAction() {
+ return _afterAction;
+ }
+}
Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/action/internal/ActionInterceptors.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/action/internal/ActionInterceptors.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/action/internal/ActionInterceptors.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/action/internal/ActionInterceptors.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.interceptor.action.internal;
+
+import org.apache.ti.pageflow.Forward;
+import org.apache.ti.pageflow.PageFlowException;
+import org.apache.ti.pageflow.interceptor.Interceptor;
+import org.apache.ti.pageflow.interceptor.InterceptorChain;
+import org.apache.ti.pageflow.interceptor.InterceptorContext;
+import org.apache.ti.pageflow.interceptor.InterceptorException;
+import org.apache.ti.pageflow.interceptor.action.ActionInterceptor;
+import org.apache.ti.pageflow.interceptor.action.ActionInterceptorContext;
+
+import java.util.List;
+
+public class ActionInterceptors {
+
+ private static final class WrapActionInterceptorChain
+ extends InterceptorChain {
+
+ private ActionExecutor _actionExecutor;
+
+ public WrapActionInterceptorChain(InterceptorContext context, List/*< Interceptor >*/ interceptors,
+ ActionExecutor actionExecutor) {
+ super(context, interceptors);
+ _actionExecutor = actionExecutor;
+ }
+
+ protected Object invoke(Interceptor interceptor)
+ throws InterceptorException {
+ return ((ActionInterceptor) interceptor).wrapAction((ActionInterceptorContext) getContext(), this);
+ }
+
+ public Object continueChain()
+ throws InterceptorException {
+ if (!isEmpty()) {
+ return invoke(removeFirst());
+ } else {
+ try {
+ return _actionExecutor.execute();
+ } catch (PageFlowException e) {
+ throw new InterceptorException(e);
+ }
+ }
+ }
+ }
+
+ public static Forward wrapAction(ActionInterceptorContext context, List/*< Interceptor >*/ interceptors,
+ ActionExecutor actionExecutor)
+ throws InterceptorException, PageFlowException {
+ try {
+ if (interceptors != null) {
+ WrapActionInterceptorChain chain = new WrapActionInterceptorChain(context, interceptors, actionExecutor);
+ return (Forward) chain.continueChain();
+ } else {
+ return actionExecutor.execute();
+ }
+ } catch (InterceptorException e) {
+ Throwable cause = e.getCause();
+
+ if (cause instanceof PageFlowException) {
+ throw (PageFlowException) cause;
+ }
+
+ throw e;
+ }
+ }
+
+ public interface ActionExecutor {
+
+ public Forward execute() throws PageFlowException, InterceptorException;
+ }
+}
Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/action/internal/OriginalForward.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/action/internal/OriginalForward.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/action/internal/OriginalForward.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/action/internal/OriginalForward.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,145 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.interceptor.action.internal;
+
+import org.apache.ti.pageflow.interceptor.action.InterceptorForward;
+import org.apache.ti.pageflow.xwork.PageFlowActionContext;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+
+public class OriginalForward
+ extends InterceptorForward {
+
+ private Map _savedAttrs;
+ private boolean _restoreQueryString = false;
+
+ private static abstract class AttributeWrapper
+ implements Serializable {
+
+ private static final long serialVersionUID = 1;
+
+ public abstract Object get();
+ }
+
+ private static final class TransientAttributeWrapper
+ extends AttributeWrapper {
+
+ private transient Object _object;
+
+ public TransientAttributeWrapper(Object object) {
+ _object = object;
+ }
+
+ public Object get() {
+ return _object;
+ }
+ }
+
+ private static final class SerializableAttributeWrapper
+ extends AttributeWrapper {
+
+ private Object _object;
+
+ public SerializableAttributeWrapper(Object object) {
+ _object = object;
+ }
+
+ public Object get() {
+ return _object;
+ }
+ }
+
+ public OriginalForward() {
+ super();
+ saveRequestAttrs();
+
+ // By default, we do restore the original query string.
+ setRestoreQueryString(true);
+ }
+
+ private void saveRequestAttrs() {
+ _savedAttrs = new HashMap();
+
+ PageFlowActionContext actionContext = PageFlowActionContext.get();
+ Map requestScope = actionContext.getRequestScope();
+
+ for (Iterator i = requestScope.entrySet().iterator(); i.hasNext();) {
+ Map.Entry entry = (Map.Entry) i.next();
+ String attrName = (String) entry.getKey();
+ Object attrVal = entry.getValue();
+
+ if (attrVal instanceof Serializable) {
+ _savedAttrs.put(attrName, new SerializableAttributeWrapper(attrVal));
+ } else {
+ _savedAttrs.put(attrName, new TransientAttributeWrapper(attrVal));
+ }
+ }
+
+ setQueryString(actionContext.getRequestQueryString());
+ }
+
+ public void rehydrateRequest() {
+ //
+ // Restore the request attributes.
+ //
+ if (_savedAttrs != null) {
+ PageFlowActionContext actionContext = PageFlowActionContext.get();
+ Map requestScope = actionContext.getRequestScope();
+
+ for (Iterator i = _savedAttrs.entrySet().iterator(); i.hasNext();) {
+ Map.Entry entry = (Map.Entry) i.next();
+ String attrName = (String) entry.getKey();
+ if (requestScope.get(attrName) == null) {
+ Object value = ((AttributeWrapper) entry.getValue()).get();
+ if (value != null) requestScope.put(attrName, value);
+ }
+ }
+ }
+
+ //
+ // Restore the query string.
+ //
+ if (doesRestoreQueryString()) {
+ String queryString = getQueryString();
+
+ if (queryString != null && queryString.length() > 0) {
+ assert queryString.charAt(0) == '?';
+ String path = getPath();
+ if (path.indexOf('?') != -1) {
+ path += '&' + queryString.substring(1);
+ } else {
+ path += queryString;
+ }
+
+ setPath(path);
+ }
+ }
+ }
+
+ public boolean doesRestoreQueryString() {
+ return _restoreQueryString;
+ }
+
+ public void setRestoreQueryString(boolean restoreQueryString) {
+ _restoreQueryString = restoreQueryString;
+ }
+}
Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/request/RequestInterceptor.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/request/RequestInterceptor.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/request/RequestInterceptor.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/request/RequestInterceptor.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.interceptor.request;
+
+import org.apache.ti.pageflow.interceptor.AbstractInterceptor;
+import org.apache.ti.pageflow.interceptor.InterceptorChain;
+import org.apache.ti.pageflow.interceptor.InterceptorContext;
+import org.apache.ti.pageflow.interceptor.InterceptorException;
+
+
+/**
+ * A request interceptor, which can run before and/or after a request. Request interceptors are configured in the
+ * <code><request-interceptors></code> element of WEB-INF/beehive-netui-config.xml.
+ */
+public abstract class RequestInterceptor
+ extends AbstractInterceptor {
+
+ /**
+ * Callback invoked before the request is processed. During this method, {@link #cancelRequest} may be called to
+ * cancel further request processing. {@link InterceptorChain#continueChain} is called to invoke the rest of the
+ * interceptor chain, anywhere within this method (e.g., at the end, or within a try/finally).
+ */
+ public abstract void preRequest(RequestInterceptorContext context, InterceptorChain chain)
+ throws InterceptorException;
+
+ /**
+ * Callback invoked before the request is processed. {@link #preRequest} may be used instead.
+ */
+ public void preInvoke(InterceptorContext context, InterceptorChain chain) throws InterceptorException {
+ preRequest((RequestInterceptorContext) context, chain);
+ }
+
+ /**
+ * Callback invoked after the request is processed. {@link InterceptorChain#continueChain} should be called to
+ * invoke the rest of the interceptor chain, anywhere within this method (e.g., at the end, or within a try/finally).
+ */
+ public abstract void postRequest(RequestInterceptorContext context, InterceptorChain chain)
+ throws InterceptorException;
+
+ /**
+ * Callback invoked after the request is processed. {@link #postRequest} may be used instead.
+ */
+ public void postInvoke(InterceptorContext context, InterceptorChain chain) throws InterceptorException {
+ postRequest((RequestInterceptorContext) context, chain);
+ }
+
+ /**
+ * Cancel the request. After this is called, no further processing will happen in the request.
+ *
+ * @param context the current RequestInterceptorContext.
+ */
+ protected void cancelRequest(RequestInterceptorContext context) {
+ context.cancelRequest(this);
+ }
+}
Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/request/RequestInterceptorContext.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/request/RequestInterceptorContext.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/request/RequestInterceptorContext.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/request/RequestInterceptorContext.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.interceptor.request;
+
+import com.opensymphony.xwork.ActionContext;
+import org.apache.ti.pageflow.interceptor.InterceptorContext;
+import org.apache.ti.pageflow.internal.InternalConstants;
+import org.apache.ti.schema.config.RequestInterceptors;
+import org.apache.ti.util.config.ConfigUtil;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Context passed to methods on {@link RequestInterceptor}.
+ */
+public class RequestInterceptorContext
+ extends InterceptorContext {
+
+ private static final String INTERCEPTORS_LIST_ATTR = InternalConstants.ATTR_PREFIX + "requestInterceptors";
+
+ public RequestInterceptorContext() {
+ }
+
+ public void cancelRequest(RequestInterceptor interceptor) {
+ setResultOverride(null, interceptor);
+ }
+
+ public boolean requestWasCancelled() {
+ return hasResultOverride() && getResultOverride() == null;
+ }
+
+ public static void init(Map appScope) {
+ RequestInterceptors requestInterceptors = ConfigUtil.getConfig().getRequestInterceptors();
+
+ if (requestInterceptors != null) {
+ RequestInterceptors.Global globalRequestInterceptors = requestInterceptors.getGlobal();
+
+ if (globalRequestInterceptors != null) {
+ org.apache.ti.schema.config.Interceptor[] interceptors =
+ globalRequestInterceptors.getRequestInterceptorArray();
+ ArrayList/*< Interceptor >*/ interceptorsList = new ArrayList/*< Interceptor >*/();
+ addInterceptors(interceptors, interceptorsList, RequestInterceptor.class);
+ appScope.put(INTERCEPTORS_LIST_ATTR, interceptorsList);
+ }
+ }
+ }
+
+ public List/*< Interceptor >*/ getRequestInterceptors() {
+ return (List /*< Interceptor >*/) ActionContext.getContext().getApplication().get(INTERCEPTORS_LIST_ATTR);
+ }
+
+ public static void addInterceptor(RequestInterceptor interceptor) {
+ Map appScope = ActionContext.getContext().getApplication();
+
+ List/*< Interceptor >*/ interceptorsList = (List /*< Interceptor >*/) appScope.get(INTERCEPTORS_LIST_ATTR);
+ if (interceptorsList == null) interceptorsList = new ArrayList/*< Interceptor >*/();
+ interceptorsList.add(interceptor);
+ appScope.put(INTERCEPTORS_LIST_ATTR, interceptorsList);
+ }
+}
Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/internal/ActionResultImpl.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/internal/ActionResultImpl.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/internal/ActionResultImpl.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/internal/ActionResultImpl.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.internal;
+
+import org.apache.ti.pageflow.ActionResult;
+
+import java.io.PrintWriter;
+
+/**
+ * Encapsulation of the results returned by {@link org.apache.ti.pageflow.PageFlowUtils#strutsLookup}.
+ */
+public class ActionResultImpl implements ActionResult {
+
+ private String _uri = null;
+ private boolean _isRedirect = false;
+ private int _statusCode = 0;
+ private String _statusMessage = null;
+ private boolean _isError = false;
+
+
+ protected ActionResultImpl() {
+ }
+
+ public ActionResultImpl(String uri, boolean redirect, int statusCode, String statusMessage, boolean isError) {
+ _uri = uri;
+ _isRedirect = redirect;
+ _statusCode = statusCode;
+ _statusMessage = statusMessage;
+ _isError = isError;
+ }
+
+ public String getURI() {
+ return _uri;
+ }
+
+ public void setURI(String uri) {
+ _uri = uri;
+ }
+
+ public boolean isRedirect() {
+ return _isRedirect;
+ }
+
+ public void setRedirect(boolean redirect) {
+ _isRedirect = redirect;
+ }
+
+ public boolean isError() {
+ return _isError;
+ }
+
+ public void setError(boolean error) {
+ _isError = error;
+ }
+
+ public int getStatusCode() {
+ return _statusCode;
+ }
+
+ public void setStatusCode(int statusCode) {
+ _statusCode = statusCode;
+ }
+
+ public String getStatusMessage() {
+ return _statusMessage;
+ }
+
+ public void setStatusMessage(String statusMessage) {
+ _statusMessage = statusMessage;
+ }
+
+ public boolean hadCompileErrors() {
+ return false;
+ }
+
+ public void printCompileErrors(PrintWriter writer) {
+ }
+}
Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/internal/AdapterManager.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/internal/AdapterManager.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/internal/AdapterManager.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/internal/AdapterManager.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,150 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.internal;
+
+import com.opensymphony.xwork.ActionContext;
+import org.apache.commons.chain.web.WebContext;
+import org.apache.ti.pageflow.ContainerAdapter;
+import org.apache.ti.pageflow.DefaultContainerAdapter;
+import org.apache.ti.pageflow.adapter.Adapter;
+import org.apache.ti.util.internal.DiscoveryUtils;
+import org.apache.ti.util.logging.Logger;
+
+
+/**
+ * @exclude
+ */
+public class AdapterManager {
+
+ private static final Logger _log = Logger.getInstance(AdapterManager.class);
+
+ private static final String SERVLET_CONTAINER_ADAPTER_ATTR = InternalConstants.ATTR_PREFIX + "servletAdapter";
+ private static final String SERVLET_CONTAINER_ADAPTER_PROP = "beehive.servletcontaineradapter";
+
+ public static ContainerAdapter getContainerAdapter() {
+ ActionContext actionContext = ActionContext.getContext();
+ ContainerAdapter adapter = (ContainerAdapter) actionContext.getApplication().get(SERVLET_CONTAINER_ADAPTER_ATTR);
+ assert adapter != null : "ContainerAdapter manager not initialized correctly.";
+ return adapter;
+ }
+
+ public static ContainerAdapter init(WebContext webContext) {
+ ContainerAdapter containerAdapter = createServletContainerAdapter(webContext);
+ webContext.getApplicationScope().put(SERVLET_CONTAINER_ADAPTER_ATTR, containerAdapter);
+ return containerAdapter;
+ }
+
+ // TODO: this method could move to a more general place.
+ private static Adapter tryAdapter(WebContext webContext, Class adapterClass) {
+ try {
+ Adapter sa = (Adapter) adapterClass.newInstance();
+
+ try {
+ if (sa.accept(webContext)) {
+ _log.info("Adapter " + adapterClass.getName() + " accepted.");
+ sa.initialize(webContext);
+ return sa;
+ } else {
+ _log.info("Adapter " + adapterClass.getName() + " is present but did not accept.");
+ }
+ } catch (Exception e) {
+ _log.error(adapterClass.getName() + ".accept() threw an exception.", e);
+ } catch (LinkageError e) {
+ _log.error(adapterClass.getName() + ".accept() caused a linkage error and may be out of date.", e);
+ }
+ } catch (InstantiationException e) {
+ _log.error("Could not create instance of Adapter class " + adapterClass.getName(), e);
+ } catch (IllegalAccessException e) {
+ _log.error("Could not create instance of Adapter class " + adapterClass.getName(), e);
+ } catch (Exception e) {
+ _log.error("Error creating instance of Adapter class " + adapterClass.getName(), e);
+ }
+
+ return null;
+ }
+
+ /*
+ private static Class loadClass( ClassLoaders classLoaders, String className, Class spiClass )
+ {
+ for ( int i = 0; i < classLoaders.size(); ++i )
+ {
+ try
+ {
+ return classLoaders.get( i ).loadClass( className );
+ }
+ catch ( ClassNotFoundException e )
+ {
+ // ignore
+ }
+ }
+
+ _log.error( "Could not load class " + className + " to implement " + spiClass.getName() );
+ return null;
+ }
+ */
+
+ private static ContainerAdapter createServletContainerAdapter(WebContext webContext) {
+ String adapterClassName = System.getProperty(SERVLET_CONTAINER_ADAPTER_PROP);
+
+ if (adapterClassName != null) {
+ Class adapterClass =
+ DiscoveryUtils.loadImplementorClass(adapterClassName, ContainerAdapter.class);
+
+ if (adapterClass != null) {
+ ContainerAdapter sa = (ContainerAdapter) tryAdapter(webContext, adapterClass);
+ if (sa != null) return sa;
+ }
+ }
+
+ /*
+ ClassLoaders loaders = ClassLoaders.getAppLoaders( ContainerAdapter.class, AdapterManager.class, true );
+ DiscoverServiceNames dsn = new DiscoverServiceNames( loaders );
+ ResourceNameIterator i = dsn.findResourceNames( ContainerAdapter.class.getName() );
+
+ while ( i.hasNext() )
+ {
+ Class adapterClass = loadClass( loaders, i.nextResourceName(), ContainerAdapter.class );
+
+ if ( adapterClass != null )
+ {
+ ContainerAdapter sa =
+ ( ContainerAdapter ) tryAdapter( adapterClass, servletContext );
+ if ( sa != null ) return sa;
+ }
+ }
+
+ */
+
+ Class[] classes = DiscoveryUtils.getImplementorClasses(ContainerAdapter.class);
+
+ for (int i = 0; i < classes.length; i++) {
+ ContainerAdapter sa = (ContainerAdapter) tryAdapter(webContext, classes[i]);
+ if (sa != null) return sa;
+ }
+
+ _log.info("No ContainerAdapter specified or discovered; using " + DefaultContainerAdapter.class);
+ ContainerAdapter sa =
+ new DefaultContainerAdapter() {
+ public boolean accept(WebContext context) {
+ return true;
+ }
+ };
+ sa.initialize(webContext);
+ return sa;
+ }
+}
Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/internal/AnnotationReader.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/internal/AnnotationReader.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/internal/AnnotationReader.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/internal/AnnotationReader.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,123 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.internal;
+
+import org.apache.commons.chain.web.WebContext;
+import org.apache.ti.pageflow.PageFlowConstants;
+import org.apache.ti.pageflow.xwork.PageFlowActionContext;
+import org.apache.ti.schema.annotations.AnnotatedElement;
+import org.apache.ti.schema.annotations.AnnotationAttribute;
+import org.apache.ti.schema.annotations.ProcessedAnnotation;
+import org.apache.ti.schema.annotations.ProcessedAnnotationsDocument;
+import org.apache.ti.util.SourceResolver;
+import org.apache.ti.util.logging.Logger;
+import org.apache.xmlbeans.XmlException;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.lang.reflect.Member;
+import java.net.URL;
+
+/**
+ * Utility for reading XML files that describe annotations in classes. These files are generated during Page Flow build.
+ */
+public class AnnotationReader
+ implements Serializable {
+
+ private static final Logger _log = Logger.getInstance(AnnotationReader.class);
+
+ private ProcessedAnnotationsDocument.ProcessedAnnotations _annotations;
+
+ public AnnotationReader(Class type, SourceResolver sourceResolver) {
+ String annotationsXml =
+ PageFlowConstants.PAGEFLOW_MODULE_CONFIG_GEN_DIR + "/jpf-annotations-"
+ + type.getName().replace('.', '-') + ".xml";
+
+ try {
+ WebContext webContext = PageFlowActionContext.get().getWebContext();
+ URL url = sourceResolver.resolve(annotationsXml, webContext);
+
+ if (url != null) {
+ ProcessedAnnotationsDocument doc = ProcessedAnnotationsDocument.Factory.parse(url);
+ _annotations = doc.getProcessedAnnotations();
+ }
+ } catch (XmlException e) {
+ _log.error("Error while parsing annotations XML file " + annotationsXml, e);
+ } catch (IOException e) {
+ _log.error("Error while reading annotations XML file " + annotationsXml, e);
+ }
+ }
+
+ public ProcessedAnnotation getAnnotation(String declarationName, String annotationTypeName) {
+ if (_annotations == null) return null;
+
+ AnnotatedElement[] elements = _annotations.getAnnotatedElementArray();
+
+ for (int i = 0; i < elements.length; i++) {
+ AnnotatedElement element = elements[i];
+ if (element.getElementName().equals(declarationName)) {
+ // For now, we can be sure that there's only one element in this array.
+ assert element.getAnnotationArray().length == 1 : element.getAnnotationArray().length;
+ ProcessedAnnotation pa = element.getAnnotationArray(0);
+ return pa.getAnnotationName().equals(annotationTypeName) ? pa : null;
+ }
+ }
+
+ return null;
+ }
+
+ public ProcessedAnnotation getJpfAnnotation(Member member, String annotationTypeName) {
+ return getAnnotation(member.getName(), InternalConstants.ANNOTATION_QUALIFIER + annotationTypeName);
+ }
+
+ public ProcessedAnnotation getJpfAnnotation(Class type, String annotationTypeName) {
+ return getAnnotation(type.getName(), InternalConstants.ANNOTATION_QUALIFIER + annotationTypeName);
+ }
+
+ public static String getStringAttribute(ProcessedAnnotation ann, String attrName) {
+ AnnotationAttribute[] attrs = ann.getAnnotationAttributeArray();
+
+ for (int i = 0; i < attrs.length; i++) {
+ AnnotationAttribute attr = attrs[i];
+
+ if (attr.getAttributeName().equals(attrName)) {
+ String value = attr.getStringValue1();
+ assert value != null : "attribute " + attrName + " did not have a String value";
+ return value;
+ }
+ }
+
+ return null;
+ }
+
+ public static ProcessedAnnotation[] getAnnotationArrayAttribute(ProcessedAnnotation ann, String attrName) {
+ AnnotationAttribute[] attrs = ann.getAnnotationAttributeArray();
+
+ for (int i = 0; i < attrs.length; i++) {
+ AnnotationAttribute attr = attrs[i];
+
+ if (attr.getAttributeName().equals(attrName)) {
+ ProcessedAnnotation[] array = attr.getAnnotationValueArray();
+ assert array != null : "attribute " + attrName + " did not have an array of annotations.";
+ return array;
+ }
+ }
+
+ return null;
+ }
+}
Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/internal/AnyBeanActionForm.java.disabled
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/internal/AnyBeanActionForm.java.disabled?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/internal/AnyBeanActionForm.java.disabled (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/internal/AnyBeanActionForm.java.disabled Thu Aug 25 22:46:03 2005
@@ -0,0 +1,204 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.internal;
+
+import org.apache.ti.pageflow.FormData;
+import org.apache.ti.pageflow.Validatable;
+import org.apache.ti.pageflow.xwork.PageFlowAction;
+import org.apache.ti.pageflow.handler.ReloadableClassHandler;
+import org.apache.ti.pageflow.handler.Handlers;
+import org.apache.ti.pageflow.xwork.PageFlowAction;
+import org.apache.ti.util.logging.Logger;
+
+import javax.servlet.http.HttpServletRequest;
+
+
+public class AnyBeanActionForm extends FormData
+{
+ private static final Logger _log = Logger.getInstance( AnyBeanActionForm.class );
+
+ private Object _bean;
+
+
+ public AnyBeanActionForm()
+ {
+ }
+
+ public AnyBeanActionForm( Object bean )
+ {
+ _bean = bean;
+ }
+
+ public Object getBean()
+ {
+ return _bean;
+ }
+
+ public void setBean( Object bean )
+ {
+ _bean = bean;
+ }
+
+ public ActionErrors validate( ActionMapping mapping, HttpServletRequest request )
+ {
+ assert _bean != null;
+ String beanName = mapping.getAttribute();
+ return validateBean( _bean, beanName, mapping, request );
+ }
+
+ public String toString()
+ {
+ return "[AnyBeanActionForm wrapper for " + _bean + ']';
+ }
+}
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.internal;
+
+import org.apache.ti.pageflow.FormData;
+import org.apache.ti.pageflow.Validatable;
+import org.apache.ti.pageflow.xwork.PageFlowAction;
+import org.apache.ti.pageflow.handler.ReloadableClassHandler;
+import org.apache.ti.pageflow.handler.Handlers;
+import org.apache.ti.pageflow.xwork.PageFlowAction;
+import org.apache.ti.util.logging.Logger;
+
+import javax.servlet.http.HttpServletRequest;
+
+
+public class AnyBeanActionForm extends FormData
+{
+ private static final Logger _log = Logger.getInstance( AnyBeanActionForm.class );
+
+ private Object _bean;
+
+
+ public AnyBeanActionForm()
+ {
+ }
+
+ public AnyBeanActionForm( Object bean )
+ {
+ _bean = bean;
+ }
+
+ public Object getBean()
+ {
+ return _bean;
+ }
+
+ public void setBean( Object bean )
+ {
+ _bean = bean;
+ }
+
+ public ActionErrors validate( ActionMapping mapping, HttpServletRequest request )
+ {
+ assert _bean != null;
+ String beanName = mapping.getAttribute();
+ return validateBean( _bean, beanName, mapping, request );
+ }
+
+ public String toString()
+ {
+ return "[AnyBeanActionForm wrapper for " + _bean + ']';
+ }
+}
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.internal;
+
+import org.apache.ti.pageflow.FormData;
+import org.apache.ti.pageflow.Validatable;
+import org.apache.ti.pageflow.xwork.PageFlowAction;
+import org.apache.ti.pageflow.handler.ReloadableClassHandler;
+import org.apache.ti.pageflow.handler.Handlers;
+import org.apache.ti.pageflow.xwork.PageFlowAction;
+import org.apache.ti.util.logging.Logger;
+
+import javax.servlet.http.HttpServletRequest;
+
+
+public class AnyBeanActionForm extends FormData
+{
+ private static final Logger _log = Logger.getInstance( AnyBeanActionForm.class );
+
+ private Object _bean;
+
+
+ public AnyBeanActionForm()
+ {
+ }
+
+ public AnyBeanActionForm( Object bean )
+ {
+ _bean = bean;
+ }
+
+ public Object getBean()
+ {
+ return _bean;
+ }
+
+ public void setBean( Object bean )
+ {
+ _bean = bean;
+ }
+
+ public ActionErrors validate( ActionMapping mapping, HttpServletRequest request )
+ {
+ assert _bean != null;
+ String beanName = mapping.getAttribute();
+ return validateBean( _bean, beanName, mapping, request );
+ }
+
+ public String toString()
+ {
+ return "[AnyBeanActionForm wrapper for " + _bean + ']';
+ }
+}
Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/internal/BindingUpdateError.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/internal/BindingUpdateError.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/internal/BindingUpdateError.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/internal/BindingUpdateError.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,96 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.internal;
+
+
+/**
+ * Encapsulation of an error that happens when a databinding expression is applied on POST.
+ */
+public class BindingUpdateError implements java.io.Serializable {
+
+ private String _expression;
+ private String _message;
+ private Throwable _cause;
+
+ /**
+ * Constructor to initialize all values.
+ *
+ * @param expression the expression associated with this error.
+ * @param message the error message.
+ * @param cause the Throwable that caused the error.
+ */
+ public BindingUpdateError(String expression, String message, Throwable cause) {
+ _expression = expression;
+ _message = message;
+ _cause = cause;
+ }
+
+ /**
+ * Get the expression associated with this error.
+ *
+ * @return a String containing the expression associated with this error.
+ */
+ public String getExpression() {
+ return _expression;
+ }
+
+ /**
+ * Set the expression associated with this error.
+ *
+ * @param expression a String containing the expression associated with this error.
+ */
+ public void setExpression(String expression) {
+ _expression = expression;
+ }
+
+ /**
+ * Get the error message.
+ *
+ * @return a String containing the error message.
+ */
+ public String getMessage() {
+ return _message;
+ }
+
+ /**
+ * Set the error message.
+ *
+ * @param message a String containing the error message.
+ */
+ public void setMessage(String message) {
+ _message = message;
+ }
+
+ /**
+ * Get the cause of the error.
+ *
+ * @return the Throwable that caused the error.
+ */
+ public Throwable getCause() {
+ return _cause;
+ }
+
+ /**
+ * Set the cause of the error.
+ *
+ * @param cause the Throwable that caused the error.
+ */
+ public void setCause(Throwable cause) {
+ _cause = cause;
+ }
+}
Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/internal/CachedFacesBackingInfo.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/internal/CachedFacesBackingInfo.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/internal/CachedFacesBackingInfo.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/internal/CachedFacesBackingInfo.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,60 @@
+/*
+* Copyright 2004 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+* $Header:$
+*/
+package org.apache.ti.pageflow.internal;
+
+import org.apache.ti.pageflow.handler.Handlers;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+
+
+/**
+ * Information that is cached per pageflow class.
+ */
+public class CachedFacesBackingInfo
+ extends CachedSharedFlowRefInfo {
+
+ /**
+ * The PageFlowController-initialized member field -- may or may not be present.
+ */
+ private Field _pageFlowMemberField;
+
+
+ public CachedFacesBackingInfo(Class facesBackingClass) {
+ Field[] fields = facesBackingClass.getDeclaredFields();
+ AnnotationReader annReader = Handlers.get().getAnnotationHandler().getAnnotationReader(facesBackingClass);
+
+ for (int i = 0; i < fields.length; i++) {
+ Field field = fields[i];
+
+ if (annReader.getJpfAnnotation(field, "pageFlowField") != null) {
+ _pageFlowMemberField = field;
+ if (!Modifier.isPublic(_pageFlowMemberField.getModifiers())) {
+ _pageFlowMemberField.setAccessible(true);
+ }
+ }
+ }
+
+ initSharedFlowFields(annReader, fields);
+ }
+
+ public Field getPageFlowMemberField() {
+ return _pageFlowMemberField;
+ }
+}
+
Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/internal/CachedPageFlowInfo.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/internal/CachedPageFlowInfo.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/internal/CachedPageFlowInfo.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/internal/CachedPageFlowInfo.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.internal;
+
+import org.apache.ti.pageflow.PageFlowConstants;
+import org.apache.ti.pageflow.handler.Handlers;
+
+
+/**
+ * Information that is cached per pageflow class.
+ */
+public class CachedPageFlowInfo
+ extends CachedSharedFlowRefInfo {
+
+ /**
+ * A cached copy of the namespace for this PageFlowController.
+ */
+ private String _namespace;
+
+ /**
+ * A cached copy of the webapp-relative URI for this PageFlowController.
+ */
+ private String _path;
+
+
+ public CachedPageFlowInfo(Class pageFlowClass) {
+ AnnotationReader annReader = Handlers.get().getAnnotationHandler().getAnnotationReader(pageFlowClass);
+ initSharedFlowFields(annReader, pageFlowClass.getDeclaredFields());
+
+ // URI
+ String className = pageFlowClass.getName();
+ _path = '/' + className.replace('.', '/') + PageFlowConstants.PAGEFLOW_EXTENSION;
+
+ // namespace
+ _namespace = InternalUtils.inferNamespaceFromClassName(className);
+ }
+
+ public String getNamespace() {
+ return _namespace;
+ }
+
+ public String getPath() {
+ return _path;
+ }
+}
Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/internal/CachedSharedFlowRefInfo.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/internal/CachedSharedFlowRefInfo.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/internal/CachedSharedFlowRefInfo.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/internal/CachedSharedFlowRefInfo.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.internal;
+
+import org.apache.ti.schema.annotations.ProcessedAnnotation;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.List;
+
+public class CachedSharedFlowRefInfo {
+
+ public static class SharedFlowFieldInfo {
+
+ public Field field;
+ public String sharedFlowName;
+ }
+
+ /**
+ * The SharedFlowController-initialized member fields -- may or may not be present.
+ */
+ private SharedFlowFieldInfo[] _sharedFlowMemberFields;
+
+ protected void initSharedFlowFields(AnnotationReader annReader, Field[] fields) {
+ List/*< SharedFlowFieldInfo >*/ sharedFlowFields = null;
+
+ for (int i = 0; i < fields.length; i++) {
+ Field field = fields[i];
+
+ ProcessedAnnotation sharedFlowFieldAnn = annReader.getJpfAnnotation(field, "sharedFlowField");
+
+ if (sharedFlowFieldAnn != null) {
+ if (!Modifier.isPublic(field.getModifiers())) field.setAccessible(true);
+ if (sharedFlowFields == null) sharedFlowFields = new ArrayList/*< SharedFlowFieldInfo >*/();
+ SharedFlowFieldInfo info = new SharedFlowFieldInfo();
+ info.field = field;
+ info.sharedFlowName = AnnotationReader.getStringAttribute(sharedFlowFieldAnn, "name");
+ sharedFlowFields.add(info);
+ }
+ }
+
+ if (sharedFlowFields != null) {
+ _sharedFlowMemberFields = (SharedFlowFieldInfo[]) sharedFlowFields.toArray(new SharedFlowFieldInfo[sharedFlowFields.size()]);
+ }
+ }
+
+ public SharedFlowFieldInfo[] getSharedFlowMemberFields() {
+ return _sharedFlowMemberFields;
+ }
+}
Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/internal/DefaultAnnotationHandler.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/internal/DefaultAnnotationHandler.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/internal/DefaultAnnotationHandler.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/internal/DefaultAnnotationHandler.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.internal;
+
+import org.apache.ti.pageflow.handler.AnnotationHandler;
+import org.apache.ti.pageflow.xwork.PageFlowActionContext;
+import org.apache.ti.util.SourceResolver;
+import org.apache.ti.util.internal.concurrent.InternalConcurrentHashMap;
+
+import java.util.Map;
+
+public class DefaultAnnotationHandler extends DefaultHandler implements AnnotationHandler {
+
+ private static final String CACHE_ATTR = InternalConstants.ATTR_PREFIX + "annCache";
+
+ private SourceResolver _sourceResolver;
+
+ public void setSourceResolver(SourceResolver sourceResolver) {
+ _sourceResolver = sourceResolver;
+ }
+
+ public AnnotationReader getAnnotationReader(Class type) {
+ Map appScope = PageFlowActionContext.get().getApplication();
+ InternalConcurrentHashMap cache = (InternalConcurrentHashMap) appScope.get(CACHE_ATTR);
+
+ if (cache == null) {
+ cache = new InternalConcurrentHashMap();
+ appScope.put(CACHE_ATTR, cache);
+ }
+
+ AnnotationReader reader = (AnnotationReader) cache.get(type);
+
+ if (reader == null) {
+ reader = new AnnotationReader(type, _sourceResolver);
+ cache.put(type, reader);
+ }
+
+ return reader;
+ }
+
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org