KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > webdocwf > util > loader > generator > BufferClass


1 /*
2 LoaderGenerator - tool for generated xml, sql and doml file needed for Octopus.
3
4
5     Copyright (C) 2003 Together
6
7     This library is free software; you can redistribute it and/or
8     modify it under the terms of the GNU Lesser General Public
9     License as published by the Free Software Foundation; either
10     version 2.1 of the License, or (at your option) any later version.
11
12     This library is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15     Lesser General Public License for more details.
16
17     You should have received a copy of the GNU Lesser General Public
18     License along with this library; if not, write to the Free Software
19     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */

21
22 package org.webdocwf.util.loader.generator;
23
24 import java.util.*;
25
26 /**
27  *
28  * BufferClass class is used for writing system out in to internal buffer.
29  * This class is a Singleton.
30  * @author Radoslav Dutina
31  * @version 1.0
32  */

33 public class BufferClass {
34
35   static private BufferClass instance;
36   private ArrayList buffer;
37   private static boolean isUsed=false;
38
39   /**
40    * Returns the single instance, creating one if it's the
41    * first time this method is called.
42    * @return BufferClass The single instance.
43    */

44   static public BufferClass getInstance() {
45     if (instance == null) {
46       instance = new BufferClass();
47     }
48     return instance;
49   }
50
51   /**
52    * A private constructor since this is a Singleton
53    */

54   private BufferClass() {
55     init();
56   }
57
58   /**
59    * Loads properties and initializes the instance.
60    */

61   private void init(){
62     buffer=new ArrayList();
63   }
64
65   /**
66    * This method write system out to parameter buffer
67    * @param msg is parameter value
68    */

69   public synchronized void writeToBuffer(String JavaDoc msg){
70     if(isUsed==true){
71       buffer.add(0,msg);
72       notify();
73     }
74   }
75
76   /**
77    * This method read value from parameter buffer
78    * @return parameter value
79    */

80   public synchronized String JavaDoc readFromBuffer(){
81     if(buffer.isEmpty()){
82       try{
83       wait();
84       }catch(Exception JavaDoc ex){
85         //
86
}
87     }
88     String JavaDoc ret=(String JavaDoc) buffer.remove(buffer.size()-1);
89     notify();
90     return ret;
91   }
92
93   /**
94    * This mehod read value from parmeter isUsed
95    * @return value of parameter
96    */

97   public boolean IsUsed(){
98     return isUsed;
99   }
100
101   /**
102    * This method clear parameter bufrrer
103    */

104   public void empty () {
105     buffer.clear();
106   }
107
108   /**
109    * This method set the value of patameter isUsed
110    */

111   public void setUsed(){
112     isUsed=true;
113   }
114 }
Popular Tags