Subversion Repositories XServices

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
6 brianR 1
/*
2
 *   Copyright 2010 Brian Rosenberger (Brutex Network)
3
 *
4
 *   Licensed under the Apache License, Version 2.0 (the "License");
5
 *   you may not use this file except in compliance with the License.
6
 *   You may obtain a copy of the License at
7
 *
8
 *       http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 *   Unless required by applicable law or agreed to in writing, software
11
 *   distributed under the License is distributed on an "AS IS" BASIS,
12
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 *   See the License for the specific language governing permissions and
14
 *   limitations under the License.
15
 */
16
 
17
package net.brutex.xservices.types;
18
 
19
import java.io.File;
20
import javax.xml.bind.annotation.XmlElement;
21
import javax.xml.bind.annotation.XmlEnum;
22
import javax.xml.bind.annotation.XmlRootElement;
23
import org.apache.tools.ant.Project;
24
import org.apache.tools.ant.types.Resource;
25
import org.apache.tools.ant.types.resources.BZip2Resource;
26
import org.apache.tools.ant.types.resources.GZipResource;
27
import org.apache.tools.ant.types.resources.URLResource;
28
 
29
/**
30
 *
31
 * @author Brian Rosenberger, bru@brutex.de
32
 */
33
@XmlRootElement(namespace="http://ws.xservices.brutex.net")
34
public class FileResource
35
implements ResourceInterface {
36
 
37
    @XmlElement(defaultValue = "FILE", nillable = false, required = true)
38
    public Type type = Type.FILE;
39
    @XmlElement(nillable = false, required = true)
40
    public String uri;
41
 
42
    @XmlEnum(String.class)
43
    public enum Type {
44
 
45
        FILE, URL, GZIP, BZIP2
46
    }
47
 
48
    public FileResource(Type type, String uri) {
49
        this.type = type;
50
        this.uri = uri;
51
    }
52
 
53
    public FileResource() {
54
    }
55
 
56
    public Resource getAntResource(Project p) {
57
        Resource res = null;
58
        switch (type) {
59
            case URL:
60
                URLResource ures = new URLResource(uri);
61
                res = ures;
62
                break;
63
 
64
            case GZIP:
65
                GZipResource gres = new GZipResource(
66
                        new org.apache.tools.ant.types.resources.FileResource(new File(uri)));
67
                res = gres;
68
                break;
69
 
70
            case BZIP2:
71
                BZip2Resource bres = new BZip2Resource(
72
                        new org.apache.tools.ant.types.resources.FileResource(new File(uri)));
73
                res = bres;
74
                break;
75
 
76
            default:
77
                //Default is Type FILE
78
                res = new org.apache.tools.ant.types.resources.FileResource(new File(uri));
79
        }
80
        res.setProject(p);
81
        return res;
82
    }
83
}