KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dbunit > dataset > csv > handlers > AbstractPipelineComponent


1 /*
2  *
3  * The DbUnit Database Testing Framework
4  * Copyright (C)2002-2004, DbUnit.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  */

21 package org.dbunit.dataset.csv.handlers;
22
23 import org.dbunit.dataset.csv.IllegalInputCharacterException;
24
25 public abstract class AbstractPipelineComponent implements PipelineComponent {
26
27     private PipelineComponent successor;
28     private Pipeline pipeline;
29
30     private Helper helper;
31
32     protected PipelineComponent getSuccessor() {
33         return successor;
34     }
35
36     public Pipeline getPipeline() {
37         return pipeline;
38     }
39
40     public void setPipeline(Pipeline pipeline) {
41         this.pipeline = pipeline;
42     }
43
44     public void setSuccessor(PipelineComponent successor) {
45         this.successor = successor;
46     }
47
48
49     private StringBuffer JavaDoc getThePiece() {
50         return getPipeline().getCurrentProduct();
51     }
52
53     public void handle(char c) throws IllegalInputCharacterException, PipelineException {
54         if (!canHandle(c)) {
55             getSuccessor().handle(c);
56         } else {
57             getHelper().helpWith(c);
58         }
59     }
60
61     public void noMoreInput() {
62         if (allowForNoMoreInput()) {
63             if (getSuccessor()!= null)
64                 getSuccessor().noMoreInput();
65         }
66     }
67
68     public boolean allowForNoMoreInput() {
69         return getHelper().allowForNoMoreInput();
70     }
71
72     protected static PipelineComponent createPipelineComponent(AbstractPipelineComponent handler, Helper helper) {
73         helper.setHandler(handler);
74         handler.setHelper(helper);
75         return handler;
76     }
77
78     /**
79      * Method invoked when the character should be accepted
80      * @param c
81      */

82     public void accept(char c) {
83         getThePiece().append(c);
84     }
85
86     protected Helper getHelper() {
87         return helper;
88     }
89
90     private void setHelper(Helper helper) {
91         this.helper = helper;
92     }
93
94     static protected class IGNORE extends Helper {
95
96         public void helpWith(char c) {
97             // IGNORE
98
}
99     }
100
101     static protected class ACCEPT extends Helper {
102
103         public void helpWith(char c) {
104             getHandler().accept(c);
105         }
106     }
107 }
108
Popular Tags