KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployapi > DeploymentStatusImplWithError


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
24 /*
25   * DeploymentStatusImplWithError.java
26   *
27   * Created on August 13, 2004, 8:54 AM
28   */

29
30 package com.sun.enterprise.deployapi;
31
32 import java.io.ByteArrayOutputStream JavaDoc;
33 import java.io.PrintWriter JavaDoc;
34
35 import javax.enterprise.deploy.shared.StateType JavaDoc;
36 import javax.enterprise.deploy.shared.CommandType JavaDoc;
37
38 /**
39   *Simple implementation of DeploymentStatus intended to describe an exception that
40   *occurred during a DeploymentManager method invocation.
41   * @author tjquinn
42   */

43 public class DeploymentStatusImplWithError extends DeploymentStatusImpl {
44     
45     /** Records the error, if any, associated with this status object */
46     private Throwable JavaDoc cause = null;
47     
48     private CommandType JavaDoc commandType = null;
49     
50     /** Creates a new instance of DeploymentStatusImplWithError */
51     public DeploymentStatusImplWithError() {
52     }
53     
54     /** Creates a new instance of DeploymentStatusImplWithError */
55     public DeploymentStatusImplWithError(CommandType JavaDoc commandType, Throwable JavaDoc cause) {
56         super();
57         initCause(cause);
58         setState(StateType.FAILED);
59         setCommand(commandType);
60     }
61     
62     /**
63      *Assigns the cause for this status.
64      *@param Throwable that describes the error to be reported
65      */

66     public void initCause(Throwable JavaDoc cause) {
67         this.cause = cause;
68         setMessage(cause.getMessage());
69     }
70     
71     /**
72      *Returns the cause for this status.
73      *@return Throwable that describes the error associated with this status
74      */

75     public Throwable JavaDoc getCause() {
76         return cause;
77     }
78     
79     /**
80      *Displays the status as a string, including stack trace information if error is present.
81      *@return String describing the status, including stack trace info from the error (if present).
82      */

83     public String JavaDoc toString() {
84         StringBuffer JavaDoc result = new StringBuffer JavaDoc(super.toString());
85         if (cause != null) {
86             String JavaDoc lineSep = System.getProperty("line.separator");
87             result.append(lineSep).append("Cause: ");
88             ByteArrayOutputStream JavaDoc baos = new ByteArrayOutputStream JavaDoc();
89             PrintWriter JavaDoc pw = new PrintWriter JavaDoc(baos);
90             cause.printStackTrace(pw);
91             pw.close();
92             result.append(baos.toString());
93         }
94         return result.toString();
95     }
96 }
97
Popular Tags