Subversion Repositories XServices

Rev

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