Coverage Report - org.apache.torque.mojo.morph.Morpher
 
Classes in this File Line Coverage Branch Coverage Complexity
Morpher
0%
0/23
0%
0/2
1.111
 
 1  
 package org.apache.torque.mojo.morph;
 2  
 
 3  
 import java.io.IOException;
 4  
 import java.io.InputStream;
 5  
 import java.io.OutputStream;
 6  
 
 7  
 import org.apache.commons.io.IOUtils;
 8  
 import org.apache.commons.logging.Log;
 9  
 import org.apache.commons.logging.LogFactory;
 10  
 
 11  
 public abstract class Morpher {
 12  0
         private static final Log log = LogFactory.getLog(Morpher.class);
 13  
 
 14  
         MorphRequest morphRequest;
 15  
         String artifactId;
 16  
 
 17  
         public Morpher() {
 18  0
                 this(null, null);
 19  0
         }
 20  
 
 21  
         public Morpher(MorphRequest morphRequest, String artifactId) {
 22  0
                 super();
 23  0
                 this.morphRequest = morphRequest;
 24  0
                 this.artifactId = artifactId;
 25  0
         }
 26  
 
 27  
         protected abstract boolean isMorphNeeded(String contents);
 28  
 
 29  
         protected abstract String getMorphedContents(String contents);
 30  
 
 31  
         public void executeMorph() throws IOException {
 32  
                 // Read the "old" data into a string
 33  0
                 InputStream in = morphRequest.getInputStream();
 34  0
                 String contents = IOUtils.toString(in, morphRequest.getEncoding());
 35  0
                 IOUtils.closeQuietly(in);
 36  
 
 37  
                 // May not need to morph
 38  0
                 if (isMorphNeeded(contents)) {
 39  0
                         contents = getMorphedContents(contents);
 40  
                 } else {
 41  0
                         log.debug("Skipping morph on " + morphRequest.getName());
 42  
                 }
 43  
 
 44  
                 // Write the morphed data to the output stream
 45  0
                 OutputStream out = morphRequest.getOutputStream();
 46  0
                 IOUtils.write(contents, out, morphRequest.getEncoding());
 47  0
                 IOUtils.closeQuietly(out);
 48  0
         }
 49  
 
 50  
         public MorphRequest getMorphRequest() {
 51  0
                 return morphRequest;
 52  
         }
 53  
 
 54  
         public void setMorphRequest(MorphRequest morphRequest) {
 55  0
                 this.morphRequest = morphRequest;
 56  0
         }
 57  
 
 58  
         public String getArtifactId() {
 59  0
                 return artifactId;
 60  
         }
 61  
 
 62  
         public void setArtifactId(String schema) {
 63  0
                 this.artifactId = schema;
 64  0
         }
 65  
 
 66  
 }