001: /*
002: LoaderGenerator - tool for generated xml, sql and doml file needed for Octopus.
003:
004:
005: Copyright (C) 2003 Together
006:
007: This library is free software; you can redistribute it and/or
008: modify it under the terms of the GNU Lesser General Public
009: License as published by the Free Software Foundation; either
010: version 2.1 of the License, or (at your option) any later version.
011:
012: This library is distributed in the hope that it will be useful,
013: but WITHOUT ANY WARRANTY; without even the implied warranty of
014: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: Lesser General Public License for more details.
016:
017: You should have received a copy of the GNU Lesser General Public
018: License along with this library; if not, write to the Free Software
019: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: */
021:
022: package org.webdocwf.util.loader;
023:
024: import java.util.*;
025:
026: /**
027: *
028: * BufferClass class is used for writing system out in to internal buffer.
029: * This class is a Singleton.
030: * @author Radoslav Dutina
031: * @version 1.0
032: */
033: public class BufferOctopusClass {
034:
035: static private BufferOctopusClass instance;
036: private ArrayList buffer;
037: private static boolean isUsed = false;
038:
039: /**
040: * Returns the single instance, creating one if it's the
041: * first time this method is called.
042: * @return BufferClass The single instance.
043: */
044: static public BufferOctopusClass getInstance() {
045: if (instance == null) {
046: instance = new BufferOctopusClass();
047: }
048: return instance;
049: }
050:
051: /**
052: * A private constructor since this is a Singleton
053: */
054: private BufferOctopusClass() {
055: init();
056: }
057:
058: /**
059: * Loads properties and initializes the instance.
060: */
061: private void init() {
062: buffer = new ArrayList();
063: }
064:
065: /**
066: * This method write system out to parameter buffer
067: * @param msg is parameter value
068: */
069: public synchronized void writeToBuffer(String msg) {
070: if (isUsed == true) {
071: buffer.add(0, msg);
072: notify();
073: }
074: }
075:
076: /**
077: * This method read value from parameter buffer
078: * @return parameter value
079: */
080: public synchronized String readFromBuffer() {
081: if (buffer.isEmpty()) {
082: try {
083: wait();
084: } catch (Exception ex) {
085: //
086: }
087: }
088: String ret = "";
089: if (buffer.size() > 0)
090: ret = (String) buffer.remove(buffer.size() - 1);
091: notify();
092: if (ret == null)
093: ret = "";
094: return ret;
095: }
096:
097: /**
098: * This mehod read value from parmeter isUsed
099: * @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: }
|