1 /* 2 * Copyright 2006 the original author or authors. 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.springframework.oxm.jibx; 18 19 import org.jibx.runtime.JiBXException; 20 import org.jibx.runtime.ValidationException; 21 import org.springframework.oxm.XmlMappingException; 22 23 /** 24 * Generic utility methods for working with JiBX. Mainly for internal use within the framework. 25 * 26 * @author Arjen Poutsma 27 * @since 1.0.0 28 */ 29 public abstract class JibxUtils { 30 31 /** 32 * Converts the given <code>JiBXException</code> to an appropriate exception from the 33 * <code>org.springframework.oxm</code> hierarchy. 34 * <p/> 35 * A boolean flag is used to indicate whether this exception occurs during marshalling or unmarshalling, since JiBX 36 * itself does not make this distinction in its exception hierarchy. 37 * 38 * @param ex <code>JiBXException</code> that occured 39 * @param marshalling indicates whether the exception occurs during marshalling (<code>true</code>), or 40 * unmarshalling (<code>false</code>) 41 * @return the corresponding <code>XmlMappingException</code> 42 */ 43 public static XmlMappingException convertJibxException(JiBXException ex, boolean marshalling) { 44 if (ex instanceof ValidationException) { 45 return new JibxValidationFailureException((ValidationException) ex); 46 } 47 else { 48 if (marshalling) { 49 return new JibxMarshallingFailureException(ex); 50 } 51 else { 52 return new JibxUnmarshallingFailureException(ex); 53 } 54 } 55 } 56 }