001: /*
002: * <copyright>
003: *
004: * Copyright 1997-2004 BBNT Solutions, LLC
005: * under sponsorship of the Defense Advanced Research Projects
006: * Agency (DARPA).
007: *
008: * You can redistribute this software and/or modify it under the
009: * terms of the Cougaar Open Source License as published on the
010: * Cougaar Open Source Website (www.cougaar.org).
011: *
012: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023: *
024: * </copyright>
025: */
026:
027: package org.cougaar.planning.ldm.plan;
028:
029: import java.io.IOException;
030: import java.io.NotSerializableException;
031: import java.io.ObjectInputStream;
032: import java.io.ObjectOutputStream;
033:
034: /**
035: * Setters for PrepositionalPhrase.
036: */
037:
038: public class PrepositionalPhraseImpl implements PrepositionalPhrase,
039: NewPrepositionalPhrase, java.io.Serializable {
040:
041: private String preposition;
042: private transient Object indirectobject; // changed to transient : Persistence
043:
044: // no-arg constructor
045: public PrepositionalPhraseImpl() {
046: }
047:
048: PrepositionalPhraseImpl(String p, Object io) {
049: preposition = p;
050: indirectobject = io;
051: }
052:
053: /** @return Answer with a nicely formatted string representation. */
054: public String toString() {
055: if (indirectobject == null && preposition == null)
056: return "[ a null valued prepositional phrase]";
057: else if (indirectobject == null)
058: return preposition + " <null>";
059: else
060: return preposition + " " + indirectobject.toString();
061: }
062:
063: /** PrepositionalPhrase interface implementations */
064:
065: /**@return String - String representation of the Preposition */
066: public String getPreposition() {
067: return preposition;
068: }
069:
070: /** @return Object - the IndirectObject */
071: public Object getIndirectObject() {
072: return indirectobject;
073: }
074:
075: /** NewPrepositionalPhrase interface implementations */
076:
077: /**@param apreposition - Set the String representation of the Preposition */
078: public void setPreposition(String apreposition) {
079: if (apreposition != null)
080: apreposition = apreposition.intern();
081: preposition = apreposition;
082: }
083:
084: /** @param anindirectobject - Set the IndirectObject of the PrespositionalPhrase */
085: public void setIndirectObject(Object anindirectobject) {
086: indirectobject = anindirectobject;
087: }
088:
089: /** PP are equals() IFF prepositions are the same and
090: * indirectobjects are .equals()
091: */
092: public boolean equals(Object o) {
093: if (this == o)
094: return true;
095: if (preposition == null)
096: return false;
097: if (o instanceof PrepositionalPhraseImpl) {
098: PrepositionalPhraseImpl ppi = (PrepositionalPhraseImpl) o;
099: String ppip = ppi.preposition;
100: return (preposition == ppip)
101: && ((indirectobject == null) ? (ppi.indirectobject == null)
102: : (indirectobject
103: .equals(ppi.indirectobject)));
104: } else {
105: return false;
106: }
107: }
108:
109: private void writeObject(ObjectOutputStream stream)
110: throws IOException {
111:
112: stream.defaultWriteObject();
113:
114: try {
115: stream.writeObject(indirectobject);
116: } catch (NotSerializableException nse) {
117: System.err.println(nse + " for indirectobject of "
118: + preposition + ": " + indirectobject);
119: throw nse;
120: }
121: }
122:
123: private void readObject(ObjectInputStream stream)
124: throws ClassNotFoundException, IOException {
125:
126: stream.defaultReadObject();
127: if (preposition != null)
128: preposition = preposition.intern();
129: indirectobject = stream.readObject();
130: }
131: }
|