| 1 | /* |
|---|
| 2 | * Copyright 2007-2008, Plutext Pty Ltd. |
|---|
| 3 | * |
|---|
| 4 | * This file is part of docx4j. |
|---|
| 5 | |
|---|
| 6 | docx4j is licensed under the Apache License, Version 2.0 (the "License"); |
|---|
| 7 | you may not use this file except in compliance with the License. |
|---|
| 8 | |
|---|
| 9 | You may obtain a copy of the License at |
|---|
| 10 | |
|---|
| 11 | http://www.apache.org/licenses/LICENSE-2.0 |
|---|
| 12 | |
|---|
| 13 | Unless required by applicable law or agreed to in writing, software |
|---|
| 14 | distributed under the License is distributed on an "AS IS" BASIS, |
|---|
| 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|---|
| 16 | See the License for the specific language governing permissions and |
|---|
| 17 | limitations under the License. |
|---|
| 18 | |
|---|
| 19 | */ |
|---|
| 20 | package org.docx4j.utils; |
|---|
| 21 | |
|---|
| 22 | import java.util.List; |
|---|
| 23 | |
|---|
| 24 | /** |
|---|
| 25 | * |
|---|
| 26 | * Extend this class to specify what should be done when a |
|---|
| 27 | * particular object (eg P or Table) is visited during the |
|---|
| 28 | * traversal. |
|---|
| 29 | * |
|---|
| 30 | * @author alberto |
|---|
| 31 | */ |
|---|
| 32 | public abstract class TraversalUtilVisitor<T> { |
|---|
| 33 | // Doing this as a class instead of an interface ensures that it is part of the inheritance hierarchy. |
|---|
| 34 | |
|---|
| 35 | /** |
|---|
| 36 | * |
|---|
| 37 | * @param element |
|---|
| 38 | * @param parent (logical?)parent in the of the element |
|---|
| 39 | * @param siblings List of the element (this includes the element itself). |
|---|
| 40 | * This list can't be changed while the visitor is running(!) |
|---|
| 41 | */ |
|---|
| 42 | public void apply(T element, Object parent, List<Object> siblings) { |
|---|
| 43 | apply(element); |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | /** Apply method if there is no need to access the surrounding elements |
|---|
| 47 | * |
|---|
| 48 | * @param element |
|---|
| 49 | */ |
|---|
| 50 | public void apply(T element) { |
|---|
| 51 | throw new UnsupportedOperationException("At least one of the methods needs to be subclassed"); |
|---|
| 52 | } |
|---|
| 53 | } |
|---|