gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / org.gvsig.tools.lib / src / main / java / org / gvsig / tools / service / AbstractService.java @ 1361
History | View | Annotate | Download (4 KB)
1 | 802 | cordinyana | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 18 | cordinyana | *
|
4 | 802 | cordinyana | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | *
|
||
6 | 18 | cordinyana | * 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 | 802 | cordinyana | *
|
11 | 18 | cordinyana | * 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 | 802 | cordinyana | *
|
16 | 18 | cordinyana | * 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 | 802 | cordinyana | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 | 18 | cordinyana | * MA 02110-1301, USA.
|
20 | 802 | cordinyana | *
|
21 | * For any additional information, do not hesitate to contact us
|
||
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | 18 | cordinyana | */
|
24 | /*
|
||
25 | * AUTHORS (In addition to CIT):
|
||
26 | * 2009 {} {{Task}}
|
||
27 | */
|
||
28 | package org.gvsig.tools.service; |
||
29 | |||
30 | import org.gvsig.tools.dynobject.DynObject; |
||
31 | 69 | jbadia | import org.gvsig.tools.service.spi.AbstractProviderServices; |
32 | 18 | cordinyana | import org.gvsig.tools.service.spi.Provider; |
33 | import org.gvsig.tools.service.spi.ProviderManager; |
||
34 | import org.gvsig.tools.service.spi.ProviderServices; |
||
35 | |||
36 | /**
|
||
37 | * {@link Service} base parent implementation, delegating in the child classes
|
||
38 | * the retrieval of the {@link ProviderManager}.
|
||
39 | *
|
||
40 | 69 | jbadia | * @author 2009- <a href="cordinyana@gvsig.org">C�sar Ordi�ana</a> - gvSIG team
|
41 | 18 | cordinyana | */
|
42 | public abstract class AbstractService implements Service { |
||
43 | |||
44 | private DynObject serviceParameters;
|
||
45 | private ProviderServices providerServices;
|
||
46 | private Provider provider; |
||
47 | |||
48 | /**
|
||
49 | * Empty constructor to be used only for persistence purposes.
|
||
50 | */
|
||
51 | public AbstractService() {
|
||
52 | // Nothing to do
|
||
53 | } |
||
54 | |||
55 | /**
|
||
56 | * Creates a new {@link AbstractService}.
|
||
57 | *
|
||
58 | * @param serviceParameters
|
||
59 | * the parameters of the current service
|
||
60 | * @throws ServiceException
|
||
61 | * if there is an error with the parameters
|
||
62 | */
|
||
63 | public AbstractService(DynObject serviceParameters) throws ServiceException { |
||
64 | init(serviceParameters, createProviderServices()); |
||
65 | } |
||
66 | |||
67 | /**
|
||
68 | * Returns the service parameters this services was created with
|
||
69 | *
|
||
70 | * @return the service parameters
|
||
71 | */
|
||
72 | 69 | jbadia | public DynObject getServiceParameters() {
|
73 | 18 | cordinyana | return serviceParameters;
|
74 | } |
||
75 | |||
76 | /**
|
||
77 | * Initialices the service.
|
||
78 | *
|
||
79 | * @param serviceParameters
|
||
80 | * the service parameters
|
||
81 | * @param providerServices
|
||
82 | * the provider services
|
||
83 | * @throws ServiceException
|
||
84 | * thrown while creating the provider
|
||
85 | */
|
||
86 | protected void init(DynObject serviceParameters, |
||
87 | ProviderServices providerServices) throws ServiceException {
|
||
88 | setServiceParameters(serviceParameters); |
||
89 | setProviderServices(providerServices); |
||
90 | setProvider(createProvider(serviceParameters)); |
||
91 | 69 | jbadia | ((AbstractProviderServices)providerServices).setService(this);
|
92 | 18 | cordinyana | } |
93 | |||
94 | /**
|
||
95 | * Returns the provider related to this service.
|
||
96 | *
|
||
97 | * @return the provider
|
||
98 | */
|
||
99 | protected Provider getProvider() { |
||
100 | return provider;
|
||
101 | } |
||
102 | |||
103 | /**
|
||
104 | * Returns the provider services to be used by the provider of this service.
|
||
105 | *
|
||
106 | * @return the provider services
|
||
107 | */
|
||
108 | protected ProviderServices getProviderServices() {
|
||
109 | return providerServices;
|
||
110 | } |
||
111 | |||
112 | /**
|
||
113 | * Returns the reference to the {@link ProviderManager}.
|
||
114 | *
|
||
115 | * @return the ProviderManager
|
||
116 | */
|
||
117 | protected abstract ProviderManager getProviderManager(); |
||
118 | |||
119 | private void setServiceParameters(DynObject serviceParameters) { |
||
120 | this.serviceParameters = serviceParameters;
|
||
121 | } |
||
122 | |||
123 | private void setProvider(Provider provider) { |
||
124 | this.provider = provider;
|
||
125 | } |
||
126 | |||
127 | private Provider createProvider(DynObject serviceParameters) |
||
128 | throws ServiceException {
|
||
129 | return getProviderManager().createProvider(serviceParameters,
|
||
130 | providerServices); |
||
131 | } |
||
132 | |||
133 | private ProviderServices createProviderServices() {
|
||
134 | return getProviderManager().createProviderServices(this); |
||
135 | } |
||
136 | |||
137 | private void setProviderServices(ProviderServices providerServices) { |
||
138 | this.providerServices = providerServices;
|
||
139 | } |
||
140 | } |