View Javadoc

1   /*
2    * Copyright 2005 The Apache Software Foundation.
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  
17  package org.apache.jdo.impl.enhancer;
18  
19  import java.io.OutputStream;
20  
21  /***
22   *  This class serves as a wrapper for an output stream of a class file. The
23   *  stream is passed as a parameter to the byte code enhancer, that can
24   *  sets the classname of the written Java class to the wrapper.
25   *  <br>
26   *  This wrapper is necessary to determine the classname outside the enhancer,
27   *  after the class has been enhanced, since do do not always know the
28   *  classname of an opened input stream.
29   *
30   */
31  public class OutputStreamWrapper
32  {
33      /***
34       *  The wrapped output stream.
35       */
36      private OutputStream out;
37  
38      /***
39       *  The classname of the written Java class. This parameter
40       *  is set by the enhancer.
41       */
42      private String className = null;
43  
44      /***
45       *  Constructs a new object.
46       *
47       *  @param  out  The output stream to wrap.
48       */
49      public OutputStreamWrapper(OutputStream out)
50      {
51          this.out = out;
52      }
53  
54      /***
55       *  Gets the wrapped output stream.
56       *
57       *  @return The wrapped output stream.
58       */
59      public final OutputStream getStream()
60      {
61          return out;
62      }
63  
64      /***
65       *  Gets the classname of the written Java class. This method should be
66       *  called after the class has been enhanced.
67       *
68       *  @return  The name of the written Java class.
69       */
70      public final String getClassName()
71      {
72          return className;
73      }
74  
75      /***
76       *  Sets the name of the written Java class. This method should be called
77       *  by the enhancer.
78       *
79       *  @param  classname  The name of the Java class.
80       */
81      public final void setClassName(String classname)
82      {
83          this.className = classname;
84      }
85  }