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.Properties;
9   
10  import org.doomdark.uuid.UUIDGenerator;
11  
12  /**
13     Default implementation of <code>BufferFactory</code>.   
14   */
15  public class DefaultBufferFactory implements BufferFactory {
16      private static BufferFactory _i;
17      
18      /**
19         Singleton pattern.
20       */
21      private DefaultBufferFactory() {
22  	//
23      }
24  
25      public synchronized static BufferFactory getInstance() {
26  	if (_i==null) _i = new DefaultBufferFactory();
27  	return _i;
28      }
29  
30      /**
31         Create a NotificationBuffer.
32         @param type The type of the buffer; this must be the fully qualified java classname of the buffer's class. The class must be subclass of <code>AbstractBuffer</code>.
33         @param props Properties that should be passed to the new buffer.
34         @return The new buffer.
35         @exception InstantiationException If the buffer could not be created.
36       */
37      public Buffer createBuffer(String type, Properties props) throws InstantiationException {
38  	try {
39  	    AbstractBuffer buffer = (AbstractBuffer)Class.forName(type).newInstance();
40  	    buffer.setProperties(props);
41  	    buffer.setID(UUIDGenerator.getInstance().generateRandomBasedUUID().toString());
42  	    return buffer;
43  	} catch (IllegalAccessException x) {
44  	    InstantiationException ix = new InstantiationException("Instatiation of buffer failed.");
45  	    ix.initCause(x);
46  	    throw ix;
47  	} catch (ClassNotFoundException x) {
48  	    InstantiationException ix = new InstantiationException("Instatiation of buffer failed.");
49  	    ix.initCause(x);
50  	    throw ix;
51  	} catch (ClassCastException x) {
52  	    InstantiationException ix = new InstantiationException("Instatiation of buffer failed.");
53  	    ix.initCause(x);
54  	    throw ix;
55  	} catch (BufferException x) {	    
56  	    InstantiationException ix = new InstantiationException("Instatiation of buffer failed. Could not set properties of new instance.");
57  	    ix.initCause(x);
58  	    throw ix;
59  	}
60      }
61  }