View Javadoc

1   /*
2    * Copyright (c) 2005, The K-Wf Grid Consortium
3    * Fraunhofer Institute for Computer Architecture and Software Technology
4    * See http://www.kwfgrid.eu and http://www.first.fraunhofer.de for more details.
5    */
6   package net.kwfgrid.gwes.uiproxy;
7   
8   import java.util.*;
9   
10  /**
11     Abstract implementation of buffer. 
12     This buffer supports the following properties:
13     <ul>
14     <li>Buffer.size</li>
15     </ul>
16   */
17  public abstract class AbstractBuffer implements Buffer {
18      public static final int DEFAULT_SIZE = 100;
19      public static final String SIZE_PROPERTY_KEY = "Buffer.size";
20  
21      protected int _size;
22      protected String _id;
23  
24      public AbstractBuffer() {
25  	_id = null;
26  	_size = DEFAULT_SIZE;
27      }
28      
29      protected void setID(String id) {
30  	_id = id;
31      }
32  
33      public String getID() {
34  	return _id;
35      }
36      
37      /**
38         Size should be set by setting property <code>Buffer.size</code>.
39       */
40      protected void setSize(int size) throws BufferException {
41  	_size = size;
42      }
43  
44      public int getSize() {
45  	return _size;
46      }
47  
48      /**
49         Generic implementation. Calls <code>setProperty(key, value)</code> for each mapping in the 
50         specified properties.
51       */
52      public void setProperties(Properties props) throws BufferException {
53  	Iterator keys = props.keySet().iterator(); while (keys.hasNext()) {
54  	    String key = keys.next().toString();
55  	    setProperty(key, props.getProperty(key));
56  	}
57      }
58      
59      /**
60         This implementation only interprets the <code>Buffer.size</code> property.
61       */
62      public void setProperty(String key, String value) throws BufferException {
63  	if (SIZE_PROPERTY_KEY.equals(key)) {
64  	    try {
65  		int size = Integer.parseInt(value);
66  		setSize(size);
67  	    } catch (NumberFormatException x) {
68  		// LOG
69  		// discard
70  	    }
71  	}
72      }
73      
74      public abstract void handle(Object message);
75      
76      public abstract Object[] read() throws BufferException;
77  }