Subversion Repositories XServices

Rev

Rev 6 | Go to most recent revision | Details | Compare with Previous | 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;
10 brianR 23
import net.brutex.xservices.util.BrutexNamespaces;
6 brianR 24
import org.apache.tools.ant.Project;
25
import org.apache.tools.ant.types.Resource;
26
import org.apache.tools.ant.types.resources.BZip2Resource;
27
import org.apache.tools.ant.types.resources.GZipResource;
28
import org.apache.tools.ant.types.resources.URLResource;
29
 
30
/**
10 brianR 31
 * File based resource declaration.
6 brianR 32
 *
33
 * @author Brian Rosenberger, bru@brutex.de
34
 */
10 brianR 35
@XmlRootElement(namespace=BrutexNamespaces.WS_XSERVICES, name="FileResourceType")
6 brianR 36
public class FileResource
37
implements ResourceInterface {
38
 
10 brianR 39
    /**
40
     * File resource type.
41
     */
6 brianR 42
    @XmlElement(defaultValue = "FILE", nillable = false, required = true)
43
    public Type type = Type.FILE;
10 brianR 44
 
45
    /**
46
     * URI to file.
47
     *
48
     * Examples:<br>
49
     * <code>c:/path/to/myfile.txt<br>
50
     * /usr/share/file<br>
51
     * http://server/path/file.zip</code>
52
     */
6 brianR 53
    @XmlElement(nillable = false, required = true)
54
    public String uri;
55
 
10 brianR 56
    /**
57
     * File resource type.
58
     *
59
     * Defines the wrapper around the source.
60
     */
61
    @XmlEnum(value=String.class)
6 brianR 62
    public enum Type {
63
 
10 brianR 64
        /**
65
         * Plain file from OS accessible file system.
66
         */
67
        FILE,
68
 
69
        /**
70
         * File from URL (http, https, ftp, ...)
71
         */
72
        URL,
73
 
74
        /**
75
         * File from file system with on-the-fly GZIP decompression
76
         */
77
        GZIP,
78
 
79
        /**
80
         * File from file system with on-the-fly BZIP2 decompression
81
         */
82
        BZIP2
6 brianR 83
    }
84
 
10 brianR 85
    /**
86
     * Creates a FileResource.
87
     *
88
     * @param type      file resource type
89
     * @param uri       file resource uri
90
     */
6 brianR 91
    public FileResource(Type type, String uri) {
92
        this.type = type;
93
        this.uri = uri;
94
    }
95
 
10 brianR 96
    /**
97
     * Create an empty FileResource
98
     */
6 brianR 99
    public FileResource() {
100
    }
101
 
10 brianR 102
    /**
103
     * Get Apache Ant Resource type.
104
     *
105
     * @param p     Ant project
106
     * @return      This FileResource as Ant Resource
107
     */
6 brianR 108
    public Resource getAntResource(Project p) {
109
        Resource res = null;
110
        switch (type) {
111
            case URL:
112
                URLResource ures = new URLResource(uri);
113
                res = ures;
114
                break;
115
 
116
            case GZIP:
117
                GZipResource gres = new GZipResource(
118
                        new org.apache.tools.ant.types.resources.FileResource(new File(uri)));
119
                res = gres;
120
                break;
121
 
122
            case BZIP2:
123
                BZip2Resource bres = new BZip2Resource(
124
                        new org.apache.tools.ant.types.resources.FileResource(new File(uri)));
125
                res = bres;
126
                break;
127
 
128
            default:
129
                //Default is Type FILE
130
                res = new org.apache.tools.ant.types.resources.FileResource(new File(uri));
131
        }
132
        res.setProject(p);
133
        return res;
134
    }
135
}