001: /*
002: * Copyright (c) 2007, intarsys consulting GmbH
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * - Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * - Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * - Neither the name of intarsys nor the names of its contributors may be used
015: * to endorse or promote products derived from this software without specific
016: * prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
020: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
021: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
022: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
023: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
024: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
025: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
026: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
027: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
028: * POSSIBILITY OF SUCH DAMAGE.
029: */
030: package de.intarsys.pdf.cos;
031:
032: import java.util.Iterator;
033:
034: /**
035: * Adapter implementation for visiting a COS object structure without navigating
036: * the indirect references.
037: * <p>
038: * More precise, this one will visit the directed acyclic data structure
039: * originating from a COS object.
040: *
041: */
042: public class COSObjectWalkerShallow implements ICOSObjectVisitor {
043: public COSObjectWalkerShallow() {
044: //
045: }
046:
047: /*
048: * (non-Javadoc)
049: *
050: * @see de.intarsys.pdf.cos.ICOSObjectVisitor#visitFromArray(de.intarsys.pdf.cos.COSArray)
051: */
052: public Object visitFromArray(COSArray array)
053: throws COSVisitorException {
054: if (visitFromArrayBefore(array)) {
055: for (Iterator i = array.basicIterator(); i.hasNext();) {
056: ((COSDocumentElement) i.next()).accept(this );
057: }
058: }
059: return visitFromArrayAfter(array);
060: }
061:
062: protected Object visitFromArrayAfter(COSArray array) {
063: return null;
064: }
065:
066: /**
067: * @param array
068: */
069: protected boolean visitFromArrayBefore(COSArray array) {
070: return true;
071: }
072:
073: /*
074: * (non-Javadoc)
075: *
076: * @see de.intarsys.pdf.cos.ICOSObjectVisitor#visitFromBoolean(de.intarsys.pdf.cos.COSBoolean)
077: */
078: public Object visitFromBoolean(COSBoolean bool)
079: throws COSVisitorException {
080: return null;
081: }
082:
083: /*
084: * (non-Javadoc)
085: *
086: * @see de.intarsys.pdf.cos.ICOSObjectVisitor#visitFromDictionary(de.intarsys.pdf.cos.COSDictionary)
087: */
088: public Object visitFromDictionary(COSDictionary dict)
089: throws COSVisitorException {
090: if (visitFromDictionaryBefore(dict)) {
091: for (Iterator i = dict.basicIterator(); i.hasNext();) {
092: ((COSDocumentElement) i.next()).accept(this );
093: }
094: }
095: return visitFromDictionaryAfter(dict);
096: }
097:
098: protected Object visitFromDictionaryAfter(COSDictionary dict) {
099: return null;
100: }
101:
102: protected boolean visitFromDictionaryBefore(COSDictionary dict) {
103: return true;
104: }
105:
106: /*
107: * (non-Javadoc)
108: *
109: * @see de.intarsys.pdf.cos.ICOSObjectVisitor#visitFromFixed(de.intarsys.pdf.cos.COSFixed)
110: */
111: public Object visitFromFixed(COSFixed fixed)
112: throws COSVisitorException {
113: return null;
114: }
115:
116: /*
117: * (non-Javadoc)
118: *
119: * @see de.intarsys.pdf.cos.ICOSObjectVisitor#visitFromInteger(de.intarsys.pdf.cos.COSInteger)
120: */
121: public Object visitFromInteger(COSInteger integer)
122: throws COSVisitorException {
123: return null;
124: }
125:
126: /*
127: * (non-Javadoc)
128: *
129: * @see de.intarsys.pdf.cos.ICOSObjectVisitor#visitFromName(de.intarsys.pdf.cos.COSName)
130: */
131: public Object visitFromName(COSName name)
132: throws COSVisitorException {
133: return null;
134: }
135:
136: /*
137: * (non-Javadoc)
138: *
139: * @see de.intarsys.pdf.cos.ICOSObjectVisitor#visitFromNull(de.intarsys.pdf.cos.COSNull)
140: */
141: public Object visitFromNull(COSNull nullObj)
142: throws COSVisitorException {
143: return null;
144: }
145:
146: /*
147: * (non-Javadoc)
148: *
149: * @see de.intarsys.pdf.cos.ICOSObjectVisitor#visitFromStream(de.intarsys.pdf.cos.COSStream)
150: */
151: public Object visitFromStream(COSStream stream)
152: throws COSVisitorException {
153: stream.getDict().accept(this );
154: return null;
155: }
156:
157: /*
158: * (non-Javadoc)
159: *
160: * @see de.intarsys.pdf.cos.ICOSObjectVisitor#visitFromString(de.intarsys.pdf.cos.COSString)
161: */
162: public Object visitFromString(COSString string)
163: throws COSVisitorException {
164: return null;
165: }
166:
167: /*
168: * (non-Javadoc)
169: *
170: * @see de.intarsys.pdf.cos.ICOSObjectVisitor#visitFromIndirectObject(de.intarsys.pdf.cos.COSIndirectObject)
171: */
172: public Object visitFromIndirectObject(COSIndirectObject io)
173: throws COSVisitorException {
174: return null;
175: }
176: }
|