Hello Berin!
This is the part of Patch #10 that may be applied right away.
It adds makeReadOnly() and writeableCopy() to
util/LifecycleExtensionManager - this will used by Part II
--- LifecycleExtensionManager.orig 2003-04-22 16:37:10.000000000 +0400
+++ LifecycleExtensionManager.java 2003-05-29 12:24:19.000000000 +0400
@@ -89,6 +89,24 @@
private final CachedArrayList m_accessorExtensions = new CachedArrayList();
private final CachedArrayList m_creatorExtensions = new CachedArrayList();
+ private boolean m_readOnly = false;
+
+ public void makeReadOnly()
+ {
+ m_readOnly = true;
+ }
+
+ /**
+ * Create a copy; it will be writeable even if the original was not.
+ */
+ public LifecycleExtensionManager writeableCopy()
+ {
+ final LifecycleExtensionManager copy = new LifecycleExtensionManager();
+ copy.m_accessorExtensions.copyFrom( m_accessorExtensions );
+ copy.m_creatorExtensions.copyFrom( m_creatorExtensions );
+ return copy;
+ }
+
/**
* <code>executeAccessExtensions</code> method, executes all access
* level extensions on the given component.
@@ -168,6 +186,7 @@
*/
public void addAccessorExtension( final Accessor extension )
{
+ checkWriteable();
m_accessorExtensions.add( extension );
}
@@ -178,6 +197,7 @@
*/
public void addCreatorExtension( final Creator extension )
{
+ checkWriteable();
m_creatorExtensions.add( extension );
}
@@ -189,6 +209,7 @@
*/
public void insertAccessorExtension( final int position, final Accessor extension
)
{
+ checkWriteable();
m_accessorExtensions.insert( position, extension );
}
@@ -200,6 +221,7 @@
*/
public void insertCreatorExtension( final int position, final Creator extension )
{
+ checkWriteable();
m_creatorExtensions.insert( position, extension );
}
@@ -211,6 +233,7 @@
*/
public Accessor removeAccessorExtension( final int position )
{
+ checkWriteable();
return (Accessor) m_accessorExtensions.remove( position );
}
@@ -222,6 +245,7 @@
*/
public Creator removeCreatorExtension( final int position )
{
+ checkWriteable();
return (Creator) m_creatorExtensions.remove( position );
}
@@ -292,6 +316,7 @@
*/
public void clearAccessorExtensions()
{
+ checkWriteable();
m_accessorExtensions.clear();
}
@@ -300,6 +325,7 @@
*/
public void clearCreatorExtensions()
{
+ checkWriteable();
m_creatorExtensions.clear();
}
@@ -367,6 +393,22 @@
}
/**
+ * Utility method to check if LifecycleExtensionsManager
+ * is writeable and if not throw exception.
+ *
+ * @throws IllegalStateException if context is read only
+ */
+ protected final void checkWriteable()
+ throws IllegalStateException
+ {
+ if( m_readOnly )
+ {
+ final String message =
+ "LifecycleExtensionsManager is read only and can not be modified";
+ throw new IllegalStateException( message );
+ }
+ }
+ /**
* <code>CachedArrayList</code> class.
*
* <p>
@@ -404,6 +446,16 @@
private Object[] m_cache = EMPTY_ARRAY;
/**
+ * Become a copy of another CachedArrayList.
+ */
+ public void copyFrom( final CachedArrayList original )
+ {
+ m_proxy.clear();
+ m_proxy.addAll( original.m_proxy );
+ m_cache = original.m_cache; // it won't mutate anyway :-)
+ }
+
+ /**
* Add an object to the list
*
* @param object an <code>Object</code> value
@@ -440,13 +492,14 @@
}
/**
- * Obtain an iterator
+ * Obtain an iterator. This iterator is read-only.
*
* @return an <code>Iterator</code> value
*/
public Iterator iterator()
{
- return m_proxy.iterator();
+ final Iterator base = m_proxy.iterator();
+ return new UnmodifiableIterator( base );
}
/**
@@ -502,4 +555,26 @@
return m_cache;
}
}
+
+ private static class UnmodifiableIterator implements Iterator
+ {
+ private final Iterator m_base;
+ UnmodifiableIterator( final Iterator base )
+ {
+ if ( base == null ) throw new NullPointerException( "base can not be
null" );
+ m_base = base;
+ }
+ public boolean hasNext()
+ {
+ return m_base.hasNext();
+ }
+ public Object next()
+ {
+ return m_base.next();
+ }
+ public void remove()
+ {
+ throw new IllegalStateException( "Unmodifiable iterator" );
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]