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