deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject git commit: DELTASPIKE-480 ViewConfigValidator
Date Thu, 26 Dec 2013 14:12:00 GMT
Updated Branches:
  refs/heads/master 4adb68be2 -> 5e213acd2


DELTASPIKE-480 ViewConfigValidator


Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/5e213acd
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/5e213acd
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/5e213acd

Branch: refs/heads/master
Commit: 5e213acd28d800df42f29ba2ddf60994fd5de2b4
Parents: 4adb68b
Author: gpetracek <gpetracek@apache.org>
Authored: Thu Dec 26 15:10:30 2013 +0100
Committer: gpetracek <gpetracek@apache.org>
Committed: Thu Dec 26 15:10:30 2013 +0100

----------------------------------------------------------------------
 .../impl/config/view/ViewConfigExtension.java   | 14 ++++
 .../impl/config/view/ViewConfigValidator.java   | 69 ++++++++++++++++++++
 .../main/resources/META-INF/web-fragment.xml    | 36 ++++++++++
 3 files changed, 119 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/5e213acd/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/config/view/ViewConfigExtension.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/config/view/ViewConfigExtension.java
b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/config/view/ViewConfigExtension.java
index 000f570..1aa9500 100644
--- a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/config/view/ViewConfigExtension.java
+++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/config/view/ViewConfigExtension.java
@@ -18,7 +18,9 @@
  */
 package org.apache.deltaspike.jsf.impl.config.view;
 
+import org.apache.deltaspike.core.api.config.view.DefaultErrorView;
 import org.apache.deltaspike.core.api.config.view.ViewConfig;
+import org.apache.deltaspike.core.api.config.view.ViewRef;
 import org.apache.deltaspike.core.spi.config.view.ConfigDescriptorValidator;
 import org.apache.deltaspike.core.api.config.view.metadata.InlineViewMetaData;
 import org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver;
@@ -171,6 +173,11 @@ public class ViewConfigExtension implements Extension, Deactivatable
 
     protected void addConfigClass(Class viewConfigClass, Set<Annotation> viewConfigAnnotations)
     {
+        if (isInternal(viewConfigClass))
+        {
+            return;
+        }
+
         String className = viewConfigClass.getName();
         if (!className.contains("."))
         {
@@ -222,6 +229,13 @@ public class ViewConfigExtension implements Extension, Deactivatable
         }
     }
 
+    private boolean isInternal(Class configClass)
+    {
+        return ViewConfig.class.equals(configClass) ||
+                DefaultErrorView.class.equals(configClass) ||
+                ViewRef.Manual.class.equals(configClass);
+    }
+
     private ViewConfigNode addNode(ViewConfigNode parentNode, Class idOfNewNode, Set<Annotation>
viewConfigAnnotations)
     {
         if (parentNode == null)

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/5e213acd/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/config/view/ViewConfigValidator.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/config/view/ViewConfigValidator.java
b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/config/view/ViewConfigValidator.java
new file mode 100644
index 0000000..fb034e0
--- /dev/null
+++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/config/view/ViewConfigValidator.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.jsf.impl.config.view;
+
+import org.apache.deltaspike.core.api.config.view.metadata.ConfigDescriptor;
+import org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver;
+import org.apache.deltaspike.core.api.provider.BeanProvider;
+import org.apache.deltaspike.core.spi.activation.Deactivatable;
+import org.apache.deltaspike.core.util.ClassDeactivationUtils;
+import org.apache.deltaspike.core.util.ExceptionUtils;
+
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+import java.net.MalformedURLException;
+
+public class ViewConfigValidator implements ServletContextListener, Deactivatable
+{
+    @Override
+    public void contextInitialized(ServletContextEvent sce)
+    {
+        if (ClassDeactivationUtils.isActivated(getClass()))
+        {
+            checkViewConfig(sce);
+        }
+    }
+
+    protected void checkViewConfig(ServletContextEvent sce)
+    {
+        ViewConfigResolver viewConfigResolver = BeanProvider.getContextualReference(ViewConfigResolver.class);
+
+        for (ConfigDescriptor configDescriptor : viewConfigResolver.getConfigDescriptors())
+        {
+            try
+            {
+                if (sce.getServletContext().getResource(configDescriptor.getPath()) == null)
+                {
+                    throw new IllegalStateException("path '" + configDescriptor.getPath()
+
+                        "' is missing, but mapped by: " + configDescriptor.getConfigClass().getName());
+                }
+            }
+            catch (MalformedURLException e)
+            {
+                throw ExceptionUtils.throwAsRuntimeException(e);
+            }
+        }
+    }
+
+    @Override
+    public void contextDestroyed(ServletContextEvent sce)
+    {
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/5e213acd/deltaspike/modules/jsf/impl/src/main/resources/META-INF/web-fragment.xml
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/resources/META-INF/web-fragment.xml b/deltaspike/modules/jsf/impl/src/main/resources/META-INF/web-fragment.xml
new file mode 100644
index 0000000..c9e9907
--- /dev/null
+++ b/deltaspike/modules/jsf/impl/src/main/resources/META-INF/web-fragment.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<web-fragment version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-fragment_3_0.xsd">
+
+    <name>deltaspike_jsf_module</name>
+
+    <distributable/>
+
+    <listener>
+        <listener-class>org.apache.deltaspike.jsf.impl.config.view.ViewConfigValidator</listener-class>
+    </listener>
+
+    <ordering>
+        <after>
+            <others/>
+        </after>
+    </ordering>
+</web-fragment>
\ No newline at end of file


Mime
View raw message