View Javadoc
1   /*
2    * Copyright 2005-2007 Werner Guttmann
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.exolab.castor.builder.printing;
17  
18  import org.exolab.javasource.JClass;
19  import org.exolab.javasource.JComment;
20  
21  /**
22   * Prints a given {@link JClass} to the file system using the
23   * {@link JClass#print(org.exolab.javasource.JSourceWriter)} method.
24   */
25  public class WriterJClassPrinter implements JClassPrinter {
26  
27      /**
28       * 
29       * {@inheritDoc}
30       * 
31       * @see org.exolab.castor.builder.printing.JClassPrinter#printClass(org.exolab.javasource.JClass,
32       *      java.lang.String, java.lang.String, java.lang.String)
33       */
34      public void printClass(final JClass jClass, final String outputDir,
35              final String lineSeparator, final String header) {
36          
37          // hack for the moment
38          // to avoid the compiler complaining with java.util.Date
39          jClass.removeImport("org.exolab.castor.types.Date");
40  
41          // add header
42          JComment comment = new JComment(JComment.HEADER_STYLE);
43          comment.appendComment(header);
44          jClass.setHeader(comment);
45  
46          // print
47          jClass.print(outputDir, lineSeparator);
48      }
49  }