openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p..@apache.org
Subject svn commit: r417856 [12/22] - in /incubator/openjpa/trunk/openjpa-lib: java/ main/ main/java/ main/java/org/apache/openjpa/lib/ant/ main/java/org/apache/openjpa/lib/conf/ main/java/org/apache/openjpa/lib/jdbc/ main/java/org/apache/openjpa/lib/log/ main...
Date Wed, 28 Jun 2006 19:34:40 GMT
Modified: incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/meta/XMLMetaDataSerializer.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/meta/XMLMetaDataSerializer.java?rev=417856&r1=415364&r2=417856&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/meta/XMLMetaDataSerializer.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/meta/XMLMetaDataSerializer.java Wed Jun 28 12:34:33 2006
@@ -15,404 +15,352 @@
  */
 package org.apache.openjpa.lib.meta;
 
+import org.apache.openjpa.lib.log.*;
+import org.apache.openjpa.lib.util.*;
+import org.apache.openjpa.lib.xml.*;
+
+import org.xml.sax.*;
+import org.xml.sax.ext.*;
+import org.xml.sax.helpers.*;
 
 import java.io.*;
+
 import java.util.*;
+
 import javax.xml.transform.*;
 import javax.xml.transform.sax.*;
 import javax.xml.transform.stream.*;
 
-import org.xml.sax.*;
-import org.xml.sax.helpers.*;
-import org.xml.sax.ext.*;
-
-import org.apache.openjpa.lib.log.*;
-import org.apache.openjpa.lib.util.*;
-import org.apache.openjpa.lib.xml.*;
-
 
 /**
- *	<p>Abstract base type for serlializers that transfer groups of objects
- *	to XML.  Includes a way of serializing objects back to the XML files
- *	they were parsed from.</p>
+ *  <p>Abstract base type for serlializers that transfer groups of objects
+ *  to XML.  Includes a way of serializing objects back to the XML files
+ *  they were parsed from.</p>
  *
- *	<p>Serializers are not thread safe.</p>
+ *  <p>Serializers are not thread safe.</p>
  *
- *	@author		Abe White
- *	@nojavadoc
- */
-public abstract class XMLMetaDataSerializer
-	implements MetaDataSerializer
-{
-	private static final Localizer _loc = Localizer.forPackage
-		(XMLMetaDataSerializer.class);
-	private static final SAXTransformerFactory _factory =
-		(SAXTransformerFactory) TransformerFactory.newInstance ();
-
-	private Log _log = null;
-
-	// current serialization state
-	private final AttributesImpl 	_attrs		= new AttributesImpl ();
-	private ContentHandler 			_handler 	= null;
-	private int						_flags		= 0;
-	private File					_backup		= null;
-
-
-	/**
-	 *	The log to write to.
- 	 */
-	public Log getLog ()
-	{
-		return _log;
-	}
-
-
-	/**
-	 *	The log to write to.
- 	 */
-	public void setLog (Log log)
-	{
-		_log = log;
-	}
-
-
-	public void serialize (int flags)
-		throws IOException
-	{
-		serialize ((Map) null, flags);
-	}
-
-
-	public void serialize (Map output, int flags)
-		throws IOException
-	{
-		Map files = getFileMap ();
-		if (files == null)
-			return;
-
-		// for each file, serialize objects
-		Map.Entry entry;
-		for (Iterator itr = files.entrySet ().iterator (); itr.hasNext ();)
-		{
-			entry = (Map.Entry) itr.next ();
-			File file = (File) entry.getKey ();
-			Collection fileObjs = (Collection) entry.getValue ();
-
-			if (_log != null && _log.isInfoEnabled ())
-				_log.info (_loc.get ("ser-file", file));
-
-			try
-			{
-				TransformerHandler trans = _factory.newTransformerHandler ();
-				Writer writer;
-				if (output == null)
-				{
-					_backup = prepareWrite (file);
-					writer = new FileWriter (file);
-				}
-				else
-					writer = new StringWriter ();
-
-				Writer xml = writer;
-				if ((flags & PRETTY) > 0)
-					xml = new XMLWriter (writer);
-				trans.setResult (new StreamResult (xml));
-				serialize (fileObjs, trans, flags);
-
-				if (output != null)
-					output.put (file, ((StringWriter) writer).toString ());
-			}
-			catch (SAXException se)
-			{
-				throw new IOException (se.toString ());
-			}
-			catch (TransformerConfigurationException tce)
-			{
-				throw new IOException (tce.toString ());
-			}
-		}
-	}
-
-
-	/**
-	 *	Prepare to write to the given file.  Back up the file and make sure the
-	 *	path to it is created.
-	 */
-	protected File prepareWrite (File file)
-		throws IOException
-	{
-		File backup = Files.backup (file, false);
-		if (backup == null)
-		{
-			File parent = file.getParentFile ();
-			if (parent != null && !parent.exists ())
-				parent.mkdirs ();
-		}
-		return backup;
-	}
-
-
-	/** 
-	 *  Returns a {@link Map} with keys of the {@link File} to be
-	 *  written to, and values of a {@link Collection} of
-	 *  {@link SourceTracker} instances.
-	 */
-	protected Map getFileMap ()
-	{
-		Collection objs = getObjects ();
-		if (objs == null || objs.isEmpty ())
-			return null;
-
-		// create a map of files to lists of objects
-		Map files = new HashMap ();
-		File file;
-		Collection fileObjs;
-		Object obj;
-		for (Iterator itr = objs.iterator (); itr.hasNext ();)
-		{
-			obj = itr.next ();
-			file = getSourceFile (obj);
-			if (file == null)
-			{
-				if (_log != null && _log.isTraceEnabled ())
-					_log.trace (_loc.get ("no-file", obj));
-				continue;
-			}
-	
-			fileObjs = (Collection) files.get (file);
-			if (fileObjs == null)	
-			{
-				fileObjs = new LinkedList ();
-				files.put (file, fileObjs);
-			}
-			fileObjs.add (obj);
-		}
-
-		return files;
-	}
-
-
-	/**
-	 *	Return the source file for the given instance.  By default, checks
-	 *	to see if the instance implements {@link SourceTracker}.
-	 */
-	protected File getSourceFile (Object obj)
-	{
-		if (obj instanceof SourceTracker) 
-			return ((SourceTracker) obj).getSourceFile ();
-		return null;
-	}
-
-
-	public void serialize (File file, int flags)
-		throws IOException
-	{
-		if (_log != null)
-			_log.info (_loc.get ("ser-file", file));
-
-		_backup = prepareWrite (file);
-		FileWriter out = new FileWriter (file.getCanonicalPath (), 
-			(flags & APPEND) > 0);
-		serialize (out, flags);
-		out.close ();
-	}
-
-
-	public void serialize (Writer out, int flags)
-		throws IOException
-	{
-		try
-		{
-			if ((flags & PRETTY) > 0)
-				serialize (new StreamResult (new XMLWriter (out)), flags);
-			else
-				serialize (new StreamResult (out), flags);
-		}
-		catch (SAXException se)
-		{
-			throw new IOException (se.toString ());
-		}
-	}
-
-
-	/**
-	 *	Serialize the current set of objects to the given result.
-	 */
-	public void serialize (Result result, int flags)
-		throws SAXException
-	{
-		try
-		{
-			TransformerHandler trans = _factory.newTransformerHandler ();		
-			trans.setResult (result);
-			serialize (trans, flags);
-		}
-		catch (TransformerConfigurationException tce)
-		{
-			throw new SAXException (tce);
-		}
-	}
-
-
-	/**
-	 *	Serilize the current set of objects to a series of SAX events on the 
-	 *	given handler.
-	 */
-	public void serialize (ContentHandler handler, int flags)
-		throws SAXException
-	{
-		serialize (getObjects (), handler, flags);
-	}
-
-
-	/**
-	 *	Serialize the given collection of objects to the given handler.
-	 */
-	private void serialize (Collection objs, ContentHandler handler, int flags)
-		throws SAXException
-	{
-		if (_log != null && _log.isTraceEnabled ())
-			_log.trace (_loc.get ("ser-objs", objs));
-
-		_handler = handler;
-		_flags = flags;
-		try
-		{
-			if (!objs.isEmpty ())
-			{
-				handler.startDocument ();
-				serialize (objs);
-				handler.endDocument ();
-			}
-		}
-		finally
-		{
-			reset ();
-		}
-	}
-
-
-	/**
-	 *	Whether this serialization is in verbose mode.
-	 */
-	protected boolean isVerbose ()
-	{
-		return (_flags & VERBOSE) > 0;
-	}
-
-
-	/**
-	 *	The backup file made for the current file being parsed.
-	 */
-	protected File currentBackupFile ()
-	{
-		return _backup;
-	}
-
-
-	/**
-	 *	Start an element with the current attribute settings.  Clears the
-	 *	attributes as well.
-	 */
-	protected void startElement (String name)
-		throws SAXException
-	{
-		_handler.startElement ("", name, name, _attrs);
-		_attrs.clear ();
-	}
-
-
-	/**
-	 *	End the current element.
-	 */
-	protected void endElement (String name)
-		throws SAXException
-	{
-		_handler.endElement ("", name, name);
-	}
-
-
-	/**
-	 *	Add text to the current element.
-	 */
-	protected void addText (String text)
-		throws SAXException
-	{
-		_handler.characters (text.toCharArray (), 0, text.length ());
-	}
-
-
-	/**
-	 *	Add an attribute to the current group.
-	 */
-	protected void addAttribute (String name, String value)
-	{
-		_attrs.addAttribute ("", name, name, "CDATA", value);
-	}
-
-
-	/**
-	 *	The current attributes.
-	 */
-	protected Attributes getAttributes ()
-	{
-		return _attrs;
-	}
-
-
-	/**
-	 *	Add a comment to the stream.
-	 */
-	protected void addComments (String[] comments)
-		throws SAXException
-	{
-		if (comments == null || comments.length == 0
-			|| !(_handler instanceof LexicalHandler))
-			return;
-
-		LexicalHandler lh = (LexicalHandler) _handler;
-		char[] chars;
-		for (int i = 0; i < comments.length; i++)
-		{
-			chars = comments[i].toCharArray ();
-			lh.comment (chars, 0, chars.length);
-		}
-	}
-
-
-	/**
-	 *	Write the given entity's comments.  By default, tests if entity is
-	 *	{@link Commentable}.
-	 */
-	protected void addComments (Object obj)
-		throws SAXException
-	{
-		if (obj instanceof Commentable)
-			addComments (((Commentable) obj).getComments ());
-	}
-
-
-	/**
-	 *	Reset serialization state for the next document.
-	 */
-	protected void reset ()
-	{
-		_attrs.clear ();
-		_handler = null;
-		_flags = 0;
-		_backup = null;
-	}
-
-
-	/**
-	 *	Serialize the given set of objects.
-	 */
-	protected abstract void serialize (Collection objs)
-		throws SAXException;
-
-
-	/**
-	 *	Return the current set of objects for serialization.
-	 */
-	protected abstract Collection getObjects ();
+ *  @author Abe White
+ *  @nojavadoc */
+public abstract class XMLMetaDataSerializer implements MetaDataSerializer {
+    private static final Localizer _loc = Localizer.forPackage(XMLMetaDataSerializer.class);
+    private static final SAXTransformerFactory _factory = (SAXTransformerFactory) TransformerFactory.newInstance();
+    private Log _log = null;
+
+    // current serialization state
+    private final AttributesImpl _attrs = new AttributesImpl();
+    private ContentHandler _handler = null;
+    private int _flags = 0;
+    private File _backup = null;
+
+    /**
+     *  The log to write to.
+      */
+    public Log getLog() {
+        return _log;
+    }
+
+    /**
+     *  The log to write to.
+      */
+    public void setLog(Log log) {
+        _log = log;
+    }
+
+    public void serialize(int flags) throws IOException {
+        serialize((Map) null, flags);
+    }
+
+    public void serialize(Map output, int flags) throws IOException {
+        Map files = getFileMap();
+
+        if (files == null) {
+            return;
+        }
+
+        // for each file, serialize objects
+        Map.Entry entry;
+
+        for (Iterator itr = files.entrySet().iterator(); itr.hasNext();) {
+            entry = (Map.Entry) itr.next();
+
+            File file = (File) entry.getKey();
+            Collection fileObjs = (Collection) entry.getValue();
+
+            if ((_log != null) && _log.isInfoEnabled()) {
+                _log.info(_loc.get("ser-file", file));
+            }
+
+            try {
+                TransformerHandler trans = _factory.newTransformerHandler();
+                Writer writer;
+
+                if (output == null) {
+                    _backup = prepareWrite(file);
+                    writer = new FileWriter(file);
+                } else {
+                    writer = new StringWriter();
+                }
+
+                Writer xml = writer;
+
+                if ((flags & PRETTY) > 0) {
+                    xml = new XMLWriter(writer);
+                }
+
+                trans.setResult(new StreamResult(xml));
+                serialize(fileObjs, trans, flags);
+
+                if (output != null) {
+                    output.put(file, ((StringWriter) writer).toString());
+                }
+            } catch (SAXException se) {
+                throw new IOException(se.toString());
+            } catch (TransformerConfigurationException tce) {
+                throw new IOException(tce.toString());
+            }
+        }
+    }
+
+    /**
+     *  Prepare to write to the given file.  Back up the file and make sure the
+     *  path to it is created.
+     */
+    protected File prepareWrite(File file) throws IOException {
+        File backup = Files.backup(file, false);
+
+        if (backup == null) {
+            File parent = file.getParentFile();
+
+            if ((parent != null) && !parent.exists()) {
+                parent.mkdirs();
+            }
+        }
+
+        return backup;
+    }
+
+    /**
+     *  Returns a {@link Map} with keys of the {@link File} to be
+     *  written to, and values of a {@link Collection} of
+     *  {@link SourceTracker} instances.
+     */
+    protected Map getFileMap() {
+        Collection objs = getObjects();
+
+        if ((objs == null) || objs.isEmpty()) {
+            return null;
+        }
+
+        // create a map of files to lists of objects
+        Map files = new HashMap();
+        File file;
+        Collection fileObjs;
+        Object obj;
+
+        for (Iterator itr = objs.iterator(); itr.hasNext();) {
+            obj = itr.next();
+            file = getSourceFile(obj);
+
+            if (file == null) {
+                if ((_log != null) && _log.isTraceEnabled()) {
+                    _log.trace(_loc.get("no-file", obj));
+                }
+
+                continue;
+            }
+
+            fileObjs = (Collection) files.get(file);
+
+            if (fileObjs == null) {
+                fileObjs = new LinkedList();
+                files.put(file, fileObjs);
+            }
+
+            fileObjs.add(obj);
+        }
+
+        return files;
+    }
+
+    /**
+     *  Return the source file for the given instance.  By default, checks
+     *  to see if the instance implements {@link SourceTracker}.
+     */
+    protected File getSourceFile(Object obj) {
+        if (obj instanceof SourceTracker) {
+            return ((SourceTracker) obj).getSourceFile();
+        }
+
+        return null;
+    }
+
+    public void serialize(File file, int flags) throws IOException {
+        if (_log != null) {
+            _log.info(_loc.get("ser-file", file));
+        }
+
+        _backup = prepareWrite(file);
+
+        FileWriter out = new FileWriter(file.getCanonicalPath(),
+                (flags & APPEND) > 0);
+        serialize(out, flags);
+        out.close();
+    }
+
+    public void serialize(Writer out, int flags) throws IOException {
+        try {
+            if ((flags & PRETTY) > 0) {
+                serialize(new StreamResult(new XMLWriter(out)), flags);
+            } else {
+                serialize(new StreamResult(out), flags);
+            }
+        } catch (SAXException se) {
+            throw new IOException(se.toString());
+        }
+    }
+
+    /**
+     *  Serialize the current set of objects to the given result.
+     */
+    public void serialize(Result result, int flags) throws SAXException {
+        try {
+            TransformerHandler trans = _factory.newTransformerHandler();
+            trans.setResult(result);
+            serialize(trans, flags);
+        } catch (TransformerConfigurationException tce) {
+            throw new SAXException(tce);
+        }
+    }
+
+    /**
+     *  Serilize the current set of objects to a series of SAX events on the
+     *  given handler.
+     */
+    public void serialize(ContentHandler handler, int flags)
+        throws SAXException {
+        serialize(getObjects(), handler, flags);
+    }
+
+    /**
+     *  Serialize the given collection of objects to the given handler.
+     */
+    private void serialize(Collection objs, ContentHandler handler, int flags)
+        throws SAXException {
+        if ((_log != null) && _log.isTraceEnabled()) {
+            _log.trace(_loc.get("ser-objs", objs));
+        }
+
+        _handler = handler;
+        _flags = flags;
+
+        try {
+            if (!objs.isEmpty()) {
+                handler.startDocument();
+                serialize(objs);
+                handler.endDocument();
+            }
+        } finally {
+            reset();
+        }
+    }
+
+    /**
+     *  Whether this serialization is in verbose mode.
+     */
+    protected boolean isVerbose() {
+        return (_flags & VERBOSE) > 0;
+    }
+
+    /**
+     *  The backup file made for the current file being parsed.
+     */
+    protected File currentBackupFile() {
+        return _backup;
+    }
+
+    /**
+     *  Start an element with the current attribute settings.  Clears the
+     *  attributes as well.
+     */
+    protected void startElement(String name) throws SAXException {
+        _handler.startElement("", name, name, _attrs);
+        _attrs.clear();
+    }
+
+    /**
+     *  End the current element.
+     */
+    protected void endElement(String name) throws SAXException {
+        _handler.endElement("", name, name);
+    }
+
+    /**
+     *  Add text to the current element.
+     */
+    protected void addText(String text) throws SAXException {
+        _handler.characters(text.toCharArray(), 0, text.length());
+    }
+
+    /**
+     *  Add an attribute to the current group.
+     */
+    protected void addAttribute(String name, String value) {
+        _attrs.addAttribute("", name, name, "CDATA", value);
+    }
+
+    /**
+     *  The current attributes.
+     */
+    protected Attributes getAttributes() {
+        return _attrs;
+    }
+
+    /**
+     *  Add a comment to the stream.
+     */
+    protected void addComments(String[] comments) throws SAXException {
+        if ((comments == null) || (comments.length == 0) ||
+                !(_handler instanceof LexicalHandler)) {
+            return;
+        }
+
+        LexicalHandler lh = (LexicalHandler) _handler;
+        char[] chars;
+
+        for (int i = 0; i < comments.length; i++) {
+            chars = comments[i].toCharArray();
+            lh.comment(chars, 0, chars.length);
+        }
+    }
+
+    /**
+     *  Write the given entity's comments.  By default, tests if entity is
+     *  {@link Commentable}.
+     */
+    protected void addComments(Object obj) throws SAXException {
+        if (obj instanceof Commentable) {
+            addComments(((Commentable) obj).getComments());
+        }
+    }
+
+    /**
+     *  Reset serialization state for the next document.
+     */
+    protected void reset() {
+        _attrs.clear();
+        _handler = null;
+        _flags = 0;
+        _backup = null;
+    }
+
+    /**
+     *  Serialize the given set of objects.
+     */
+    protected abstract void serialize(Collection objs)
+        throws SAXException;
+
+    /**
+     *  Return the current set of objects for serialization.
+     */
+    protected abstract Collection getObjects();
 }

Modified: incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/meta/ZipFileMetaDataIterator.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/meta/ZipFileMetaDataIterator.java?rev=417856&r1=415364&r2=417856&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/meta/ZipFileMetaDataIterator.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/meta/ZipFileMetaDataIterator.java Wed Jun 28 12:34:33 2006
@@ -15,142 +15,135 @@
  */
 package org.apache.openjpa.lib.meta;
 
-
 import java.io.*;
+
 import java.net.*;
+
 import java.util.*;
 import java.util.zip.*;
 
 
 /**
- *	<p>Iterator over all metadata resources in a given zip file.</p>
+ *  <p>Iterator over all metadata resources in a given zip file.</p>
  *
- *	@author		Abe White
- *	@nojavadoc
- */
-public class ZipFileMetaDataIterator
-	implements MetaDataIterator, MetaDataFilter.Resource
-{
-	private final ZipFile			_file;
-	private final MetaDataFilter	_filter;
-	private final Enumeration 		_entries;
-	private final boolean			_close;
-	private ZipEntry				_entry 	= null;
-	private ZipEntry				_last	= null;
-
-
-	/**
-	 *	Constructor; supply zip/jar URL and optional file filter.
-	 */
-	public ZipFileMetaDataIterator (URL url, MetaDataFilter filter)
-		throws IOException
-	{
-		_file = (url == null) ? null : (ZipFile) url.getContent ();
-		_filter = filter;
-		_entries = (_file == null) ? null : _file.entries ();
-		_close = false;
-	}
-
-
-	/**
-	 *	Constructor; supply zip file and optional file filter.
-	 */
-	public ZipFileMetaDataIterator (ZipFile file, MetaDataFilter filter)
-	{
-		_file = file;
-		_filter = filter;
-		_entries = (file == null) ? null : file.entries ();
-		_close = true;
-	}
-
-
-	public boolean hasNext ()
-		throws IOException
-	{
-		if (_entries == null)
-			return false;
-
-		// search for next metadata file
-		while (_entry == null && _entries.hasMoreElements ())
-		{
-			_entry = (ZipEntry) _entries.nextElement ();
-			if (_filter != null && !_filter.matches (this))
-				_entry = null;
-		}
-		return _entry != null;
-	}
-
-
-	public Object next ()
-		throws IOException
-	{
-		if (!hasNext ())
-			throw new NoSuchElementException ();
-		String ret = _entry.getName (); 
-		_last = _entry;
-		_entry = null;
-		return ret;
-	}
-
-
-	public InputStream getInputStream ()
-		throws IOException
-	{
-		if (_last == null)
-			throw new IllegalStateException ();
-		return _file.getInputStream (_last);
-	}
-
-
-	public File getFile ()
-	{
-		if (_last == null)
-			throw new IllegalStateException ();
-		return null;
-	}
-
-
-	public void close ()
-	{
-		if (_close)
-			try { _file.close (); } catch (IOException ioe) {}
-	}
-
-
-	//////////////////////////////////////////
-	// MetaDataFilter.Resource implementation
-	//////////////////////////////////////////
-
-
-	public String getName ()
-	{
-		return _entry.getName ();
-	}
-
-
-	public byte[] getContent ()
-		throws IOException
-	{
-		long size = _entry.getSize ();
-		if (size == 0)
-			return new byte[0];
-
-		InputStream in = _file.getInputStream (_entry);
-		byte[] content;
-		if (size < 0)
-		{
-			ByteArrayOutputStream bout = new ByteArrayOutputStream ();
-			byte[] buf = new byte[1024];
-			for (int r; (r = in.read (buf)) != -1; bout.write (buf, 0, r));
-			content = bout.toByteArray ();
-		}
-		else
-		{
-			content = new byte[(int) size];
-			in.read (content);
-		}
-		in.close ();
-		return content;
-	}
-}
+ *  @author Abe White
+ *  @nojavadoc */
+public class ZipFileMetaDataIterator implements MetaDataIterator,
+    MetaDataFilter.Resource {
+    private final ZipFile _file;
+    private final MetaDataFilter _filter;
+    private final Enumeration _entries;
+    private final boolean _close;
+    private ZipEntry _entry = null;
+    private ZipEntry _last = null;
+
+    /**
+     *  Constructor; supply zip/jar URL and optional file filter.
+     */
+    public ZipFileMetaDataIterator(URL url, MetaDataFilter filter)
+        throws IOException {
+        _file = (url == null) ? null : (ZipFile) url.getContent();
+        _filter = filter;
+        _entries = (_file == null) ? null : _file.entries();
+        _close = false;
+    }
+
+    /**
+     *  Constructor; supply zip file and optional file filter.
+     */
+    public ZipFileMetaDataIterator(ZipFile file, MetaDataFilter filter) {
+        _file = file;
+        _filter = filter;
+        _entries = (file == null) ? null : file.entries();
+        _close = true;
+    }
+
+    public boolean hasNext() throws IOException {
+        if (_entries == null) {
+            return false;
+        }
+
+        // search for next metadata file
+        while ((_entry == null) && _entries.hasMoreElements()) {
+            _entry = (ZipEntry) _entries.nextElement();
+
+            if ((_filter != null) && !_filter.matches(this)) {
+                _entry = null;
+            }
+        }
+
+        return _entry != null;
+    }
+
+    public Object next() throws IOException {
+        if (!hasNext()) {
+            throw new NoSuchElementException();
+        }
+
+        String ret = _entry.getName();
+        _last = _entry;
+        _entry = null;
+
+        return ret;
+    }
+
+    public InputStream getInputStream() throws IOException {
+        if (_last == null) {
+            throw new IllegalStateException();
+        }
+
+        return _file.getInputStream(_last);
+    }
+
+    public File getFile() {
+        if (_last == null) {
+            throw new IllegalStateException();
+        }
+
+        return null;
+    }
+
+    public void close() {
+        if (_close) {
+            try {
+                _file.close();
+            } catch (IOException ioe) {
+            }
+        }
+    }
+
+    //////////////////////////////////////////
+    // MetaDataFilter.Resource implementation
+    //////////////////////////////////////////
+    public String getName() {
+        return _entry.getName();
+    }
+
+    public byte[] getContent() throws IOException {
+        long size = _entry.getSize();
+
+        if (size == 0) {
+            return new byte[0];
+        }
+
+        InputStream in = _file.getInputStream(_entry);
+        byte[] content;
+
+        if (size < 0) {
+            ByteArrayOutputStream bout = new ByteArrayOutputStream();
+            byte[] buf = new byte[1024];
+
+            for (int r; (r = in.read(buf)) != -1; bout.write(buf, 0, r))
+                ;
+
+            content = bout.toByteArray();
+        } else {
+            content = new byte[(int) size];
+            in.read(content);
+        }
+
+        in.close();
 
+        return content;
+    }
+}

Modified: incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/meta/ZipStreamMetaDataIterator.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/meta/ZipStreamMetaDataIterator.java?rev=417856&r1=415364&r2=417856&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/meta/ZipStreamMetaDataIterator.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/meta/ZipStreamMetaDataIterator.java Wed Jun 28 12:34:33 2006
@@ -15,168 +15,149 @@
  */
 package org.apache.openjpa.lib.meta;
 
-
 import java.io.*;
+
 import java.util.*;
 import java.util.zip.*;
 
 
 /**
- *	<p>Iterator over all metadata resources in a given zip input stream.</p>
+ *  <p>Iterator over all metadata resources in a given zip input stream.</p>
  *
- *	@author		Abe White
- *	@nojavadoc
- */
-public class ZipStreamMetaDataIterator
-	implements MetaDataIterator, MetaDataFilter.Resource
-{
-	private final ZipInputStream	_stream;
-	private final MetaDataFilter	_filter;
-	private ZipEntry				_entry 	= null;
-	private ZipEntry				_last 	= null;
-	private byte[]					_buf	= null;
-
-
-	/**
-	 *	Constructor; supply zip stream and optional metadata filter.
-	 */
-	public ZipStreamMetaDataIterator (ZipInputStream stream, 
-		MetaDataFilter filter)
-	{
-		_stream = stream;
-		_filter = filter;
-	}
-
-
-	public boolean hasNext ()
-		throws IOException
-	{
-		if (_stream == null)
-			return false;
-		if (_entry != null)
-			return true;
-
-		// close last rsrc
-		if (_buf == null && _last != null)
-			_stream.closeEntry ();
-		_last = null;
-		_buf = null;
-
-		// search for next file
-		ZipEntry entry;
-		while (_entry == null && (entry = _stream.getNextEntry ()) != null)
-		{
-			_entry = entry;
-			if (_filter != null && !_filter.matches (this))
-			{
-				_entry = null;
-				_stream.closeEntry ();
-			}
-		}
-		return _entry != null;
-	}
-
-
-	public Object next ()
-		throws IOException
-	{
-		if (!hasNext ())
-			throw new NoSuchElementException ();
-		String ret = _entry.getName ();
-		_last = _entry;
-		_entry = null;
-		return ret;
-	}
-
-
-	public InputStream getInputStream ()
-	{
-		if (_last == null)
-			throw new IllegalStateException ();
-
-		if (_buf != null)
-			return new ByteArrayInputStream (_buf);
-		return new NoCloseInputStream ();
-	}
-
-
-	public File getFile ()
-	{
-		return null;
-	}
-
-
-	public void close ()
-	{
-		try { _stream.close (); } catch (IOException ioe) {}
-	}
-
-
-	//////////////////////////////////////////
-	// MetaDataFilter.Resource implementation
-	//////////////////////////////////////////
-
-
-	public String getName ()
-	{
-		return _entry.getName ();
-	}
-
-
-	public byte[] getContent ()
-		throws IOException
-	{
-		// buffer content so that future calls to getInputStream can read
-		// the same data
-		int size = (int) _entry.getSize ();
-		if (size < 0)
-		{
-			ByteArrayOutputStream bout = new ByteArrayOutputStream ();
-			byte[] buf = new byte[1024];
-			for (int r; (r = _stream.read (buf)) != -1; bout.write (buf, 0, r));
-			_buf = bout.toByteArray ();
-		}
-		else 
-		{
-			_buf = new byte[size];		
-			_stream.read (_buf);
-		}
-		_stream.closeEntry ();
-		return _buf;
-	}
-
-
-	/**
-	 *	Non-closing input stream used to make sure the underlying zip
-	 *	stream is not closed.
-	 */
-	private class NoCloseInputStream
-		extends InputStream
-	{
-		public int available ()
-			throws IOException
-		{
-			return _stream.available ();
-		}
-
-
-		public int read ()
-			throws IOException
-		{
-			return _stream.read ();
-		}
-
-
-		public int read (byte[] b, int off, int len)
-			throws IOException
-		{
-			return _stream.read (b, off, len);
-		}
-
-
-		public void close ()
-		{
-		}
-	}
+ *  @author Abe White
+ *  @nojavadoc */
+public class ZipStreamMetaDataIterator implements MetaDataIterator,
+    MetaDataFilter.Resource {
+    private final ZipInputStream _stream;
+    private final MetaDataFilter _filter;
+    private ZipEntry _entry = null;
+    private ZipEntry _last = null;
+    private byte[] _buf = null;
+
+    /**
+     *  Constructor; supply zip stream and optional metadata filter.
+     */
+    public ZipStreamMetaDataIterator(ZipInputStream stream,
+        MetaDataFilter filter) {
+        _stream = stream;
+        _filter = filter;
+    }
+
+    public boolean hasNext() throws IOException {
+        if (_stream == null) {
+            return false;
+        }
+
+        if (_entry != null) {
+            return true;
+        }
+
+        // close last rsrc
+        if ((_buf == null) && (_last != null)) {
+            _stream.closeEntry();
+        }
+
+        _last = null;
+        _buf = null;
+
+        // search for next file
+        ZipEntry entry;
+
+        while ((_entry == null) && ((entry = _stream.getNextEntry()) != null)) {
+            _entry = entry;
+
+            if ((_filter != null) && !_filter.matches(this)) {
+                _entry = null;
+                _stream.closeEntry();
+            }
+        }
+
+        return _entry != null;
+    }
+
+    public Object next() throws IOException {
+        if (!hasNext()) {
+            throw new NoSuchElementException();
+        }
+
+        String ret = _entry.getName();
+        _last = _entry;
+        _entry = null;
+
+        return ret;
+    }
+
+    public InputStream getInputStream() {
+        if (_last == null) {
+            throw new IllegalStateException();
+        }
+
+        if (_buf != null) {
+            return new ByteArrayInputStream(_buf);
+        }
+
+        return new NoCloseInputStream();
+    }
+
+    public File getFile() {
+        return null;
+    }
+
+    public void close() {
+        try {
+            _stream.close();
+        } catch (IOException ioe) {
+        }
+    }
+
+    //////////////////////////////////////////
+    // MetaDataFilter.Resource implementation
+    //////////////////////////////////////////
+    public String getName() {
+        return _entry.getName();
+    }
+
+    public byte[] getContent() throws IOException {
+        // buffer content so that future calls to getInputStream can read
+        // the same data
+        int size = (int) _entry.getSize();
+
+        if (size < 0) {
+            ByteArrayOutputStream bout = new ByteArrayOutputStream();
+            byte[] buf = new byte[1024];
+
+            for (int r; (r = _stream.read(buf)) != -1; bout.write(buf, 0, r))
+                ;
+
+            _buf = bout.toByteArray();
+        } else {
+            _buf = new byte[size];
+            _stream.read(_buf);
+        }
+
+        _stream.closeEntry();
+
+        return _buf;
+    }
+
+    /**
+     *  Non-closing input stream used to make sure the underlying zip
+     *  stream is not closed.
+     */
+    private class NoCloseInputStream extends InputStream {
+        public int available() throws IOException {
+            return _stream.available();
+        }
+
+        public int read() throws IOException {
+            return _stream.read();
+        }
+
+        public int read(byte[] b, int off, int len) throws IOException {
+            return _stream.read(b, off, len);
+        }
+
+        public void close() {
+        }
+    }
 }
-

Modified: incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/meta/package.html
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/meta/package.html?rev=417856&r1=415364&r2=417856&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/meta/package.html (original)
+++ incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/meta/package.html Wed Jun 28 12:34:33 2006
@@ -1,18 +1,3 @@
-<!--
-  Copyright 2006 The Apache Software Foundation.
-
-  Licensed under the Apache License, Version 2.0 (the "License");
-  you may not use this file except in compliance with the License.
-  You may obtain a copy of the License at
-
-     http://www.apache.org/licenses/LICENSE-2.0
-
-  Unless required by applicable law or agreed to in writing, software
-  distributed under the License is distributed on an "AS IS" BASIS,
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  See the License for the specific language governing permissions and
-  limitations under the License.
--->
 <html>
 <body>
 	<p><strong>Metadata Framework</strong></p>

Modified: incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/rop/AbstractListIterator.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/rop/AbstractListIterator.java?rev=417856&r1=415364&r2=417856&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/rop/AbstractListIterator.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/rop/AbstractListIterator.java Wed Jun 28 12:34:33 2006
@@ -15,39 +15,28 @@
  */
 package org.apache.openjpa.lib.rop;
 
+import org.apache.openjpa.lib.util.*;
 
 import java.util.*;
 
-import org.apache.openjpa.lib.util.*;
-
 
 /**
- *	<p>Abstract read-only list iterator.</p>
+ *  <p>Abstract read-only list iterator.</p>
  *
- *	@author		Abe White
- *	@nojavadoc
- */
-abstract class AbstractListIterator
-	implements ListIterator
-{
-	private static final Localizer _loc = Localizer.forPackage
-		(AbstractListIterator.class);
-
-
-	public void add (Object o)
-	{
-		throw new UnsupportedOperationException (_loc.get ("read-only"));
-	}
-
-
-	public void set (Object o)
-	{
-		throw new UnsupportedOperationException (_loc.get ("read-only"));
-	}
-
-
-	public void remove ()
-	{
-		throw new UnsupportedOperationException (_loc.get ("read-only"));
-	}
+ *  @author Abe White
+ *  @nojavadoc */
+abstract class AbstractListIterator implements ListIterator {
+    private static final Localizer _loc = Localizer.forPackage(AbstractListIterator.class);
+
+    public void add(Object o) {
+        throw new UnsupportedOperationException(_loc.get("read-only"));
+    }
+
+    public void set(Object o) {
+        throw new UnsupportedOperationException(_loc.get("read-only"));
+    }
+
+    public void remove() {
+        throw new UnsupportedOperationException(_loc.get("read-only"));
+    }
 }

Modified: incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/rop/AbstractNonSequentialResultList.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/rop/AbstractNonSequentialResultList.java?rev=417856&r1=415364&r2=417856&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/rop/AbstractNonSequentialResultList.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/rop/AbstractNonSequentialResultList.java Wed Jun 28 12:34:33 2006
@@ -15,211 +15,209 @@
  */
 package org.apache.openjpa.lib.rop;
 
+import org.apache.commons.lang.*;
 
 import java.util.*;
 
-import org.apache.commons.lang.*;
-
 
-/** 
+/**
  *  <p>Abstract base class for random-access result lists.  Unlike the
- *	{@link AbstractList}, this class doesn't rely on the 
- *	{@link Collection#size} method.</p>
- *  
+ *  {@link AbstractList}, this class doesn't rely on the
+ *  {@link Collection#size} method.</p>
+ *
  *  @author Abe White
- *	@nojavadoc
- */
-public abstract class AbstractNonSequentialResultList
-	extends AbstractResultList
-{
-	protected static final Object PAST_END = new Object ();
-
-
-	/**
-	 *	Implement this method and {@link #size}.  Return {@link #PAST_END}
-	 *	if the index is out of bounds.
- 	 */
-	protected abstract Object getInternal (int index);
-
-
-	public boolean contains (Object o)
-	{
-		assertOpen ();
-		Object obj;
-		for (int i = 0; true; i++)
-		{
-			obj = getInternal (i);
-			if (obj == PAST_END)
-				break;
-			if (ObjectUtils.equals (o, obj))
-				return true;
-		}
-		return false;
-	}
-
-
-	public boolean containsAll (Collection c)
-	{
-		assertOpen ();
-		for (Iterator itr = c.iterator (); itr.hasNext ();)
-			if (!contains (itr.next ()))
-				return false;
-		return true;
-	}
-
-
-	public Object get (int index)
-	{
-		assertOpen ();
-		Object obj = getInternal (index);
-		if (obj == PAST_END)
-			throw new NoSuchElementException ();
-		return obj;
-	}
-
-
-	public int indexOf (Object o)
-	{
-		assertOpen ();
-		Object obj;
-		for (int i = 0; true; i++)
-		{
-			obj = getInternal (i);
-			if (obj == PAST_END)
-				break;
-			if (ObjectUtils.equals (o, obj))
-				return i;
-		}
-		return -1;
-	}
-
-
-	public int lastIndexOf (Object o)
-	{
-		assertOpen ();
-		int index = -1;
-		Object obj;
-		for (int i = 0; true; i++)
-		{
-			obj = getInternal (i);
-			if (obj == PAST_END)
-				break;
-			if (ObjectUtils.equals (o, obj))
-				index = i;
-		}
-		return index;
-	}
-
-
-	public boolean isEmpty ()
-	{
-		assertOpen ();
-		return getInternal (0) == PAST_END;
-	}
-
-
-	public Iterator iterator ()
-	{
-		return listIterator ();
-	}
-
-
-	public ListIterator listIterator ()
-	{
-		return listIterator (0);
-	}
-
-
-	public ListIterator listIterator (int index)
-	{
-		return new ResultListIterator (new Itr (index), this);
-	}
-
-
-	public Object[] toArray ()
-	{
-		assertOpen ();
-		ArrayList list = new ArrayList ();
-		Object obj;
-		for (int i = 0; true; i++)
-		{
-			obj = getInternal (i);
-			if (obj == PAST_END)
-				break;
-			list.add (obj);
-		}
-		return list.toArray ();
-	}
-
-
-	public Object[] toArray (Object[] a)
-	{
-		assertOpen ();
-		ArrayList list = new ArrayList ();
-		Object obj;
-		for (int i = 0; true; i++)
-		{
-			obj = getInternal (i);
-			if (obj == PAST_END)
-				break;
-			list.add (obj);
-		}
-		return list.toArray (a);
-	}
-
-
-	private class Itr
-		extends AbstractListIterator
-	{
-		private int 	_idx	= 0;
-		private Object	_next	= PAST_END;
-
-
-		public Itr (int index)
-		{
-			_idx = index;
-		}
-
-
-		public int nextIndex ()
-		{
-			return _idx;
-		}
-
-
-		public int previousIndex ()
-		{
-			return _idx - 1;
-		}
-
-
-		public boolean hasNext ()
-		{
-			_next = getInternal (_idx);
-			return _next != PAST_END;	
-		}
-
-
-		public boolean hasPrevious ()
-		{
-			return _idx > 0;
-		}
-
-
-		public Object previous ()
-		{
-			if (_idx == 0)
-				throw new NoSuchElementException ();
-			return getInternal (--_idx);
-		}
-
-
-		public Object next ()
-		{
-			if (!hasNext ())
-				throw new NoSuchElementException ();
-			_idx++;
-			return _next;
-		}
-	}
+ *  @nojavadoc */
+public abstract class AbstractNonSequentialResultList extends AbstractResultList {
+    protected static final Object PAST_END = new Object();
+
+    /**
+     *  Implement this method and {@link #size}.  Return {@link #PAST_END}
+     *  if the index is out of bounds.
+      */
+    protected abstract Object getInternal(int index);
+
+    public boolean contains(Object o) {
+        assertOpen();
+
+        Object obj;
+
+        for (int i = 0; true; i++) {
+            obj = getInternal(i);
+
+            if (obj == PAST_END) {
+                break;
+            }
+
+            if (ObjectUtils.equals(o, obj)) {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+    public boolean containsAll(Collection c) {
+        assertOpen();
+
+        for (Iterator itr = c.iterator(); itr.hasNext();)
+            if (!contains(itr.next())) {
+                return false;
+            }
+
+        return true;
+    }
+
+    public Object get(int index) {
+        assertOpen();
+
+        Object obj = getInternal(index);
+
+        if (obj == PAST_END) {
+            throw new NoSuchElementException();
+        }
+
+        return obj;
+    }
+
+    public int indexOf(Object o) {
+        assertOpen();
+
+        Object obj;
+
+        for (int i = 0; true; i++) {
+            obj = getInternal(i);
+
+            if (obj == PAST_END) {
+                break;
+            }
+
+            if (ObjectUtils.equals(o, obj)) {
+                return i;
+            }
+        }
+
+        return -1;
+    }
+
+    public int lastIndexOf(Object o) {
+        assertOpen();
+
+        int index = -1;
+        Object obj;
+
+        for (int i = 0; true; i++) {
+            obj = getInternal(i);
+
+            if (obj == PAST_END) {
+                break;
+            }
+
+            if (ObjectUtils.equals(o, obj)) {
+                index = i;
+            }
+        }
+
+        return index;
+    }
+
+    public boolean isEmpty() {
+        assertOpen();
+
+        return getInternal(0) == PAST_END;
+    }
+
+    public Iterator iterator() {
+        return listIterator();
+    }
+
+    public ListIterator listIterator() {
+        return listIterator(0);
+    }
+
+    public ListIterator listIterator(int index) {
+        return new ResultListIterator(new Itr(index), this);
+    }
+
+    public Object[] toArray() {
+        assertOpen();
+
+        ArrayList list = new ArrayList();
+        Object obj;
+
+        for (int i = 0; true; i++) {
+            obj = getInternal(i);
+
+            if (obj == PAST_END) {
+                break;
+            }
+
+            list.add(obj);
+        }
+
+        return list.toArray();
+    }
+
+    public Object[] toArray(Object[] a) {
+        assertOpen();
+
+        ArrayList list = new ArrayList();
+        Object obj;
+
+        for (int i = 0; true; i++) {
+            obj = getInternal(i);
+
+            if (obj == PAST_END) {
+                break;
+            }
+
+            list.add(obj);
+        }
+
+        return list.toArray(a);
+    }
+
+    private class Itr extends AbstractListIterator {
+        private int _idx = 0;
+        private Object _next = PAST_END;
+
+        public Itr(int index) {
+            _idx = index;
+        }
+
+        public int nextIndex() {
+            return _idx;
+        }
+
+        public int previousIndex() {
+            return _idx - 1;
+        }
+
+        public boolean hasNext() {
+            _next = getInternal(_idx);
+
+            return _next != PAST_END;
+        }
+
+        public boolean hasPrevious() {
+            return _idx > 0;
+        }
+
+        public Object previous() {
+            if (_idx == 0) {
+                throw new NoSuchElementException();
+            }
+
+            return getInternal(--_idx);
+        }
+
+        public Object next() {
+            if (!hasNext()) {
+                throw new NoSuchElementException();
+            }
+
+            _idx++;
+
+            return _next;
+        }
+    }
 }

Modified: incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/rop/AbstractResultList.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/rop/AbstractResultList.java?rev=417856&r1=415364&r2=417856&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/rop/AbstractResultList.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/rop/AbstractResultList.java Wed Jun 28 12:34:33 2006
@@ -15,102 +15,71 @@
  */
 package org.apache.openjpa.lib.rop;
 
+import org.apache.openjpa.lib.util.*;
 
 import java.util.*;
 
-import org.apache.openjpa.lib.util.*;
-
 
-/** 
+/**
  *  <p>Abstract base class for read-only result lists.</p>
- *  
+ *
  *  @author Abe White
- *	@nojavadoc
- */
-public abstract class AbstractResultList
-	implements ResultList
-{
-	private static final Localizer _loc = Localizer.forPackage 
-		(AbstractResultList.class);
-
-
-	public void add (int index, Object element)
-	{
-		throw new UnsupportedOperationException (_loc.get ("read-only"));
-	}
-
-
-	public boolean add (Object o)
-	{
-		throw new UnsupportedOperationException (_loc.get ("read-only"));
-	}
-
-
-	public boolean addAll (Collection c)
-	{
-		throw new UnsupportedOperationException (_loc.get ("read-only"));
-	}
-
-
-	public boolean addAll (int index, Collection c)
-	{
-		throw new UnsupportedOperationException (_loc.get ("read-only"));
-	}
-
-
-	public Object remove (int index)
-	{
-		throw new UnsupportedOperationException (_loc.get ("read-only"));
-	}
-		
-	
-	public boolean remove (Object o)
-	{
-		throw new UnsupportedOperationException (_loc.get ("read-only"));
-	}
-
-
-	public boolean removeAll (Collection c)
-	{
-		throw new UnsupportedOperationException (_loc.get ("read-only"));
-	}
-
-
-	public boolean retainAll (Collection c)
-	{
-		throw new UnsupportedOperationException (_loc.get ("read-only"));
-	}
-
-
-	public Object set (int index, Object element)
-	{
-		throw new UnsupportedOperationException (_loc.get ("read-only"));
-	}
-
-
-	public void clear ()
-	{
-		throw new UnsupportedOperationException (_loc.get ("read-only"));
-	}
-
-
-	public List subList (int from, int to)
-	{
-		throw new UnsupportedOperationException ();
-	}
-
-
-	protected void finalize ()
-		throws Throwable
-	{
-		super.finalize ();
-		close ();
-	}
-
-
-	protected void assertOpen ()
-	{
-		if (isClosed ())
-			throw new NoSuchElementException (_loc.get ("closed"));
-	}
+ *  @nojavadoc */
+public abstract class AbstractResultList implements ResultList {
+    private static final Localizer _loc = Localizer.forPackage(AbstractResultList.class);
+
+    public void add(int index, Object element) {
+        throw new UnsupportedOperationException(_loc.get("read-only"));
+    }
+
+    public boolean add(Object o) {
+        throw new UnsupportedOperationException(_loc.get("read-only"));
+    }
+
+    public boolean addAll(Collection c) {
+        throw new UnsupportedOperationException(_loc.get("read-only"));
+    }
+
+    public boolean addAll(int index, Collection c) {
+        throw new UnsupportedOperationException(_loc.get("read-only"));
+    }
+
+    public Object remove(int index) {
+        throw new UnsupportedOperationException(_loc.get("read-only"));
+    }
+
+    public boolean remove(Object o) {
+        throw new UnsupportedOperationException(_loc.get("read-only"));
+    }
+
+    public boolean removeAll(Collection c) {
+        throw new UnsupportedOperationException(_loc.get("read-only"));
+    }
+
+    public boolean retainAll(Collection c) {
+        throw new UnsupportedOperationException(_loc.get("read-only"));
+    }
+
+    public Object set(int index, Object element) {
+        throw new UnsupportedOperationException(_loc.get("read-only"));
+    }
+
+    public void clear() {
+        throw new UnsupportedOperationException(_loc.get("read-only"));
+    }
+
+    public List subList(int from, int to) {
+        throw new UnsupportedOperationException();
+    }
+
+    protected void finalize() throws Throwable {
+        super.finalize();
+        close();
+    }
+
+    protected void assertOpen() {
+        if (isClosed()) {
+            throw new NoSuchElementException(_loc.get("closed"));
+        }
+    }
 }

Modified: incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/rop/AbstractSequentialResultList.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/rop/AbstractSequentialResultList.java?rev=417856&r1=415364&r2=417856&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/rop/AbstractSequentialResultList.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/rop/AbstractSequentialResultList.java Wed Jun 28 12:34:33 2006
@@ -15,120 +15,116 @@
  */
 package org.apache.openjpa.lib.rop;
 
+import org.apache.commons.lang.*;
 
 import java.util.*;
 
-import org.apache.commons.lang.*;
-
 
-/** 
+/**
  *  <p>Abstract base class for sequential result lists.  Unlike the
- *	{@link AbstractSequentialList}, this class doesn't rely on the 
- *	{@link Collection#size} method.</p>
- *  
+ *  {@link AbstractSequentialList}, this class doesn't rely on the
+ *  {@link Collection#size} method.</p>
+ *
  *  @author Abe White
- *	@nojavadoc
- */
-public abstract class AbstractSequentialResultList
-	extends AbstractResultList
-{
-	/**
-	 *	Implement this method and {@link #size}.
- 	 */
-	protected abstract ListIterator itr (int index);
-
-
-	public boolean contains (Object o)
-	{
-		assertOpen ();
-		for (Iterator itr = itr (0); itr.hasNext ();)
-			if (ObjectUtils.equals (o, itr.next ()))
-				return true;
-		return false;
-	}
-
-
-	public boolean containsAll (Collection c)
-	{
-		assertOpen ();
-		for (Iterator itr = c.iterator (); itr.hasNext ();)
-			if (!contains (itr.next ()))
-				return false;
-		return true;
-	}
-
-
-	public Object get (int index)
-	{
-		assertOpen ();
-		return itr (index).next ();
-	}
-
-
-	public int indexOf (Object o)
-	{
-		assertOpen ();
-		int index = 0;
-		for (Iterator itr = itr (0); itr.hasNext (); index++)
-			if (ObjectUtils.equals (o, itr.next ()))
-				return index;
-		return -1;
-	}
-
-
-	public int lastIndexOf (Object o)
-	{
-		assertOpen ();
-		int index = -1;
-		int i = 0;
-		for (Iterator itr = itr (0); itr.hasNext (); i++)
-			if (ObjectUtils.equals (o, itr.next ()))
-				index = i;
-		return index;
-	}
-
-
-	public boolean isEmpty ()
-	{
-		assertOpen ();
-		return !itr (0).hasNext ();
-	}
-
-
-	public Iterator iterator ()
-	{
-		return listIterator ();
-	}
-
-
-	public ListIterator listIterator ()
-	{
-		return listIterator (0);
-	}
-
-
-	public ListIterator listIterator (int index)
-	{
-		return new ResultListIterator (itr (index), this);
-	}
-
-
-	public Object[] toArray ()
-	{
-		assertOpen ();
-		ArrayList list = new ArrayList ();
-		for (Iterator itr = itr (0); itr.hasNext ();)
-			list.add (itr.next ());
-		return list.toArray ();
-	}
-
-
-	public Object[] toArray (Object[] a)
-	{
-		assertOpen ();
-		ArrayList list = new ArrayList ();
-		for (Iterator itr = itr (0); itr.hasNext ();)
-			list.add (itr.next ());
-		return list.toArray (a);
-	}
+ *  @nojavadoc */
+public abstract class AbstractSequentialResultList extends AbstractResultList {
+    /**
+     *  Implement this method and {@link #size}.
+      */
+    protected abstract ListIterator itr(int index);
+
+    public boolean contains(Object o) {
+        assertOpen();
+
+        for (Iterator itr = itr(0); itr.hasNext();)
+            if (ObjectUtils.equals(o, itr.next())) {
+                return true;
+            }
+
+        return false;
+    }
+
+    public boolean containsAll(Collection c) {
+        assertOpen();
+
+        for (Iterator itr = c.iterator(); itr.hasNext();)
+            if (!contains(itr.next())) {
+                return false;
+            }
+
+        return true;
+    }
+
+    public Object get(int index) {
+        assertOpen();
+
+        return itr(index).next();
+    }
+
+    public int indexOf(Object o) {
+        assertOpen();
+
+        int index = 0;
+
+        for (Iterator itr = itr(0); itr.hasNext(); index++)
+            if (ObjectUtils.equals(o, itr.next())) {
+                return index;
+            }
+
+        return -1;
+    }
+
+    public int lastIndexOf(Object o) {
+        assertOpen();
+
+        int index = -1;
+        int i = 0;
+
+        for (Iterator itr = itr(0); itr.hasNext(); i++)
+            if (ObjectUtils.equals(o, itr.next())) {
+                index = i;
+            }
+
+        return index;
+    }
+
+    public boolean isEmpty() {
+        assertOpen();
+
+        return !itr(0).hasNext();
+    }
+
+    public Iterator iterator() {
+        return listIterator();
+    }
+
+    public ListIterator listIterator() {
+        return listIterator(0);
+    }
+
+    public ListIterator listIterator(int index) {
+        return new ResultListIterator(itr(index), this);
+    }
+
+    public Object[] toArray() {
+        assertOpen();
+
+        ArrayList list = new ArrayList();
+
+        for (Iterator itr = itr(0); itr.hasNext();)
+            list.add(itr.next());
+
+        return list.toArray();
+    }
+
+    public Object[] toArray(Object[] a) {
+        assertOpen();
+
+        ArrayList list = new ArrayList();
+
+        for (Iterator itr = itr(0); itr.hasNext();)
+            list.add(itr.next());
+
+        return list.toArray(a);
+    }
 }

Modified: incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/rop/EagerResultList.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/rop/EagerResultList.java?rev=417856&r1=415364&r2=417856&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/rop/EagerResultList.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/rop/EagerResultList.java Wed Jun 28 12:34:33 2006
@@ -15,41 +15,32 @@
  */
 package org.apache.openjpa.lib.rop;
 
-
 import java.util.*;
 
 
 /**
- *	Simple, non-lazy ResultList implementation
+ *  Simple, non-lazy ResultList implementation
  *
- *	@author Patrick Linskey
- *	@nojavadoc
- */
-public class EagerResultList
-	extends ListResultList
-	implements ResultList
-{
-	public EagerResultList (ResultObjectProvider rop)
-	{
-		super (new ArrayList ());
-		try
-		{
-			rop.open ();
-			while (rop.next ())
-				getDelegate ().add (rop.getResultObject ());
-		}
-		catch (RuntimeException re)
-		{
-			throw re;
-		}
-		catch (Exception e)
-		{
-			rop.handleCheckedException (e);
-		}
-		finally
-		{
-			try { rop.close (); } catch (Exception e) {}
-		}
-	}
-}
+ *  @author Patrick Linskey
+ *  @nojavadoc */
+public class EagerResultList extends ListResultList implements ResultList {
+    public EagerResultList(ResultObjectProvider rop) {
+        super(new ArrayList());
 
+        try {
+            rop.open();
+
+            while (rop.next())
+                getDelegate().add(rop.getResultObject());
+        } catch (RuntimeException re) {
+            throw re;
+        } catch (Exception e) {
+            rop.handleCheckedException(e);
+        } finally {
+            try {
+                rop.close();
+            } catch (Exception e) {
+            }
+        }
+    }
+}

Modified: incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/rop/LazyForwardResultList.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/rop/LazyForwardResultList.java?rev=417856&r1=415364&r2=417856&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/rop/LazyForwardResultList.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/rop/LazyForwardResultList.java Wed Jun 28 12:34:33 2006
@@ -15,235 +15,201 @@
  */
 package org.apache.openjpa.lib.rop;
 
-
 import java.io.*;
+
 import java.util.*;
 
 
 /**
- *	<p>Lazy forward-only result list.</p>
+ *  <p>Lazy forward-only result list.</p>
  *
- *	@author Abe White
- *	@nojavadoc
- */
-public class LazyForwardResultList
-	extends AbstractSequentialResultList
-	implements ResultList
-{
-	private static final int OPEN 	= 0;
-	private static final int CLOSED	= 1;
-	private static final int FREED	= 2;
-
-	private ResultObjectProvider	_rop	= null;
-	private final List 				_list	= new ArrayList ();
-	private int						_state	= OPEN;
-	private int						_size	= -1;
-
-
-	public LazyForwardResultList (ResultObjectProvider rop)
-	{
-		_rop = rop;
-		try
-		{
-			_rop.open ();
-		}
-		catch (RuntimeException re)
-		{
-			close ();
-			throw re;
-		}
-		catch (Exception e)
-		{
-			close ();
-			_rop.handleCheckedException (e);
-		}
-	}
-
-
-	public boolean isProviderOpen ()
-	{
-		return _state == OPEN;
-	}
-
-
-	public boolean isClosed ()
-	{
-		return _state == CLOSED;
-	}
-
-
-	public void close ()
-	{
-		if (_state != CLOSED)
-		{
-			free ();
-			_state = CLOSED;
-		}
-	}
-
-
-	public Object get (int index)
-	{
-		assertOpen ();
-
-		// optimization for getting sequntially
-		if (index == _list.size ())
-			addNext ();
-		if (index < _list.size ())
-			return _list.get (index);
-
-		return super.get (index);
-	}
-
-
-	protected ListIterator itr (int index)
-	{
-		return (_state != OPEN) ? _list.listIterator (index) : new Itr (index);
-	}
-
-
-	public int size ()
-	{
-		assertOpen ();
-		if (_size != -1)
-			return _size;
-		if (_state != OPEN)
-			return _list.size ();
-		try
-		{
-			_size = _rop.size ();
-			return _size;
-		}
-		catch (RuntimeException re)
-		{
-			close ();
-			throw re;
-		}
-		catch (Exception e)
-		{
-			close ();
-			_rop.handleCheckedException (e);
-			return -1;
-		}
-	}
-
-
-	private boolean addNext ()
-	{
-		try
-		{
-			if (!_rop.next ())
-			{
-				free ();
-				return false;
-			}
-			_list.add (_rop.getResultObject ());
-			return true;
-		}
-		catch (RuntimeException re)
-		{
-			close ();
-			throw re;
-		}
-		catch (Exception e)
-		{
-			close ();
-			_rop.handleCheckedException (e);
-			return false;
-		}
-	}
-
-
-	private void free ()
-	{
-		if (_state == OPEN)
-		{
-			try { _rop.close (); } catch (Exception e) {}
-			_state = FREED;
-		}
-	}
-
-
-	public Object writeReplace ()
-		throws ObjectStreamException
-	{
-		// fully traverse results
-		if (_state == OPEN)
-			for (Iterator itr = itr (_list.size ()); itr.hasNext ();)
-				itr.next ();
-		return _list;
-	}
-
-
-	public int hashCode ()
-	{
-		// superclass tries to traverses entire list for hashcode 
-		return System.identityHashCode (this);
-	}
-
-
-	public boolean equals (Object other)
-	{
-		// superclass tries to traverse entire list for equality
-		return other == this;
-	}
-
-
-	private class Itr
-		extends AbstractListIterator
-	{
-		private int _idx = 0;
-
-
-		public Itr (int index)
-		{
-			_idx = Math.min (index, _list.size ());
-			while (_idx < index)
-				next ();
-		}
-
-
-		public int nextIndex ()
-		{
-			return _idx;
-		}
-
-
-		public int previousIndex ()
-		{
-			return _idx - 1;
-		}
-
-
-		public boolean hasNext ()
-		{
-			if (_list.size () > _idx)
-				return true;
-			if (_state != OPEN)
-				return false;
-			return addNext ();
-		}
-
-
-		public boolean hasPrevious ()
-		{
-			return _idx > 0;
-		}
-
-
-		public Object previous ()
-		{
-			if (_idx == 0)
-				throw new NoSuchElementException ();
-			return _list.get (--_idx);
-		}
-
-
-		public Object next ()
-		{
-			if (!hasNext ())
-				throw new NoSuchElementException ();
-			return _list.get (_idx++);
-		}
-	}
+ *  @author Abe White
+ *  @nojavadoc */
+public class LazyForwardResultList extends AbstractSequentialResultList
+    implements ResultList {
+    private static final int OPEN = 0;
+    private static final int CLOSED = 1;
+    private static final int FREED = 2;
+    private ResultObjectProvider _rop = null;
+    private final List _list = new ArrayList();
+    private int _state = OPEN;
+    private int _size = -1;
+
+    public LazyForwardResultList(ResultObjectProvider rop) {
+        _rop = rop;
+
+        try {
+            _rop.open();
+        } catch (RuntimeException re) {
+            close();
+            throw re;
+        } catch (Exception e) {
+            close();
+            _rop.handleCheckedException(e);
+        }
+    }
+
+    public boolean isProviderOpen() {
+        return _state == OPEN;
+    }
+
+    public boolean isClosed() {
+        return _state == CLOSED;
+    }
+
+    public void close() {
+        if (_state != CLOSED) {
+            free();
+            _state = CLOSED;
+        }
+    }
+
+    public Object get(int index) {
+        assertOpen();
+
+        // optimization for getting sequntially
+        if (index == _list.size()) {
+            addNext();
+        }
+
+        if (index < _list.size()) {
+            return _list.get(index);
+        }
+
+        return super.get(index);
+    }
+
+    protected ListIterator itr(int index) {
+        return (_state != OPEN) ? _list.listIterator(index) : new Itr(index);
+    }
+
+    public int size() {
+        assertOpen();
+
+        if (_size != -1) {
+            return _size;
+        }
+
+        if (_state != OPEN) {
+            return _list.size();
+        }
+
+        try {
+            _size = _rop.size();
+
+            return _size;
+        } catch (RuntimeException re) {
+            close();
+            throw re;
+        } catch (Exception e) {
+            close();
+            _rop.handleCheckedException(e);
+
+            return -1;
+        }
+    }
+
+    private boolean addNext() {
+        try {
+            if (!_rop.next()) {
+                free();
+
+                return false;
+            }
+
+            _list.add(_rop.getResultObject());
+
+            return true;
+        } catch (RuntimeException re) {
+            close();
+            throw re;
+        } catch (Exception e) {
+            close();
+            _rop.handleCheckedException(e);
+
+            return false;
+        }
+    }
+
+    private void free() {
+        if (_state == OPEN) {
+            try {
+                _rop.close();
+            } catch (Exception e) {
+            }
+
+            _state = FREED;
+        }
+    }
+
+    public Object writeReplace() throws ObjectStreamException {
+        // fully traverse results
+        if (_state == OPEN) {
+            for (Iterator itr = itr(_list.size()); itr.hasNext();)
+                itr.next();
+        }
+
+        return _list;
+    }
+
+    public int hashCode() {
+        // superclass tries to traverses entire list for hashcode 
+        return System.identityHashCode(this);
+    }
+
+    public boolean equals(Object other) {
+        // superclass tries to traverse entire list for equality
+        return other == this;
+    }
+
+    private class Itr extends AbstractListIterator {
+        private int _idx = 0;
+
+        public Itr(int index) {
+            _idx = Math.min(index, _list.size());
+
+            while (_idx < index)
+                next();
+        }
+
+        public int nextIndex() {
+            return _idx;
+        }
+
+        public int previousIndex() {
+            return _idx - 1;
+        }
+
+        public boolean hasNext() {
+            if (_list.size() > _idx) {
+                return true;
+            }
+
+            if (_state != OPEN) {
+                return false;
+            }
+
+            return addNext();
+        }
+
+        public boolean hasPrevious() {
+            return _idx > 0;
+        }
+
+        public Object previous() {
+            if (_idx == 0) {
+                throw new NoSuchElementException();
+            }
+
+            return _list.get(--_idx);
+        }
+
+        public Object next() {
+            if (!hasNext()) {
+                throw new NoSuchElementException();
+            }
+
+            return _list.get(_idx++);
+        }
+    }
 }

Modified: incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/rop/ListResultList.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/rop/ListResultList.java?rev=417856&r1=415364&r2=417856&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/rop/ListResultList.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/rop/ListResultList.java Wed Jun 28 12:34:33 2006
@@ -15,142 +15,111 @@
  */
 package org.apache.openjpa.lib.rop;
 
-
 import java.util.*;
 
 
-/** 
+/**
  *  <p>A basic {@link ResultList} implementation that wraps a normal list.</p>
- *  
+ *
  *  @author Abe White
- *	@nojavadoc
- */
-public class ListResultList
-	extends AbstractResultList
-{
-	private final List 	_list;
-	private boolean 	_closed = false;
-
-
-	/**
-	 *	Constructor.  Supply delegate.
-	 */
-	public ListResultList (List list)
-	{
-		_list = list;
-	}
-
-
-	/**
-	 *	Return the wrapped list.
-	 */
-	public List getDelegate ()
-	{
-		return _list;
-	}
-
-
-	public boolean isProviderOpen ()
-	{
-		return false;
-	}
-
-
-	public boolean isClosed ()
-	{
-		return _closed;
-	}
+ *  @nojavadoc */
+public class ListResultList extends AbstractResultList {
+    private final List _list;
+    private boolean _closed = false;
 
+    /**
+     *  Constructor.  Supply delegate.
+     */
+    public ListResultList(List list) {
+        _list = list;
+    }
 
-	public void close ()
-	{
-		_closed = true;
-	}
+    /**
+     *  Return the wrapped list.
+     */
+    public List getDelegate() {
+        return _list;
+    }
 
+    public boolean isProviderOpen() {
+        return false;
+    }
 
-	public boolean contains (Object o)
-	{
-		assertOpen ();
-		return _list.contains (o);
-	}
+    public boolean isClosed() {
+        return _closed;
+    }
 
+    public void close() {
+        _closed = true;
+    }
 
-	public boolean containsAll (Collection c)
-	{
-		assertOpen ();
-		return _list.containsAll (c);
-	}
+    public boolean contains(Object o) {
+        assertOpen();
 
+        return _list.contains(o);
+    }
 
-	public Object get (int index)
-	{
-		assertOpen ();
-		return _list.get (index);
-	}
+    public boolean containsAll(Collection c) {
+        assertOpen();
 
+        return _list.containsAll(c);
+    }
 
-	public int indexOf (Object o)
-	{
-		assertOpen ();
-		return _list.indexOf (o);
-	}
+    public Object get(int index) {
+        assertOpen();
 
+        return _list.get(index);
+    }
 
-	public int lastIndexOf (Object o)
-	{
-		assertOpen ();
-		return _list.lastIndexOf (o);
-	}
+    public int indexOf(Object o) {
+        assertOpen();
 
+        return _list.indexOf(o);
+    }
 
-	public int size ()
-	{
-		assertOpen ();
-		return _list.size ();
-	}
+    public int lastIndexOf(Object o) {
+        assertOpen();
 
+        return _list.lastIndexOf(o);
+    }
 
-	public boolean isEmpty ()
-	{
-		assertOpen ();
-		return _list.isEmpty ();
-	}
+    public int size() {
+        assertOpen();
 
+        return _list.size();
+    }
 
-	public Iterator iterator ()
-	{
-		return listIterator ();
-	}
+    public boolean isEmpty() {
+        assertOpen();
 
+        return _list.isEmpty();
+    }
 
-	public ListIterator listIterator ()
-	{
-		return new ResultListIterator (_list.listIterator (), this);
-	}
+    public Iterator iterator() {
+        return listIterator();
+    }
 
+    public ListIterator listIterator() {
+        return new ResultListIterator(_list.listIterator(), this);
+    }
 
-	public ListIterator listIterator (int index)
-	{
-		return new ResultListIterator (_list.listIterator (index), this);
-	}
+    public ListIterator listIterator(int index) {
+        return new ResultListIterator(_list.listIterator(index), this);
+    }
 
+    public Object[] toArray() {
+        assertOpen();
 
-	public Object[] toArray ()
-	{
-		assertOpen ();
-		return _list.toArray ();
-	}
+        return _list.toArray();
+    }
 
+    public Object[] toArray(Object[] a) {
+        assertOpen();
 
-	public Object[] toArray (Object[] a)
-	{
-		assertOpen ();
-		return _list.toArray (a);
-	}
+        return _list.toArray(a);
+    }
 
-	
-	public Object writeReplace ()
-	{
-		return _list;
-	}
+    public Object writeReplace() {
+        return _list;
+    }
 }

Modified: incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/rop/ListResultObjectProvider.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/rop/ListResultObjectProvider.java?rev=417856&r1=415364&r2=417856&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/rop/ListResultObjectProvider.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/rop/ListResultObjectProvider.java Wed Jun 28 12:34:33 2006
@@ -15,104 +15,77 @@
  */
 package org.apache.openjpa.lib.rop;
 
-
-import java.util.*;
-
 import org.apache.commons.lang.exception.*;
 
 import org.apache.openjpa.lib.util.*;
 
+import java.util.*;
+
 
 /**
- *	<p>A result object provider wrapped around a normal list.</p>
+ *  <p>A result object provider wrapped around a normal list.</p>
  *
- *	@author Abe White
+ *  @author Abe White
  */
-public class ListResultObjectProvider
-	implements ResultObjectProvider
-{
-	private final List 	_list;
-	private int			_idx = -1;
-
-
-	/**
-	 *	Constructor.  Supply delegate.
-	 */
-	public ListResultObjectProvider (List list)
-	{
-		_list = list;
-	}
-
-
-	public List getDelegate ()
-	{
-		return _list;
-	}
-
-
-	public boolean supportsRandomAccess ()
-	{
-		return true;
-	}
-
-
-	public void open ()
-		throws Exception
-	{
-	}
-
-
-	public Object getResultObject ()
-		throws Exception
-	{
-		return _list.get (_idx);
-	}
-
-
-	public boolean next ()
-		throws Exception
-	{
-		return absolute (_idx + 1);
-	}
-
-
-	public boolean absolute (int pos)
-		throws Exception
-	{
-		if (pos >= 0 && pos < _list.size ())
-		{
-			_idx = pos;
-			return true;
-		}
-		return false;
-	}
-
-
-	public int size ()
-		throws Exception
-	{
-		return _list.size ();
-	}
-
-
-	public void reset ()
-		throws Exception
-	{
-		_idx = -1;
-	}
-	
-
-	public void close ()
-		throws Exception
-	{
-		if (_list instanceof Closeable)
-			try { ((Closeable) _list).close (); } catch (Exception e) {}
-	}
-
-
-	public void handleCheckedException (Exception e)
-	{
-		// shouldn't ever happen
-		throw new NestableRuntimeException (e);
-	}
+public class ListResultObjectProvider implements ResultObjectProvider {
+    private final List _list;
+    private int _idx = -1;
+
+    /**
+     *  Constructor.  Supply delegate.
+     */
+    public ListResultObjectProvider(List list) {
+        _list = list;
+    }
+
+    public List getDelegate() {
+        return _list;
+    }
+
+    public boolean supportsRandomAccess() {
+        return true;
+    }
+
+    public void open() throws Exception {
+    }
+
+    public Object getResultObject() throws Exception {
+        return _list.get(_idx);
+    }
+
+    public boolean next() throws Exception {
+        return absolute(_idx + 1);
+    }
+
+    public boolean absolute(int pos) throws Exception {
+        if ((pos >= 0) && (pos < _list.size())) {
+            _idx = pos;
+
+            return true;
+        }
+
+        return false;
+    }
+
+    public int size() throws Exception {
+        return _list.size();
+    }
+
+    public void reset() throws Exception {
+        _idx = -1;
+    }
+
+    public void close() throws Exception {
+        if (_list instanceof Closeable) {
+            try {
+                ((Closeable) _list).close();
+            } catch (Exception e) {
+            }
+        }
+    }
+
+    public void handleCheckedException(Exception e) {
+        // shouldn't ever happen
+        throw new NestableRuntimeException(e);
+    }
 }

Modified: incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/rop/MergedResultObjectProvider.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/rop/MergedResultObjectProvider.java?rev=417856&r1=415364&r2=417856&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/rop/MergedResultObjectProvider.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/main/java/org/apache/openjpa/lib/rop/MergedResultObjectProvider.java Wed Jun 28 12:34:33 2006
@@ -15,269 +15,249 @@
  */
 package org.apache.openjpa.lib.rop;
 
+import org.apache.commons.lang.exception.*;
 
 import java.util.*;
 
-import org.apache.commons.lang.exception.*;
-
 
-/** 
+/**
  *  <p>A result object provider that merges multiple result object provider
- *	delegates. Support exists for maintaining ordering of the internally held 
- *	results, provided that each of the individual results is itself ordered.</p>
- *  
- *	@author	Abe White
- *  @author	Marc Prud'hommeaux
+ *  delegates. Support exists for maintaining ordering of the internally held
+ *  results, provided that each of the individual results is itself ordered.</p>
+ *
+ *  @author Abe White
+ *  @author Marc Prud'hommeaux
  */
-public class MergedResultObjectProvider
-	implements ResultObjectProvider
-{
-	private static final byte UNOPENED	= 0;
-	private static final byte OPENED 	= 1;
-	private static final byte VALUE 	= 2;
-	private static final byte DONE 		= 3;
-
-	private final ResultObjectProvider[]	_rops;
-	private final Comparator 				_comp;
-	private final byte[]					_status;
-	private Object[]						_values;
-	private Object[]						_orderValues;
-	private Object							_cur	= null;
-	private int 							_size 	= -1;
-
-
-	/**
-	 *	Constructor.  Provide delegates.
-	 */
-	public MergedResultObjectProvider (ResultObjectProvider[] rops)
-	{
-		this (rops, null);
-	}
-
-
-	/**
-	 *	Constructor.  Provide delegates and optional comparator.
-	 */
-	public MergedResultObjectProvider (ResultObjectProvider[] rops, 
-		Comparator comp)
-	{
-		_rops = rops;
-		_comp = comp;
-		_status = new byte[rops.length];
-		_values = (comp == null) ? null : new Object[rops.length];
-		_orderValues = (comp == null) ? null : new Object[rops.length];
-	}
-
-
-	public boolean supportsRandomAccess ()
-	{
-		return false;
-	}
-
-
-	public void open ()
-		throws Exception
-	{
-		// if we have a comparator, then open all; else open first
-		int len = (_comp != null) ? _rops.length : 1;
-		for (int i = 0; i < len; i++)
-		{
-			_rops[i].open ();
-			_status[i] = OPENED;
-		}
-	}
-
-
-	public boolean absolute (int pos)
-		throws Exception
-	{
-		throw new UnsupportedOperationException ();
-	}
-
-
-	public int size ()
-		throws Exception
-	{
-		if (_size != -1)
-			return _size;
-
-		// have to open all to get sizes
-		for (int i = 0; i < _status.length; i++)
-		{
-			if (_status[i] == UNOPENED)
-			{
-				_rops[i].open ();
-				_status[i] = OPENED;
-			}
-		}
-
-		int total = 0;
-		int size;
-		for (int i = 0; i < _rops.length; i++)
-		{
-			size = _rops[i].size ();
-			if (size == Integer.MAX_VALUE)
-			{
-				total = size;
-				break;
-			}
-			total += size;	
-		}
-		_size = total;
-		return _size;
-	}
-
-
-	public void reset ()
-		throws Exception
-	{
-		for (int i = 0; i < _rops.length; i++)
-			if (_status[i] != UNOPENED)
-				_rops[i].reset ();
-		clear ();
-	}
-
-
-	public void close ()
-		throws Exception
-	{
-		Exception err = null;
-		for (int i = 0; i < _rops.length; i++)
-		{
-			try
-			{
-				if (_status[i] != UNOPENED)
-					_rops[i].close ();
-			}
-			catch (Exception e)
-			{
-				if (err == null)
-					err = e;
-			}
-		}
-
-		clear ();
-		if (err != null)
-			throw err;
-	}
-
-
-	private void clear ()
-	{
-		_cur = null;
-		for (int i = 0; i < _rops.length; i++)
-		{
-			_status[i] = OPENED;
-			if (_values != null)
-				_values[i] = null;
-			if (_orderValues != null)
-				_orderValues[i] = null;	
-		}
-	}
-
-
-	public void handleCheckedException (Exception e)
-	{
-		if (_rops.length == 0)
-			throw new NestableRuntimeException (e);
-		_rops[0].handleCheckedException (e);
-	}
-
-
-	public boolean next ()
-		throws Exception
-	{
-		// initialize all rops with the latest values
-		boolean hasValue = false;
-		for (int i = 0; i < _status.length; i++)
-		{
-			switch (_status[i])
-			{
-			case UNOPENED:
-				// this will only ever be the case if we aren't ordering
-				_rops[i].open ();
-				_status[i] = OPENED;
-				// no break
-			case OPENED:
-				// if this rop has a value, cache it; if we're not ordering,
-				// then that's the value to return
-				if (_rops[i].next ())
-				{
-					if (_comp == null)
-					{
-						_cur = _rops[i].getResultObject ();
-						return true;
-					}
-					else
-					{
-						hasValue = true;
-						_status[i] = VALUE;
-						_values[i] = _rops[i].getResultObject ();	
-						_orderValues[i] = getOrderingValue (_values[i], 
-							i, _rops[i]);
-					}
-				}
-				else
-					_status[i] = DONE;
-				break;
-			case VALUE:
-				// we only use this state when ordering
-				hasValue = true;
-				break;
-			}
-		}
-
-		// if we get to this point without a comparator, it means none
-		// of our rops have any more values
-		if (_comp == null || !hasValue)
-			return false;
-
-		// for all the rops with values, find the 'least' one according to
-		// the comparator
-		int least = -1;
-		Object orderVal = null;
-		for (int i = 0; i < _orderValues.length; i++)
-		{
-			if (_status[i] != VALUE)
-				continue;
-			if (least == -1 || _comp.compare (_orderValues[i], orderVal) < 0)
-			{
-				least = i;
-				orderVal = _orderValues[i];	
-			}
-		}
-
-		// assign the least value to the current one, and clear the cached
-		// value for that rop so that we know to get the next value for
-		// the next comparison
-		_cur = _values[least];
-		_values[least] = null;
-		_orderValues[least] = null;
-		_status[least] = OPENED;
-		return true;
-	}
-
-
-	public Object getResultObject ()
-		throws Exception
-	{
-		return _cur;
-	}
-
-
-	/**
-	 *	Return the value to use for ordering on the given result value.  Returns
-	 *	the result value by default.
-	 *
-	 *	@param	val		the result value
-	 *	@param	idx		the index of the result object provider in the array
-	 *					given on construction that produced the result value
-	 *	@param	rop		the result object provider that produced the result 
-	 *					value
-	 */
-	protected Object getOrderingValue (Object val, int idx, 
-		ResultObjectProvider rop)
-	{
-		return val;
-	}
+public class MergedResultObjectProvider implements ResultObjectProvider {
+    private static final byte UNOPENED = 0;
+    private static final byte OPENED = 1;
+    private static final byte VALUE = 2;
+    private static final byte DONE = 3;
+    private final ResultObjectProvider[] _rops;
+    private final Comparator _comp;
+    private final byte[] _status;
+    private Object[] _values;
+    private Object[] _orderValues;
+    private Object _cur = null;
+    private int _size = -1;
+
+    /**
+     *  Constructor.  Provide delegates.
+     */
+    public MergedResultObjectProvider(ResultObjectProvider[] rops) {
+        this(rops, null);
+    }
+
+    /**
+     *  Constructor.  Provide delegates and optional comparator.
+     */
+    public MergedResultObjectProvider(ResultObjectProvider[] rops,
+        Comparator comp) {
+        _rops = rops;
+        _comp = comp;
+        _status = new byte[rops.length];
+        _values = (comp == null) ? null : new Object[rops.length];
+        _orderValues = (comp == null) ? null : new Object[rops.length];
+    }
+
+    public boolean supportsRandomAccess() {
+        return false;
+    }
+
+    public void open() throws Exception {
+        // if we have a comparator, then open all; else open first
+        int len = (_comp != null) ? _rops.length : 1;
+
+        for (int i = 0; i < len; i++) {
+            _rops[i].open();
+            _status[i] = OPENED;
+        }
+    }
+
+    public boolean absolute(int pos) throws Exception {
+        throw new UnsupportedOperationException();
+    }
+
+    public int size() throws Exception {
+        if (_size != -1) {
+            return _size;
+        }
+
+        // have to open all to get sizes
+        for (int i = 0; i < _status.length; i++) {
+            if (_status[i] == UNOPENED) {
+                _rops[i].open();
+                _status[i] = OPENED;
+            }
+        }
+
+        int total = 0;
+        int size;
+
+        for (int i = 0; i < _rops.length; i++) {
+            size = _rops[i].size();
+
+            if (size == Integer.MAX_VALUE) {
+                total = size;
+
+                break;
+            }
+
+            total += size;
+        }
+
+        _size = total;
+
+        return _size;
+    }
+
+    public void reset() throws Exception {
+        for (int i = 0; i < _rops.length; i++)
+            if (_status[i] != UNOPENED) {
+                _rops[i].reset();
+            }
+
+        clear();
+    }
+
+    public void close() throws Exception {
+        Exception err = null;
+
+        for (int i = 0; i < _rops.length; i++) {
+            try {
+                if (_status[i] != UNOPENED) {
+                    _rops[i].close();
+                }
+            } catch (Exception e) {
+                if (err == null) {
+                    err = e;
+                }
+            }
+        }
+
+        clear();
+
+        if (err != null) {
+            throw err;
+        }
+    }
+
+    private void clear() {
+        _cur = null;
+
+        for (int i = 0; i < _rops.length; i++) {
+            _status[i] = OPENED;
+
+            if (_values != null) {
+                _values[i] = null;
+            }
+
+            if (_orderValues != null) {
+                _orderValues[i] = null;
+            }
+        }
+    }
+
+    public void handleCheckedException(Exception e) {
+        if (_rops.length == 0) {
+            throw new NestableRuntimeException(e);
+        }
+
+        _rops[0].handleCheckedException(e);
+    }
+
+    public boolean next() throws Exception {
+        // initialize all rops with the latest values
+        boolean hasValue = false;
+
+        for (int i = 0; i < _status.length; i++) {
+            switch (_status[i]) {
+            case UNOPENED:
+                // this will only ever be the case if we aren't ordering
+                _rops[i].open();
+                _status[i] = OPENED;
+
+            // no break
+            case OPENED:
+
+                // if this rop has a value, cache it; if we're not ordering,
+                // then that's the value to return
+                if (_rops[i].next()) {
+                    if (_comp == null) {
+                        _cur = _rops[i].getResultObject();
+
+                        return true;
+                    } else {
+                        hasValue = true;
+                        _status[i] = VALUE;
+                        _values[i] = _rops[i].getResultObject();
+                        _orderValues[i] = getOrderingValue(_values[i], i,
+                                _rops[i]);
+                    }
+                } else {
+                    _status[i] = DONE;
+                }
+
+                break;
+
+            case VALUE:
+                // we only use this state when ordering
+                hasValue = true;
+
+                break;
+            }
+        }
+
+        // if we get to this point without a comparator, it means none
+        // of our rops have any more values
+        if ((_comp == null) || !hasValue) {
+            return false;
+        }
+
+        // for all the rops with values, find the 'least' one according to
+        // the comparator
+        int least = -1;
+        Object orderVal = null;
+
+        for (int i = 0; i < _orderValues.length; i++) {
+            if (_status[i] != VALUE) {
+                continue;
+            }
+
+            if ((least == -1) ||
+                    (_comp.compare(_orderValues[i], orderVal) < 0)) {
+                least = i;
+                orderVal = _orderValues[i];
+            }
+        }
+
+        // assign the least value to the current one, and clear the cached
+        // value for that rop so that we know to get the next value for
+        // the next comparison
+        _cur = _values[least];
+        _values[least] = null;
+        _orderValues[least] = null;
+        _status[least] = OPENED;
+
+        return true;
+    }
+
+    public Object getResultObject() throws Exception {
+        return _cur;
+    }
+
+    /**
+     *  Return the value to use for ordering on the given result value.  Returns
+     *  the result value by default.
+     *
+     *  @param val                the result value
+     *  @param idx                the index of the result object provider in the array
+     *                                  given on construction that produced the result value
+     *  @param rop                the result object provider that produced the result
+     *                                  value
+     */
+    protected Object getOrderingValue(Object val, int idx,
+        ResultObjectProvider rop) {
+        return val;
+    }
 }



Mime
View raw message