[seam-commits] Seam SVN: r7724 - in trunk/src/main/org/jboss/seam: servlet and 1 other directories.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Thu Mar 27 14:09:46 EDT 2008
Author: pete.muir at jboss.org
Date: 2008-03-27 14:09:46 -0400 (Thu, 27 Mar 2008)
New Revision: 7724
Modified:
trunk/src/main/org/jboss/seam/Component.java
trunk/src/main/org/jboss/seam/servlet/SeamFilter.java
trunk/src/main/org/jboss/seam/util/SortItem.java
trunk/src/main/org/jboss/seam/util/Sorter.java
Log:
Revert r7722 and r7723
Modified: trunk/src/main/org/jboss/seam/Component.java
===================================================================
--- trunk/src/main/org/jboss/seam/Component.java 2008-03-27 17:33:32 UTC (rev 7723)
+++ trunk/src/main/org/jboss/seam/Component.java 2008-03-27 18:09:46 UTC (rev 7724)
@@ -957,46 +957,44 @@
private List<Interceptor> newSort(List<Interceptor> list)
{
-
- List<SortItem<Interceptor>> sortable = new ArrayList<SortItem<Interceptor>>();
-
- for (final Interceptor i : list)
+ List<SortItem<Interceptor>> siList = new ArrayList<SortItem<Interceptor>>();
+ Map<Class<?>,SortItem<Interceptor>> ht = new HashMap<Class<?>,SortItem<Interceptor>>();
+
+ for (Interceptor i : list)
{
-
-
- sortable.add(new SortItem<Interceptor>()
- {
-
- Class<?> clazz = i.getUserInterceptorClass();
- org.jboss.seam.annotations.intercept.Interceptor interceptor = clazz.getAnnotation(org.jboss.seam.annotations.intercept.Interceptor.class);
+ SortItem<Interceptor> si = new SortItem<Interceptor>(i);
+ siList.add(si);
+ ht.put( i.getUserInterceptorClass(), si );
+ }
- @Override
- public List<Class> getAround()
+ for (SortItem<Interceptor> si : siList)
+ {
+ Class<?> clazz = si.getObj().getUserInterceptorClass();
+ if ( clazz.isAnnotationPresent(org.jboss.seam.annotations.intercept.Interceptor.class) )
+ {
+ org.jboss.seam.annotations.intercept.Interceptor interceptorAnn = clazz.getAnnotation(org.jboss.seam.annotations.intercept.Interceptor.class);
+ for (Class<?> cl : Arrays.asList( interceptorAnn.around() ) )
{
- return Arrays.asList(interceptor.around());
+ SortItem<Interceptor> sortItem = ht.get(cl);
+ if (sortItem!=null) si.getAround().add( sortItem );
}
-
- @Override
- protected Interceptor getObject()
+ for (Class<?> cl : Arrays.asList( interceptorAnn.within() ) )
{
- return i;
+ SortItem<Interceptor> sortItem = ht.get(cl);
+ if (sortItem!=null) si.getWithin().add( sortItem );
}
+ }
+ }
- @Override
- public List<Class> getWithin()
- {
- return Arrays.asList(interceptor.within());
- }
-
- @Override
- public Class getKey()
- {
- return clazz;
- }
-
- });
+ Sorter<Interceptor> sList = new Sorter<Interceptor>();
+ siList = sList.sort(siList);
+
+ list.clear();
+ for (SortItem<Interceptor> si : siList)
+ {
+ list.add( si.getObj() );
}
- return new Sorter<Interceptor>().sort(sortable);
+ return list ;
}
private void initDefaultInterceptors()
Modified: trunk/src/main/org/jboss/seam/servlet/SeamFilter.java
===================================================================
--- trunk/src/main/org/jboss/seam/servlet/SeamFilter.java 2008-03-27 17:33:32 UTC (rev 7723)
+++ trunk/src/main/org/jboss/seam/servlet/SeamFilter.java 2008-03-27 18:09:46 UTC (rev 7724)
@@ -3,7 +3,9 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
@@ -103,60 +105,51 @@
private List<Filter> getSortedFilters()
{
- List<SortItem<Filter>> sortable = new ArrayList<SortItem<Filter>>();
//retrieve the Filter instances from the application context
+ Map<String, SortItem<Filter>> sortItemsMap = new HashMap<String, SortItem<Filter>>();
+ List<SortItem<Filter>> sortItems = new ArrayList<SortItem<Filter>>();
-
- for (final String filterName : Init.instance().getInstalledFilters())
+ for (String filterName : Init.instance().getInstalledFilters())
{
-
- sortable.add(new SortItem<Filter>()
+ Filter filter = (Filter) Component.getInstance(filterName, ScopeType.APPLICATION);
+ boolean disabled = false;
+ if (filter instanceof AbstractFilter)
{
+ disabled = ((AbstractFilter) filter).isDisabled();
+ }
+ if (!disabled)
+ {
+ SortItem<Filter> si = new SortItem<Filter>(filter);
+ sortItemsMap.put(filterName, si);
+ sortItems.add(si);
+ }
+ }
- private Filter filter = (Filter) Component.getInstance(filterName, ScopeType.APPLICATION);
-
- @Override
- public List<String> getAround()
+ //create sort items
+ for (SortItem<Filter> sortItem : sortItems)
+ {
+ org.jboss.seam.annotations.web.Filter filterAnn = getFilterAnnotation(sortItem.getObj().getClass());
+ if ( filterAnn != null )
+ {
+ for (String s : Arrays.asList( filterAnn.around() ) )
{
- return Arrays.asList( getFilterAnnotation( filter.getClass() ).around() );
+ SortItem<Filter> aroundSortItem = sortItemsMap.get(s);
+ if (sortItem!=null && aroundSortItem != null) sortItem.getAround().add( aroundSortItem );
}
-
- @Override
- protected Filter getObject()
+ for (String s : Arrays.asList( filterAnn.within() ) )
{
- return filter;
+ SortItem<Filter> withinSortItem = sortItemsMap.get(s);
+ if (sortItem!=null && withinSortItem != null) sortItem.getWithin().add( withinSortItem );
}
-
- @Override
- public List<String> getWithin()
- {
- return Arrays.asList( getFilterAnnotation( filter.getClass() ).within() );
- }
-
- @Override
- public boolean isAddable()
- {
- if (filter instanceof AbstractFilter)
- {
- return !((AbstractFilter) filter).isDisabled();
- }
- else
- {
- return true;
- }
- }
-
- @Override
- public String getKey()
- {
- return filter.getClass().getName();
- }
-
-
- });
+ }
}
- return new Sorter<Filter>().sort(sortable);
-
+
+ // Do the sort
+ Sorter<Filter> sList = new Sorter<Filter>();
+ sortItems = sList.sort(sortItems);
+ List<Filter> sorted = new ArrayList<Filter>();
+ for (SortItem<Filter> si: sortItems) sorted.add( si.getObj() );
+ return sorted;
}
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
Modified: trunk/src/main/org/jboss/seam/util/SortItem.java
===================================================================
--- trunk/src/main/org/jboss/seam/util/SortItem.java 2008-03-27 17:33:32 UTC (rev 7723)
+++ trunk/src/main/org/jboss/seam/util/SortItem.java 2008-03-27 18:09:46 UTC (rev 7724)
@@ -3,42 +3,31 @@
import java.util.ArrayList;
import java.util.List;
-
-public abstract class SortItem<T>
+public class SortItem<T>
{
- private List<SortItem> around = new ArrayList<SortItem>();
- private List<SortItem> within = new ArrayList<SortItem>();
-
- final List<SortItem> getAroundSortItems()
+ private T obj;
+ private List<SortItem> around = new ArrayList<SortItem>();
+ private List<SortItem> within = new ArrayList<SortItem>();
+
+ public SortItem(T obj)
{
- return around;
- }
+ this.obj = obj;
+ }
- final List<SortItem> getWithinSortItems()
+ public T getObj()
{
- return within;
- }
+ return obj;
+ }
- public Object getKey()
+ public List<SortItem> getAround()
{
- return getObject().hashCode();
- }
+ return around;
+ }
- protected abstract T getObject();
-
- public boolean isAddable()
+ public List<SortItem> getWithin()
{
- return true;
- }
+ return within;
+ }
- public abstract List<? extends Object> getAround();
- public abstract List<? extends Object> getWithin();
-
- @Override
- public String toString()
- {
- return getObject().toString() + " within [" + getWithin() + "] around [" + getAround() + "]";
- }
-
}
Modified: trunk/src/main/org/jboss/seam/util/Sorter.java
===================================================================
--- trunk/src/main/org/jboss/seam/util/Sorter.java 2008-03-27 17:33:32 UTC (rev 7723)
+++ trunk/src/main/org/jboss/seam/util/Sorter.java 2008-03-27 18:09:46 UTC (rev 7724)
@@ -1,28 +1,54 @@
package org.jboss.seam.util;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
public class Sorter<T>
{
- private void remove(SortItem<T> item, List<SortItem<T>> list)
+ private List<SortItem<T>> list = null; //new ArrayList();
+
+ public List<SortItem<T>> sort(List<SortItem<T>> lst)
{
+
+ this.list = lst;
+ List<SortItem<T>> res = new ArrayList<SortItem<T>>();
+ SortItem<T> inmost = null;
+
+ do
+ {
+ inmost = getInmost();
+ if (inmost!=null)
+ {
+ res.add(inmost);
+ remove(inmost);
+ }
+ }
+ while ( !list.isEmpty() && inmost!=null );
+
+ if ( !list.isEmpty() )
+ {
+ throw new IllegalArgumentException("Can not sort list:"+list);
+ }
+
+ return res;
+ }
+
+ private void remove(SortItem<T> item)
+ {
list.remove(item);
for (SortItem<T> o: list)
{
- o.getWithinSortItems().remove(item);
+ o.getWithin().remove(item);
}
}
- private SortItem<T> getInmost(List<SortItem<T>> list)
+ private SortItem<T> getInmost()
{
SortItem<T> res=null;
for (SortItem<T> o: list)
{
- if ( o.getWithinSortItems().isEmpty() && nobodyWantsAround(o, list) )
+ if ( o.getWithin().isEmpty() && nobodyWantsAround(o) )
{
res = o;
break;
@@ -31,12 +57,12 @@
return res;
}
- private boolean nobodyWantsAround(SortItem<T> item, List<SortItem<T>> list)
+ private boolean nobodyWantsAround(SortItem<T> item)
{
boolean res = true;
for (SortItem<T> o: list)
{
- if ( o.getAroundSortItems().contains(item) )
+ if ( o.getAround().contains(item) )
{
res = false;
break;
@@ -45,69 +71,4 @@
return res;
}
- public List<T> sort(List<SortItem<T>> sortable)
- {
-
- // Build a map of items
- Map<Object, SortItem<T>> sortItemsMap = new HashMap<Object, SortItem<T>>();
- for (SortItem<T> item : sortable)
- {
- if (item.isAddable())
- {
- sortItemsMap.put(item.getKey(), item);
- }
- }
-
- List<SortItem<T>> sortItemsList = new ArrayList<SortItem<T>>();
-
- for ( Object key : sortItemsMap.keySet() )
- {
- SortItem<T> sortItem = sortItemsMap.get(key);
- for ( Object aroundKey : sortItem.getAround() )
- {
- if ( sortItemsMap.get( aroundKey ) != null )
- {
- sortItem.getAroundSortItems().add( sortItemsMap.get(aroundKey) );
- }
- }
- for ( Object withinKey : sortItem.getWithin() )
- {
- if ( sortItemsMap.get( withinKey ) != null )
- {
- sortItem.getWithinSortItems().add( sortItemsMap.get( withinKey ) );
- }
- }
- sortItemsList.add(sortItem);
- }
-
- List<SortItem<T>> result = new ArrayList<SortItem<T>>();
- SortItem<T> inmost = null;
-
- do
- {
- inmost = getInmost(sortItemsList);
- if (inmost!=null)
- {
- result.add(inmost);
- remove(inmost, sortItemsList);
- }
- }
- while ( !sortItemsList.isEmpty() && inmost!=null );
-
- if ( !sortItemsList.isEmpty() )
- {
- throw new IllegalArgumentException("Can not sort list:" + sortItemsList);
- }
-
-
- List<T> sorted = new ArrayList<T>();
- for (SortItem<T> sortItem : result)
- {
- sorted.add( sortItem.getObject() );
- }
- return sorted;
- }
-
-
-
}
More information about the seam-commits
mailing list