001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.proxy.ejb;
023:
024: import java.io.Externalizable;
025: import java.io.ObjectOutput;
026: import java.io.ObjectInput;
027: import java.io.IOException;
028: import java.util.ArrayList;
029:
030: /**
031: * A result of get-method invocation of CMP 2.0 entity bean in the case where read ahead is turned on.
032: * Usage: on server set main result via {@link #setMainResult(java.lang.Object)} and add ahead results via
033: * {@link #addAheadResult(java.lang.Object)}. On client get main result via {@link #getMainResult()} and
034: * array of ahead results via {@link #getAheadResults()}.
035: *
036: * @author <a href="mailto:on@ibis.odessa.ua">Oleg Nitz</a>
037: * @version $Revision: 57209 $
038: */
039: public class ReadAheadResult implements Externalizable {
040: /** Serial Version Identifier. @since 1.1 */
041: private static final long serialVersionUID = -4041516583763000658L;
042:
043: // Attributes ----------------------------------------------------
044:
045: /**
046: * A List of read ahead values, during externalization is replaces by array
047: */
048: private ArrayList aheadList = new ArrayList();
049:
050: /**
051: * A List of read ahead values, during externalization is replaces by array
052: */
053: private Object[] aheadArray;
054:
055: /**
056: * A hash map of read ahead values, maps Methods to values.
057: */
058: private Object mainResult;
059:
060: // Static --------------------------------------------------------
061:
062: // Constructors --------------------------------------------------
063:
064: public ReadAheadResult() {
065: }
066:
067: // Static --------------------------------------------------------
068:
069: // Public --------------------------------------------------------
070:
071: public void setMainResult(Object mainResult) {
072: this .mainResult = mainResult;
073: }
074:
075: public void addAheadResult(Object aheadResult) {
076: aheadList.add(aheadResult);
077: }
078:
079: public Object getMainResult() {
080: return mainResult;
081: }
082:
083: public Object[] getAheadResult() {
084: if (aheadArray == null) {
085: aheadArray = aheadList
086: .toArray(new Object[aheadList.size()]);
087: aheadList = null;
088: }
089: return aheadArray;
090: }
091:
092: // Package protected ---------------------------------------------
093:
094: // Protected -----------------------------------------------------
095:
096: // Private -------------------------------------------------------
097:
098: public void writeExternal(ObjectOutput out) throws IOException {
099: out.writeObject(mainResult);
100: out.writeObject(getAheadResult());
101: }
102:
103: public void readExternal(ObjectInput in) throws IOException,
104: ClassNotFoundException {
105: mainResult = in.readObject();
106: aheadArray = (Object[]) in.readObject();
107: }
108:
109: // Inner classes -------------------------------------------------
110: }
|