You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by gp...@apache.org on 2013/04/27 03:25:52 UTC
git commit: DELTASPIKE-336 stereotype support for view-meta-data
(first step)
Updated Branches:
refs/heads/master f06069e94 -> 7a86ca020
DELTASPIKE-336 stereotype support for view-meta-data (first step)
Project: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/commit/7a86ca02
Tree: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/tree/7a86ca02
Diff: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/diff/7a86ca02
Branch: refs/heads/master
Commit: 7a86ca020768bb6a468aa755741a152c33bbc7c1
Parents: f06069e
Author: gpetracek <gp...@apache.org>
Authored: Sat Apr 27 03:03:24 2013 +0200
Committer: gpetracek <gp...@apache.org>
Committed: Sat Apr 27 03:24:36 2013 +0200
----------------------------------------------------------------------
.../view/DefaultViewConfigInheritanceStrategy.java | 40 ++++-
.../view/custom/uc004/TestFacesRedirect.java | 1 -
.../config/view/navigation/syntax/uc007/Pages.java | 41 ++++
.../navigation/syntax/uc007/TestFacesRedirect.java | 45 +++++
.../navigation/syntax/uc007/ViewConfigTest.java | 148 +++++++++++++++
5 files changed, 272 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/7a86ca02/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/config/view/DefaultViewConfigInheritanceStrategy.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/config/view/DefaultViewConfigInheritanceStrategy.java b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/config/view/DefaultViewConfigInheritanceStrategy.java
index 1b455dd..00e7f7a 100644
--- a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/config/view/DefaultViewConfigInheritanceStrategy.java
+++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/config/view/DefaultViewConfigInheritanceStrategy.java
@@ -19,13 +19,14 @@
package org.apache.deltaspike.jsf.impl.config.view;
import org.apache.deltaspike.core.api.config.view.ViewConfig;
+import org.apache.deltaspike.core.api.config.view.metadata.ViewMetaData;
import org.apache.deltaspike.core.spi.config.view.ViewConfigInheritanceStrategy;
import org.apache.deltaspike.core.spi.config.view.ViewConfigNode;
import org.apache.deltaspike.jsf.impl.util.ViewConfigUtils;
+import javax.enterprise.inject.Stereotype;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -60,7 +61,7 @@ public class DefaultViewConfigInheritanceStrategy implements ViewConfigInheritan
//don't add the annotations of the final view-config class itself (we just need the inherited annotations)
if (ViewConfigUtils.isFolderConfig(currentClass))
{
- inheritedAnnotations.addAll(Arrays.asList(currentClass.getAnnotations()));
+ inheritedAnnotations.addAll(addViewMetaData(currentClass));
}
Class nextClass = currentClass.getSuperclass();
@@ -72,9 +73,44 @@ public class DefaultViewConfigInheritanceStrategy implements ViewConfigInheritan
}
}
}
+
+ //add meta-data inherited via stereotypes on the node itself
+ inheritedAnnotations.addAll(addViewMetaData(viewConfigNode.getSource()));
+
return inheritedAnnotations;
}
+ private List<Annotation> addViewMetaData(Class currentClass)
+ {
+ List<Annotation> result = new ArrayList<Annotation>();
+
+ for (Annotation annotation : currentClass.getAnnotations())
+ {
+ Class<? extends Annotation> annotationClass = annotation.annotationType();
+
+ if (annotationClass.getName().startsWith("java"))
+ {
+ continue;
+ }
+
+ if (annotationClass.isAnnotationPresent(ViewMetaData.class))
+ {
+ result.add(annotation);
+ }
+ else if (annotationClass.isAnnotationPresent(Stereotype.class))
+ {
+ for (Annotation inheritedViaStereotype : annotationClass.getAnnotations())
+ {
+ if (inheritedViaStereotype.annotationType().isAnnotationPresent(ViewMetaData.class))
+ {
+ result.add(inheritedViaStereotype);
+ }
+ }
+ }
+ }
+ return result;
+ }
+
private void addInterfaces(Set<Class> processedTypes, Stack<Class> classesToAnalyze, Class nextClass)
{
for (Class<?> interfaceToAdd : nextClass.getInterfaces())
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/7a86ca02/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/custom/uc004/TestFacesRedirect.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/custom/uc004/TestFacesRedirect.java b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/custom/uc004/TestFacesRedirect.java
index b4e3fb1..b586d67 100644
--- a/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/custom/uc004/TestFacesRedirect.java
+++ b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/custom/uc004/TestFacesRedirect.java
@@ -40,7 +40,6 @@ import static org.apache.deltaspike.jsf.api.config.view.View.NavigationMode.REDI
@Documented
@Stereotype
-@ViewMetaData
@View(navigation = REDIRECT)
@interface TestFacesRedirect
{
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/7a86ca02/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/navigation/syntax/uc007/Pages.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/navigation/syntax/uc007/Pages.java b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/navigation/syntax/uc007/Pages.java
new file mode 100644
index 0000000..d247d9a
--- /dev/null
+++ b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/navigation/syntax/uc007/Pages.java
@@ -0,0 +1,41 @@
+/*
+ * 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.test.jsf.impl.config.view.navigation.syntax.uc007;
+
+import org.apache.deltaspike.core.api.config.view.ViewConfig;
+import org.apache.deltaspike.jsf.api.config.view.View;
+
+import static org.apache.deltaspike.jsf.api.config.view.View.ViewParameterMode.INCLUDE;
+
+interface Pages
+{
+ @TestFacesRedirect
+ interface Public extends ViewConfig
+ {
+ class Index implements Public
+ {
+ }
+ }
+
+ @TestFacesRedirect
+ @View(viewParams = INCLUDE)
+ class Home implements ViewConfig
+ {
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/7a86ca02/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/navigation/syntax/uc007/TestFacesRedirect.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/navigation/syntax/uc007/TestFacesRedirect.java b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/navigation/syntax/uc007/TestFacesRedirect.java
new file mode 100644
index 0000000..4fe8b87
--- /dev/null
+++ b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/navigation/syntax/uc007/TestFacesRedirect.java
@@ -0,0 +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.deltaspike.test.jsf.impl.config.view.navigation.syntax.uc007;
+
+import org.apache.deltaspike.jsf.api.config.view.View;
+
+import javax.enterprise.inject.Stereotype;
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import static org.apache.deltaspike.jsf.api.config.view.View.NavigationMode.REDIRECT;
+
+/**
+ * Custom meta-data
+ */
+
+//don't use @Inherited
+@Target({TYPE})
+@Retention(RUNTIME)
+@Documented
+
+@Stereotype
+@View(navigation = REDIRECT)
+@interface TestFacesRedirect
+{
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/7a86ca02/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/navigation/syntax/uc007/ViewConfigTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/navigation/syntax/uc007/ViewConfigTest.java b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/navigation/syntax/uc007/ViewConfigTest.java
new file mode 100644
index 0000000..971006d
--- /dev/null
+++ b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/view/navigation/syntax/uc007/ViewConfigTest.java
@@ -0,0 +1,148 @@
+/*
+ * 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.test.jsf.impl.config.view.navigation.syntax.uc007;
+
+import org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor;
+import org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver;
+import org.apache.deltaspike.core.spi.config.view.ViewConfigNode;
+import org.apache.deltaspike.jsf.api.config.view.View;
+import org.apache.deltaspike.jsf.impl.config.view.ViewConfigExtension;
+import org.apache.deltaspike.jsf.impl.config.view.ViewConfigResolverProducer;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.lang.annotation.Annotation;
+
+public class ViewConfigTest
+{
+ private ViewConfigExtension viewConfigExtension;
+
+ private ViewConfigResolverProducer viewConfigResolverProducer;
+
+ @Before
+ public void before()
+ {
+ this.viewConfigExtension = new ViewConfigExtension();
+ this.viewConfigResolverProducer = new ViewConfigResolverProducer(this.viewConfigExtension);
+ }
+
+ @After
+ public void after()
+ {
+ this.viewConfigExtension.freeViewConfigCache(null);
+ }
+
+ @Test
+ public void testMetaDataTreeWithStereotypeMetaData()
+ {
+ this.viewConfigExtension.addPageDefinition(Pages.Home.class);
+ this.viewConfigExtension.addPageDefinition(Pages.Public.Index.class);
+
+ ViewConfigNode node = this.viewConfigExtension.findNode(Pages.Home.class);
+
+ Assert.assertNotNull(node);
+ Assert.assertNotNull(node.getParent());
+ Assert.assertNotNull(node.getParent().getParent());
+ Assert.assertNull(node.getParent().getParent().getParent());
+
+ Assert.assertNotNull(node.getChildren());
+ Assert.assertEquals(0, node.getChildren().size());
+
+ Assert.assertNotNull(node.getMetaData());
+ Assert.assertEquals(2, node.getMetaData().size());
+
+ Assert.assertEquals(2, node.getMetaData().size());
+
+ boolean facesRedirectAnnotationFound = false;
+ boolean viewAnnotationFound = false;
+
+ for (Annotation metaData : node.getMetaData())
+ {
+ if (TestFacesRedirect.class.isAssignableFrom(metaData.annotationType()))
+ {
+ facesRedirectAnnotationFound = true;
+ }
+ else if (View.class.isAssignableFrom(metaData.annotationType()))
+ {
+ viewAnnotationFound = true;
+ }
+ }
+
+ Assert.assertTrue(facesRedirectAnnotationFound);
+ Assert.assertTrue(viewAnnotationFound);
+
+ Assert.assertNotNull(node.getInheritedMetaData());
+ Assert.assertEquals(0, node.getInheritedMetaData().size());
+
+ Assert.assertNotNull(node.getCallbackDescriptors());
+ Assert.assertEquals(0, node.getCallbackDescriptors().size());
+
+
+ node = this.viewConfigExtension.findNode(Pages.Public.Index.class);
+
+ Assert.assertNotNull(node);
+ Assert.assertNotNull(node.getParent());
+ Assert.assertNotNull(node.getParent().getParent());
+ Assert.assertNotNull(node.getParent().getParent().getParent());
+ Assert.assertNull(node.getParent().getParent().getParent().getParent());
+
+ Assert.assertNotNull(node.getChildren());
+ Assert.assertEquals(0, node.getChildren().size());
+
+ Assert.assertNotNull(node.getMetaData());
+ Assert.assertEquals(0, node.getMetaData().size());
+
+ Assert.assertNotNull(node.getInheritedMetaData());
+ Assert.assertEquals(0, node.getInheritedMetaData().size());
+
+ Assert.assertNotNull(node.getCallbackDescriptors());
+ Assert.assertEquals(0, node.getCallbackDescriptors().size());
+ }
+
+ @Test
+ public void testViewConfigWithStereotypeMetaData()
+ {
+ this.viewConfigExtension.addPageDefinition(Pages.Home.class);
+ this.viewConfigExtension.addPageDefinition(Pages.Public.Index.class);
+
+ ViewConfigResolver viewConfigResolver = this.viewConfigResolverProducer.createViewConfigResolver();
+
+
+ ViewConfigDescriptor viewConfigDescriptor = viewConfigResolver.getViewConfigDescriptor(Pages.Home.class);
+
+ Assert.assertNotNull(viewConfigDescriptor);
+ Assert.assertNotNull(viewConfigDescriptor.getMetaData());
+ Assert.assertEquals(1, viewConfigDescriptor.getMetaData().size());
+ Assert.assertEquals(1, viewConfigDescriptor.getMetaData(View.class).size());
+ Assert.assertEquals(View.NavigationMode.REDIRECT, viewConfigDescriptor.getMetaData(View.class).iterator().next().navigation());
+ Assert.assertEquals(View.ViewParameterMode.INCLUDE, viewConfigDescriptor.getMetaData(View.class).iterator().next().viewParams());
+
+
+ viewConfigDescriptor = viewConfigResolver.getViewConfigDescriptor(Pages.Public.Index.class);
+
+ Assert.assertNotNull(viewConfigDescriptor);
+ Assert.assertNotNull(viewConfigDescriptor.getMetaData());
+ Assert.assertEquals(1, viewConfigDescriptor.getMetaData().size());
+ Assert.assertEquals(1, viewConfigDescriptor.getMetaData(View.class).size());
+ Assert.assertEquals(View.NavigationMode.REDIRECT, viewConfigDescriptor.getMetaData(View.class).iterator().next().navigation());
+ Assert.assertEquals(View.ViewParameterMode.EXCLUDE, viewConfigDescriptor.getMetaData(View.class).iterator().next().viewParams());
+ }
+}