001: /*
002: * Copyright 2001-2006 C:1 Financial Services GmbH
003: *
004: * This software is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License Version 2.1, as published by the Free Software Foundation.
007: *
008: * This software is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
011: * Lesser General Public License for more details.
012: *
013: * You should have received a copy of the GNU Lesser General Public
014: * License along with this library; if not, write to the Free Software
015: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
016: */
017:
018: package de.finix.contelligent.client.remote;
019:
020: import org.xml.sax.helpers.AttributesImpl;
021:
022: import de.finix.contelligent.client.i18n.Resources;
023: import de.zeigermann.xml.simpleImporter.SimpleImportHandler;
024: import de.zeigermann.xml.simpleImporter.SimplePath;
025:
026: /**
027: * Generates an {@link ActionResult} object from XML input stream.
028: */
029: public class ImportErrorHandler implements SimpleImportHandler {
030:
031: private boolean requestValid = false;
032:
033: private ActionResult actionResult;
034:
035: // needed for Error
036: private String errorPath;
037:
038: private String level;
039:
040: private String origin;
041:
042: private String timeStamp;
043:
044: private String componentPath;
045:
046: private String faultString;
047:
048: private String faultMessage;
049:
050: private String exceptionClass;
051:
052: private String exceptionMessage;
053:
054: private String exceptionTrace;
055:
056: private String details;
057:
058: public boolean isRequestValid() {
059: return requestValid;
060: }
061:
062: public ActionResult getActionResult() throws RemoteActionException {
063: if (requestValid) {
064: return actionResult;
065: } else {
066: // action failed - no valid xml-response
067: throw new RemoteActionException(Resources
068: .getLocalString("no_valid_response"));
069: }
070: }
071:
072: // callbacks start here
073:
074: public void startDocument() {
075: // initially a request is not valid, as no data has been seen, yet
076: requestValid = false;
077: actionResult = new ActionResult();
078: }
079:
080: public void endDocument() {
081: }
082:
083: public void cData(SimplePath path, String cdata) {
084: }
085:
086: public void startElement(SimplePath path, String name,
087: AttributesImpl attrs, String firstPCData) {
088:
089: if (path.matches("/response")) {
090: requestValid = true;
091:
092: String state = attrs.getValue("state");
093: actionResult.setState(state);
094:
095: errorPath = "";
096: level = "";
097: origin = "";
098: timeStamp = "";
099: componentPath = "";
100: faultString = "";
101: faultMessage = "";
102: exceptionClass = "";
103: exceptionMessage = "";
104: exceptionTrace = "";
105:
106: } else if (path.matches("/response/error")) {
107: errorPath = attrs.getValue("errorPath");
108: String level = attrs.getValue("level");
109: origin = attrs.getValue("origin");
110: timeStamp = attrs.getValue("timestamp");
111: componentPath = attrs.getValue("path");
112:
113: } else if (path.matches("/response/error/shortMessage")) {
114: faultString = firstPCData;
115:
116: } else if (path.matches("/response/error/longMessage")) {
117: faultMessage = firstPCData;
118: } else if (path.matches("/response/error/details")) {
119: details = firstPCData;
120:
121: } else if (path.matches("/response/error/exception")) {
122: exceptionClass = attrs.getValue("class");
123:
124: } else if (path
125: .matches("/response/error/exception/exception-message")) {
126: exceptionMessage = firstPCData;
127:
128: } else if (path
129: .matches("/response/error/exception/stack-trace")) {
130: exceptionTrace = firstPCData;
131: }
132: }
133:
134: public void endElement(SimplePath path, String name) {
135:
136: if (path.matches("/response/error")) {
137: actionResult.addError(errorPath, faultString, faultMessage,
138: details, exceptionClass, exceptionMessage,
139: exceptionTrace, level, origin, timeStamp,
140: componentPath);
141: }
142: }
143:
144: }
|