myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject svn commit: r1067586 - in /myfaces/extensions/cdi/trunk: examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/examples/codi/jsf12/view/inline/ examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/webapp/ jee-modules/jsf-mo...
Date Sun, 06 Feb 2011 05:05:16 GMT
Author: gpetracek
Date: Sun Feb  6 05:05:16 2011
New Revision: 1067586

URL: http://svn.apache.org/viewvc?rev=1067586&view=rev
Log:
EXTCDI-125 inline view-configs (initial draft)

Added:
    myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/examples/codi/jsf12/view/inline/
    myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/examples/codi/jsf12/view/inline/HelloMyFacesCodiInlineViewConfigPageBean.java
    myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/examples/codi/jsf12/view/inline/InlineViewConfigRootMarker.java
    myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/webapp/helloMyFacesCodiInlineViewConfig.jsp
Modified:
    myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/config/view/DefaultViewConfigExtractor.java
    myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/config/view/ExtractedInlineViewConfigDefinitionEntry.java
    myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/config/view/ViewConfigCache.java
    myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/config/view/ViewConfigExtension.java
    myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/TestableViewConfigExtension.java
    myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/ViewConfigTest.java

Added: myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/examples/codi/jsf12/view/inline/HelloMyFacesCodiInlineViewConfigPageBean.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/examples/codi/jsf12/view/inline/HelloMyFacesCodiInlineViewConfigPageBean.java?rev=1067586&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/examples/codi/jsf12/view/inline/HelloMyFacesCodiInlineViewConfigPageBean.java
(added)
+++ myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/examples/codi/jsf12/view/inline/HelloMyFacesCodiInlineViewConfigPageBean.java
Sun Feb  6 05:05:16 2011
@@ -0,0 +1,47 @@
+/*
+ * 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.examples.codi.jsf12.view.inline;
+
+import org.apache.myfaces.extensions.cdi.jsf.api.config.view.Page;
+import org.apache.myfaces.extensions.cdi.jsf.api.config.view.PreRenderView;
+import static org.apache.myfaces.extensions.cdi.jsf.api.config.view.Page.Extension.JSP;
+import org.apache.myfaces.extensions.cdi.core.api.config.view.ViewConfig;
+
+import javax.enterprise.inject.Model;
+
+/**
+ * @author Gerhard Petracek
+ */
+@Page(extension = JSP)
+@Model
+public class HelloMyFacesCodiInlineViewConfigPageBean implements ViewConfig
+{
+    private boolean preloaded = false;
+
+    @PreRenderView
+    protected void preload()
+    {
+        this.preloaded = true;
+    }
+
+    public boolean isPreloaded()
+    {
+        return preloaded;
+    }
+}

Added: myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/examples/codi/jsf12/view/inline/InlineViewConfigRootMarker.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/examples/codi/jsf12/view/inline/InlineViewConfigRootMarker.java?rev=1067586&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/examples/codi/jsf12/view/inline/InlineViewConfigRootMarker.java
(added)
+++ myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/examples/codi/jsf12/view/inline/InlineViewConfigRootMarker.java
Sun Feb  6 05:05:16 2011
@@ -0,0 +1,29 @@
+/*
+ * 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.examples.codi.jsf12.view.inline;
+
+import org.apache.myfaces.extensions.cdi.jsf.api.config.view.InlineViewConfigRoot;
+
+/**
+ * @author Gerhard Petracek
+ */
+@InlineViewConfigRoot(basePath = "/", pageBeanPostfix = "PageBean")
+public interface InlineViewConfigRootMarker
+{
+}

Added: myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/webapp/helloMyFacesCodiInlineViewConfig.jsp
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/webapp/helloMyFacesCodiInlineViewConfig.jsp?rev=1067586&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/webapp/helloMyFacesCodiInlineViewConfig.jsp
(added)
+++ myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/webapp/helloMyFacesCodiInlineViewConfig.jsp
Sun Feb  6 05:05:16 2011
@@ -0,0 +1,32 @@
+<%--
+ * 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.
+--%>
+
+<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
+<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
+<html>
+    <head>
+        <title>Hello World</title>
+    </head>
+    <body>
+        <f:view>
+            <h1>Inline ViewConfig-Demo</h1>
+            <h:outputText value="bean with inline view-config - preloaded: #{helloMyFacesCodiInlineViewConfigPageBean.preloaded}"/>
+
+            <h:messages globalOnly="true" infoStyle="color: blue;" warnStyle="color: orange;"
errorStyle="color: red;" fatalStyle="color:darkred;"/>
+        </f:view>
+    </body>
+</html>

Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/config/view/DefaultViewConfigExtractor.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/config/view/DefaultViewConfigExtractor.java?rev=1067586&r1=1067585&r2=1067586&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/config/view/DefaultViewConfigExtractor.java
(original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/config/view/DefaultViewConfigExtractor.java
Sun Feb  6 05:05:16 2011
@@ -62,10 +62,19 @@ class DefaultViewConfigExtractor impleme
         }
 
         int startIndex = viewConfigRootMarker.getPackage().getName().length() + 1;
-        String basePath = viewDefinitionClass.getName()
-                .substring(startIndex, viewDefinitionClass.getName().lastIndexOf("."));
+        int endIndex = viewDefinitionClass.getName().lastIndexOf(".");
 
-        basePath = basePath.replace(".", "/");
+        String basePath;
+        if(startIndex < endIndex)
+        {
+            basePath = viewDefinitionClass.getName()
+                    .substring(startIndex, endIndex);
+            basePath = basePath.replace(".", "/");
+        }
+        else
+        {
+            basePath = null; //both are in the same package
+        }
 
         //use the interface to make clear which information we really need
         ViewConfigEntry viewConfigEntry = new ExtractedInlineViewConfigDefinitionEntry(viewDefinitionClass,
basePath);

Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/config/view/ExtractedInlineViewConfigDefinitionEntry.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/config/view/ExtractedInlineViewConfigDefinitionEntry.java?rev=1067586&r1=1067585&r2=1067586&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/config/view/ExtractedInlineViewConfigDefinitionEntry.java
(original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/config/view/ExtractedInlineViewConfigDefinitionEntry.java
Sun Feb  6 05:05:16 2011
@@ -31,7 +31,15 @@ class ExtractedInlineViewConfigDefinitio
     public ExtractedInlineViewConfigDefinitionEntry(Class<? extends ViewConfig> viewDefinitionClass,
String basePath)
     {
         super(viewDefinitionClass);
-        this.basePath = basePath + "/";
+
+        if(basePath != null)
+        {
+            this.basePath = basePath + "/";
+        }
+        else
+        {
+            this.basePath = "";
+        }
     }
 
     @Override

Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/config/view/ViewConfigCache.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/config/view/ViewConfigCache.java?rev=1067586&r1=1067585&r2=1067586&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/config/view/ViewConfigCache.java
(original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/config/view/ViewConfigCache.java
Sun Feb  6 05:05:16 2011
@@ -62,6 +62,25 @@ public class ViewConfigCache
             inlineViewConfigRootMarker =
             new HashMap<ClassLoader, Class>();
 
+    private static Map<ClassLoader, Boolean>
+            lazyInitAllowed =
+            new HashMap<ClassLoader, Boolean>();
+
+    static void activateWriteMode()
+    {
+        setLazyInit(false);
+    }
+
+    static void deactivateWriteMode()
+    {
+        setLazyInit(true);
+    }
+
+    private static void setLazyInit(boolean newValue)
+    {
+        lazyInitAllowed.put(getClassloader(), newValue);
+    }
+
     static void addViewDefinition(String viewId, ViewConfigEntry viewDefinitionEntry)
     {
         storeViewDefinition(viewId, viewDefinitionEntry, false);
@@ -247,9 +266,19 @@ public class ViewConfigCache
             return;
         }
 
+        if(isInWriteMode())
+        {
+            return;
+        }
+
         registerInlineViewConfigEntry();
     }
 
+    private static boolean isInWriteMode()
+    {
+        return !Boolean.TRUE.equals(lazyInitAllowed.get(getClassloader()));
+    }
+
     private synchronized static void registerInlineViewConfigEntry()
     {
         List<InlineViewConfigEntry> inlineViewConfigEntryList =

Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/config/view/ViewConfigExtension.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/config/view/ViewConfigExtension.java?rev=1067586&r1=1067585&r2=1067586&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/config/view/ViewConfigExtension.java
(original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/config/view/ViewConfigExtension.java
Sun Feb  6 05:05:16 2011
@@ -65,6 +65,8 @@ public class ViewConfigExtension impleme
             return;
         }
 
+        beginViewConfigExtraction();
+
         if (processAnnotatedType.getAnnotatedType().isAnnotationPresent(Page.class))
         {
             validateViewConfigDefinition(processAnnotatedType.getAnnotatedType().getJavaClass());
@@ -93,6 +95,18 @@ public class ViewConfigExtension impleme
             processAnnotatedType.setAnnotatedType(
                                 new ViewControllerWrapper(processAnnotatedType.getAnnotatedType()));
         }
+
+        endViewConfigExtraction();
+    }
+
+    protected void beginViewConfigExtraction()
+    {
+        ViewConfigCache.activateWriteMode();
+    }
+
+    protected void endViewConfigExtraction()
+    {
+        ViewConfigCache.deactivateWriteMode();
     }
 
     protected void setInlineViewConfigRootMarker(Class markerClass)

Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/TestableViewConfigExtension.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/TestableViewConfigExtension.java?rev=1067586&r1=1067585&r2=1067586&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/TestableViewConfigExtension.java
(original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/TestableViewConfigExtension.java
Sun Feb  6 05:05:16 2011
@@ -49,4 +49,15 @@ class TestableViewConfigExtension extend
     {
         return super.isInlineViewConfig(beanClass);
     }
+
+    @Override
+    public void beginViewConfigExtraction()
+    {
+        super.beginViewConfigExtraction();
+    }
+
+    public void finalizeConfig()
+    {
+        super.endViewConfigExtraction();
+    }
 }

Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/ViewConfigTest.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/ViewConfigTest.java?rev=1067586&r1=1067585&r2=1067586&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/ViewConfigTest.java
(original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/jsf/test/impl/config/view/ViewConfigTest.java
Sun Feb  6 05:05:16 2011
@@ -46,6 +46,7 @@ public class ViewConfigTest
     public void resetCache()
     {
         ViewConfigCache.reset();
+        viewConfigExtension.beginViewConfigExtraction(); //allow lazy init
     }
 
     @Test
@@ -286,6 +287,8 @@ public class ViewConfigTest
         viewConfigExtension.addInlinePageDefinition(OrderOverviewPage.class);
         viewConfigExtension.addInlinePageDefinition(RegistrationStep01PageBean.class);
 
+        viewConfigExtension.finalizeConfig();
+
         assertEquals(ViewConfigCache.getViewDefinition(
                 OrderOverviewPage.class).getViewId(),
                 "/pages/order/orderOverview.xhtml");
@@ -311,6 +314,8 @@ public class ViewConfigTest
         viewConfigExtension.addInlinePageDefinition(OrderOverviewPage.class);
         viewConfigExtension.addInlinePageDefinition(RegistrationStep01PageBean.class);
 
+        viewConfigExtension.finalizeConfig();
+
         assertEquals(ViewConfigCache.getViewDefinition(
                 OrderOverviewPage.class).getViewId(),
                 "/views/order/orderOverview.xhtml");
@@ -336,6 +341,8 @@ public class ViewConfigTest
         viewConfigExtension.addInlinePageDefinition(OrderOverviewPage.class);
         viewConfigExtension.addInlinePageDefinition(RegistrationStep01PageBean.class);
 
+        viewConfigExtension.finalizeConfig();
+
         assertEquals(ViewConfigCache.getViewDefinition(
                 OrderOverviewPage.class).getViewId(),
                 "/order/orderOverview.xhtml");
@@ -366,6 +373,8 @@ public class ViewConfigTest
     {
         viewConfigExtension.addInlinePageDefinition(OrderOverviewPage.class);
 
+        viewConfigExtension.finalizeConfig();
+
         try
         {
             assertEquals(ViewConfigCache.getViewDefinition(



Mime
View raw message