KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright (C) The Apache Software Foundation. All rights reserved.
3  *
4  * This software is published under the terms of the Apache Software License
5  * version 1.1, a copy of which has been included with this distribution in
6  * the docs/licenses/apache-1.1.txt file.
7  */

8 package org.jboss.axis.attachments;
9
10
11 import org.jboss.axis.utils.Messages;
12
13
14 /**
15  * This class is a single part for DIME mulitpart message.
16  */

17
18
19 public final class DimeTypeNameFormat
20 {
21    private byte format = 0;
22
23    private DimeTypeNameFormat()
24    {
25    }
26
27    private DimeTypeNameFormat(byte f)
28    {
29       format = f;
30    }
31
32    //Current type values.
33
static final byte NOCHANGE_VALUE = 0x00; // indicates the type is unchanged from the previous record (used for chunking)
34
static final byte MIME_VALUE = 0x01; //indicates the type is specified as a MIME media-type
35
static final byte URI_VALUE = 0x02; // indicates the type is specified as an absolute URI
36
static final byte UNKNOWN_VALUE = 0x03; // indicates the type is not specified
37
static final byte NODATA_VALUE = 0x04; // indicates the record has no payload
38

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