Search in sources :

Example 16 with ViewConfigNode

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());
}
Also used : ArrayList(java.util.ArrayList) ViewConfigNode(org.apache.deltaspike.core.spi.config.view.ViewConfigNode) Annotation(java.lang.annotation.Annotation) Test(org.junit.Test)

Example 17 with ViewConfigNode

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());
}
Also used : ViewConfigNode(org.apache.deltaspike.core.spi.config.view.ViewConfigNode) Test(org.junit.Test)

Example 18 with ViewConfigNode

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;
}
Also used : ViewConfig(org.apache.deltaspike.core.api.config.view.ViewConfig) ViewConfigNode(org.apache.deltaspike.core.spi.config.view.ViewConfigNode)

Example 19 with 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;
        }
    }
}
Also used : ViewConfigNode(org.apache.deltaspike.core.spi.config.view.ViewConfigNode) ApplicationScoped(javax.enterprise.context.ApplicationScoped) Annotation(java.lang.annotation.Annotation) HashSet(java.util.HashSet)

Example 20 with ViewConfigNode

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;
}
Also used : ArrayList(java.util.ArrayList) ViewConfigNode(org.apache.deltaspike.core.spi.config.view.ViewConfigNode) Annotation(java.lang.annotation.Annotation)

Aggregations

ViewConfigNode (org.apache.deltaspike.core.spi.config.view.ViewConfigNode)31 Test (org.junit.Test)24 Annotation (java.lang.annotation.Annotation)7 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 Set (java.util.Set)3 CopyOnWriteArraySet (java.util.concurrent.CopyOnWriteArraySet)2 ViewConfig (org.apache.deltaspike.core.api.config.view.ViewConfig)2 View (org.apache.deltaspike.jsf.api.config.view.View)2 ApplicationScoped (javax.enterprise.context.ApplicationScoped)1 CallbackDescriptor (org.apache.deltaspike.core.api.config.view.metadata.CallbackDescriptor)1 InlineViewMetaData (org.apache.deltaspike.core.api.config.view.metadata.InlineViewMetaData)1 ViewConfigDescriptor (org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor)1 ViewConfigResolver (org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver)1 InlineMetaDataTransformer (org.apache.deltaspike.core.spi.config.view.InlineMetaDataTransformer)1 TargetViewConfigProvider (org.apache.deltaspike.core.spi.config.view.TargetViewConfigProvider)1