use of org.apache.deltaspike.core.spi.config.view.ViewConfigNode in project deltaspike by apache.
the class ViewConfigTest method testSimpleMetaDataTreeWithViewControllerCallback.
@Test
public void testSimpleMetaDataTreeWithViewControllerCallback() {
this.viewConfigExtension.addPageDefinition(SimplePageConfig.class);
ViewConfigNode node = this.viewConfigExtension.findNode(SimplePageConfig.class);
Assert.assertNotNull(node);
Assert.assertNotNull(node.getParent());
Assert.assertNull(node.getParent().getParent());
Assert.assertNotNull(node.getChildren());
Assert.assertEquals(0, node.getChildren().size());
Assert.assertNotNull(node.getMetaData());
Assert.assertEquals(2, node.getMetaData().size());
Iterator<Annotation> metaDataIterator = node.getMetaData().iterator();
List<Class<? extends Annotation>> possibleMetaDataTypes = new ArrayList<Class<? extends Annotation>>();
possibleMetaDataTypes.add(ViewControllerRef.class);
possibleMetaDataTypes.add(TestSecured.class);
Class<? extends Annotation> foundMetaData = metaDataIterator.next().annotationType();
possibleMetaDataTypes.remove(foundMetaData);
foundMetaData = metaDataIterator.next().annotationType();
possibleMetaDataTypes.remove(foundMetaData);
Assert.assertTrue(possibleMetaDataTypes.isEmpty());
Assert.assertNotNull(node.getInheritedMetaData());
Assert.assertEquals(0, node.getInheritedMetaData().size());
Assert.assertNotNull(node.getCallbackDescriptors());
// TODO related to the discussion about #getInheritedMetaData (see TODOs in other use-cases)
// get added directly before adding the meta-data
Assert.assertEquals(0, node.getCallbackDescriptors().size());
}
use of org.apache.deltaspike.core.spi.config.view.ViewConfigNode in project deltaspike by apache.
the class ViewConfigTest method testSimpleMetaDataTreeWithCustomMetaData.
@Test
public void testSimpleMetaDataTreeWithCustomMetaData() {
this.viewConfigExtension.addPageDefinition(SimplePageConfig.class);
ViewConfigNode node = this.viewConfigExtension.findNode(SimplePageConfig.class);
Assert.assertNotNull(node);
Assert.assertNotNull(node.getParent());
Assert.assertNull(node.getParent().getParent());
Assert.assertNotNull(node.getChildren());
Assert.assertEquals(0, node.getChildren().size());
Assert.assertNotNull(node.getMetaData());
Assert.assertEquals(1, node.getMetaData().size());
Assert.assertEquals(TestEntryPoint.class, node.getMetaData().iterator().next().annotationType());
Assert.assertNotNull(node.getInheritedMetaData());
Assert.assertEquals(0, node.getInheritedMetaData().size());
Assert.assertNotNull(node.getCallbackDescriptors());
Assert.assertEquals(0, node.getCallbackDescriptors().size());
}
use of org.apache.deltaspike.core.spi.config.view.ViewConfigNode in project deltaspike by apache.
the class ViewConfigExtension method addNode.
private ViewConfigNode addNode(ViewConfigNode parentNode, Class idOfNewNode, Set<Annotation> viewConfigAnnotations) {
if (parentNode == null) {
parentNode = this.rootViewConfigNode;
}
ViewConfigNode viewConfigNode;
if (ViewConfigUtils.isFolderConfig(idOfNewNode)) {
viewConfigNode = new FolderConfigNode(idOfNewNode, parentNode, viewConfigAnnotations);
} else {
viewConfigNode = new PageViewConfigNode((Class<? extends ViewConfig>) idOfNewNode, parentNode, viewConfigAnnotations);
}
parentNode.getChildren().add(viewConfigNode);
return viewConfigNode;
}
use of org.apache.deltaspike.core.spi.config.view.ViewConfigNode in project deltaspike by apache.
the class ViewConfigExtension method addConfigClass.
protected void addConfigClass(Class viewConfigClass, Set<Annotation> viewConfigAnnotations) {
if (isInternal(viewConfigClass)) {
return;
}
String className = viewConfigClass.getName();
if (!className.contains(".")) {
if (className.contains("$")) {
className = className.substring(0, className.indexOf("$"));
}
throw new IllegalStateException("Please move the class '" + className + "' to a package!");
}
for (Annotation annotation : viewConfigAnnotations) {
if (annotation.annotationType().equals(ViewConfigRoot.class)) {
if (this.rootViewConfigNode.getSource() != null) {
throw new IllegalStateException("@" + ViewConfigRoot.class.getName() + " has been found at " + viewConfigClass.getName() + " and " + this.rootViewConfigNode.getSource().getName());
}
this.rootViewConfigNode.getMetaData().add(annotation);
this.rootViewConfigNode = new FolderConfigNode(this.rootViewConfigNode, viewConfigClass);
// needed for cdi 1.1+ with bean-discovery-mode 'annotated'
if (viewConfigClass.getAnnotation(ApplicationScoped.class) != null) {
Set<Class> manuallyDiscoveredViewConfigs = new HashSet<Class>();
findNestedClasses(viewConfigClass, manuallyDiscoveredViewConfigs);
for (Class foundClass : manuallyDiscoveredViewConfigs) {
buildViewConfigMetaDataTreeFor(foundClass, new HashSet<Annotation>(Arrays.asList(foundClass.getAnnotations())), new VetoCallback() {
@Override
public void veto() {
}
});
}
}
break;
}
}
List<Class> treePath = ViewConfigUtils.toNodeList(viewConfigClass);
ViewConfigNode previousRootNode = null;
for (Class currentNode : treePath) {
// can only return a node if a folder was added already
ViewConfigNode baseNode = findNode(currentNode);
if (baseNode == null) {
Set<Annotation> metaData = viewConfigAnnotations;
if (// small tweak
!currentNode.equals(viewConfigClass)) {
metaData = new HashSet<Annotation>(Arrays.asList(currentNode.getAnnotations()));
}
previousRootNode = addNode(previousRootNode, currentNode, metaData);
} else {
previousRootNode = baseNode;
}
}
}
use of org.apache.deltaspike.core.spi.config.view.ViewConfigNode in project deltaspike by apache.
the class DefaultViewConfigInheritanceStrategy method tryToReplaceWithMergedMetaDataFromAncestor.
// only supported for meta-data which isn't aggregated
protected List<Annotation> tryToReplaceWithMergedMetaDataFromAncestor(Class currentClass, ViewConfigNode parentViewConfigNode, List<Annotation> foundResult) {
ViewConfigNode ancestorNode = findNodeWithClass(currentClass, parentViewConfigNode);
if (ancestorNode == null) {
return foundResult;
}
List<Annotation> result = new ArrayList<Annotation>(foundResult.size());
// only replace the meta-data found for the node and don't add all meta-data from the ancestor-node
for (Annotation annotation : foundResult) {
Annotation finalMetaData = getFinalMetaDataFromNode(ancestorNode, annotation);
result.add(finalMetaData);
}
return result;
}
Aggregations