KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > ErrorPageDescriptorImpl


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23  package com.sun.enterprise.deployment;
24
25 import com.sun.enterprise.deployment.web.ErrorPageDescriptor;
26
27     /** Objects exhiniting this interface represent an error page and the exception type or
28     ** error code that will cause the redirect from the web container.
29     * @author Danny Coward
30     */

31
32 public class ErrorPageDescriptorImpl implements ErrorPageDescriptor, java.io.Serializable JavaDoc{
33     private int errorCode;
34     private String JavaDoc exceptionType;
35     private String JavaDoc location;
36     
37     /** The default constructor.
38     */

39     public ErrorPageDescriptorImpl() {
40     
41     }
42     
43     /** Constructor for error code to error page mapping.*/
44     public ErrorPageDescriptorImpl(int errorCode, String JavaDoc location) {
45     this.errorCode = errorCode;
46     this.location = location;
47     }
48     
49      /** Constructor for Java exception type to error page mapping.*/
50     public ErrorPageDescriptorImpl(String JavaDoc exceptionType, String JavaDoc location) {
51     this.exceptionType = exceptionType;
52     this.location = location;
53     }
54     /** Return the error code. -1 if none. */
55     public int getErrorCode() {
56     return this.errorCode;
57     }
58     /** Sets the error code.*/
59     public void setErrorCode(int errorCode) {
60     this.errorCode = errorCode;
61     }
62     /** Return the error code as a string if there is no exception type, or the exception type if the error code is -1.*/
63     public String JavaDoc getErrorSignifierAsString() {
64     if ("".equals(this.getExceptionType())) {
65         return (new Integer JavaDoc(this.getErrorCode())).toString();
66     }
67     return this.getExceptionType();
68     }
69     /**Sets the error code if the argument is parsable as an int, or the exception type else.*/
70     public void setErrorSignifierAsString(String JavaDoc errorSignifier) {
71     try {
72         int errorCode = Integer.parseInt(errorSignifier);
73         this.setErrorCode(errorCode);
74         this.setExceptionType(null);
75         return;
76     } catch (NumberFormatException JavaDoc nfe) {
77     
78     }
79     this.setExceptionType(errorSignifier);
80     }
81     
82     /** Return the exception type or the empty string if none.*/
83     public String JavaDoc getExceptionType() {
84     if (this.exceptionType == null) {
85         this.exceptionType = "";
86     }
87     return this.exceptionType;
88     }
89     
90     /** Sets the exception type.*/
91     public void setExceptionType(String JavaDoc exceptionType) {
92     this.exceptionType = exceptionType;
93     }
94     /** Return the page to map to */
95     public String JavaDoc getLocation() {
96     if (this.location == null) {
97         this.location = "";
98     }
99     return this.location;
100     }
101     /* Set the page to map to */
102     public void setLocation(String JavaDoc location) {
103     this.location = location;
104     }
105     /* A formatted version of my state as a String. */
106     public void print(StringBuffer JavaDoc toStringBuffer) {
107     toStringBuffer.append("ErrorPage ").append(this.getErrorCode()).append(" ").append(
108             this.getExceptionType()).append(" ").append(this.getLocation());
109     }
110
111 }
112
113
Popular Tags