KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > attachments > DimeTypeNameFormat


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
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 /**
18  * @author Rick Rineholt
19  */

20
21 package org.apache.axis.attachments;
22
23
24 import org.apache.axis.utils.Messages;
25
26
27 /**
28  * This class is a single part for DIME mulitpart message.
29  */

30
31
32 public final class DimeTypeNameFormat {
33     private byte format = 0;
34     private DimeTypeNameFormat() {}
35     private DimeTypeNameFormat(byte f) {
36         format = f;
37     }
38     //Current type values.
39
static final byte NOCHANGE_VALUE = 0x00; // indicates the type is unchanged from the previous record (used for chunking)
40
static final byte MIME_VALUE = 0x01; //indicates the type is specified as a MIME media-type
41
static final byte URI_VALUE = 0x02; // indicates the type is specified as an absolute URI
42
static final byte UNKNOWN_VALUE = 0x03; // indicates the type is not specified
43
static final byte NODATA_VALUE = 0x04; // indicates the record has no payload
44

45     static final DimeTypeNameFormat NOCHANGE =
46       new DimeTypeNameFormat(NOCHANGE_VALUE);
47
48     public static final DimeTypeNameFormat MIME=
49       new DimeTypeNameFormat(MIME_VALUE);
50
51     public static final DimeTypeNameFormat URI=
52       new DimeTypeNameFormat(URI_VALUE);
53
54     public static final DimeTypeNameFormat UNKNOWN=
55       new DimeTypeNameFormat(UNKNOWN_VALUE);
56
57     static final DimeTypeNameFormat NODATA=
58       new DimeTypeNameFormat(NODATA_VALUE);
59
60     private static String JavaDoc[] toEnglish = {"NOCHANGE", "MIME", "URI",
61       "UNKNOWN", "NODATA"};
62     private static DimeTypeNameFormat[] fromByte = {NOCHANGE, MIME,
63       URI, UNKNOWN, NODATA};
64
65     public final String JavaDoc toString() {
66         return toEnglish[format];
67     }
68
69     public final byte toByte() {
70         return format;
71     }
72
73     public int hashCode() {
74         return (int) format;
75     }
76
77     public final boolean equals(final Object JavaDoc x) {
78         if (x == null) {
79             return false;
80         }
81         if (!(x instanceof DimeTypeNameFormat)) {
82             return false;
83         }
84         return ((DimeTypeNameFormat) x).format == this.format;
85     }
86
87     public static DimeTypeNameFormat parseByte(byte x) {
88         if (x < 0 || x > fromByte.length) {
89             throw new IllegalArgumentException JavaDoc(Messages.getMessage(
90                         "attach.DimeStreamBadType", "" + x));
91         }
92         return fromByte[x];
93     }
94
95     public static DimeTypeNameFormat parseByte(Byte JavaDoc x) {
96         return parseByte(x.byteValue());
97     }
98 }
99
Popular Tags