Subversion Repositories XServices

Rev

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

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