/** * Parses the string <code>text</code> into an float. If text is null or does not contain a parsable value, the * message given in <code>message</code> is used to throw a SAXException. * * @param text the text to parse. * @param message the error message if parsing fails. * @param locator the SAX locator to print meaningfull error messages. * @return the float value. * @throws ParseException if the text is no valid float number. */ public static float parseFloat( final String text, final String message, final Locator locator ) throws ParseException { if ( text == null ) { throw new ParseException( message, locator ); } try { return Float.parseFloat( text ); } catch ( NumberFormatException nfe ) { throw new ParseException( "NumberFormatError: " + message, locator ); } }
/** * Creates a new ParseException with the given root exception. * * @param e the exception */ public ParseException( final Exception e ) { super( e ); fillLocation( null ); noOwnMessage = true; }
/** * Prints the stack trace to the specified stream. * * @param stream the output stream. */ public void printStackTrace( final PrintStream stream ) { super.printStackTrace( stream ); if ( getException() != null ) { stream.println( "ParentException: " ); getException().printStackTrace( stream ); } }
/** * Override toString to pick up any embedded exception. * * @return A string representation of this exception. */ public String toString() { return getClass().getName() + ": " + getMessage(); }
/** * Reads an attribute as float and returns <code>def</code> if that fails. * * @param value * the attribute value. * @param locator * the locator provides the current parse position for meaningful error messages. * @return the float value. * @throws ParseException * if an parse error occured. */ public static Float parseFloat( final String value, final Locator locator ) throws ParseException { if ( value == null ) { return null; } try { return new Float( value ); } catch ( Exception ex ) { throw new ParseException( "Failed to parse value", locator ); } }
/** * Creates a new ParseException with the given message and root exception. * * @param message the message * @param e the exception */ public ParseException( final String message, final Exception e ) { super( message, e ); fillLocation( null ); noOwnMessage = ( message == null ); }
/** * Prints the stack trace to the specified writer. * * @param writer the writer. */ public void printStackTrace( final PrintWriter writer ) { super.printStackTrace( writer ); if ( getException() != null ) { writer.println( "ParentException: " ); getException().printStackTrace( writer ); } }
/** * Reads an attribute as float and returns <code>def</code> if that fails. * * @param value * the attribute value. * @param locator * the locator provides the current parse position for meaningful error messages. * @return the float value. * @throws ParseException * if an parse error occured. */ public static Integer parseInteger( final String value, final Locator locator ) throws ParseException { if ( value == null ) { return null; } try { return new Integer( value ); } catch ( Exception ex ) { throw new ParseException( "Failed to parse value", locator ); } }
/** * Creates a new ParseException with the given root exception and the locator. * * @param e the exception * @param locator the locator of the parser */ public ParseException( final Exception e, final Locator locator ) { super( e ); fillLocation( locator ); noOwnMessage = true; }
final Exception parentEx = getException(); if ( parentEx instanceof ParseException ) { return parentEx.getMessage();
public StyleReadHandler getReadHandler( final String namespace, final String tagName, final Locator locator ) throws ParseException { try { final Class<? extends StyleReadHandler> attribute = styleReadHandlers.getAttribute( namespace, tagName ); if ( attribute != null ) { return attribute.newInstance(); } throw new ParseException( "Failed to locate style-read-handler for [" + namespace + "|" + tagName + "]", locator ); } catch ( ParseException e ) { throw e; } catch ( Exception e ) { throw new ParseException( "Failed to instantiate style-read-handler for [" + namespace + "|" + tagName + "]", locator ); } }
/** * Creates a new ParseException with the given message. * * @param message the message */ public ParseException( final String message ) { super( message ); fillLocation( null ); noOwnMessage = ( message == null ); }
/** * Parses the string <code>text</code> into an int. If text is null or does not contain a parsable value, the message * given in <code>message</code> is used to throw a SAXException. * * @param text the text to parse. * @param message the error message if parsing fails. * @param locator the SAX locator to print meaningfull error messages. * @return the int value. * @throws SAXException if there is a problem with the parsing. */ public static int parseInt( final String text, final String message, final Locator locator ) throws SAXException { if ( text == null ) { throw new SAXException( message ); } try { return Integer.parseInt( text ); } catch ( NumberFormatException nfe ) { throw new ParseException( "NumberFormatError: " + message, locator ); } }
/** * Creates a new ParseException with the given message and the locator. * * @param message the message * @param locator the locator of the parser */ public ParseException( final String message, final Locator locator ) { super( message ); fillLocation( locator ); noOwnMessage = ( message == null ); }
protected AbstractRootLevelBand createElement() throws ParseException { try { return (AbstractRootLevelBand) elementType.create(); } catch ( Exception e ) { throw new ParseException( e ); } }
/** * Creates a new ParseException with the given message, root exception and the locator. * * @param message the message * @param e the exception * @param locator the locator of the parser */ public ParseException( final String message, final Exception e, final Locator locator ) { super( message, e ); fillLocation( locator ); noOwnMessage = ( message == null ); }
public ElementReadHandler getReadHandler( final String namespace, final String tagName, final Locator locator ) throws ParseException { try { final Class<? extends ElementReadHandler> attribute = readHandlers.getAttribute( namespace, tagName ); if ( attribute != null ) { return attribute.newInstance(); } // this is valid .. // logger.debug("No handler for [" + namespace + "|" + tagName + "] at " + locator); return null; } catch ( Exception e ) { throw new ParseException( "Failed to instantiate element-read-handler for [" + namespace + "|" + tagName + "]", locator ); } }
public static Boolean parseBoolean( final String value, final Locator locator ) throws ParseException { if ( value == null ) { return null; } if ( "true".equals( value ) ) { return Boolean.TRUE; } else if ( "false".equals( value ) ) { return Boolean.FALSE; } else { if ( strictParsing ) { throw new ParseException( "Failed to parse value", locator ); } if ( locator == null ) { logger.warn( "Invalid value encountered for boolean attribute." ); } else { logger.warn( "Invalid value encountered for boolean attribute. [Line: " + locator.getLineNumber() + " Column: " + locator.getColumnNumber() + "]" ); } return Boolean.FALSE; } }
protected void doneParsing() throws SAXException { final ArrayList<IDatabaseConnection> connections = new ArrayList<IDatabaseConnection>(); for ( int i = 0; i < readHandlers.size(); i++ ) { final DatabaseMetaReadHandler readHandler = readHandlers.get( i ); connections.add( readHandler.getObject() ); } try { collection = new DatabaseConnectionCollection( connections.toArray( new IDatabaseConnection[connections.size()] ) ); } catch ( IOException e ) { throw new ParseException( e, getLocator() ); } }
private Class<?> parseValueType( final Attributes attrs ) throws ParseException { final String valueTypeText = attrs.getValue( getUri(), "value-type" ); // NON-NLS if ( valueTypeText == null ) { throw new ParseException( "Attribute 'value-type' is undefined", getLocator() ); } try { final ClassLoader classLoader = ObjectUtilities.getClassLoader( getClass() ); return Class.forName( valueTypeText, false, classLoader ); } catch ( final Exception e ) { throw new ParseException( "Attribute 'value-type' is not valid", e, getLocator() ); } }