Repository: deltaspike Updated Branches: refs/heads/master 15fef2fdb -> d05f67195
DELTASPIKE-612 optional ConfigurableNavigationHandlerWrapper Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/d05f6719 Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/d05f6719 Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/d05f6719 Branch: refs/heads/master Commit: d05f671957582385a60a2e8d39d94fa80a83620c Parents: 15fef2f Author: gpetracek <[email protected]> Authored: Mon May 26 22:42:37 2014 +0200 Committer: gpetracek <[email protected]> Committed: Mon May 26 22:42:37 2014 +0200 ---------------------------------------------------------------------- .../DeltaSpikeNavigationHandlerWrapper.java | 63 ++++++++++++++++ .../NavigationHandlerAwareApplication.java | 78 ++++++++++++++++++++ ...avigationHandlerAwareApplicationFactory.java | 57 ++++++++++++++ .../main/resources/META-INF/faces-config.xml | 2 +- 4 files changed, 199 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/deltaspike/blob/d05f6719/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/navigation/DeltaSpikeNavigationHandlerWrapper.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/navigation/DeltaSpikeNavigationHandlerWrapper.java b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/navigation/DeltaSpikeNavigationHandlerWrapper.java new file mode 100644 index 0000000..28ccb82 --- /dev/null +++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/navigation/DeltaSpikeNavigationHandlerWrapper.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ +package org.apache.deltaspike.jsf.impl.navigation; + +import javax.faces.application.ConfigurableNavigationHandler; +import javax.faces.application.ConfigurableNavigationHandlerWrapper; +import javax.faces.application.NavigationCase; +import javax.faces.context.FacesContext; +import java.util.Map; +import java.util.Set; + +@SuppressWarnings("UnusedDeclaration") +public class DeltaSpikeNavigationHandlerWrapper extends ConfigurableNavigationHandlerWrapper +{ + private final ConfigurableNavigationHandler wrapped; + private final DeltaSpikeNavigationHandler deltaSpikeNavigationHandler; + + public DeltaSpikeNavigationHandlerWrapper(ConfigurableNavigationHandler wrapped) + { + this.wrapped = wrapped; + //only for delegating the methods implemented by DeltaSpikeNavigationHandler + this.deltaSpikeNavigationHandler = new DeltaSpikeNavigationHandler(wrapped); + } + + @Override + public void handleNavigation(FacesContext context, String fromAction, String outcome) + { + this.deltaSpikeNavigationHandler.handleNavigation(context, fromAction, outcome); + } + + @Override + public Map<String, Set<NavigationCase>> getNavigationCases() + { + return this.deltaSpikeNavigationHandler.getNavigationCases(); + } + + @Override + public NavigationCase getNavigationCase(FacesContext context, String fromAction, String outcome) + { + return this.deltaSpikeNavigationHandler.getNavigationCase(context, fromAction, outcome); + } + + public ConfigurableNavigationHandler getWrapped() + { + return wrapped; + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/d05f6719/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/navigation/NavigationHandlerAwareApplication.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/navigation/NavigationHandlerAwareApplication.java b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/navigation/NavigationHandlerAwareApplication.java new file mode 100644 index 0000000..b2ce07c --- /dev/null +++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/navigation/NavigationHandlerAwareApplication.java @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ +package org.apache.deltaspike.jsf.impl.navigation; + +import org.apache.deltaspike.core.util.ClassUtils; +import org.apache.deltaspike.core.util.ExceptionUtils; + +import javax.faces.application.Application; +import javax.faces.application.ApplicationWrapper; +import javax.faces.application.ConfigurableNavigationHandler; +import javax.faces.application.NavigationHandler; +import java.lang.reflect.Constructor; + +public class NavigationHandlerAwareApplication extends ApplicationWrapper +{ + private final Application wrapped; + + public NavigationHandlerAwareApplication(Application wrapped) + { + this.wrapped = wrapped; + } + + @Override + public void setNavigationHandler(NavigationHandler handler) + { + Class wrapperClass = ClassUtils + .tryToLoadClassForName("javax.faces.application.ConfigurableNavigationHandlerWrapper"); + + //jsf 2.2+ + if (wrapperClass != null) + { + if (ConfigurableNavigationHandler.class.isAssignableFrom(handler.getClass())) + { + try + { + Class deltaSpikeWrapperClass = ClassUtils.tryToLoadClassForName( + "org.apache.deltaspike.jsf.impl.navigation.DeltaSpikeNavigationHandlerWrapper"); + Constructor deltaSpikeNavigationHandlerWrapperConstructor = + deltaSpikeWrapperClass.getConstructor(ConfigurableNavigationHandler.class); + + NavigationHandler navigationHandlerWrapper = + (NavigationHandler)deltaSpikeNavigationHandlerWrapperConstructor.newInstance(handler); + this.wrapped.setNavigationHandler(navigationHandlerWrapper); + return; + } + catch (Exception e) + { + throw ExceptionUtils.throwAsRuntimeException(e); + } + } + } + + //jsf 2.0 and 2.1 + this.wrapped.setNavigationHandler(new DeltaSpikeNavigationHandler(handler)); + } + + @Override + public Application getWrapped() + { + return wrapped; + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/d05f6719/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/navigation/NavigationHandlerAwareApplicationFactory.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/navigation/NavigationHandlerAwareApplicationFactory.java b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/navigation/NavigationHandlerAwareApplicationFactory.java new file mode 100644 index 0000000..59491f6 --- /dev/null +++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/navigation/NavigationHandlerAwareApplicationFactory.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ +package org.apache.deltaspike.jsf.impl.navigation; + +import org.apache.deltaspike.core.spi.activation.Deactivatable; +import org.apache.deltaspike.core.util.ClassDeactivationUtils; + +import javax.faces.application.Application; +import javax.faces.application.ApplicationFactory; + +public class NavigationHandlerAwareApplicationFactory extends ApplicationFactory implements Deactivatable +{ + private final ApplicationFactory wrapped; + + public NavigationHandlerAwareApplicationFactory(ApplicationFactory wrapped) + { + this.wrapped = wrapped; + } + + @Override + public Application getApplication() + { + if (ClassDeactivationUtils.isActivated(getClass())) + { + return new NavigationHandlerAwareApplication(wrapped.getApplication()); + } + + return wrapped.getApplication(); + } + + @Override + public void setApplication(Application application) + { + wrapped.setApplication(application); + } + + public ApplicationFactory getWrapped() + { + return wrapped; + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/d05f6719/deltaspike/modules/jsf/impl/src/main/resources/META-INF/faces-config.xml ---------------------------------------------------------------------- diff --git a/deltaspike/modules/jsf/impl/src/main/resources/META-INF/faces-config.xml b/deltaspike/modules/jsf/impl/src/main/resources/META-INF/faces-config.xml index fbebb8f..c4345dc 100644 --- a/deltaspike/modules/jsf/impl/src/main/resources/META-INF/faces-config.xml +++ b/deltaspike/modules/jsf/impl/src/main/resources/META-INF/faces-config.xml @@ -30,7 +30,6 @@ <application> <view-handler>org.apache.deltaspike.jsf.impl.view.DeltaSpikeViewHandler</view-handler> - <navigation-handler>org.apache.deltaspike.jsf.impl.navigation.DeltaSpikeNavigationHandler</navigation-handler> <action-listener>org.apache.deltaspike.jsf.impl.listener.action.DeltaSpikeActionListener</action-listener> <resource-handler>org.apache.deltaspike.jsf.impl.resource.DeltaSpikeResourceHandler</resource-handler> @@ -51,6 +50,7 @@ <factory> <lifecycle-factory>org.apache.deltaspike.jsf.impl.listener.request.DeltaSpikeLifecycleFactoryWrapper</lifecycle-factory> <faces-context-factory>org.apache.deltaspike.jsf.impl.listener.request.DeltaSpikeFacesContextFactory</faces-context-factory> + <application-factory>org.apache.deltaspike.jsf.impl.navigation.NavigationHandlerAwareApplicationFactory</application-factory> </factory> </faces-config>
