Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.installer / org.gvsig.installer.lib / org.gvsig.installer.lib.impl / src / main / java / org / gvsig / installer / lib / impl / DefaultPackageInfo.java @ 34974

History | View | Annotate | Download (6.98 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
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2010 {Prodevelop}   {Task}
26
 */
27

    
28
package org.gvsig.installer.lib.impl;
29

    
30
import java.io.File;
31
import java.io.IOException;
32
import java.net.URL;
33
import java.text.MessageFormat;
34
import java.util.ArrayList;
35
import java.util.List;
36

    
37
import org.gvsig.installer.lib.api.PackageInfo;
38
import org.gvsig.installer.lib.api.InstallerManager.ARCH;
39
import org.gvsig.installer.lib.api.InstallerManager.JVM;
40
import org.gvsig.installer.lib.api.InstallerManager.OS;
41
import org.gvsig.installer.lib.api.InstallerManager.STATE;
42
import org.gvsig.installer.lib.api.execution.InstallPackageServiceException;
43
import org.gvsig.installer.lib.impl.info.InstallerInfoTags;
44
import org.gvsig.installer.lib.impl.utils.Download;
45
import org.gvsig.tools.task.SimpleTaskStatus;
46

    
47
/**
48
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodr&aacute;</a>
49
 */
50
public class DefaultPackageInfo implements PackageInfo {
51

    
52
    private String code = null;
53
    private String name = null;
54
    private String description = null;
55
    private String version = "0.0.1";
56
    private int build = 0;
57
    private boolean official;
58
    private List<File> auxFiles = null;
59
    private String antScript = null;
60
    private String type = null;
61

    
62
    private String state = STATE.DEVEL;
63
    private String operatingSystem = OS.ALL;
64
    private String architecture = ARCH.ALL;
65
    private String javaVM = JVM.J1_5;
66

    
67
    private String gvSIGVersion;
68

    
69
    private URL defaultDownloadURL = null;
70

    
71
    private String modelVersion = "1.0.0";
72

    
73
    public DefaultPackageInfo() {
74
        super();
75
        auxFiles = new ArrayList<File>();
76
    }
77

    
78
    public String getCode() {
79
        return code;
80
    }
81

    
82
    public String getName() {
83
        return name;
84
    }
85

    
86
    public String getDescription() {
87
        return description;
88
    }
89

    
90
    public String getVersion() {
91
        return version;
92
    }
93

    
94
    public int getBuild() {
95
        return build;
96
    }
97

    
98
    public String getState() {
99
        return state;
100
    }
101

    
102
    public boolean isOfficial() {
103
        return official;
104
    }
105

    
106
    public void setCode(String code) {
107
        this.code = code;
108
    }
109

    
110
    public void setName(String name) {
111
        this.name = name;
112
    }
113

    
114
    public void setDescription(String description) {
115
        this.description = description;
116
    }
117

    
118
    public void setVersion(String version) {
119
        this.version = version;
120
    }
121

    
122
    public void setBuild(int build) {
123
        this.build = build;
124
    }
125

    
126
    public void setState(String state) {
127
        this.state = state;
128
    }
129

    
130
    public void setOfficial(boolean official) {
131
        this.official = official;
132
    }
133

    
134
    public String getOperatingSystem() {
135
        return operatingSystem;
136
    }
137

    
138
    public void setOperatingSystem(String operatingSystem) {
139
        this.operatingSystem = operatingSystem;
140
    }
141

    
142
    public String getArchitecture() {
143
        return architecture;
144
    }
145

    
146
    public void setArchitecture(String architecture) {
147
        this.architecture = architecture;
148
    }
149

    
150
    public String getJavaVM() {
151
        return javaVM;
152
    }
153

    
154
    public void setJavaVM(String javaVM) {
155
        this.javaVM = javaVM;
156
    }
157

    
158
    public List<File> getAuxFiles() {
159
        return this.auxFiles;
160
    }
161

    
162
    public String getAntScript() {
163
        return antScript;
164
    }
165

    
166
    public void setAntScript(String antScript) {
167
        this.antScript = antScript;
168
    }
169

    
170
    public String getType() {
171
        return type;
172
    }
173

    
174
    public void setType(String type) {
175
        this.type = type;
176
    }
177

    
178
    public String getGvSIGVersion() {
179
        return gvSIGVersion;
180
    }
181

    
182
    public void setGvSIGVersion(String gvSIGVersion) {
183
        this.gvSIGVersion = gvSIGVersion;
184
    }
185

    
186
    public URL getDownloadURL() {
187
        return defaultDownloadURL;
188
    }
189

    
190
    public void setDownloadURL(URL defaultDownloadURL) {
191
        this.defaultDownloadURL = defaultDownloadURL;
192
    }
193

    
194
    public String getModelVersion() {
195
        return modelVersion;
196
    }
197

    
198
    public void setModelVersion(String modelVersion) {
199
        this.modelVersion = modelVersion;
200
    }
201

    
202
    @Override
203
    public String toString() {
204
        StringBuffer buffer = new StringBuffer(super.toString()).append(" (");
205

    
206
        append(buffer, InstallerInfoTags.CODE, getCode());
207
        append(buffer, InstallerInfoTags.NAME, getName());
208
        append(buffer, InstallerInfoTags.DESCRIPTION, getDescription());
209
        append(buffer, InstallerInfoTags.GVSIG_VERSION, getGvSIGVersion());
210
        append(buffer, InstallerInfoTags.VERSION, getVersion());
211
        append(buffer, InstallerInfoTags.BUILD, getBuild());
212
        append(buffer, InstallerInfoTags.OS, getOperatingSystem());
213
        append(buffer, InstallerInfoTags.ARCHITECTURE, getArchitecture());
214
        append(buffer, InstallerInfoTags.JVM, getJavaVM());
215
        append(buffer, InstallerInfoTags.DOWNLOAD_URL, getDownloadURL());
216
        append(buffer, InstallerInfoTags.STATE, getState());
217
        append(buffer, InstallerInfoTags.OFFICIAL, isOfficial());
218
        append(buffer, InstallerInfoTags.TYPE, getType());
219
        append(buffer, InstallerInfoTags.MODEL_VERSION, getModelVersion());
220

    
221
        return buffer.append(')').toString();
222
    }
223

    
224
    private DefaultPackageInfo append(StringBuffer buffer, String key,
225
        Object value) {
226
        buffer.append("\n\t").append(key).append(": ").append(
227
            value == null ? "" : value);
228
        return this;
229
    }
230

    
231
    @Override
232
    public Object clone() throws CloneNotSupportedException {
233
        DefaultPackageInfo clone = (DefaultPackageInfo) super.clone();
234
        clone.auxFiles = new ArrayList<File>(auxFiles);
235
        return clone;
236
    }
237

    
238
    public File downloadFile() throws InstallPackageServiceException {
239
        return this.downloadFile(null);
240
    }
241

    
242
    public File downloadFile(SimpleTaskStatus taskStatus)
243
        throws InstallPackageServiceException {
244
        Download download = new Download(taskStatus);
245
        try {
246
            return download.downloadFile(this.getDownloadURL(), null);
247
        } catch (IOException e) {
248
            throw new InstallPackageServiceException(MessageFormat.format(
249
                "__Cant_download_{0}_.from the URL:_\n_{1}", this.getName(),
250
                this.getDownloadURL(), e));
251
        }
252
    }
253

    
254
}