You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by pa...@apache.org on 2013/11/15 22:00:04 UTC
[2/4] git commit: revert wicket-cdi-1.1 to wicket-cdi
revert wicket-cdi-1.1 to wicket-cdi
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/6f5464a8
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/6f5464a8
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/6f5464a8
Branch: refs/heads/wicket-cdi-1.1-rewrite
Commit: 6f5464a8f0afc9170b71f4f462076e601e3d2768
Parents: 49840c0
Author: Emond Papegaaij <em...@topicus.nl>
Authored: Fri Nov 15 21:57:37 2013 +0100
Committer: Emond Papegaaij <em...@topicus.nl>
Committed: Fri Nov 15 21:57:37 2013 +0100
----------------------------------------------------------------------
.../apache/wicket/cdi/AbstractCdiContainer.java | 84 --
.../org/apache/wicket/cdi/AbstractInjector.java | 88 +-
.../apache/wicket/cdi/ApplicationQualifier.java | 45 -
.../main/java/org/apache/wicket/cdi/Auto.java | 37 -
.../org/apache/wicket/cdi/AutoConversation.java | 49 +
.../apache/wicket/cdi/BeanManagerLookup.java | 43 -
.../org/apache/wicket/cdi/BehaviorInjector.java | 85 +-
.../org/apache/wicket/cdi/CdiConfiguration.java | 744 +++++---------
.../org/apache/wicket/cdi/CdiContainer.java | 167 ++++
.../apache/wicket/cdi/CdiShutdownCleaner.java | 112 ++-
.../wicket/cdi/CdiWebApplicationFactory.java | 207 ----
.../org/apache/wicket/cdi/CdiWicketFilter.java | 49 -
.../apache/wicket/cdi/ComponentInjector.java | 86 +-
.../wicket/cdi/ConfigurationParameters.java | 149 ---
.../cdi/ConversationExpiredException.java | 104 +-
.../wicket/cdi/ConversationExpiryChecker.java | 146 ++-
.../wicket/cdi/ConversationIdMetaKey.java | 50 +-
.../apache/wicket/cdi/ConversationManager.java | 124 ---
.../wicket/cdi/ConversationPropagation.java | 157 ++-
.../wicket/cdi/ConversationPropagator.java | 977 +++++++++----------
.../org/apache/wicket/cdi/Conversational.java | 40 -
.../wicket/cdi/ConversationalComponent.java | 11 +-
.../java/org/apache/wicket/cdi/DetachEvent.java | 1 +
.../apache/wicket/cdi/DetachEventEmitter.java | 16 +-
.../cdi/ICdiAwareRequestCycleListener.java | 39 +
.../wicket/cdi/IConversationPropagation.java | 20 +-
.../wicket/cdi/INonContextualManager.java | 111 ++-
.../org/apache/wicket/cdi/NonContextual.java | 308 +++---
.../apache/wicket/cdi/NonContextualManager.java | 152 +--
.../java/org/apache/wicket/cdi/Propagation.java | 36 -
.../org/apache/wicket/cdi/SessionInjector.java | 83 +-
.../java/org/apache/wicket/cdi/WicketApp.java | 50 -
32 files changed, 1730 insertions(+), 2640 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/6f5464a8/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/AbstractCdiContainer.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/AbstractCdiContainer.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/AbstractCdiContainer.java
deleted file mode 100644
index a795d0f..0000000
--- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/AbstractCdiContainer.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * 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.wicket.cdi;
-
-import javax.enterprise.context.Conversation;
-import javax.servlet.http.HttpServletRequest;
-
-import org.apache.wicket.Page;
-import org.apache.wicket.request.cycle.RequestCycle;
-import org.apache.wicket.util.lang.Args;
-
-/**
- * Provides access to CDI features from inside a Wicket request
- *
- * @author igor
- */
-public abstract class AbstractCdiContainer
-{
-
- /**
- * Activates the conversational context and starts the conversation with the
- * specified cid
- *
- * @param cycle
- * @param cid
- */
- public abstract void activateConversationalContext(RequestCycle cycle, String cid);
-
- /**
- * Retrieve the current conversation associated with the ConversationContext
- *
- * @return The current Conversation attached to the current Conversation
- * Context
- */
- public abstract Conversation getCurrentConversation();
-
- protected HttpServletRequest getRequest(RequestCycle cycle)
- {
- return (HttpServletRequest)cycle.getRequest().getContainerRequest();
- }
-
- /**
- * Retrieves a conversation id, if any, that is associated with a
- * {@link Page} instance
- *
- * @param page
- * page instance
- * @return conversation id, if any
- */
- public String getConversationMarker(Page page)
- {
- return page.getMetaData(ConversationIdMetaKey.INSTANCE);
- }
-
- /**
- * Removes conversation marker from the page instance which prevents the
- * conversation from propagating to the page. This method should usually be
- * called from page's {@code onDetach()} method.
- *
- * @param page
- */
- public void removeConversationMarker(Page page)
- {
- Args.notNull(page, "page");
-
- page.setMetaData(ConversationIdMetaKey.INSTANCE, null);
- page.getPageParameters().remove(ConversationPropagator.CID_ATTR);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/wicket/blob/6f5464a8/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/AbstractInjector.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/AbstractInjector.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/AbstractInjector.java
index a7f3ddc..b77aa6e 100644
--- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/AbstractInjector.java
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/AbstractInjector.java
@@ -1,43 +1,45 @@
-/*
- * 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.wicket.cdi;
-
-import javax.inject.Inject;
-
-/**
- * Base class for injectors
- *
- * @author igor
- */
-public class AbstractInjector<T>
-{
- @Inject
- INonContextualManager nonContextualManager;
-
- @Inject
- CdiConfiguration cdiConfiguration;
-
- protected void postConstruct(T instance)
- {
- nonContextualManager.postConstruct(instance);
- }
-
- protected void inject(T instance)
- {
- nonContextualManager.inject(instance);
- }
-}
+/*
+ * 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.wicket.cdi;
+
+import org.apache.wicket.util.lang.Args;
+
+/**
+ * Base class for injectors
+ *
+ * @author igor
+ */
+class AbstractInjector
+{
+ private final CdiContainer container;
+
+ public AbstractInjector(CdiContainer container)
+ {
+ Args.notNull(container, "container");
+ this.container = container;
+ }
+
+ protected <T> void postConstruct(T instance)
+ {
+ container.getNonContextualManager().postConstruct(instance);
+ }
+
+ protected <T> void inject(T instance)
+ {
+ container.getNonContextualManager().inject(instance);
+ }
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/6f5464a8/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ApplicationQualifier.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ApplicationQualifier.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ApplicationQualifier.java
deleted file mode 100644
index 5b95502..0000000
--- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ApplicationQualifier.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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.wicket.cdi;
-
-import javax.enterprise.util.AnnotationLiteral;
-
-/**
- * Allows for Programmatic lookup of WebApplications based on the Named
- * Annotation.
- *
- * @author jsarman
- */
-public class ApplicationQualifier extends AnnotationLiteral<WicketApp> implements WicketApp
-{
- private static final long serialVersionUID = 1L;
-
- private String value;
-
- public ApplicationQualifier(String value)
- {
- super();
- this.value = value;
- }
-
- @Override
- public String value()
- {
- return value;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/wicket/blob/6f5464a8/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/Auto.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/Auto.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/Auto.java
deleted file mode 100644
index 0acc6cc..0000000
--- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/Auto.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * 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.wicket.cdi;
-
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-import javax.inject.Qualifier;
-
-/**
- * Qualifier for injecting the Automatic Conversation begin boolean
- *
- * @author jsarman
- */
-@Qualifier
-@Target({ ElementType.TYPE, ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD })
-@Retention(RetentionPolicy.RUNTIME)
-public @interface Auto {
-
-}
http://git-wip-us.apache.org/repos/asf/wicket/blob/6f5464a8/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/AutoConversation.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/AutoConversation.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/AutoConversation.java
new file mode 100644
index 0000000..0193a7d
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/AutoConversation.java
@@ -0,0 +1,49 @@
+/*
+ * 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.wicket.cdi;
+
+import javax.enterprise.context.ConversationScoped;
+
+import org.apache.wicket.util.io.IClusterable;
+
+/**
+ * A bean that can be used to override whether the lifecycle of the conversation should be managed
+ * automatically or not. See {@link CdiConfiguration#setAutoConversationManagement(boolean)} for
+ * details.
+ *
+ * @author igor
+ */
+@ConversationScoped
+public class AutoConversation implements IClusterable
+{
+ private boolean automatic;
+
+ public AutoConversation()
+ {
+ automatic = false;
+ }
+
+ public void setAutomatic(boolean automatic)
+ {
+ this.automatic = automatic;
+ }
+
+ public boolean isAutomatic()
+ {
+ return automatic;
+ }
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/6f5464a8/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/BeanManagerLookup.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/BeanManagerLookup.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/BeanManagerLookup.java
deleted file mode 100644
index 97b0550..0000000
--- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/BeanManagerLookup.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * 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.wicket.cdi;
-
-import javax.enterprise.inject.spi.BeanManager;
-import javax.enterprise.inject.spi.CDI;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-
-public final class BeanManagerLookup
-{
- private BeanManagerLookup()
- {
- }
-
- public static BeanManager lookup()
- {
- try
- {
- BeanManager ret = InitialContext.doLookup("java:comp/BeanManager");
- if (ret != null)
- return ret;
- }
- catch (NamingException e)
- {
- }
- return CDI.current().getBeanManager();
- }
-}
http://git-wip-us.apache.org/repos/asf/wicket/blob/6f5464a8/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/BehaviorInjector.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/BehaviorInjector.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/BehaviorInjector.java
index 61d473f..0ba6219 100644
--- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/BehaviorInjector.java
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/BehaviorInjector.java
@@ -1,40 +1,45 @@
-/*
- * 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.wicket.cdi;
-
-import javax.enterprise.context.ApplicationScoped;
-
-import org.apache.wicket.IBehaviorInstantiationListener;
-import org.apache.wicket.behavior.Behavior;
-
-/**
- * Injects components with CDI dependencies
- *
- * @author igor
- */
-@ApplicationScoped
-public class BehaviorInjector extends AbstractInjector<Behavior>
- implements
- IBehaviorInstantiationListener
-{
-
- @Override
- public void onInstantiation(Behavior behavior)
- {
- inject(behavior);
- }
-}
+/*
+ * 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.wicket.cdi;
+
+import org.apache.wicket.IBehaviorInstantiationListener;
+import org.apache.wicket.behavior.Behavior;
+
+/**
+ * Injects components with CDI dependencies
+ *
+ * @author igor
+ *
+ */
+class BehaviorInjector extends AbstractInjector implements IBehaviorInstantiationListener
+{
+ /**
+ * Constructor
+ *
+ * @param container
+ */
+ public BehaviorInjector(CdiContainer container)
+ {
+ super(container);
+ }
+
+ @Override
+ public void onInstantiation(Behavior behavior)
+ {
+ inject(behavior);
+ }
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/6f5464a8/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/CdiConfiguration.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/CdiConfiguration.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/CdiConfiguration.java
index 99b1880..10ae80a 100644
--- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/CdiConfiguration.java
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/CdiConfiguration.java
@@ -1,514 +1,230 @@
-/*
- * 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.wicket.cdi;
-
-import java.util.Iterator;
-import java.util.Map;
-import java.util.TreeMap;
-
-import javax.annotation.PostConstruct;
-import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.context.spi.CreationalContext;
-import javax.enterprise.inject.Produces;
-import javax.enterprise.inject.spi.Bean;
-import javax.enterprise.inject.spi.BeanManager;
-import javax.inject.Inject;
-
-import org.apache.wicket.Application;
-import org.apache.wicket.Component;
-import org.apache.wicket.WicketRuntimeException;
-import org.apache.wicket.application.IComponentOnBeforeRenderListener;
-import org.apache.wicket.request.IRequestHandler;
-import org.apache.wicket.request.Url;
-import org.apache.wicket.request.cycle.AbstractRequestCycleListener;
-import org.apache.wicket.request.cycle.IRequestCycleListener;
-import org.apache.wicket.request.cycle.RequestCycle;
-import org.apache.wicket.request.cycle.RequestCycleListenerCollection;
-import org.apache.wicket.util.lang.Args;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Configures CDI integration
- *
- * @author igor
- * @author jsarman
- */
-@ApplicationScoped
-public class CdiConfiguration
-{
- private static final Logger logger = LoggerFactory.getLogger(CdiConfiguration.class);
-
- @Inject
- AbstractCdiContainer container;
-
- @Inject
- INonContextualManager nonContextualManager;
-
- @Inject
- ConversationPropagator conversationPropagator;
-
- @Inject
- ConversationExpiryChecker conversationExpiryChecker;
-
- @Inject
- DetachEventEmitter detachEventEmitter;
-
- @Inject
- BehaviorInjector behaviorInjector;
-
- @Inject
- ComponentInjector componentInjector;
-
- @Inject
- SessionInjector sessionInjector;
-
- @Inject
- ConversationManager conversationManager;
-
- protected Map<String, ConfigurationParameters> parameters;
-
- /**
- * Not intended for public use. Use {@link #get()}
- */
- public CdiConfiguration()
- {
- }
-
-
- @PostConstruct
- public void init()
- {
- parameters = new TreeMap<String, ConfigurationParameters>();
- }
-
- public boolean isInjectComponents()
- {
- return getApplicationParameters().isInjectComponents();
- }
-
- /**
- * Flag to set if ComponentInjection is enabled.
- * <p/>
- * This method will throw IllegalStateException if called after configured.
- *
- * @param injectComponents
- * @return {@code this} for easy chaining
- * @deprecated Application Level Configuration replaced with
- * {@link CdiWicketFilter}
- */
- @Deprecated
- public CdiConfiguration setInjectComponents(boolean injectComponents)
- {
- ConfigurationParameters params = getApplicationParameters();
- if (params.isConfigured())
- {
- throw new IllegalStateException(
- "Component Injection can only be changed before configure is called");
- }
- params.setInjectComponents(injectComponents);
- return this;
- }
-
- public boolean isInjectApplication()
- {
- return getApplicationParameters().isInjectApplication();
- }
-
- /**
- * Flag to set if ApplicationInjection is enabled.
- * <p/>
- * This method will throw IllegalStateException if called after configured.
- *
- * @param injectApplication
- * @return {@code this} for easy chaining
- * @deprecated Application Level Configuration replaced with
- * {@link CdiWicketFilter}
- */
- @Deprecated
- public CdiConfiguration setInjectApplication(boolean injectApplication)
- {
- ConfigurationParameters params = getApplicationParameters();
- if (params.isConfigured())
- {
- throw new IllegalStateException(
- "Application Injection can only be changed before configure is called");
- }
- params.setInjectApplication(injectApplication);
- return this;
- }
-
- public boolean isInjectSession()
- {
- return getApplicationParameters().isInjectSession();
- }
-
- /**
- * Flag to set if SessionInjection is enabled.
- * <p/>
- * This method will throw IllegalStateException if called after configured.
- *
- * @param injectSession
- * @return {@code this} for easy chaining
- * @deprecated Application Level Configuration replaced with
- * {@link CdiWicketFilter}
- */
- @Deprecated
- public CdiConfiguration setInjectSession(boolean injectSession)
- {
- ConfigurationParameters params = getApplicationParameters();
- if (params.isConfigured())
- {
- throw new IllegalStateException(
- "Session Injection can only be changed before configure is called");
- }
- params.setInjectSession(injectSession);
- return this;
- }
-
- public boolean isInjectBehaviors()
- {
- return getApplicationParameters().isInjectBehaviors();
- }
-
- /**
- * Flag to set if BehaviorInjection is enabled.
- * <p/>
- * This method will throw IllegalStateException if called after configured.
- *
- * @param injectBehaviors
- * @return {@code this} for easy chaining
- * @deprecated Application Level Configuration replaced with
- * {@link CdiWicketFilter}
- */
- @Deprecated
- public CdiConfiguration setInjectBehaviors(boolean injectBehaviors)
- {
- ConfigurationParameters params = getApplicationParameters();
- if (params.isConfigured())
- {
- throw new IllegalStateException(
- "Behavior Injection can only be changed before configure is called");
- }
- params.setInjectBehaviors(injectBehaviors);
- return this;
- }
-
-
- public @Produces
- @Propagation
- IConversationPropagation getPropagation()
- {
- return getApplicationParameters().getPropagation();
- }
-
-
- public @Produces
- @Auto
- Boolean isAutoConversationManagement()
- {
- return getApplicationParameters().isAutoConversationManagement();
- }
-
- /**
- * Toggles automatic conversation management feature.
- * <p/>
- * Automatic conversation management controls the lifecycle of the
- * conversation based on presence of components implementing the
- * {@link ConversationalComponent} interface. If such components are found
- * in the page a conversation is marked persistent, and if they are not the
- * conversation is marked transient. This greatly simplifies the management
- * of conversation lifecycle.
- * <p/>
- * ConversationManagement can also be enable per Conversation after
- * configured. Once the CdiConfiguration is configured this call is passed
- * to {@link ConversationManager#setManageConversation(java.lang.Boolean) }
- * for the ConversationManager in the current ConversationScope. This allows
- * for ConversationManagement per active Conversation.
- * <p/>
- *
- * @param enabled
- * @return {@code this} for easy chaining
- */
- public CdiConfiguration setAutoConversationManagement(boolean enabled)
- {
- ConfigurationParameters params = getApplicationParameters();
- if (params.isConfigured())
- {
- if (container.getCurrentConversation().isTransient())
- {
- logger.warn("Not setting AutoConversationManagement because the conversation context is transient.");
- return this;
- }
- conversationManager.setManageConversation(enabled);
- }
- else
- {
- params.setAutoConversationManagement(enabled);
- }
- return this;
- }
-
- /**
- * Method to set the ConversationPropagation.
- * <p/>
- *
- * @param propagation
- * @return {@code this} for easy chaining
- */
- public CdiConfiguration setPropagation(IConversationPropagation propagation)
- {
- Args.notNull(propagation, "propagation");
-
- ConfigurationParameters params = getApplicationParameters();
- if (params.isConfigured())
- {
- if (container.getCurrentConversation().isTransient())
- {
- logger.warn("Not setting propagation because the conversation context is transient.");
- return this;
- }
- conversationManager.setPropagation(propagation);
- }
- else
- {
- params.setPropagation(propagation);
- }
- return this;
- }
-
- public INonContextualManager getNonContextualManager()
- {
- return nonContextualManager;
- }
-
- /**
- * @return true if configured for Application
- */
- public boolean isConfigured()
- {
- return getApplicationParameters().isConfigured();
- }
-
- protected ConfigurationParameters getApplicationParameters()
- {
- ConfigurationParameters params = parameters.get(Application.get().getApplicationKey());
- if (params == null)
- {
- try
- {
- Application app = Application.get();
- if (app.getApplicationKey() == null)
- {
- throw new WicketRuntimeException();
- }
- params = new ConfigurationParameters();
- parameters.put(app.getApplicationKey(), params);
- }
- catch (WicketRuntimeException wre)
- {
- throw new IllegalStateException("Application is not ready.");
- }
- }
- return params;
- }
-
- /**
- * Configures the specified application. This method allows for
- * CdiConfiguration to be setup at the Application Level. Use the
- * {@link CdiWicketFilter} as the filterClass or add the
- * {@link CdiWebApplicationFactory} to the Standard WicketFilter with
- * init-param applicationFactoryClassName for setup during Application
- * Initialization. This allows for Injected classes in the WebApplication to
- * be ready before init() is called.
- *
- * @param application
- * @return
- * @deprecated Application Level Configuration replaced with
- * {@link CdiWicketFilter}
- */
- @Deprecated
- public void configure(Application application)
- {
- ConfigurationParameters params = getApplicationParameters();
- configure(application.getApplicationKey(), application, params);
- }
-
- protected synchronized void configure(String appKey, Application application,
- ConfigurationParameters params)
- {
-
- if (parameters.containsKey(appKey))
- {
- params = parameters.get(appKey);
- if (params.isConfigured())
- {
- throw new IllegalStateException("Cannot configure CdiConfiguration multiple times");
- }
- }
- else
- {
- parameters.put(appKey, params);
- }
-
- RequestCycleListenerCollection listeners = new RequestCycleListenerCollection();
- application.getRequestCycleListeners().add(listeners);
-
- // enable conversation propagation
- if (params.getPropagation() != ConversationPropagation.NONE)
- {
- enablePropagation(params, application);
- }
-
- // enable detach event
- listeners.add(detachEventEmitter);
-
-
- // inject application instance
- if (params.isInjectApplication())
- {
- nonContextualManager.postConstruct(application);
- }
-
- // enable injection of various framework components
-
- if (params.isInjectSession())
- {
- application.getSessionListeners().add(sessionInjector);
- }
-
- if (params.isInjectComponents())
- {
- application.getComponentInstantiationListeners().add(componentInjector);
- }
-
- if (params.isInjectBehaviors())
- {
- application.getBehaviorInstantiationListeners().add(behaviorInjector);
- }
-
- // enable cleanup
-
- application.getApplicationListeners().add(
- new CdiShutdownCleaner(params.isInjectApplication()));
-
-
- params.setConfigured(true);
- }
-
- /**
- * Convenience Method to get an Injected Instance of CdiConfiguration
- * programmatically.
- *
- * @return
- */
- @SuppressWarnings("unchecked")
- public static CdiConfiguration get()
- {
- BeanManager beanManager = BeanManagerLookup.lookup();
- Iterator<Bean<?>> iter = beanManager.getBeans(CdiConfiguration.class).iterator();
- if (!iter.hasNext())
- {
- throw new IllegalStateException("CDI BeanManager cannot find CdiConfiguration");
- }
- Bean<CdiConfiguration> bean = (Bean<CdiConfiguration>)iter.next();
- CreationalContext<CdiConfiguration> ctx = beanManager.createCreationalContext(bean);
- return (CdiConfiguration)beanManager.getReference(bean, CdiConfiguration.class, ctx);
- }
-
- private void enablePropagation(ConfigurationParameters params, Application application)
- {
- disablePropagation(params); // Force remove active listeners if any
- IRequestCycleListener requestCycleListener = conversationPropagator;// new
- // RequestCycleListenerWrapper();
- application.getRequestCycleListeners().add(requestCycleListener);
- params.setActiveRequestCycleListener(requestCycleListener);
-
- IComponentOnBeforeRenderListener componentOnBeforeRenderListener = new ComponentOnBeforeRenderListenerWrapper();
- application.getComponentPreOnBeforeRenderListeners().add(componentOnBeforeRenderListener);
- params.setActiveComponentOnBeforeRenderListener(componentOnBeforeRenderListener);
- }
-
- private void disablePropagation(ConfigurationParameters params)
- {
- IRequestCycleListener requestCycleListener = params.getActiveRequestCycleListener();
- if (requestCycleListener != null)
- {
- Application.get().getRequestCycleListeners().remove(requestCycleListener);
- params.setActiveRequestCycleListener(null);
- }
- IComponentOnBeforeRenderListener componentOnBeforeRenderListener = params
- .getActiveComponentOnBeforeRenderListener();
- if (componentOnBeforeRenderListener != null)
- {
- Application.get().getComponentPreOnBeforeRenderListeners()
- .remove(componentOnBeforeRenderListener);
- params.setActiveComponentOnBeforeRenderListener(null);
- }
- }
-
- /**
- * Wrapper for the Current ConversationPropagator which allows the removal
- * of the listener.
- */
- class RequestCycleListenerWrapper extends AbstractRequestCycleListener
- {
-
- @Override
- public void onEndRequest(RequestCycle cycle)
- {
- conversationPropagator.onEndRequest(cycle);
- }
-
- @Override
- public void onRequestHandlerScheduled(RequestCycle cycle, IRequestHandler handler)
- {
- conversationPropagator.onRequestHandlerScheduled(cycle, handler);
- }
-
- @Override
- public void onRequestHandlerResolved(RequestCycle cycle, IRequestHandler handler)
- {
- conversationPropagator.onRequestHandlerResolved(cycle, handler);
- }
-
- @Override
- public void onRequestHandlerExecuted(RequestCycle cycle, IRequestHandler handler)
- {
- conversationPropagator.onRequestHandlerExecuted(cycle, handler);
- }
-
- @Override
- public void onUrlMapped(RequestCycle cycle, IRequestHandler handler, Url url)
- {
- conversationPropagator.onUrlMapped(cycle, handler, url);
- }
-
- }
-
- class ComponentOnBeforeRenderListenerWrapper implements IComponentOnBeforeRenderListener
- {
-
- @Override
- public void onBeforeRender(Component component)
- {
- conversationExpiryChecker.onBeforeRender(component);
- }
-
- }
-
-}
+/*
+ * 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.wicket.cdi;
+
+import javax.enterprise.inject.spi.BeanManager;
+
+import org.apache.wicket.Application;
+import org.apache.wicket.request.cycle.RequestCycleListenerCollection;
+import org.apache.wicket.util.lang.Args;
+import org.jboss.seam.conversation.spi.SeamConversationContextFactory;
+
+/**
+ * Configures CDI integration
+ *
+ * @author igor
+ *
+ */
+public class CdiConfiguration
+{
+ private BeanManager beanManager;
+ private IConversationPropagation propagation = ConversationPropagation.NONBOOKMARKABLE;
+ private INonContextualManager nonContextualManager;
+
+ private boolean injectComponents = true;
+ private boolean injectApplication = true;
+ private boolean injectSession = true;
+ private boolean injectBehaviors = true;
+ private boolean autoConversationManagement = false;
+
+ /**
+ * Constructor
+ *
+ * @param beanManager
+ */
+ public CdiConfiguration(BeanManager beanManager)
+ {
+ Args.notNull(beanManager, "beanManager");
+
+ this.beanManager = beanManager;
+ nonContextualManager = new NonContextualManager(beanManager);
+ }
+
+ /**
+ * Gets the configured bean manager
+ *
+ * @return bean manager or {@code null} if none
+ */
+ public BeanManager getBeanManager()
+ {
+ return beanManager;
+ }
+
+ public IConversationPropagation getPropagation()
+ {
+ return propagation;
+ }
+
+ /**
+ * Checks if auto conversation management is enabled. See
+ * {@link #setAutoConversationManagement(boolean)} for details.
+ */
+ public boolean isAutoConversationManagement()
+ {
+ return autoConversationManagement;
+ }
+
+ /**
+ * Toggles automatic conversation management feature.
+ *
+ * Automatic conversation management controls the lifecycle of the conversation based on
+ * presence of components implementing the {@link ConversationalComponent} interface. If such
+ * components are found in the page a conversation is marked persistent, and if they are not the
+ * conversation is marked transient. This greatly simplifies the management of conversation
+ * lifecycle.
+ *
+ * Sometimes it is necessary to manually control the application. For these cases, once a
+ * conversation is started {@link AutoConversation} bean can be used to mark the conversation as
+ * manually-managed.
+ *
+ * @param enabled
+ *
+ * @return {@code this} for easy chaining
+ */
+ public CdiConfiguration setAutoConversationManagement(boolean enabled)
+ {
+ autoConversationManagement = enabled;
+ return this;
+ }
+
+ public CdiConfiguration setPropagation(IConversationPropagation propagation)
+ {
+ this.propagation = propagation;
+ return this;
+ }
+
+ public INonContextualManager getNonContextualManager()
+ {
+ return nonContextualManager;
+ }
+
+ public CdiConfiguration setNonContextualManager(INonContextualManager nonContextualManager)
+ {
+ this.nonContextualManager = nonContextualManager;
+ return this;
+ }
+
+ public boolean isInjectComponents()
+ {
+ return injectComponents;
+ }
+
+ public CdiConfiguration setInjectComponents(boolean injectComponents)
+ {
+ this.injectComponents = injectComponents;
+ return this;
+ }
+
+ public boolean isInjectApplication()
+ {
+ return injectApplication;
+ }
+
+ public CdiConfiguration setInjectApplication(boolean injectApplication)
+ {
+ this.injectApplication = injectApplication;
+ return this;
+ }
+
+ public boolean isInjectSession()
+ {
+ return injectSession;
+ }
+
+ public CdiConfiguration setInjectSession(boolean injectSession)
+ {
+ this.injectSession = injectSession;
+ return this;
+ }
+
+ public boolean isInjectBehaviors()
+ {
+ return injectBehaviors;
+ }
+
+ public CdiConfiguration setInjectBehaviors(boolean injectBehaviors)
+ {
+ this.injectBehaviors = injectBehaviors;
+ return this;
+ }
+
+ /**
+ * Configures the specified application
+ *
+ * @param application
+ * @return
+ */
+ public CdiContainer configure(Application application)
+ {
+ if (beanManager == null)
+ {
+ throw new IllegalStateException(
+ "Configuration does not have a BeanManager instance configured");
+ }
+
+ CdiContainer container = new CdiContainer(beanManager, nonContextualManager);
+ container.bind(application);
+
+ RequestCycleListenerCollection listeners = new RequestCycleListenerCollection();
+ application.getRequestCycleListeners().add(listeners);
+
+ // enable conversation propagation
+ if (getPropagation() != ConversationPropagation.NONE)
+ {
+ listeners.add(new ConversationPropagator(application, container, getPropagation(),
+ autoConversationManagement));
+ application.getComponentPreOnBeforeRenderListeners().add(
+ new ConversationExpiryChecker(container));
+ SeamConversationContextFactory.setDisableNoopInstance(true);
+ }
+
+ // enable detach event
+ listeners.add(new DetachEventEmitter(container));
+
+
+ // inject application instance
+ if (isInjectApplication())
+ {
+ container.getNonContextualManager().postConstruct(application);
+ }
+
+ // enable injection of various framework components
+
+ if (isInjectSession())
+ {
+ application.getSessionListeners().add(new SessionInjector(container));
+ }
+
+ if (isInjectComponents())
+ {
+ application.getComponentInstantiationListeners().add(new ComponentInjector(container));
+ }
+
+ if (isInjectBehaviors())
+ {
+ application.getBehaviorInstantiationListeners().add(new BehaviorInjector(container));
+ }
+
+ // enable cleanup
+
+ application.getApplicationListeners().add(
+ new CdiShutdownCleaner(beanManager, isInjectApplication()));
+
+ return container;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/6f5464a8/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/CdiContainer.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/CdiContainer.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/CdiContainer.java
new file mode 100644
index 0000000..3a5cc96
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/CdiContainer.java
@@ -0,0 +1,167 @@
+/*
+ * 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.wicket.cdi;
+
+import javax.enterprise.inject.spi.BeanManager;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.wicket.Application;
+import org.apache.wicket.MetaDataKey;
+import org.apache.wicket.Page;
+import org.apache.wicket.request.cycle.RequestCycle;
+import org.apache.wicket.util.lang.Args;
+import org.jboss.seam.conversation.spi.SeamConversationContext;
+import org.jboss.seam.conversation.spi.SeamConversationContextFactory;
+
+/**
+ * Provides access to CDI features from inside a Wicket request
+ *
+ * @author igor
+ *
+ */
+public class CdiContainer
+{
+ private static final MetaDataKey<CdiContainer> CONTEXT_KEY = new MetaDataKey<CdiContainer>()
+ {
+ private static final long serialVersionUID = 1L;
+ };
+
+ protected final BeanManager beanManager;
+ private final SeamConversationContext<HttpServletRequest> conversationContext;
+ private final INonContextualManager nonContextualManager;
+
+ /**
+ * Constructor
+ *
+ * @param beanManager
+ * bean manager
+ */
+ public CdiContainer(BeanManager beanManager, INonContextualManager nonContextualManager)
+ {
+ Args.notNull(beanManager, "beanManager");
+ Args.notNull(nonContextualManager, "nonContextualManager");
+
+ this.beanManager = beanManager;
+ this.nonContextualManager = nonContextualManager;
+
+ conversationContext = SeamConversationContextFactory.getContext(HttpServletRequest.class);
+ if (conversationContext == null)
+ {
+ throw new IllegalStateException(
+ "Could not resolve conversation context manager. Make sure a Seam-Conversation module for your CDI container implementation is included in your dependencies.");
+ }
+ }
+
+ public INonContextualManager getNonContextualManager()
+ {
+ return nonContextualManager;
+ }
+
+ /**
+ * Deactivates conversational context
+ *
+ * @param cycle
+ */
+ public void deactivateConversationalContext(RequestCycle cycle)
+ {
+ conversationContext.deactivate();
+ conversationContext.dissociate(getRequest(cycle));
+ }
+
+ /**
+ * Activates the conversational context and starts the conversation with the specified cid
+ *
+ * @param cycle
+ * @param cid
+ */
+ public void activateConversationalContext(RequestCycle cycle, String cid)
+ {
+ conversationContext.associate(getRequest(cycle));
+ conversationContext.activate(cid);
+ }
+
+ private HttpServletRequest getRequest(RequestCycle cycle)
+ {
+ return (HttpServletRequest)cycle.getRequest().getContainerRequest();
+ }
+
+ /**
+ * Retrieves a conversation id, if any, that is associated with a {@link Page} instance
+ *
+ * @param page
+ * page instance
+ * @return conversation id, if any
+ */
+ public String getConversationMarker(Page page)
+ {
+ return page.getMetaData(ConversationIdMetaKey.INSTANCE);
+ }
+
+ /**
+ * Removes conversation marker from the page instance which prevents the conversation from
+ * propagating to the page. This method should usually be called from page's {@code onDetach()}
+ * method.
+ *
+ * @param page
+ */
+ public void removeConversationMarker(Page page)
+ {
+ Args.notNull(page, "page");
+
+ page.setMetaData(ConversationIdMetaKey.INSTANCE, null);
+ page.getPageParameters().remove(ConversationPropagator.CID);
+ }
+
+ /**
+ * Binds this container instance to the {@link Application}, making it possible to retrieve it
+ * later
+ *
+ * @param application
+ */
+ protected void bind(Application application)
+ {
+ application.setMetaData(CONTEXT_KEY, this);
+ }
+
+ /**
+ * Retrieves container instance stored in the application
+ *
+ * @param application
+ * @return container instance or {@code null} if none
+ */
+ public static final CdiContainer get(Application application)
+ {
+ CdiContainer ctx = application.getMetaData(CONTEXT_KEY);
+ if (ctx == null)
+ {
+ throw new IllegalStateException("No CDI Context bound to application");
+ }
+ return ctx;
+ }
+
+ /**
+ * Retrieves container instance stored in the current thread's application
+ *
+ * @return container instance or {@code null} if none
+ */
+ public static final CdiContainer get()
+ {
+ return get(Application.get());
+ }
+
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/wicket/blob/6f5464a8/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/CdiShutdownCleaner.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/CdiShutdownCleaner.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/CdiShutdownCleaner.java
index fb8eb25..5cb8a6e 100644
--- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/CdiShutdownCleaner.java
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/CdiShutdownCleaner.java
@@ -1,53 +1,59 @@
-/*
- * 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.wicket.cdi;
-
-import org.apache.wicket.Application;
-import org.apache.wicket.IApplicationListener;
-
-/**
- * Listens to application shutdown and cleans up
- *
- * @author igor
- */
-class CdiShutdownCleaner implements IApplicationListener
-{
-
- private final boolean preDestroyApplication;
-
- public CdiShutdownCleaner(boolean preDestroyApplication)
- {
- this.preDestroyApplication = preDestroyApplication;
- }
-
- @Override
- public void onAfterInitialized(Application application)
- {
- // noop
- }
-
- @Override
- public void onBeforeDestroyed(Application application)
- {
- if (preDestroyApplication)
- {
- NonContextual.of(application.getClass()).preDestroy(application);
- }
- NonContextual.undeploy();
- }
-
-}
+/*
+ * 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.wicket.cdi;
+
+import javax.enterprise.inject.spi.BeanManager;
+
+import org.apache.wicket.Application;
+import org.apache.wicket.IApplicationListener;
+import org.apache.wicket.util.lang.Args;
+
+/**
+ * Listens to application shutdown and cleans up
+ *
+ * @author igor
+ */
+class CdiShutdownCleaner implements IApplicationListener
+{
+ private final BeanManager beanManager;
+ private final boolean preDestroyApplication;
+
+ public CdiShutdownCleaner(BeanManager beanManager, boolean preDestroyApplication)
+ {
+ Args.notNull(beanManager, "beanManager");
+
+ this.beanManager = beanManager;
+ this.preDestroyApplication = preDestroyApplication;
+ }
+
+ @Override
+ public void onAfterInitialized(Application application)
+ {
+ // noop
+ }
+
+ @Override
+ public void onBeforeDestroyed(Application application)
+ {
+ if (preDestroyApplication)
+ {
+ NonContextual.of(application.getClass(), beanManager).preDestroy(application);
+ }
+ NonContextual.undeploy(beanManager);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/6f5464a8/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/CdiWebApplicationFactory.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/CdiWebApplicationFactory.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/CdiWebApplicationFactory.java
deleted file mode 100644
index 09c1b0e..0000000
--- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/CdiWebApplicationFactory.java
+++ /dev/null
@@ -1,207 +0,0 @@
-/*
- * 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.wicket.cdi;
-
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.inject.Any;
-import javax.enterprise.inject.Instance;
-import javax.enterprise.inject.UnsatisfiedResolutionException;
-import javax.inject.Inject;
-import javax.servlet.FilterConfig;
-
-import org.apache.wicket.protocol.http.ContextParamWebApplicationFactory;
-import org.apache.wicket.protocol.http.WebApplication;
-import org.apache.wicket.protocol.http.WicketFilter;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * WebApplicationFactory designed for CDI Injection.
- * <p/>
- * This class can be added to the default WicketFilter by setting the init-param
- * 'applicationFactoryClassName' with this classes fully qualified path. In this
- * case the applicationClassName init-param is required. The CdiConfiguration is
- * automatically configured and the Application class is postConstructed, unless
- * overriding with the enableApplicationInjection init-param.
- * <p/>
- * This class is also used by CdiWicketFilter. When using CdiWicketFilter you do
- * not need to use the applicationClassName init-param. CdiWicketFilter uses the
- * Injected CdiWebApplicationFactory. When createApplication is called a
- * WebApplication Instance iterator is searched to find the proper
- * WebApplication. Search works by first looking up the init-param
- * applicationName. If this is found then the WebApplication annotated with
- * {@link WicketApp}('someApp') is selected. This allows for multiple
- * WebApplications to exist in the classloader. If multiple WebApplication are
- * in the classloader then the use of {@link WicketApp} is required. If the
- * init-param applicationName is not set then the classloader is searched to
- * verify there is only one WebApplication. If there is only one WebApplication
- * then it is used. If there are no WebApplications or multiple Applications
- * without applicationName being set then an exception will be thrown. When
- * using CdiWicketFilter the Application is always Injected. When using this in
- * a EE container like glassfish the {@link WicketApp} is required to let EE
- * container manage the object.
- *
- * @author jsarman
- */
-@ApplicationScoped
-public class CdiWebApplicationFactory extends ContextParamWebApplicationFactory
-{
-
- private final static Logger log = LoggerFactory.getLogger(CdiWebApplicationFactory.class);
- static final String WICKET_APP_NAME = "applicationName";
- static final String INJECT_APP = "enableApplicationInjection";
- static final String INJECT_COMPONENT = "enableComponentInjection";
- static final String INJECT_SESSION = "enableSessionInjection";
- static final String INJECT_BEHAVIOR = "enableBehaviorInjecion";
- static final String AUTO_CONVERSATION = "enableAutoConversationManagement";
- static final String PROPAGATION = "initialConversationPropagation";
- @Inject
- @Any
- Instance<WebApplication> applications;
- private boolean overrideApplicationInjection;
-
- public CdiWebApplicationFactory()
- {
- }
-
- @Override
- public WebApplication createApplication(WicketFilter filter)
- {
-
- WebApplication application;
- if (applications == null)
- {
- application = super.createApplication(filter);
- }
- else
- {
- String appName = filter.getFilterConfig().getInitParameter(WICKET_APP_NAME);
- if (appName != null)
- {
- try
- {
- ApplicationQualifier qualifier = new ApplicationQualifier(appName);
- application = applications.select(qualifier).get();
- log.info("Found WicketApp('{}') annotated WebApplication: {} ", appName,
- application.getClass());
- }
- catch (IllegalArgumentException iae)
- {
- log.error(
- "The init param {} set to {} is either has no @Named parameter or duplicates.",
- WICKET_APP_NAME, appName);
- throw iae;
- }
- catch (UnsatisfiedResolutionException ure)
- {
- log.error(
- "The init param {} set to {} requires a WebApplication to be annotated with @Named(\"{}\").",
- new Object[] { WICKET_APP_NAME, appName, appName });
- throw ure;
- }
- }
- else
- {
- Iterator<WebApplication> possibleApps = applications.iterator();
- try
- {
- application = possibleApps.next();
- }
- catch (NoSuchElementException nsee)
- {
- log.error("The classLoader does not contain any WebApplications. Please create a WebApplication.");
- throw new RuntimeException("Missing WebApplication");
- }
- if (possibleApps.hasNext())
- {
- log.error(
- "Multiple WebApplications are in the classloader. This requires using @Named parameter on WebApplication"
- + " and setting the init-param {} with the matching name in web.xml",
- WICKET_APP_NAME);
- throw new IllegalArgumentException("Missing init-param " + WICKET_APP_NAME
- + " to match against multiple WebApplications in classLoader. ");
- }
- log.info("Found Single WebApplication: {}", application.getClass());
- }
- overrideApplicationInjection = true; // Already injected so don't
- // let CdiConfiguration
- // reinject it.
- }
-
- ConfigurationParameters parameters = buildParameters(filter.getFilterConfig());
- CdiConfiguration.get().configure(filter.getFilterConfig().getFilterName(), application,
- parameters);
- return application;
- }
-
- private ConfigurationParameters buildParameters(FilterConfig filterConfig)
- {
- ConfigurationParameters parameters = new ConfigurationParameters();
- if (!overrideApplicationInjection)
- {
- final String injectApp = filterConfig.getInitParameter(INJECT_APP);
-
- if (injectApp != null)
- {
- parameters.setInjectApplication(Boolean.parseBoolean(injectApp));
- }
- }
- else
- {
- parameters.setInjectApplication(false);
- }
- final String injectComponent = filterConfig.getInitParameter(INJECT_COMPONENT);
- if (injectComponent != null)
- {
- parameters.setInjectComponents(Boolean.parseBoolean(injectComponent));
- }
- final String injectSession = filterConfig.getInitParameter(INJECT_SESSION);
- if (injectSession != null)
- {
- parameters.setInjectSession(Boolean.parseBoolean(injectSession));
- }
- final String injectBehavior = filterConfig.getInitParameter(INJECT_BEHAVIOR);
- if (injectBehavior != null)
- {
- parameters.setInjectBehaviors(Boolean.parseBoolean(injectBehavior));
- }
- final String autoConversation = filterConfig.getInitParameter(AUTO_CONVERSATION);
- if (autoConversation != null)
- {
- parameters.setAutoConversationManagement(Boolean.parseBoolean(autoConversation));
- }
- final String propagation = filterConfig.getInitParameter(PROPAGATION);
- if (propagation != null)
- {
- try
- {
- parameters.setPropagation(ConversationPropagation.valueOf(propagation));
- }
- catch (IllegalArgumentException iae)
- {
- log.warn("Init Param {} = {} is not a valid propagation type. Using Default {}",
- new Object[] { PROPAGATION, propagation,
- parameters.getPropagation().toString() });
- }
- }
-
- return parameters;
- }
-}
http://git-wip-us.apache.org/repos/asf/wicket/blob/6f5464a8/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/CdiWicketFilter.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/CdiWicketFilter.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/CdiWicketFilter.java
deleted file mode 100644
index aa0d5e5..0000000
--- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/CdiWicketFilter.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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.wicket.cdi;
-
-import javax.inject.Inject;
-
-import org.apache.wicket.protocol.http.IWebApplicationFactory;
-import org.apache.wicket.protocol.http.WicketFilter;
-
-/**
- * CdiWicketFilter is a Cdi Enabled version of WicketFilter. It uses the Managed
- * Version of {@link CdiWebApplicationFactory} therefore the WebApplication is
- * also Managed via the Cdi container.
- *
- * @author jsarman
- */
-
-public class CdiWicketFilter extends WicketFilter
-{
-
- @Inject
- CdiWebApplicationFactory applicationFactory;
-
- public CdiWicketFilter()
- {
- }
-
-
- @Override
- protected IWebApplicationFactory getApplicationFactory()
- {
- return applicationFactory;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/wicket/blob/6f5464a8/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ComponentInjector.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ComponentInjector.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ComponentInjector.java
index dcf31bd..bc302ef 100644
--- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ComponentInjector.java
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ComponentInjector.java
@@ -1,40 +1,46 @@
-/*
- * 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.wicket.cdi;
-
-import javax.enterprise.context.ApplicationScoped;
-
-import org.apache.wicket.Component;
-import org.apache.wicket.application.IComponentInstantiationListener;
-
-/**
- * Injects components with CDI dependencies
- *
- * @author igor
- */
-@ApplicationScoped
-public class ComponentInjector extends AbstractInjector<Component>
- implements
- IComponentInstantiationListener
-{
-
- @Override
- public void onInstantiation(Component component)
- {
- inject(component);
- }
-}
+/*
+ * 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.wicket.cdi;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.application.IComponentInstantiationListener;
+
+/**
+ * Injects components with CDI dependencies
+ *
+ * @author igor
+ *
+ */
+class ComponentInjector extends AbstractInjector implements IComponentInstantiationListener
+{
+ /**
+ * Constructor
+ *
+ * @param container
+ */
+ public ComponentInjector(CdiContainer container)
+ {
+ super(container);
+ }
+
+ @Override
+ public void onInstantiation(Component component)
+ {
+ inject(component);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/6f5464a8/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConfigurationParameters.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConfigurationParameters.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConfigurationParameters.java
deleted file mode 100644
index 647cf1e..0000000
--- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConfigurationParameters.java
+++ /dev/null
@@ -1,149 +0,0 @@
-/*
- * 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.wicket.cdi;
-
-import java.io.Serializable;
-
-import org.apache.wicket.application.IComponentOnBeforeRenderListener;
-import org.apache.wicket.request.cycle.IRequestCycleListener;
-
-/**
- * Simple POJO bean for storing the initial configuration parameters as well as
- * the state of the dynamic variables used by {@link CdiConfiguration}.
- *
- * @author jsarman
- */
-public class ConfigurationParameters implements Serializable
-{
- private static final long serialVersionUID = 1L;
-
- private IConversationPropagation propagation = ConversationPropagation.NONBOOKMARKABLE;
- private boolean injectComponents = true;
- private boolean injectApplication = true;
- private boolean injectSession = true;
- private boolean injectBehaviors = true;
- private boolean autoConversationManagement = false;
- private boolean configured = false;
-
- private IRequestCycleListener activeRequestCycleListener;
- private IComponentOnBeforeRenderListener activeComponentOnBeforeRenderListener;
-
- public ConfigurationParameters()
- {
-
- }
-
-
- public IConversationPropagation getPropagation()
- {
- return propagation;
- }
-
- ConfigurationParameters setPropagation(IConversationPropagation propagation)
- {
- this.propagation = propagation;
- return this;
- }
-
-
- public boolean isInjectComponents()
- {
- return injectComponents;
- }
-
- ConfigurationParameters setInjectComponents(boolean injectComponents)
- {
- this.injectComponents = injectComponents;
- return this;
- }
-
- public boolean isInjectApplication()
- {
- return injectApplication;
- }
-
- ConfigurationParameters setInjectApplication(boolean injectApplication)
- {
- this.injectApplication = injectApplication;
- return this;
- }
-
- public boolean isInjectSession()
- {
- return injectSession;
- }
-
- ConfigurationParameters setInjectSession(boolean injectSession)
- {
- this.injectSession = injectSession;
- return this;
- }
-
- public boolean isInjectBehaviors()
- {
- return injectBehaviors;
- }
-
- ConfigurationParameters setInjectBehaviors(boolean injectBehaviors)
- {
- this.injectBehaviors = injectBehaviors;
- return this;
- }
-
- public boolean isAutoConversationManagement()
- {
- return autoConversationManagement;
- }
-
- ConfigurationParameters setAutoConversationManagement(boolean autoConversationManagement)
- {
- this.autoConversationManagement = autoConversationManagement;
- return this;
- }
-
- IRequestCycleListener getActiveRequestCycleListener()
- {
- return activeRequestCycleListener;
- }
-
- void setActiveRequestCycleListener(IRequestCycleListener activeRequestCycleListener)
- {
- this.activeRequestCycleListener = activeRequestCycleListener;
- }
-
- IComponentOnBeforeRenderListener getActiveComponentOnBeforeRenderListener()
- {
- return activeComponentOnBeforeRenderListener;
- }
-
- void setActiveComponentOnBeforeRenderListener(
- IComponentOnBeforeRenderListener activeComponentOnBeforeRenderListener)
- {
- this.activeComponentOnBeforeRenderListener = activeComponentOnBeforeRenderListener;
- }
-
- public boolean isConfigured()
- {
- return configured;
- }
-
- void setConfigured(boolean configured)
- {
- this.configured = configured;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/wicket/blob/6f5464a8/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConversationExpiredException.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConversationExpiredException.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConversationExpiredException.java
index 347608b..7993ae4 100644
--- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConversationExpiredException.java
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConversationExpiredException.java
@@ -1,53 +1,51 @@
-/*
- * 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.wicket.cdi;
-
-import org.apache.wicket.Page;
-import org.apache.wicket.request.IRequestHandler;
-
-public class ConversationExpiredException extends RuntimeException
-{
- private static final long serialVersionUID = 1L;
-
- private final String cid;
- private final Page page;
- private final IRequestHandler handler;
-
- public ConversationExpiredException(Throwable cause, String cid, Page page,
- IRequestHandler handler)
- {
- super(cause);
- this.cid = cid;
- this.page = page;
- this.handler = handler;
- }
-
- public String getCid()
- {
- return cid;
- }
-
- public Page getPage()
- {
- return page;
- }
-
- public IRequestHandler getHandler()
- {
- return handler;
- }
-}
+/*
+ * 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.wicket.cdi;
+
+import org.apache.wicket.Page;
+import org.apache.wicket.request.IRequestHandler;
+
+public class ConversationExpiredException extends RuntimeException
+{
+ private String cid;
+ private Page page;
+ private IRequestHandler handler;
+
+ public ConversationExpiredException(Throwable cause, String cid, Page page,
+ IRequestHandler handler)
+ {
+ super(cause);
+ this.cid = cid;
+ this.page = page;
+ this.handler = handler;
+ }
+
+ public String getCid()
+ {
+ return cid;
+ }
+
+ public Page getPage()
+ {
+ return page;
+ }
+
+ public IRequestHandler getHandler()
+ {
+ return handler;
+ }
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/6f5464a8/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConversationExpiryChecker.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConversationExpiryChecker.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConversationExpiryChecker.java
index 02d5191..d58b417 100644
--- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConversationExpiryChecker.java
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConversationExpiryChecker.java
@@ -1,74 +1,72 @@
-/*
- * 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.wicket.cdi;
-
-import java.io.Serializable;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.context.Conversation;
-import javax.inject.Inject;
-
-import org.apache.wicket.Component;
-import org.apache.wicket.Page;
-import org.apache.wicket.ajax.AjaxRequestTarget;
-import org.apache.wicket.application.IComponentOnBeforeRenderListener;
-import org.apache.wicket.request.cycle.RequestCycle;
-import org.apache.wicket.util.lang.Objects;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Checks for conversation expiration during page render and throws a
- * {@link ConversationExpiredException} when an expired conversation is
- * detected.
- * <p/>
- * For example a link that calls {@link Conversation#end()} but does not
- * redirect to a non-conversation-dependent page will be caught by this
- * listener.
- *
- * @author igor
- */
-@ApplicationScoped
-public class ConversationExpiryChecker implements IComponentOnBeforeRenderListener, Serializable
-{
- private static final long serialVersionUID = 1L;
- private static final Logger logger = LoggerFactory.getLogger(ConversationExpiryChecker.class);
-
- @Inject
- AbstractCdiContainer container;
-
- public ConversationExpiryChecker()
- {
-
- }
-
- @Override
- public void onBeforeRender(Component component)
- {
- if (component instanceof Page || RequestCycle.get().find(AjaxRequestTarget.class) != null)
- {
- Page page = component.getPage();
- String cid = container.getConversationMarker(page);
- if (cid != null && !Objects.isEqual(container.getCurrentConversation().getId(), cid))
- {
- logger.info("Conversation {} has expired for {}", cid, page);
- throw new ConversationExpiredException(null, cid, page, RequestCycle.get()
- .getActiveRequestHandler());
- }
- }
- }
-}
+/*
+ * 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.wicket.cdi;
+
+import javax.enterprise.context.Conversation;
+import javax.inject.Inject;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.Page;
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.application.IComponentOnBeforeRenderListener;
+import org.apache.wicket.request.cycle.RequestCycle;
+import org.apache.wicket.util.lang.Objects;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Checks for conversation expiration during page render and throws a
+ * {@link ConversationExpiredException} when an expired conversation is detected.
+ *
+ * For example a link that calls {@link Conversation#end()} but does not redirect to a
+ * non-conversation-dependent page will be caught by this listener.
+ *
+ * @author igor
+ *
+ */
+public class ConversationExpiryChecker implements IComponentOnBeforeRenderListener
+{
+ private static final Logger logger = LoggerFactory.getLogger(ConversationExpiryChecker.class);
+
+ @Inject
+ private Conversation conversation;
+
+ private final CdiContainer container;
+
+ public ConversationExpiryChecker(CdiContainer container)
+ {
+ this.container = container;
+
+ container.getNonContextualManager().inject(this);
+ }
+
+ @Override
+ public void onBeforeRender(Component component)
+ {
+ if (component instanceof Page || RequestCycle.get().find(AjaxRequestTarget.class) != null)
+ {
+ Page page = component.getPage();
+ String cid = container.getConversationMarker(page);
+ if (cid != null && !Objects.isEqual(conversation.getId(), cid))
+ {
+ logger.info("Conversation {} has expired for {}", cid, page);
+ throw new ConversationExpiredException(null, cid, page, RequestCycle.get()
+ .getActiveRequestHandler());
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/6f5464a8/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConversationIdMetaKey.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConversationIdMetaKey.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConversationIdMetaKey.java
index ca53292..94cc70f 100644
--- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConversationIdMetaKey.java
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConversationIdMetaKey.java
@@ -1,26 +1,24 @@
-/*
- * 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.wicket.cdi;
-
-import org.apache.wicket.MetaDataKey;
-
-final class ConversationIdMetaKey extends MetaDataKey<String>
-{
- private static final long serialVersionUID = 1L;
-
- static final ConversationIdMetaKey INSTANCE = new ConversationIdMetaKey();
-}
+/*
+ * 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.wicket.cdi;
+
+import org.apache.wicket.MetaDataKey;
+
+final class ConversationIdMetaKey extends MetaDataKey<String>
+{
+ static final ConversationIdMetaKey INSTANCE = new ConversationIdMetaKey();
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/wicket/blob/6f5464a8/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConversationManager.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConversationManager.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConversationManager.java
deleted file mode 100644
index 332ed9d..0000000
--- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConversationManager.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * 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.wicket.cdi;
-
-import java.io.Serializable;
-
-import javax.annotation.PostConstruct;
-import javax.enterprise.context.Conversation;
-import javax.enterprise.context.ConversationScoped;
-import javax.inject.Inject;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * @author jsarman
- */
-@ConversationScoped
-public class ConversationManager implements Serializable
-{
- private static final long serialVersionUID = 1L;
-
- private static final Logger logger = LoggerFactory.getLogger(ConversationManager.class);
-
- @Inject
- AbstractCdiContainer container;
-
- @Inject
- @Auto
- Boolean globalAuto;
-
- @Inject
- @Propagation
- IConversationPropagation globalPropagation;
-
- IConversationPropagation propagation;
- Boolean manageConversation;
-
- boolean terminateConversation;
-
- @PostConstruct
- public void init()
- {
- logger.debug("Starting new Conversation manager for id = {}", getConversation().getId());
- propagation = globalPropagation;
- manageConversation = globalAuto;
- logger.debug("Setting initial values to auto = {} prop = {}", manageConversation,
- propagation);
- }
-
- private Conversation getConversation()
- {
- return container.getCurrentConversation();
- }
-
- public IConversationPropagation getPropagation()
- {
- return propagation;
- }
-
- public void setPropagation(IConversationPropagation propagation)
- {
- if (propagation == null)
- {
- throw new IllegalArgumentException("Propagation cannot be null");
- }
- if (this.propagation == propagation)
- {
- return;
- }
-
- logger.debug("Changing conversation dependent propagation to {} for id = {}", propagation,
- getConversation().getId());
-
- this.propagation = propagation;
- }
-
- public Boolean getManageConversation()
- {
- return manageConversation;
- }
-
- public void setManageConversation(boolean manageConversation)
- {
- if (this.manageConversation == manageConversation)
- {
- return;
- }
- logger.debug("Setting conversation dependent manageConversation to {} for id = {} ",
- manageConversation, getConversation().getId());
-
- this.manageConversation = manageConversation;
- }
-
- void cancelConversationEnd()
- {
- terminateConversation = false;
- }
-
- void scheduleConversationEnd()
- {
- terminateConversation = true;
- }
-
- boolean isConversationScheduledForEnd()
- {
- return terminateConversation;
- }
-
-}