KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > apollo > jnlp > JnlpServiceResolver


1 /*
2 ** Apollo - Test Skeleton Toolkit for Web Start/JNLP
3 ** Copyright (c) 2001, 2002, 2003 by Gerald Bauer
4 **
5 ** This program is free software.
6 **
7 ** You may redistribute it and/or modify it under the terms of the GNU
8 ** General Public License as published by the Free Software Foundation.
9 ** Version 2 of the license should be included with this distribution in
10 ** the file LICENSE, as well as License.html. If the license is not
11 ** included with this distribution, you may find a copy at the FSF web
12 ** site at 'www.gnu.org' or 'www.fsf.org', or you may write to the
13 ** Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139 USA.
14 **
15 ** THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND,
16 ** NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR
17 ** OF THIS SOFTWARE, ASSUMES _NO_ RESPONSIBILITY FOR ANY
18 ** CONSEQUENCE RESULTING FROM THE USE, MODIFICATION, OR
19 ** REDISTRIBUTION OF THIS SOFTWARE.
20 **
21 */

22
23 package apollo.jnlp;
24
25 import apollo.*;
26 import apollo.spi.*;
27
28 public class JnlpServiceResolver implements ServiceResolver
29 {
30
31    private BasicService _basic;
32    private ClipboardService _clipboard;
33    private ServiceResolver _fallback;
34    private FileOpenService _fileOpen;
35    private FileSaveService _fileSave;
36    private PersistenceService _persistence;
37    private PrintService _print;
38
39    public JnlpServiceResolver( ServiceResolver fallback )
40    {
41       _fallback = fallback;
42    }
43
44    public BasicService lookupBasicService()
45    {
46       if( _basic == null )
47       {
48          try
49          {
50             _basic = new JnlpBasicService(
51                   ( javax.jnlp.BasicService ) javax.jnlp.ServiceManager.lookup( Jnlp.Class.BASIC_SERVICE ) );
52          }
53          catch( javax.jnlp.UnavailableServiceException uex )
54          {
55             // todo: issue warning/error
56
_basic = _fallback.lookupBasicService();
57          }
58       }
59       return _basic;
60    }
61
62    public ClipboardService lookupClipboardService()
63    {
64       if( _clipboard == null )
65       {
66          try
67          {
68             _clipboard = new JnlpClipboardService(
69                   ( javax.jnlp.ClipboardService ) javax.jnlp.ServiceManager.lookup( Jnlp.Class.CLIPBOARD_SERVICE ) );
70          }
71          catch( javax.jnlp.UnavailableServiceException uex )
72          {
73             // todo: issue warning/error
74
_clipboard = _fallback.lookupClipboardService();
75          }
76       }
77       return _clipboard;
78    }
79
80    public FileOpenService lookupFileOpenService()
81    {
82       if( _fileOpen == null )
83       {
84          try
85          {
86             _fileOpen = new JnlpFileOpenService(
87                   ( javax.jnlp.FileOpenService ) javax.jnlp.ServiceManager.lookup( Jnlp.Class.FILE_OPEN_SERVICE ) );
88          }
89          catch( javax.jnlp.UnavailableServiceException uex )
90          {
91             // todo: issue warning/error
92
_fileOpen = _fallback.lookupFileOpenService();
93          }
94       }
95       return _fileOpen;
96    }
97
98    public FileSaveService lookupFileSaveService()
99    {
100       if( _fileSave == null )
101       {
102          try
103          {
104             _fileSave = new JnlpFileSaveService(
105                   ( javax.jnlp.FileSaveService ) javax.jnlp.ServiceManager.lookup( Jnlp.Class.FILE_SAVE_SERVICE ) );
106          }
107          catch( javax.jnlp.UnavailableServiceException uex )
108          {
109             // todo: issue warning/error
110
_fileSave = _fallback.lookupFileSaveService();
111          }
112       }
113       return _fileSave;
114    }
115
116    public PersistenceService lookupPersistenceService()
117    {
118       if( _persistence == null )
119       {
120          try
121          {
122             _persistence = new JnlpPersistenceService(
123                   ( javax.jnlp.PersistenceService ) javax.jnlp.ServiceManager.lookup( Jnlp.Class.PERSISTENCE_SERVICE ) );
124          }
125          catch( javax.jnlp.UnavailableServiceException uex )
126          {
127             // todo: issue warning/error
128
_persistence = _fallback.lookupPersistenceService();
129          }
130       }
131       return _persistence;
132    }
133
134    public PrintService lookupPrintService()
135    {
136       if( _print == null )
137       {
138          try
139          {
140             _print = new JnlpPrintService(
141                   ( javax.jnlp.PrintService ) javax.jnlp.ServiceManager.lookup( Jnlp.Class.PRINT_SERVICE ) );
142          }
143          catch( javax.jnlp.UnavailableServiceException uex )
144          {
145             // todo: issue warning/error
146
_print = _fallback.lookupPrintService();
147          }
148       }
149       return _print;
150    }
151 }
152
Popular Tags