root / branches / v2_0_0_prep / extensions / org.gvsig.mkmvnproject / templates / SPI+UIAPI / org.gvsig.fortunecookies / org.gvsig.fortunecookies.lib / org.gvsig.fortunecookies.lib.impl / src / main / java / org / gvsig / fortunecookies / impl / DefaultFortuneCookieService.java @ 32378
History | View | Annotate | Download (2.79 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
|
23 |
package org.gvsig.fortunecookies.impl; |
24 |
|
25 |
import java.util.Date; |
26 |
|
27 |
import org.gvsig.fortunecookies.FortuneCookieService; |
28 |
import org.gvsig.fortunecookies.exception.FortuneCookieMessageException; |
29 |
import org.gvsig.fortunecookies.lib.spi.FortuneCookieProvider; |
30 |
import org.gvsig.tools.dynobject.DynObject; |
31 |
import org.gvsig.tools.service.AbstractService; |
32 |
import org.gvsig.tools.service.Manager; |
33 |
import org.gvsig.tools.service.ServiceException; |
34 |
import org.gvsig.tools.service.spi.AbstractProviderServices; |
35 |
import org.gvsig.tools.service.spi.ProviderManager; |
36 |
|
37 |
public class DefaultFortuneCookieService extends AbstractService implements FortuneCookieService{ |
38 |
|
39 |
private String message; |
40 |
private DefaultFortuneCookieManager manager;
|
41 |
private Date date = null; |
42 |
|
43 |
public DefaultFortuneCookieService(DefaultFortuneCookieManager manager, DynObject parameters, AbstractProviderServices providerServices) throws ServiceException { |
44 |
this.manager = manager;
|
45 |
this.message = null; |
46 |
this.init(parameters, providerServices);
|
47 |
} |
48 |
|
49 |
|
50 |
public String getMessage() throws FortuneCookieMessageException { |
51 |
if(message==null){ |
52 |
FortuneCookieProvider provider = (FortuneCookieProvider)this.getProvider();
|
53 |
try {
|
54 |
this.message = provider.getMessage();
|
55 |
} catch (Exception e) { |
56 |
throw new FortuneCookieMessageException(e); |
57 |
} |
58 |
this.date = new Date(); |
59 |
} |
60 |
return this.message; |
61 |
} |
62 |
|
63 |
|
64 |
/*
|
65 |
* (non-Javadoc)
|
66 |
* @see org.gvsig.tools.service.Service#getProviderManager()
|
67 |
*
|
68 |
* This method must be implemented in all Services
|
69 |
*/
|
70 |
protected ProviderManager getProviderManager() {
|
71 |
return this.manager.getProviderManager(); |
72 |
} |
73 |
|
74 |
/*
|
75 |
* (non-Javadoc)
|
76 |
* @see org.gvsig.tools.service.Service#getManager()
|
77 |
*
|
78 |
* This method must be implemented in all Services
|
79 |
*/
|
80 |
public Manager getManager() {
|
81 |
return this.manager; |
82 |
} |
83 |
|
84 |
public Date getDate() { |
85 |
return this.date; |
86 |
} |
87 |
|
88 |
public String getProviderInfo() { |
89 |
return this.getProvider().toString(); |
90 |
} |
91 |
|
92 |
} |