KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > scripting > php > dbginterface > models > DebugError


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.scripting.php.dbginterface.models;
21
22 import java.text.MessageFormat JavaDoc;
23 import org.netbeans.modules.scripting.php.dbginterface.DbgConstants;
24 import org.openide.ErrorManager;
25 import org.openide.filesystems.FileObject;
26 import org.openide.filesystems.FileStateInvalidException;
27 import org.openide.text.Line;
28 import org.openide.util.NbBundle;
29
30 /**
31  *
32  * @author marcow
33  */

34 public class DebugError {
35     private Line line;
36     private int type;
37     private String JavaDoc description;
38     
39     /** Creates a new instance of DebugError */
40     public DebugError(Line line, int type, String JavaDoc desc) {
41         this.line = line;
42         this.type = type;
43         this.description = desc;
44     }
45     
46     public boolean isError() {
47         return type == DbgConstants.ERR_CORE_ERROR || type == DbgConstants.ERR_ERROR ||
48                 type == DbgConstants.ERR_PARSE;
49     }
50     
51     public boolean isWarning() {
52         return type == DbgConstants.ERR_CORE_WARNING || type == DbgConstants.ERR_WARNING;
53     }
54     
55     public boolean isNotice() {
56         return type == DbgConstants.ERR_NOTICE;
57     }
58     
59     public Line getLine() {
60         return line;
61     }
62     
63     public FileObject getSourceFile() {
64         return (FileObject)line.getLookup().lookup(FileObject.class);
65     }
66     
67     public String JavaDoc getDisplayName() {
68         String JavaDoc ret = "";
69         
70         try {
71             ret += getSourceFile().getURL().toString() + ":" + (line.getLineNumber() + 1);
72         }
73         catch (FileStateInvalidException fsie) {
74             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, fsie);
75             
76             ret += getSourceFile().getPath() + ":" + (line.getLineNumber() + 1);
77         }
78
79         ret += " : " + getString();
80         
81         return ret;
82     }
83     
84     public String JavaDoc getString() {
85         String JavaDoc ret;
86         String JavaDoc id = null;
87         
88         switch (type) {
89         case DbgConstants.ERR_CORE_ERROR:
90             id = "ERR_coreError";
91             break;
92             
93         case DbgConstants.ERR_CORE_WARNING:
94             id = "ERR_coreWarning";
95             break;
96             
97         case DbgConstants.ERR_ERROR:
98             id = "ERR_error";
99             break;
100             
101         case DbgConstants.ERR_NOTICE:
102             id = "ERR_notice";
103             break;
104             
105         case DbgConstants.ERR_PARSE:
106             id = "ERR_parseError";
107             break;
108             
109         case DbgConstants.ERR_WARNING:
110             id = "ERR_warning";
111             break;
112         }
113
114         if (id != null) {
115             ret = MessageFormat.format(NbBundle.getMessage(DebugError.class, id), description);
116         }
117         else {
118             ret = description;
119         }
120         
121         return ret;
122     }
123 }
124
Popular Tags