01: // HeaderDescription.java
02: // $Id: HeaderDescription.java,v 1.6 1999/01/06 14:20:37 ylafon Exp $
03: // (c) COPYRIGHT MIT and INRIA, 1996.
04: // Please first read the full copyright statement in file COPYRIGHT.html
05:
06: package org.w3c.www.http;
07:
08: public class HeaderDescription {
09: Class cls = null; // Class of parser to use.
10: String name = null; // lower case name.
11: byte title[] = null; // title for header emitting.
12: int offset = -1; // Offset of header in its message holder.
13:
14: /**
15: * Get this header name, lower case (can be used as header id).
16: * @return A String giving the header identifier.
17: */
18:
19: public String getName() {
20: return name;
21: }
22:
23: /**
24: * Get this header title, ready for emission.
25: * @return The actual bytes to be emited for this header title.
26: */
27:
28: public byte[] getTitle() {
29: return title;
30: }
31:
32: /**
33: * Get this header parser, as an HeaderValue compatible instance.
34: * @return An instance of HeaderValue, suitable for holding and parsing
35: * the header value.
36: */
37:
38: public HeaderValue getHolder() {
39: try {
40: return (HeaderValue) cls.newInstance();
41: } catch (NoSuchMethodError er) {
42: throw new RuntimeException("Invalid class (method) for "
43: + name);
44: } catch (InstantiationError ex) {
45: throw new RuntimeException("Invalid class (method) for "
46: + name);
47: } catch (Exception ex) {
48: throw new RuntimeException("Invalid class for " + name);
49: }
50: }
51:
52: /**
53: * Is this header description the one of that header.
54: * @param h The header access token.
55: */
56:
57: public boolean isHeader(int h) {
58: return h == offset;
59: }
60:
61: HeaderDescription(String title, String clsname, int offset) {
62: try {
63: this .title = new byte[title.length()];
64: title.getBytes(0, this .title.length, this .title, 0);
65: this .name = title.toLowerCase();
66: this .offset = offset;
67: this .cls = Class.forName(clsname);
68: // This is a nasty kludge due to a bug in jdk1.2 on NT
69: // this.cls = Class.forName(clsname, true,
70: // this.getClass().getClassLoader());
71: // works and not
72: // this.cls = Class.forName(clsname);
73: // even if it is exactly the same thing :)
74: // and the creation of a new object is enough to make it run...
75: this .cls.newInstance();
76: } catch (Exception ex) {
77: ex.printStackTrace();
78: throw new RuntimeException("Invalid header description "
79: + name);
80: }
81:
82: }
83:
84: HeaderDescription(String title, String clsname) {
85: this (title, clsname, -1);
86: }
87:
88: }
|