Skip to content

Commit

Permalink
SEAMFACES-33 Refactored ViewData* to ViewConfig*
Browse files Browse the repository at this point in the history
  • Loading branch information
bleathem committed Mar 23, 2011
1 parent dc7cf59 commit 8d1895f
Show file tree
Hide file tree
Showing 14 changed files with 69 additions and 74 deletions.
@@ -1,4 +1,4 @@
package org.jboss.seam.faces.viewdata;
package org.jboss.seam.faces.view.config;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
Expand Down
@@ -1,4 +1,4 @@
package org.jboss.seam.faces.viewdata;
package org.jboss.seam.faces.view.config;

import java.lang.annotation.Annotation;
import java.util.List;
Expand All @@ -7,7 +7,7 @@
* @author Stuart Douglas
*
*/
public interface ViewDataStore
public interface ViewConfigStore
{

/**
Expand Down
@@ -1,4 +1,4 @@
package org.jboss.seam.faces.viewdata;
package org.jboss.seam.faces.view.config;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
Expand All @@ -16,7 +16,7 @@
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@Documented
public @interface ViewData
public @interface ViewPattern
{
String value();
}
Expand Up @@ -9,7 +9,7 @@
import javax.inject.Inject;

import org.jboss.logging.Logger;
import org.jboss.seam.faces.viewdata.ViewDataStore;
import org.jboss.seam.faces.view.config.ViewConfigStore;
import org.jboss.seam.persistence.PersistenceContexts;
import org.jboss.seam.transaction.DefaultTransaction;
import org.jboss.seam.transaction.SeamTransaction;
Expand All @@ -31,7 +31,7 @@ public class TransactionPhaseListener implements PhaseListener
private static final Logger log = Logger.getLogger(TransactionPhaseListener.class);

@Inject
private ViewDataStore dataStore;
private ViewConfigStore dataStore;

@Inject
@DefaultTransaction
Expand Down
@@ -1,4 +1,4 @@
package org.jboss.seam.faces.viewdata;
package org.jboss.seam.faces.view.config;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
Expand All @@ -21,10 +21,10 @@
* @author stuart
*
*/
public class ViewDataConfigurationExtension implements Extension
public class ViewConfigExtension implements Extension
{

private static final Logger log = Logger.getLogger(ViewDataConfigurationExtension.class);
private static final Logger log = Logger.getLogger(ViewConfigExtension.class);

private final Map<String, Set<Annotation>> data = new HashMap<String, Set<Annotation>>();

Expand All @@ -41,16 +41,16 @@ public <T> void processAnnotatedType(@Observes ProcessAnnotatedType<T> event)
{
for (Field f : tp.getJavaClass().getDeclaredFields())
{
if (f.isAnnotationPresent(ViewData.class))
if (f.isAnnotationPresent(ViewPattern.class))
{
ViewData viewConfig = f.getAnnotation(ViewData.class);
Set<Annotation> viewData = new HashSet<Annotation>();
data.put(viewConfig.value(), viewData);
ViewPattern viewConfig = f.getAnnotation(ViewPattern.class);
Set<Annotation> viewPattern = new HashSet<Annotation>();
data.put(viewConfig.value(), viewPattern);
for (Annotation a : f.getAnnotations())
{
if (a.annotationType() != ViewData.class)
if (a.annotationType() != ViewPattern.class)
{
viewData.add(a);
viewPattern.add(a);
}
}
}
Expand Down
@@ -1,33 +1,28 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package org.jboss.seam.faces.security;
package org.jboss.seam.faces.view.config;

import javax.enterprise.event.Observes;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.PostConstructViewMapEvent;
import javax.faces.event.PreRenderViewEvent;
import javax.inject.Inject;

import org.jboss.logging.Logger;
import org.jboss.seam.faces.transaction.TransactionPhaseListener;
import org.jboss.seam.faces.viewmeta.ViewMetaStore;
import org.jboss.seam.faces.security.Restrict;
import org.jboss.seam.solder.el.Expressions;

/**
*
* @author bleathem
*/
public class ViewMetaRestrictEnforcer
public class ViewConfigSecurityEnforcer
{
private static final Logger log = Logger.getLogger(TransactionPhaseListener.class);
private static final Logger log = Logger.getLogger(ViewConfigSecurityEnforcer.class);

@Inject
private ViewMetaStore metaStore;
private ViewConfigStore metaStore;
@Inject
private Expressions expressions;

public void enforce (@Observes PostConstructViewMapEvent event)
public void enforce (@Observes PreRenderViewEvent event)
{
log.info("PostConstructViewMapEvent");
Restrict annotation = metaStore.getDataForCurrentViewId(Restrict.class);
Expand Down
@@ -1,4 +1,4 @@
package org.jboss.seam.faces.viewdata;
package org.jboss.seam.faces.view.config;

import java.lang.annotation.Annotation;
import java.util.ArrayList;
Expand All @@ -22,7 +22,7 @@
*
*/
@ApplicationScoped
public class ViewDataStoreImpl implements ViewDataStore
public class ViewConfigStoreImpl implements ViewConfigStore
{
/**
* cache of viewId to a given data list
Expand All @@ -40,7 +40,7 @@ public class ViewDataStoreImpl implements ViewDataStore
*
*/
@Inject
public void setup(ViewDataConfigurationExtension extension)
public void setup(ViewConfigExtension extension)
{
for (Entry<String, Set<Annotation>> e : extension.getData().entrySet())
{
Expand Down Expand Up @@ -120,11 +120,11 @@ private <T extends Annotation> List<T> prepareCache(String viewId, Class<T> type
if (annotationData == null)
{
List<Annotation> newList = new ArrayList<Annotation>();
Map<String, Annotation> viewData = data.get(type);
Map<String, Annotation> viewPattern = data.get(type);
List<String> resultingViews = new ArrayList<String>();
if (viewData != null)
if (viewPattern != null)
{
for (Entry<String, Annotation> e : viewData.entrySet())
for (Entry<String, Annotation> e : viewPattern.entrySet())
{
if (e.getKey().endsWith("*"))
{
Expand All @@ -147,7 +147,7 @@ private <T extends Annotation> List<T> prepareCache(String viewId, Class<T> type
Collections.sort(resultingViews, StringLengthComparator.INSTANCE);
for (String i : resultingViews)
{
newList.add(viewData.get(i));
newList.add(viewPattern.get(i));
}
}

Expand Down
Expand Up @@ -2,4 +2,4 @@ org.jboss.seam.faces.component.FormValidationTypeOverrideExtension
org.jboss.seam.faces.context.ViewScopedExtension
org.jboss.seam.faces.context.RenderScopedExtension
org.jboss.seam.faces.context.FacesAnnotationsAdapterExtension
org.jboss.seam.faces.viewdata.ViewDataConfigurationExtension
org.jboss.seam.faces.view.config.ViewConfigExtension
@@ -1,4 +1,4 @@
package org.jboss.seam.faces.test.viewdata;
package org.jboss.seam.faces.test.view.config;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
Expand Down
@@ -1,4 +1,4 @@
package org.jboss.seam.faces.test.viewdata;
package org.jboss.seam.faces.test.view.config;

import javax.enterprise.util.AnnotationLiteral;

Expand Down
@@ -0,0 +1,21 @@
package org.jboss.seam.faces.test.view.config;

import org.jboss.seam.faces.view.config.ViewConfig;
import org.jboss.seam.faces.view.config.ViewPattern;

@ViewConfig
public enum ViewConfigEnum
{
@ViewPattern("/*")
@Icon("default.gif")
DEFAULT,
@ViewPattern("/happy/*")
@Icon("happy.gif")
HAPPY,
@ViewPattern("/sad/*")
@Icon("sad.gif")
SAD,
@ViewPattern("/happy/done.xhtml")
@Icon("finished.gif")
HAPPY_DONE;
}
@@ -1,19 +1,19 @@
package org.jboss.seam.faces.test.viewdata;
package org.jboss.seam.faces.test.view.config;

import java.util.List;

import junit.framework.Assert;

import org.jboss.seam.faces.viewdata.ViewDataStore;
import org.jboss.seam.faces.viewdata.ViewDataStoreImpl;
import org.jboss.seam.faces.view.config.ViewConfigStore;
import org.jboss.seam.faces.view.config.ViewConfigStoreImpl;
import org.junit.Test;

public class ViewDataStoreTest
public class ViewConfigStoreTest
{
@Test
public void testViewDataStore()
public void testViewConfigStore()
{
ViewDataStore store = new ViewDataStoreImpl();
ViewConfigStore store = new ViewConfigStoreImpl();
store.addData("/*", new IconLiteral("default.gif"));
store.addData("/sad/*", new IconLiteral("sad.gif"));
store.addData("/happy/*", new IconLiteral("happy.gif"));
Expand Down
@@ -1,4 +1,4 @@
package org.jboss.seam.faces.test.viewdata;
package org.jboss.seam.faces.test.view.config;

import java.util.List;

Expand All @@ -8,8 +8,8 @@

import org.jboss.arquillian.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.seam.faces.viewdata.ViewDataStore;
import org.jboss.seam.faces.viewdata.ViewDataStoreImpl;
import org.jboss.seam.faces.view.config.ViewConfigStore;
import org.jboss.seam.faces.view.config.ViewConfigStoreImpl;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ArchivePaths;
import org.jboss.shrinkwrap.api.ShrinkWrap;
Expand All @@ -19,24 +19,24 @@
import org.junit.runner.RunWith;

@RunWith(Arquillian.class)
public class ViewDataConfigurationTest
public class ViewConfigTest
{

@Deployment
public static Archive<?> createTestArchive()
{
JavaArchive archive = ShrinkWrap.create(JavaArchive.class)
.addClass(ViewDataStoreImpl.class)
.addPackage(ViewDataConfigurationTest.class.getPackage())
.addClass(ViewConfigStoreImpl.class)
.addPackage(ViewConfigTest.class.getPackage())
.addManifestResource(new ByteArrayAsset(new byte[0]), ArchivePaths.create("beans.xml"));
return archive;
}

@Inject
ViewDataStore store;
ViewConfigStore store;

@Test
public void testViewDataStore()
public void testViewConfigStore()
{

store.addData("/*", new IconLiteral("default.gif"));
Expand Down

This file was deleted.

0 comments on commit 8d1895f

Please sign in to comment.