KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > generation > ParseExceptionGenerator


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.cocoon.generation;
18
19 import net.sourceforge.chaperon.process.ParseException;
20
21 import org.apache.cocoon.ProcessingException;
22 import org.apache.cocoon.environment.ObjectModelHelper;
23
24 import org.apache.commons.lang.exception.ExceptionUtils;
25
26 import org.exolab.castor.xml.MarshalException;
27 import org.exolab.castor.xml.Marshaller;
28 import org.exolab.castor.xml.ValidationException;
29
30 import org.xml.sax.SAXException JavaDoc;
31
32 import java.io.IOException JavaDoc;
33
34 /**
35  * Exception generator.
36  *
37  * @version CVS $Id: ParseExceptionGenerator.java 30932 2004-07-29 17:35:38Z vgritsenko $
38  */

39 public class ParseExceptionGenerator extends AbstractGenerator
40 {
41   public void generate() throws IOException JavaDoc, SAXException JavaDoc, ProcessingException
42   {
43     Throwable JavaDoc throwable = ObjectModelHelper.getThrowable(objectModel);
44
45     while ((!(throwable instanceof ParseException)) &&
46            (ExceptionUtils.getCause(throwable)!=null))
47       throwable = ExceptionUtils.getCause(throwable);
48
49     if (!(throwable instanceof ParseException))
50     {
51       ((ParseException)throwable).toXML(super.contentHandler);
52       return;
53     }
54       
55     Marshaller marshaller = new Marshaller(super.contentHandler);
56
57     try
58     {
59       marshaller.marshal(throwable);
60     }
61     catch (MarshalException me)
62     {
63       throw new ProcessingException(me);
64     }
65     catch (ValidationException ve)
66     {
67       throw new ProcessingException(ve);
68     }
69   }
70 }
71
Popular Tags