myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From we...@apache.org
Subject svn commit: r1309683 - in /myfaces/extensions/scripting/trunk: extscript-core-root/extscript-cdi/src/main/java/org/apache/myfaces/extensions/scripting/cdi/api/ extscript-core-root/extscript-cdi/src/main/java/org/apache/myfaces/extensions/scripting/cdi/...
Date Thu, 05 Apr 2012 08:00:19 GMT
Author: werpu
Date: Thu Apr  5 08:00:18 2012
New Revision: 1309683

URL: http://svn.apache.org/viewvc?rev=1309683&view=rev
Log:
EXTSCRIPT-107: CDI Integration work started

Added:
    myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/java/org/apache/myfaces/extensions/scripting/cdi/api/
    myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/java/org/apache/myfaces/extensions/scripting/cdi/api/CdiContainer.java
    myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/java/org/apache/myfaces/extensions/scripting/cdi/api/CdiContainerLoader.java
    myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/java/org/apache/myfaces/extensions/scripting/cdi/api/ContextControl.java
    myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/java/org/apache/myfaces/extensions/scripting/cdi/listener/
    myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/java/org/apache/myfaces/extensions/scripting/cdi/listener/ReloadingListener.java
    myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/java/org/apache/myfaces/extensions/scripting/cdi/owb/
    myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/java/org/apache/myfaces/extensions/scripting/cdi/owb/OpenWebBeansContainerControl.java
    myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/java/org/apache/myfaces/extensions/scripting/cdi/owb/OpenWebBeansContextControl.java
    myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/java/org/apache/myfaces/extensions/scripting/cdi/startup/readme.txt
    myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/resources/META-INF/services/org.apache.myfaces.extensions.scripting.cdi.api.CdiContainer
    myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/api/eventhandling/events/RefreshBeginEvent.java
Modified:
    myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/java/org/apache/myfaces/extensions/scripting/cdi/startup/StartupPlugin.java
    myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/resources/META-INF/services/org.apache.myfaces.extensions.scripting.core.api.Plugin
    myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/jsf/startup/RefreshPhaseListener.java
    myfaces/extensions/scripting/trunk/extscript-examples/cdi-example/pom.xml

Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/java/org/apache/myfaces/extensions/scripting/cdi/api/CdiContainer.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/java/org/apache/myfaces/extensions/scripting/cdi/api/CdiContainer.java?rev=1309683&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/java/org/apache/myfaces/extensions/scripting/cdi/api/CdiContainer.java
(added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/java/org/apache/myfaces/extensions/scripting/cdi/api/CdiContainer.java
Thu Apr  5 08:00:18 2012
@@ -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.myfaces.extensions.scripting.cdi.api;
+
+
+
+import javax.enterprise.inject.spi.BeanManager;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpSession;
+
+/**
+ * <p>A CdiTestContainer provides access to an underlying JSR-299 (CDI)
+ * Container. It allows starting and stopping the container and to start
+ * and stop the built-in contexts of that container.</p>
+ *
+ * <p>The intention is to provide a portable control for CDI containers in
+ * Java SE environments. It is <b>not</b> intended for environments in which
the
+ * CDI container is under full control of the server already, e.g. in
+ * EE-containers.</p>
+ */
+public interface CdiContainer
+{
+    /**
+     * Booting the CdiTestContainer will scan the whole classpath
+     * for Beans and extensions available.
+     * The container might throw a DeploymentException or similar on startup.
+     */
+    void boot();
+    
+    /**
+     * This will shutdown the underlying CDI container.
+     */
+    void shutdown();
+    
+
+    /**
+     * @return the {@link javax.enterprise.inject.spi.BeanManager} or <code>null</code>
it not available
+     */
+    BeanManager getBeanManager();
+
+    /**
+     * @return ContextControl for the started Container. <code>null</code> if
the container is not yet started
+     */
+    ContextControl getContextControl(ServletContext context, HttpSession session);
+
+}
+

Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/java/org/apache/myfaces/extensions/scripting/cdi/api/CdiContainerLoader.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/java/org/apache/myfaces/extensions/scripting/cdi/api/CdiContainerLoader.java?rev=1309683&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/java/org/apache/myfaces/extensions/scripting/cdi/api/CdiContainerLoader.java
(added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/java/org/apache/myfaces/extensions/scripting/cdi/api/CdiContainerLoader.java
Thu Apr  5 08:00:18 2012
@@ -0,0 +1,81 @@
+/*
+ * 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.myfaces.extensions.scripting.cdi.api;
+
+
+import java.util.Iterator;
+import java.util.ServiceLoader;
+
+/**
+ * <p>This class provides access to the ContainerControl.</p>
+ * <p>It uses the {@code java.util.ServiceLoader} mechanism  to 
+ * automatically pickup the container providers from the classpath.</p>
+ */
+public final class CdiContainerLoader
+{
+    private CdiContainerLoader()
+    {
+        // private ct to prevent instantiation
+    }
+
+    
+    public static CdiContainer getCdiContainer()
+    {
+        CdiContainer testContainer;
+
+        //doesn't support the implementation loader (there is no dependency to owb-impl
+        ServiceLoader<CdiContainer> cdiContainerLoader = ServiceLoader.load(CdiContainer.class);
+        Iterator<CdiContainer> cdiIt = cdiContainerLoader.iterator();
+        if (cdiIt.hasNext())
+        {
+            testContainer = cdiIt.next();
+        }
+        else
+        {
+            throw new IllegalStateException("Could not find an implementation of " + org.apache.deltaspike.cdise.api.CdiContainer.class.getName()
+
+                " available in the classpath!");
+        }
+
+        if (cdiIt.hasNext())
+        {
+            String foundContainers = getContainerDetails();
+            throw new IllegalStateException("Too many implementations of " + org.apache.deltaspike.cdise.api.CdiContainer.class.getName()
+
+                " found in the classpath! Details: " + foundContainers);
+        }
+
+        return testContainer;
+    }
+
+    private static String getContainerDetails()
+    {
+        StringBuilder result = new StringBuilder();
+
+        Class containerClass;
+        for (CdiContainer cdiContainer : ServiceLoader.load(CdiContainer.class))
+        {
+            containerClass = cdiContainer.getClass();
+            result.append(containerClass.getProtectionDomain().getCodeSource().getLocation().toExternalForm());
+            result.append(containerClass.getName());
+
+            result.append(System.getProperty("line.separator"));
+        }
+
+        return result.toString();
+    }
+}

Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/java/org/apache/myfaces/extensions/scripting/cdi/api/ContextControl.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/java/org/apache/myfaces/extensions/scripting/cdi/api/ContextControl.java?rev=1309683&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/java/org/apache/myfaces/extensions/scripting/cdi/api/ContextControl.java
(added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/java/org/apache/myfaces/extensions/scripting/cdi/api/ContextControl.java
Thu Apr  5 08:00:18 2012
@@ -0,0 +1,64 @@
+/*
+ * 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.myfaces.extensions.scripting.cdi.api;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpSession;
+import java.lang.annotation.Annotation;
+
+/**
+ * Control native CDI Container Contexts.
+ * Just inject this interface and you gain manual access over built-in Contexts.
+ * The respective integration code will provide a &064;Dependent scoped instance.
+ */
+public interface ContextControl
+{
+    /**
+     * This will start all container built-in Contexts
+     */
+    void startContexts();
+
+    /**
+     * Stop all container built-in Contexts and destroy all beans properly
+     */
+    void stopContexts();
+
+    /**
+     * Start the specified scope. This only works for scopes which are handled
+     * by the CDI container itself. Custom scoped of 3rd party
+     * Context implementations shall be started directly (they are portable anyway).
+     *
+     * @param scopeClass e.g. RequestScoped.class
+     */
+    void startContext(Class<? extends Annotation> scopeClass);
+
+    /**
+     * Stop the specified scope. This only works for scopes which are handled
+     * by the CDI container itself. Custom scoped of 3rd party
+     * Context implementations shall be stopped directly (they are portable anyway).
+     *
+     * @param scopeClass e.g. RequestScoped.class
+     */
+    void stopContext(Class<? extends Annotation> scopeClass);
+
+
+    void setSession(HttpSession session);
+
+    void setServletContext(ServletContext servletContext);
+}

Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/java/org/apache/myfaces/extensions/scripting/cdi/listener/ReloadingListener.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/java/org/apache/myfaces/extensions/scripting/cdi/listener/ReloadingListener.java?rev=1309683&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/java/org/apache/myfaces/extensions/scripting/cdi/listener/ReloadingListener.java
(added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/java/org/apache/myfaces/extensions/scripting/cdi/listener/ReloadingListener.java
Thu Apr  5 08:00:18 2012
@@ -0,0 +1,82 @@
+/*
+ * 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.myfaces.extensions.scripting.cdi.listener;
+
+import org.apache.myfaces.extensions.scripting.cdi.api.CdiContainerLoader;
+import org.apache.myfaces.extensions.scripting.core.api.eventhandling.WeavingEvent;
+import org.apache.myfaces.extensions.scripting.core.api.eventhandling.WeavingEventListener;
+import org.apache.myfaces.extensions.scripting.core.api.eventhandling.events.RefreshBeginEvent;
+import org.apache.myfaces.extensions.scripting.core.api.eventhandling.events.TaintedEvent;
+import org.apache.myfaces.extensions.scripting.core.engine.ThrowAwayClassloader;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ *          <p/>
+ *          Reloading listener which triggers a container reload
+ *          the reload can happen at the end of the extscript lifecycle
+ *          when all beans have been tainted
+ */
+public class ReloadingListener implements WeavingEventListener
+{
+    boolean _tainted = false;
+    ServletContext context;
+
+    @Override
+    public void onEvent(WeavingEvent evt)
+    {
+        if (evt instanceof TaintedEvent)
+        {
+            _tainted = true;
+        } else if (evt instanceof RefreshBeginEvent)
+        {
+            RefreshBeginEvent refreshEvent = (RefreshBeginEvent) evt;
+            if (_tainted)
+            {
+                _tainted = false;
+                HttpServletRequest req = (HttpServletRequest) refreshEvent.getRequest();
+                //TODO plug reloadable classloader in here temporarily
+                //as context classloader, then restart the container
+                //then restore the old classloader
+                ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
+                ClassLoader tempClassLoader = new ThrowAwayClassloader(oldClassLoader);
+                Thread.currentThread().setContextClassLoader(tempClassLoader);
+                try
+                {
+                    CdiContainerLoader.getCdiContainer().getContextControl(req.getServletContext(),
+                            req.getSession()).stopContexts();
+                    CdiContainerLoader.getCdiContainer().shutdown();
+
+                    CdiContainerLoader.getCdiContainer().boot();
+
+                    CdiContainerLoader.getCdiContainer().getContextControl(req.getServletContext(),
+                            req.getSession()).startContexts();
+                }
+                finally
+                {
+                    Thread.currentThread().setContextClassLoader(oldClassLoader);
+                }
+            }
+        }
+    }
+}

Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/java/org/apache/myfaces/extensions/scripting/cdi/owb/OpenWebBeansContainerControl.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/java/org/apache/myfaces/extensions/scripting/cdi/owb/OpenWebBeansContainerControl.java?rev=1309683&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/java/org/apache/myfaces/extensions/scripting/cdi/owb/OpenWebBeansContainerControl.java
(added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/java/org/apache/myfaces/extensions/scripting/cdi/owb/OpenWebBeansContainerControl.java
Thu Apr  5 08:00:18 2012
@@ -0,0 +1,90 @@
+/*
+ * 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.myfaces.extensions.scripting.cdi.owb;
+
+import org.apache.myfaces.extensions.scripting.cdi.api.CdiContainer;
+import org.apache.myfaces.extensions.scripting.cdi.api.ContextControl;
+import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.spi.ContainerLifecycle;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpSession;
+import java.util.Set;
+
+/**
+ * OpenWebBeans specific implementation of {@link org.apache.deltaspike.cdise.api.CdiContainer}.
+ */
+public class OpenWebBeansContainerControl implements CdiContainer
+{
+
+    private ContainerLifecycle lifecycle;
+
+    private ContextControl ctxCtrl = null;
+    private Bean<ContextControl> ctxCtrlBean = null;
+    private CreationalContext<ContextControl> ctxCtrlCreationalContext = null;
+
+    @Override
+    public  BeanManager getBeanManager()
+    {
+        return lifecycle.getBeanManager();
+    }
+
+    @Override
+    public synchronized void boot()
+    {
+
+        lifecycle = WebBeansContext.getInstance().getService(ContainerLifecycle.class);
+        lifecycle.startApplication(null);
+    }
+
+    @Override
+    public synchronized void shutdown()
+    {
+        if (ctxCtrl != null)
+        {
+            ctxCtrlBean.destroy(ctxCtrl, ctxCtrlCreationalContext);
+
+        }
+
+        if (lifecycle != null) 
+        {
+            lifecycle.stopApplication(null);
+        }
+    }
+
+    public synchronized ContextControl getContextControl(ServletContext context, HttpSession
session)
+    {
+        if (ctxCtrl == null)
+        {
+            Set<Bean<?>> beans = getBeanManager().getBeans(ContextControl.class);
+            ctxCtrlBean = (Bean<ContextControl>) getBeanManager().resolve(beans);
+            ctxCtrlCreationalContext = getBeanManager().createCreationalContext(ctxCtrlBean);
+            ctxCtrl = (ContextControl)
+                    getBeanManager().getReference(ctxCtrlBean, ContextControl.class, ctxCtrlCreationalContext);
+            ctxCtrl.setServletContext(context);
+            ctxCtrl.setSession(session);
+        }
+        return ctxCtrl;
+    }
+
+
+}

Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/java/org/apache/myfaces/extensions/scripting/cdi/owb/OpenWebBeansContextControl.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/java/org/apache/myfaces/extensions/scripting/cdi/owb/OpenWebBeansContextControl.java?rev=1309683&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/java/org/apache/myfaces/extensions/scripting/cdi/owb/OpenWebBeansContextControl.java
(added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/java/org/apache/myfaces/extensions/scripting/cdi/owb/OpenWebBeansContextControl.java
Thu Apr  5 08:00:18 2012
@@ -0,0 +1,245 @@
+/*
+ * 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.myfaces.extensions.scripting.cdi.owb;
+
+import org.apache.myfaces.extensions.scripting.cdi.api.ContextControl;
+import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.context.ContextFactory;
+import org.apache.webbeans.context.type.ContextTypes;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.context.ConversationScoped;
+import javax.enterprise.context.Dependent;
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.context.SessionScoped;
+import javax.enterprise.context.spi.Context;
+import javax.inject.Named;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpSession;
+import java.lang.annotation.Annotation;
+import java.util.logging.Logger;
+
+/**
+ * OWB specific impl of the {@link ContextControl}
+ */
+@Named
+@Dependent
+public class OpenWebBeansContextControl implements ContextControl
+{
+
+    private static final Logger LOG = Logger.getLogger(org.apache.deltaspike.cdise.owb.OpenWebBeansContextControl.class.getName());
+
+    private HttpSession session = null;
+    private ServletContext servletContext  = null;
+
+    public OpenWebBeansContextControl()
+    {
+    }
+
+    public OpenWebBeansContextControl(HttpSession session, ServletContext servletContext)
+    {
+        this.session = session;
+        this.servletContext = servletContext;
+    }
+
+    @Override
+    public void startContexts()
+    {
+        ContextFactory contextFactory = getContextFactory();
+
+        contextFactory.initSingletonContext(servletContext);
+        contextFactory.initApplicationContext(servletContext);
+        contextFactory.initSessionContext(session);
+        contextFactory.initRequestContext(null);
+        contextFactory.initConversationContext(null);
+    }
+
+
+    public void stopContexts()
+    {
+        stopSessionScope();
+        stopConversationScope();
+        stopRequestScope();
+        stopApplicationScope();
+        stopSingletonScope();
+    }
+
+
+
+    @Override
+    public void startContext(Class<? extends Annotation> scopeClass)
+    {
+        if (scopeClass.isAssignableFrom(ApplicationScoped.class))
+        {
+            startApplicationScope();
+        }
+        else if (scopeClass.isAssignableFrom(SessionScoped.class))
+        {
+            startSessionScope();
+        }
+        else if (scopeClass.isAssignableFrom(RequestScoped.class))
+        {
+            startRequestScope();
+        }
+        else if (scopeClass.isAssignableFrom(ConversationScoped.class))
+        {
+            startConversationScope();
+        }
+    }
+
+
+    public void stopContext(Class<? extends Annotation> scopeClass)
+    {
+        if (scopeClass.isAssignableFrom(ApplicationScoped.class))
+        {
+            stopApplicationScope();
+        }
+        else if (scopeClass.isAssignableFrom(SessionScoped.class))
+        {
+            stopSessionScope();
+        }
+        else if (scopeClass.isAssignableFrom(RequestScoped.class))
+        {
+            stopRequestScope();
+        }
+        else if (scopeClass.isAssignableFrom(ConversationScoped.class))
+        {
+            stopConversationScope();
+        }
+    }
+
+    /*
+    * start scopes
+    */
+
+    private void startApplicationScope()
+    {
+        ContextFactory contextFactory = getContextFactory();
+
+        contextFactory.initApplicationContext(servletContext);
+    }
+
+    private void startSessionScope()
+    {
+        ContextFactory contextFactory = getContextFactory();
+
+        contextFactory.initSessionContext(session);
+    }
+
+    private void startRequestScope()
+    {
+        ContextFactory contextFactory = getContextFactory();
+
+        contextFactory.initRequestContext(null);
+    }
+
+    private void startConversationScope()
+    {
+        ContextFactory contextFactory = getContextFactory();
+
+        contextFactory.initConversationContext(null);
+    }
+
+    /*
+     * stop scopes
+     */
+
+    private void stopSingletonScope()
+    {
+        ContextFactory contextFactory = getContextFactory();
+
+        Context context = contextFactory.getStandardContext(ContextTypes.SINGLETON);
+        if (context != null)
+        {
+            contextFactory.destroySingletonContext(servletContext);
+        }
+    }
+
+    private void stopApplicationScope()
+    {
+        ContextFactory contextFactory = getContextFactory();
+
+        Context context = contextFactory.getStandardContext(ContextTypes.APPLICATION);
+        if (context != null)
+        {
+            contextFactory.destroyApplicationContext(servletContext);
+        }
+    }
+
+    private void stopSessionScope()
+    {
+        ContextFactory contextFactory = getContextFactory();
+
+        Context context = contextFactory.getStandardContext(ContextTypes.SESSION);
+        if (context != null)
+        {
+            contextFactory.destroySessionContext(session);
+        }
+    }
+
+    private void stopRequestScope()
+    {
+        ContextFactory contextFactory = getContextFactory();
+
+        Context context = contextFactory.getStandardContext(ContextTypes.REQUEST);
+        if (context != null)
+        {
+            contextFactory.destroyRequestContext(null);
+        }
+    }
+
+    private void stopConversationScope()
+    {
+        ContextFactory contextFactory = getContextFactory();
+
+        Context context = contextFactory.getStandardContext(ContextTypes.CONVERSATION);
+        if (context != null)
+        {
+            contextFactory.destroyConversationContext();
+        }
+    }
+
+    private ContextFactory getContextFactory()
+    {
+        WebBeansContext webBeansContext = WebBeansContext.getInstance();
+        return webBeansContext.getContextFactory();
+    }
+
+    //--------------------Setter and Getter------------------------------------
+
+    public HttpSession getSession()
+    {
+        return session;
+    }
+
+    public void setSession(HttpSession session)
+    {
+        this.session = session;
+    }
+
+    public ServletContext getServletContext()
+    {
+        return servletContext;
+    }
+
+    public void setServletContext(ServletContext servletContext)
+    {
+        this.servletContext = servletContext;
+    }
+}

Modified: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/java/org/apache/myfaces/extensions/scripting/cdi/startup/StartupPlugin.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/java/org/apache/myfaces/extensions/scripting/cdi/startup/StartupPlugin.java?rev=1309683&r1=1309682&r2=1309683&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/java/org/apache/myfaces/extensions/scripting/cdi/startup/StartupPlugin.java
(original)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/java/org/apache/myfaces/extensions/scripting/cdi/startup/StartupPlugin.java
Thu Apr  5 08:00:18 2012
@@ -21,6 +21,7 @@ package org.apache.myfaces.extensions.sc
 
 import javax.servlet.ServletContextEvent;
 import org.apache.myfaces.extensions.scripting.core.api.Plugin;
+import org.apache.myfaces.extensions.scripting.core.api.WeavingContext;
 
 /**
  * @author Werner Punz (latest modification by $Author$)
@@ -36,7 +37,7 @@ public class StartupPlugin implements Pl
      */
     public void preInit(ServletContextEvent evt)
     {
-        System.out.println("-----------------PREINIT--------------------");
+        //WeavingContext.getInstance().
     }
 
     /**
@@ -46,7 +47,7 @@ public class StartupPlugin implements Pl
      */
     public void postInit(ServletContextEvent evt)
     {
-        System.out.println("-----------------POSTINIT--------------------");
+
     }
 
     /**
@@ -56,7 +57,6 @@ public class StartupPlugin implements Pl
      */
     public void preDestroy(ServletContextEvent evt)
     {
-        System.out.println("-----------------PREDESTROY--------------------");
     }
 
     /**
@@ -66,6 +66,5 @@ public class StartupPlugin implements Pl
      */
     public void postDestroy(ServletContextEvent evt)
     {
-        System.out.println("-----------------POSTDESTROY--------------------");
     }
 }

Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/java/org/apache/myfaces/extensions/scripting/cdi/startup/readme.txt
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/java/org/apache/myfaces/extensions/scripting/cdi/startup/readme.txt?rev=1309683&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/java/org/apache/myfaces/extensions/scripting/cdi/startup/readme.txt
(added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/java/org/apache/myfaces/extensions/scripting/cdi/startup/readme.txt
Thu Apr  5 08:00:18 2012
@@ -0,0 +1,5 @@
+What is missing is a cdi plugin which triggers the initial lifecycle once
+at cdi startup time to make a first compile then pushes the
+ThrowAwayClassloader in once for the bean loading
+and once the beans are loaded deregisters everything so that the jsf lifecycle
+can start.

Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/resources/META-INF/services/org.apache.myfaces.extensions.scripting.cdi.api.CdiContainer
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/resources/META-INF/services/org.apache.myfaces.extensions.scripting.cdi.api.CdiContainer?rev=1309683&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/resources/META-INF/services/org.apache.myfaces.extensions.scripting.cdi.api.CdiContainer
(added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/resources/META-INF/services/org.apache.myfaces.extensions.scripting.cdi.api.CdiContainer
Thu Apr  5 08:00:18 2012
@@ -0,0 +1,20 @@
+#####################################################################################
+# 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.
+#####################################################################################
+
+org.apache.myfaces.extensions.scripting.cdi.owb.OpenWebBeansContainerControl
\ No newline at end of file

Modified: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/resources/META-INF/services/org.apache.myfaces.extensions.scripting.core.api.Plugin
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/resources/META-INF/services/org.apache.myfaces.extensions.scripting.core.api.Plugin?rev=1309683&r1=1309682&r2=1309683&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/resources/META-INF/services/org.apache.myfaces.extensions.scripting.core.api.Plugin
(original)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-cdi/src/main/resources/META-INF/services/org.apache.myfaces.extensions.scripting.core.api.Plugin
Thu Apr  5 08:00:18 2012
@@ -0,0 +1,20 @@
+#####################################################################################
+# 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.
+#####################################################################################
+
+org.apache.myfaces.extensions.scripting.cdi.startup.StartupPlugin
\ No newline at end of file

Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/api/eventhandling/events/RefreshBeginEvent.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/api/eventhandling/events/RefreshBeginEvent.java?rev=1309683&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/api/eventhandling/events/RefreshBeginEvent.java
(added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/api/eventhandling/events/RefreshBeginEvent.java
Thu Apr  5 08:00:18 2012
@@ -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.myfaces.extensions.scripting.core.api.eventhandling.events;
+
+import org.apache.myfaces.extensions.scripting.core.api.eventhandling.WeavingEvent;
+
+import javax.servlet.ServletRequest;
+
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class RefreshBeginEvent implements WeavingEvent
+{
+    Object request;
+
+    public RefreshBeginEvent(Object request)
+    {
+        this.request = request;
+    }
+
+    public Object getRequest()
+    {
+        return request;
+    }
+
+    public void setRequest(Object request)
+    {
+        this.request = request;
+    }
+}

Modified: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/jsf/startup/RefreshPhaseListener.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/jsf/startup/RefreshPhaseListener.java?rev=1309683&r1=1309682&r2=1309683&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/jsf/startup/RefreshPhaseListener.java
(original)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/jsf/startup/RefreshPhaseListener.java
Thu Apr  5 08:00:18 2012
@@ -20,11 +20,13 @@
 package org.apache.myfaces.extensions.scripting.jsf.startup;
 
 import org.apache.myfaces.extensions.scripting.core.api.WeavingContext;
+import org.apache.myfaces.extensions.scripting.core.api.eventhandling.events.RefreshBeginEvent;
 
 import javax.faces.context.FacesContext;
 import javax.faces.event.PhaseEvent;
 import javax.faces.event.PhaseId;
 import javax.faces.event.PhaseListener;
+import javax.servlet.ServletRequest;
 import java.util.Map;
 
 /**
@@ -50,6 +52,10 @@ public class RefreshPhaseListener implem
         Map<Object, Object> params = context.getAttributes();
         if(params.containsKey("ANN_PROCESSED")) return;
         else params.put("ANN_PROCESSED", Boolean.TRUE);
+        WeavingContext.getInstance().sendWeavingEvent(new RefreshBeginEvent(FacesContext
+                .getCurrentInstance()
+                .getExternalContext().getRequest()));
+
         WeavingContext.getInstance().getImplementationSPI().refreshManagedBeans();
         WeavingContext.getInstance().annotationScan();
     }

Modified: myfaces/extensions/scripting/trunk/extscript-examples/cdi-example/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-examples/cdi-example/pom.xml?rev=1309683&r1=1309682&r2=1309683&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-examples/cdi-example/pom.xml (original)
+++ myfaces/extensions/scripting/trunk/extscript-examples/cdi-example/pom.xml Thu Apr  5 08:00:18
2012
@@ -10,7 +10,7 @@
     <groupId>org.apache.myfaces.extensions.scripting</groupId>
     <artifactId>myfaces21-extscript-cdi</artifactId>
     <packaging>war</packaging>
-    <name>A simple project for MyFaces 2.1 and Ext-Scripting 1.0</name>
+    <name>A simple project for MyFaces 2.1 and Ext-Scripting 1.0 and CDI</name>
     <version>1.0.4-SNAPSHOT</version>
     <url>http://www.apache.org</url>
 



Mime
View raw message