Subversion Repositories XServices

Rev

Rev 6 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6 Rev 10
1
/*
1
/*
2
 *   Copyright 2010 Brian Rosenberger (Brutex Network)
2
 *   Copyright 2010 Brian Rosenberger (Brutex Network)
3
 *
3
 *
4
 *   Licensed under the Apache License, Version 2.0 (the "License");
4
 *   Licensed under the Apache License, Version 2.0 (the "License");
5
 *   you may not use this file except in compliance with 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
6
 *   You may obtain a copy of the License at
7
 *
7
 *
8
 *       http://www.apache.org/licenses/LICENSE-2.0
8
 *       http://www.apache.org/licenses/LICENSE-2.0
9
 *
9
 *
10
 *   Unless required by applicable law or agreed to in writing, software
10
 *   Unless required by applicable law or agreed to in writing, software
11
 *   distributed under the License is distributed on an "AS IS" BASIS,
11
 *   distributed under the License is distributed on an "AS IS" BASIS,
12
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 *   See the License for the specific language governing permissions and
13
 *   See the License for the specific language governing permissions and
14
 *   limitations under the License.
14
 *   limitations under the License.
15
 */
15
 */
16
 
16
 
17
package net.brutex.xservices.types;
17
package net.brutex.xservices.types;
18
 
18
 
19
import java.io.File;
19
import java.io.File;
20
import javax.xml.bind.annotation.XmlElement;
20
import javax.xml.bind.annotation.XmlElement;
21
import javax.xml.bind.annotation.XmlEnum;
21
import javax.xml.bind.annotation.XmlEnum;
22
import javax.xml.bind.annotation.XmlRootElement;
22
import javax.xml.bind.annotation.XmlRootElement;
-
 
23
import net.brutex.xservices.util.BrutexNamespaces;
23
import org.apache.tools.ant.Project;
24
import org.apache.tools.ant.Project;
24
import org.apache.tools.ant.types.Resource;
25
import org.apache.tools.ant.types.Resource;
25
import org.apache.tools.ant.types.resources.BZip2Resource;
26
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.GZipResource;
27
import org.apache.tools.ant.types.resources.URLResource;
28
import org.apache.tools.ant.types.resources.URLResource;
28
 
29
 
29
/**
30
/**
-
 
31
 * File based resource declaration.
30
 *
32
 *
31
 * @author Brian Rosenberger, bru@brutex.de
33
 * @author Brian Rosenberger, bru@brutex.de
32
 */
34
 */
33
@XmlRootElement(namespace="http://ws.xservices.brutex.net")
35
@XmlRootElement(namespace=BrutexNamespaces.WS_XSERVICES, name="FileResourceType")
34
public class FileResource
36
public class FileResource
35
implements ResourceInterface {
37
implements ResourceInterface {
-
 
38
 
-
 
39
    /**
-
 
40
     * File resource type.
36
 
41
     */
37
    @XmlElement(defaultValue = "FILE", nillable = false, required = true)
42
    @XmlElement(defaultValue = "FILE", nillable = false, required = true)
-
 
43
    public Type type = Type.FILE;
-
 
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>
38
    public Type type = Type.FILE;
52
     */
39
    @XmlElement(nillable = false, required = true)
53
    @XmlElement(nillable = false, required = true)
40
    public String uri;
54
    public String uri;
-
 
55
 
-
 
56
    /**
-
 
57
     * File resource type.
-
 
58
     * 
-
 
59
     * Defines the wrapper around the source.
41
 
60
     */
42
    @XmlEnum(String.class)
61
    @XmlEnum(value=String.class)
-
 
62
    public enum Type {
-
 
63
 
-
 
64
        /**
43
    public enum Type {
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
44
 
81
         */
-
 
82
        BZIP2
-
 
83
    }
-
 
84
 
-
 
85
    /**
-
 
86
     * Creates a FileResource.
-
 
87
     *
45
        FILE, URL, GZIP, BZIP2
88
     * @param type      file resource type
46
    }
89
     * @param uri       file resource uri
47
 
90
     */
48
    public FileResource(Type type, String uri) {
91
    public FileResource(Type type, String uri) {
49
        this.type = type;
92
        this.type = type;
50
        this.uri = uri;
93
        this.uri = uri;
51
    }
94
    }
-
 
95
 
-
 
96
    /**
-
 
97
     * Create an empty FileResource
52
 
98
     */
53
    public FileResource() {
99
    public FileResource() {
54
    }
100
    }
-
 
101
 
-
 
102
    /**
-
 
103
     * Get Apache Ant Resource type.
-
 
104
     *
-
 
105
     * @param p     Ant project
-
 
106
     * @return      This FileResource as Ant Resource
55
 
107
     */
56
    public Resource getAntResource(Project p) {
108
    public Resource getAntResource(Project p) {
57
        Resource res = null;
109
        Resource res = null;
58
        switch (type) {
110
        switch (type) {
59
            case URL:
111
            case URL:
60
                URLResource ures = new URLResource(uri);
112
                URLResource ures = new URLResource(uri);
61
                res = ures;
113
                res = ures;
62
                break;
114
                break;
63
 
115
 
64
            case GZIP:
116
            case GZIP:
65
                GZipResource gres = new GZipResource(
117
                GZipResource gres = new GZipResource(
66
                        new org.apache.tools.ant.types.resources.FileResource(new File(uri)));
118
                        new org.apache.tools.ant.types.resources.FileResource(new File(uri)));
67
                res = gres;
119
                res = gres;
68
                break;
120
                break;
69
 
121
 
70
            case BZIP2:
122
            case BZIP2:
71
                BZip2Resource bres = new BZip2Resource(
123
                BZip2Resource bres = new BZip2Resource(
72
                        new org.apache.tools.ant.types.resources.FileResource(new File(uri)));
124
                        new org.apache.tools.ant.types.resources.FileResource(new File(uri)));
73
                res = bres;
125
                res = bres;
74
                break;
126
                break;
75
 
127
 
76
            default:
128
            default:
77
                //Default is Type FILE
129
                //Default is Type FILE
78
                res = new org.apache.tools.ant.types.resources.FileResource(new File(uri));
130
                res = new org.apache.tools.ant.types.resources.FileResource(new File(uri));
79
        }
131
        }
80
        res.setProject(p);
132
        res.setProject(p);
81
        return res;
133
        return res;
82
    }
134
    }
83
}
135
}