Statistics
| Revision:

svn-gvsig-desktop / tags / v2_0_0_Build_2032 / libraries / org.gvsig.newlayer / org.gvsig.newlayer.prov / org.gvsig.newlayer.prov.generic / src / main / java / org / gvsig / newlayer / prov / generic / NewLayerGenericProvider.java @ 36177

History | View | Annotate | Download (6.2 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
package org.gvsig.newlayer.prov.generic;
23

    
24
import java.util.ArrayList;
25
import java.util.List;
26

    
27
import org.gvsig.fmap.dal.DALLocator;
28
import org.gvsig.fmap.dal.DataManager;
29
import org.gvsig.fmap.dal.DataServerExplorerParameters;
30
import org.gvsig.fmap.dal.exception.InitializeException;
31
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
32
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
33
import org.gvsig.fmap.dal.feature.EditableFeatureType;
34
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters;
35
import org.gvsig.newlayer.NewLayerProviderPanel;
36
import org.gvsig.newlayer.NewLayerService;
37
import org.gvsig.newlayer.prov.generic.panels.ExplorerParamsPanel;
38
import org.gvsig.newlayer.prov.generic.panels.SelectExplorerPanel;
39
import org.gvsig.newlayer.prov.generic.panels.SelectStoreTypePanel;
40
import org.gvsig.newlayer.prov.generic.panels.StoreParamsPanel;
41
import org.gvsig.newlayer.spi.AbstractNewLayerProvider;
42
import org.gvsig.tools.exception.BaseRuntimeException;
43
import org.slf4j.Logger;
44
import org.slf4j.LoggerFactory;
45

    
46
/**
47
 * NewLayer provider which create a NewLayer.
48
 * 
49
 * @author gvSIG Team
50
 * @version $Id$
51
 */
52
public class NewLayerGenericProvider extends AbstractNewLayerProvider {
53

    
54
        List<NewLayerProviderPanel> panels = new ArrayList<NewLayerProviderPanel>();
55
        private String explorerName = null; 
56
        private DataServerExplorerParameters explorerParameters = null;
57
        private NewFeatureStoreParameters storeParameters = null;
58
        
59
    protected NewLayerGenericProvider(NewLayerService service) {
60
                super(service);
61
                panels.add(new SelectExplorerPanel(this));
62
                panels.add(new ExplorerParamsPanel(this));
63
                panels.add(new SelectStoreTypePanel(this));
64
                panels.add(new StoreParamsPanel(this));
65
        }
66

    
67
        private static final Logger LOG =
68
        LoggerFactory.getLogger(NewLayerGenericProvider.class);
69

    
70
        public EditableFeatureType getFeatureType() {
71
                // TODO Auto-generated method stub
72
                return null;
73
        }
74

    
75
        public NewFeatureStoreParameters getNewStoreParameters() {
76
                if (storeParameters != null){
77
                        if (storeParameters.getDataStoreName().equals(this.getStoreName())){
78
                                return storeParameters;
79
                        }
80
                }
81
                DataManager dataManager = DALLocator.getDataManager();
82
                try {
83
                        storeParameters = (NewFeatureStoreParameters) dataManager.createNewStoreParameters(this.getExplorerName(), this.getStoreName());
84
                        return storeParameters;
85
                } catch (InitializeException e) {
86
                        LOG.error("Can't initialize store parameters.");
87
                        throw new CantInitializeStoreParametersException(e);
88
                } catch (ProviderNotRegisteredException e) {
89
                        LOG.error("Can't create store parameters, provider not registered.");
90
                        throw new CantCreateStoreParametersException(e);
91
                }
92
        }
93

    
94
        class CantCreateStoreParametersException extends BaseRuntimeException {
95
                /**
96
                 * 
97
                 */
98
                private static final long serialVersionUID = -3487961532247258393L;
99
                private final static String MESSAGE_FORMAT = "Can't create store parameters, provider not registered.";
100
                private final static String MESSAGE_KEY = "_Cant_create_store_parameters_provider_not_registered";
101

    
102
                public CantCreateStoreParametersException(Throwable cause) {
103
                        super(MESSAGE_FORMAT, cause, MESSAGE_KEY, serialVersionUID);
104
                }
105
        }
106
        
107
        class CantInitializeStoreParametersException extends BaseRuntimeException {
108
                /**
109
                 * 
110
                 */
111
                private static final long serialVersionUID = -5263149018209261288L;
112
                private final static String MESSAGE_FORMAT = "Can't initialize store parameters.";
113
                private final static String MESSAGE_KEY = "_Cant_initialize_store_parameters";
114

    
115
                public CantInitializeStoreParametersException(Throwable cause) {
116
                        super(MESSAGE_FORMAT, cause, MESSAGE_KEY, serialVersionUID);
117
                }
118
        }
119

    
120
        
121
        public List<NewLayerProviderPanel> getPanels() {
122
                return panels;
123
        }
124
        
125
        public List<String> getExplorerNames(){
126
                DataManager dataManager = DALLocator.getDataManager();
127
        return dataManager.getExplorerProviders();
128
        }
129

    
130
        public List<String> getStoreNames(){
131
                DataManager dataManager = DALLocator.getDataManager();
132
        return dataManager.getStoreProviders();
133
        }
134

    
135
        public void setStoreName(String storeName) {
136
                this.storeName = storeName;
137
        }
138
        
139
        public String getExplorerName(){
140
                return this.explorerName;
141
        }
142
        
143
        public void setExplorerName(String explorerName) {
144
                this.explorerName = explorerName;
145
        }
146
        
147
        public DataServerExplorerParameters getExplorerParameters() throws InitializeException, ProviderNotRegisteredException{
148
                if (this.explorerParameters==null || !this.explorerParameters.getExplorerName().equalsIgnoreCase(this.getExplorerName())) {
149
                        if (this.explorerName == null) {
150
                                LOG.error("Can't create explorer parameters, unknow explorer name.");
151
                                throw new RuntimeException("Can't create explorer parameters, unknow explorer name.");
152
                        }
153
                        DataManager manager = DALLocator.getDataManager();
154
                        this.explorerParameters = manager.createServerExplorerParameters(this.getExplorerName()); 
155
                        
156
                }
157
                return this.explorerParameters;
158
        }
159

    
160
        public void createExplorer() {
161
                DataManager manager = DALLocator.getDataManager();
162
                try {
163
                        explorer = manager.openServerExplorer(getExplorerName(), getExplorerParameters());
164
                } catch (ValidateDataParametersException e) {
165
                        // TODO Auto-generated catch block
166
                        e.printStackTrace();
167
                } catch (InitializeException e) {
168
                        // TODO Auto-generated catch block
169
                        e.printStackTrace();
170
                } catch (ProviderNotRegisteredException e) {
171
                        // TODO Auto-generated catch block
172
                        e.printStackTrace();
173
                }
174
        }
175
 }