1 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 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 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 } 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 |