KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > webdocwf > util > loader > BufferOctopusClass


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;
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 BufferOctopusClass {
34
35   static private BufferOctopusClass 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 BufferOctopusClass getInstance() {
45     if (instance == null) {
46       instance = new BufferOctopusClass();
47     }
48     return instance;
49   }
50
51   /**
52    * A private constructor since this is a Singleton
53    */

54   private BufferOctopusClass() {
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="";
89     if(buffer.size()>0)
90       ret=(String JavaDoc) buffer.remove(buffer.size()-1);
91     notify();
92     if( ret == null )
93         ret = "";
94     return ret;
95   }
96
97   /**
98    * This mehod read value from parmeter isUsed
99    * @return value of parameter
100    */

101   public boolean IsUsed(){
102     return isUsed;
103   }
104
105   /**
106    * This method clear parameter bufrrer
107    */

108   public void empty () {
109     buffer.clear();
110   }
111
112   /**
113    * This method set the value of patameter isUsed
114    */

115   public void setUsed(){
116     isUsed=true;
117   }
118 }
Popular Tags