View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software 
12   * distributed under the License is distributed on an "AS IS" BASIS, 
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
14   * See the License for the specific language governing permissions and 
15   * limitations under the License.
16   */
17  
18  package org.apache.jdo.impl.enhancer;
19  
20  import java.io.OutputStream;
21  
22  /***
23   *  This class serves as a wrapper for an output stream of a class file. The
24   *  stream is passed as a parameter to the byte code enhancer, that can
25   *  sets the classname of the written Java class to the wrapper.
26   *  <br>
27   *  This wrapper is necessary to determine the classname outside the enhancer,
28   *  after the class has been enhanced, since do do not always know the
29   *  classname of an opened input stream.
30   *
31   */
32  public class OutputStreamWrapper
33  {
34      /***
35       *  The wrapped output stream.
36       */
37      private OutputStream out;
38  
39      /***
40       *  The classname of the written Java class. This parameter
41       *  is set by the enhancer.
42       */
43      private String className = null;
44  
45      /***
46       *  Constructs a new object.
47       *
48       *  @param  out  The output stream to wrap.
49       */
50      public OutputStreamWrapper(OutputStream out)
51      {
52          this.out = out;
53      }
54  
55      /***
56       *  Gets the wrapped output stream.
57       *
58       *  @return The wrapped output stream.
59       */
60      public final OutputStream getStream()
61      {
62          return out;
63      }
64  
65      /***
66       *  Gets the classname of the written Java class. This method should be
67       *  called after the class has been enhanced.
68       *
69       *  @return  The name of the written Java class.
70       */
71      public final String getClassName()
72      {
73          return className;
74      }
75  
76      /***
77       *  Sets the name of the written Java class. This method should be called
78       *  by the enhancer.
79       *
80       *  @param  classname  The name of the Java class.
81       */
82      public final void setClassName(String classname)
83      {
84          this.className = classname;
85      }
86  }