Author: trustin
Date: Wed Apr 18 00:58:07 2007
New Revision: 529905
URL: http://svn.apache.org/viewvc?view=rev&rev=529905
Log:
Resolved issue: DIRMINA-339 (IoFilterChain.replace())
* Added IoFilterChain.replace() and its implementation
Modified:
mina/trunk/core/src/main/java/org/apache/mina/common/IoFilterChain.java
mina/trunk/core/src/main/java/org/apache/mina/common/support/AbstractIoFilterChain.java
Modified:
mina/trunk/core/src/main/java/org/apache/mina/common/IoFilterChain.java
URL:
http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/common/IoFilterChain.java?view=diff&rev=529905&r1=529904&r2=529905
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/common/IoFilterChain.java
(original)
+++ mina/trunk/core/src/main/java/org/apache/mina/common/IoFilterChain.java Wed
Apr 18 00:58:07 2007
@@ -80,7 +80,7 @@
/**
* Returns <tt>true</tt> if this chain contains an [EMAIL PROTECTED]
IoFilter} of the
- * specified <tt>filterType</tt>.
+ * specified <tt>filterType</tt>.
*/
boolean contains( Class<? extends IoFilter> filterType );
@@ -118,6 +118,32 @@
*/
void addAfter( String baseName, String name, IoFilter filter );
+ /**
+ * Replace the filter with the specified name with the specified new
+ * filter.
+ *
+ * @return the old filter
+ * @throws IllegalArgumentException if there's no such filter
+ */
+ IoFilter replace( String name, IoFilter newFilter );
+
+ /**
+ * Replace the filter with the specified name with the specified new
+ * filter.
+ *
+ * @throws IllegalArgumentException if there's no such filter
+ */
+ void replace( IoFilter oldFilter, IoFilter newFilter );
+
+ /**
+ * Replace the filter of the specified type with the specified new
+ * filter. If there's more than one filter with the specified type,
+ * the first match will be replaced.
+ *
+ * @throws IllegalArgumentException if there's no such filter
+ */
+ void replace( Class<? extends IoFilter> oldFilterType, IoFilter newFilter
);
+
/**
* Removes the filter with the specified name from this chain.
* @throws IoFilterLifeCycleException
Modified:
mina/trunk/core/src/main/java/org/apache/mina/common/support/AbstractIoFilterChain.java
URL:
http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/common/support/AbstractIoFilterChain.java?view=diff&rev=529905&r1=529904&r2=529905
==============================================================================
---
mina/trunk/core/src/main/java/org/apache/mina/common/support/AbstractIoFilterChain.java
(original)
+++
mina/trunk/core/src/main/java/org/apache/mina/common/support/AbstractIoFilterChain.java
Wed Apr 18 00:58:07 2007
@@ -154,6 +154,41 @@
deregister( entry );
return entry.getFilter();
}
+
+ public synchronized IoFilter replace( String name, IoFilter newFilter ) {
+ EntryImpl entry = checkOldName( name );
+ IoFilter oldFilter = entry.getFilter();
+ entry.setFilter(newFilter);
+ return oldFilter;
+ }
+
+ public synchronized void replace( IoFilter oldFilter, IoFilter newFilter )
{
+ EntryImpl e = head.nextEntry;
+ while( e != tail )
+ {
+ if( e.getFilter() == oldFilter )
+ {
+ e.setFilter(newFilter);
+ return;
+ }
+ e = e.nextEntry;
+ }
+ throw new IllegalArgumentException("Filter not found: " +
oldFilter.getClass().getName());
+ }
+
+ public synchronized void replace( Class<? extends IoFilter> oldFilterType,
IoFilter newFilter ) {
+ EntryImpl e = head.nextEntry;
+ while( e != tail )
+ {
+ if( oldFilterType.isAssignableFrom( e.getFilter().getClass() ) )
+ {
+ e.setFilter(newFilter);
+ return;
+ }
+ e = e.nextEntry;
+ }
+ throw new IllegalArgumentException("Filter not found: " +
oldFilterType.getName());
+ }
public synchronized void clear() throws Exception
{
@@ -168,7 +203,6 @@
{
EntryImpl newEntry = new EntryImpl( prevEntry, prevEntry.nextEntry,
name, filter );
-
try
{
filter.onPreAdd( this, name, newEntry.getNextFilter() );
@@ -240,7 +274,7 @@
EntryImpl e = ( EntryImpl ) name2entry.get( baseName );
if ( e == null )
{
- throw new IllegalArgumentException( "Unknown filter name:" +
+ throw new IllegalArgumentException( "Filter not found:" +
baseName );
}
return e;
@@ -741,13 +775,9 @@
private class EntryImpl implements Entry
{
private EntryImpl prevEntry;
-
private EntryImpl nextEntry;
-
private final String name;
-
- private final IoFilter filter;
-
+ private IoFilter filter;
private final NextFilter nextFilter;
private EntryImpl( EntryImpl prevEntry, EntryImpl nextEntry,
@@ -845,6 +875,14 @@
public IoFilter getFilter()
{
return filter;
+ }
+
+ private void setFilter(IoFilter filter) {
+ if (filter == null) {
+ throw new NullPointerException("filter");
+ }
+
+ this.filter = filter;
}
public NextFilter getNextFilter()