List of usage examples for org.xml.sax SAXException SAXException
public SAXException(Exception e)
From source file:org.eclipse.rdf4j.rio.rdfxml.RDFXMLParser.java
/** * Implementation of SAX ErrorHandler.fatalError *//*from w w w .j a va 2s . c o m*/ @Override public void fatalError(SAXParseException exception) throws SAXException { try { this.reportFatalError(exception); } catch (RDFParseException rdfpe) { throw new SAXException(rdfpe); } }
From source file:org.eclipse.rdf4j.rio.trix.TriXParser.java
/** * Implementation of SAX ErrorHandler.error *///from w w w .jav a 2 s.c om @Override public void error(SAXParseException exception) throws SAXException { try { this.reportError(exception.getMessage(), XMLParserSettings.FAIL_ON_SAX_NON_FATAL_ERRORS); } catch (RDFParseException rdfpe) { throw new SAXException(rdfpe); } }
From source file:org.eclipse.rdf4j.rio.trix.TriXParser.java
/** * Implementation of SAX ErrorHandler.fatalError *//*w w w .j a v a 2s . c o m*/ @Override public void fatalError(SAXParseException exception) throws SAXException { try { this.reportFatalError(exception.getMessage()); } catch (RDFParseException rdfpe) { throw new SAXException(rdfpe); } }
From source file:org.eclipse.uomo.xml.impl.XMLReader.java
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException { XMLObjectParser handler;//from www .j a v a2 s . c om String namespace; String name; if (uri == null || uri.equals("")) { namespace = ""; name = qName; } else { namespace = uri; name = localName; } if (!stack.hasCurrent()) { if (root != null) { stack.push(root); root.setPath(name); root.start(namespace, name, "", atts); root = null; current().use(); } else throw new SAXException("no handler available"); } else { handler = current().startElement(namespace, name, "", atts); if (handler == null) current().use(); else { handler.use(); handler.setPath(current().getPath() + "\\" + name); handler.setNamespace(namespace); handler.setName(name); stack.push(handler); current().start(namespace, name, "", atts); } } }
From source file:org.eclipse.uomo.xml.impl.XMLReader.java
public void parse(InputStream stream) throws SAXException { org.xml.sax.XMLReader xml;//from w ww.j av a 2s .co m try { xml = SAXParserFactory.newInstance().newSAXParser().getXMLReader(); xml.setFeature("http://xml.org/sax/features/namespaces", true); xml.setFeature("http://xml.org/sax/features/namespace-prefixes", false); xml.setContentHandler(this); xml.parse(new InputSource(stream)); } catch (Exception e) { throw new SAXException(e); } }
From source file:org.efaps.update.AbstractUpdate.java
/** * Read event for given tags path with attributes and text. * * @param _tags tags path as list/*from ww w . j av a 2 s . co m*/ * @param _attributes map of attributes for current tag * @param _text content text of this tags path TODO: error could not be * thrown because db properties is not read correctly * @throws SAXException on error * @throws EFapsException on error */ @Override public void readXML(final List<String> _tags, final Map<String, String> _attributes, final String _text) throws SAXException, EFapsException { if (_tags.size() == 1) { final String value = _tags.get(0); if ("uuid".equals(value)) { this.uuid = _text; } else if ("file-application".equals(value)) { this.fileApplication = _text; } else if ("definition".equals(value)) { this.definitions.add(newDefinition()); } } else if ("definition".equals(_tags.get(0))) { final AbstractDefinition curDef = this.definitions.get(this.definitions.size() - 1); curDef.readXML(_tags.subList(1, _tags.size()), _attributes, _text); } else { throw new SAXException("Unknown XML Tag: " + _tags + " for: " + this.installFile); } }
From source file:org.enhydra.shark.asap.util.BeanDeserializerShark.java
/** * startElement/*from ww w .java2 s. com*/ * * The ONLY reason that this method is overridden is so that * the object value can be set or a reasonable exception is thrown * indicating that the object cannot be created. This is done * at this point so that it occurs BEFORE href/id processing. * @param namespace is the namespace of the element * @param localName is the name of the element * @param prefix is the prefix of the element * @param attributes are the attributes on the element...used to get the * type * @param context is the DeserializationContext */ public void startElement(String namespace, String localName, String prefix, Attributes attributes, DeserializationContext context) throws SAXException { // Create the bean object if it was not already // created in the constructor. if (value == null) { try { value = javaType.newInstance(); } catch (Exception e) { // Failed to create an object. throw new SAXException(Messages.getMessage("cantCreateBean00", javaType.getName(), e.toString())); } } // Invoke super.startElement to do the href/id processing. super.startElement(namespace, localName, prefix, attributes, context); }
From source file:org.enhydra.shark.asap.util.BeanDeserializerShark.java
/** * Deserializer interface called on each child element encountered in * the XML stream./* ww w. j av a 2 s . c o m*/ * @param namespace is the namespace of the child element * @param localName is the local name of the child element * @param prefix is the prefix used on the name of the child element * @param attributes are the attributes of the child element * @param context is the deserialization context. * @return is a Deserializer to use to deserialize a child (must be * a derived class of SOAPHandler) or null if no deserialization should * be performed. */ public SOAPHandler onStartChild(String namespace, String localName, String prefix, Attributes attributes, DeserializationContext context) throws SAXException { //System.err.println("onStartChild namespace:"+namespace); //System.err.println("onStartChild localName:"+localName); //System.err.println("onStartChild prefix :"+prefix); if (xmlType.toString().endsWith("GetPropertiesRs") || xmlType.toString().endsWith("SetPropertiesRs")) { //new Throwable("onStartChild namespace:"+namespace // + "\nonStartChild localName:"+localName // + "\nonStartChild prefix :"+prefix).printStackTrace(); int failures = 0; SOAPHandler sHnd = null; for (int n = 0; n < 3; ++n) { try { if (alreadyFailed[n]) { ++failures; continue; } sHnd = additional[n].onStartChild(namespace, localName, prefix, attributes, context); } catch (Throwable t) { //t.printStackTrace(); alreadyFailed[n] = true; ++failures; } } if (3 == failures) throw new SAXException(Messages.getMessage("cantCreateBean00", _addLocalNames[0], "")); return sHnd; } handleMixedContent(); BeanPropertyDescriptor propDesc = null; FieldDesc fieldDesc = null; SOAPConstants soapConstants = context.getSOAPConstants(); String encodingStyle = context.getMessageContext().getEncodingStyle(); boolean isEncoded = Constants.isSOAP_ENC(encodingStyle); QName elemQName = new QName(namespace, localName); // The collectionIndex needs to be reset for Beans with multiple arrays if ((prevQName == null) || (!prevQName.equals(elemQName))) { collectionIndex = -1; } prevQName = elemQName; if (typeDesc != null) { // Lookup the name appropriately (assuming an unqualified // name for SOAP encoding, using the namespace otherwise) String fieldName = typeDesc.getFieldNameForElement(elemQName, isEncoded); propDesc = (BeanPropertyDescriptor) propertyMap.get(fieldName); fieldDesc = typeDesc.getFieldByName(fieldName); } if (propDesc == null) { // look for a field by this name. propDesc = (BeanPropertyDescriptor) propertyMap.get(localName); } // try and see if this is an xsd:any namespace="##any" element before // reporting a problem if (propDesc == null) { // try to put unknown elements into a SOAPElement property, if // appropriate propDesc = getAnyPropertyDesc(); if (propDesc != null) { try { MessageElement[] curElements = (MessageElement[]) propDesc.get(value); int length = 0; if (curElements != null) { length = curElements.length; } MessageElement[] newElements = new MessageElement[length + 1]; if (curElements != null) { System.arraycopy(curElements, 0, newElements, 0, length); } MessageElement thisEl = context.getCurElement(); newElements[length] = thisEl; propDesc.set(value, newElements); // if this is the first pass through the MessageContexts // make sure that the correct any element is set, // that is the child of the current MessageElement, however // on the first pass this child has not been set yet, so // defer it to the child SOAPHandler if (!localName.equals(thisEl.getName())) { return new SOAPHandler(newElements, length); } return new SOAPHandler(); } catch (Exception e) { throw new SAXException(e); } } } if (propDesc == null) { // No such field throw new SAXException(Messages.getMessage("badElem00", javaType.getName(), localName)); } // Get the child's xsi:type if available QName childXMLType = context.getTypeFromAttributes(namespace, localName, attributes); String href = attributes.getValue(soapConstants.getAttrHref()); // If no xsi:type or href, check the meta-data for the field if (childXMLType == null && fieldDesc != null && href == null) { childXMLType = fieldDesc.getXmlType(); } // Get Deserializer for child, default to using DeserializerImpl Deserializer dSer = getDeserializer(childXMLType, propDesc.getType(), href, context); // It is an error if the dSer is not found - the only case where we // wouldn't have a deserializer at this point is when we're trying // to deserialize something we have no clue about (no good xsi:type, // no good metadata). if (dSer == null) { dSer = context.getDeserializerForClass(propDesc.getType()); } // Fastpath nil checks... if (context.isNil(attributes)) { if (propDesc != null && propDesc.isIndexed()) { if (!((dSer != null) && (dSer instanceof ArrayDeserializer)) || propDesc.getType().isArray()) { collectionIndex++; dSer.registerValueTarget(new BeanPropertyTarget(value, propDesc, collectionIndex)); addChildDeserializer(dSer); return (SOAPHandler) dSer; } } return null; } if (dSer == null) { throw new SAXException(Messages.getMessage("noDeser00", childXMLType.toString())); } // Register value target if (propDesc.isWriteable()) { // If this is an indexed property, and the deserializer we found // was NOT the ArrayDeserializer, this is a non-SOAP array: // <bean> // <field>value1</field> // <field>value2</field> // ... // In this case, we want to use the collectionIndex and make sure // the deserialized value for the child element goes into the // right place in the collection. if (propDesc.isIndexed() && (!(dSer instanceof ArrayDeserializer) || propDesc.getType().isArray())) { collectionIndex++; dSer.registerValueTarget(new BeanPropertyTarget(value, propDesc, collectionIndex)); } else { // If we're here, the element maps to a single field value, // whether that be a "basic" type or an array, so use the // normal (non-indexed) BeanPropertyTarget form. collectionIndex = -1; dSer.registerValueTarget(new BeanPropertyTarget(value, propDesc)); } } // Let the framework know that we need this deserializer to complete // for the bean to complete. addChildDeserializer(dSer); return (SOAPHandler) dSer; }
From source file:org.enhydra.shark.asap.util.BeanDeserializerShark.java
/** * Set the bean properties that correspond to element attributes. * * This method is invoked after startElement when the element requires * deserialization (i.e. the element is not an href and the value is not * nil.)//from w w w.j ava 2 s .com * @param namespace is the namespace of the element * @param localName is the name of the element * @param prefix is the prefix of the element * @param attributes are the attributes on the element...used to get the * type * @param context is the DeserializationContext */ public void onStartElement(String namespace, String localName, String prefix, Attributes attributes, DeserializationContext context) throws SAXException { if (xmlType.toString().endsWith("GetPropertiesRs") || xmlType.toString().endsWith("SetPropertiesRs")) { //new Throwable("onStartElement namespace:"+namespace // + "\nonStartElement localName:"+localName // + "\nonStartElement prefix :"+prefix).printStackTrace(); String pp = xmlType.toString().substring(0, xmlType.toString().length() - "GetPropertiesRs".length()); try { additional = new BeanDeserializerShark[3]; additional[0] = new BeanDeserializerShark( Class.forName("org.enhydra.shark.asap.types.ObserverPropertiesGroup"), new QName(pp + _addLocalNames[0])); additional[1] = new BeanDeserializerShark( Class.forName("org.enhydra.shark.asap.types.InstancePropertiesGroup"), new QName(pp + _addLocalNames[1])); additional[2] = new BeanDeserializerShark( Class.forName("org.enhydra.shark.asap.types.FactoryPropertiesGroup"), new QName(pp + _addLocalNames[2])); } catch (Throwable t) { t.printStackTrace(); throw new SAXException(t.getMessage()); } alreadyFailed = new boolean[3]; int failures = 0; for (int n = 0; n < 3; ++n) { try { alreadyFailed[n] = false; additional[n].startElement(namespace, _addLocalNames[n], prefix, attributes, context); } catch (Throwable t) { t.printStackTrace(); alreadyFailed[n] = true; ++failures; } } if (3 == failures) throw new SAXException(Messages.getMessage("cantCreateBean00", _addLocalNames[0], "")); } // The value should have been created or assigned already. // This code may no longer be needed. if (value == null) { // create a value try { value = javaType.newInstance(); } catch (Exception e) { throw new SAXException(Messages.getMessage("cantCreateBean00", javaType.getName(), e.toString())); } } // If no type description meta data, there are no attributes, // so we are done. if (typeDesc == null) return; // loop through the attributes and set bean properties that // correspond to attributes for (int i = 0; i < attributes.getLength(); i++) { QName attrQName = new QName(attributes.getURI(i), attributes.getLocalName(i)); String fieldName = typeDesc.getFieldNameForAttribute(attrQName); if (fieldName == null) continue; FieldDesc fieldDesc = typeDesc.getFieldByName(fieldName); // look for the attribute property BeanPropertyDescriptor bpd = (BeanPropertyDescriptor) propertyMap.get(fieldName); if (bpd != null) { if (!bpd.isWriteable() || bpd.isIndexed()) continue; // Get the Deserializer for the attribute Deserializer dSer = getDeserializer(fieldDesc.getXmlType(), bpd.getType(), null, context); if (dSer == null) { dSer = context.getDeserializerForClass(bpd.getType()); } if (dSer == null) throw new SAXException(Messages.getMessage("unregistered00", bpd.getType().toString())); if (!(dSer instanceof SimpleDeserializer)) throw new SAXException( Messages.getMessage("AttrNotSimpleType00", bpd.getName(), bpd.getType().toString())); // Success! Create an object from the string and set // it in the bean try { dSer.onStartElement(namespace, localName, prefix, attributes, context); Object val = ((SimpleDeserializer) dSer).makeValue(attributes.getValue(i)); bpd.set(value, val); } catch (Exception e) { throw new SAXException(e); } } // if } // attribute loop }
From source file:org.enhydra.shark.asap.util.BeanDeserializerShark.java
public void onEndElement(String namespace, String localName, DeserializationContext context) throws SAXException { if (xmlType.toString().endsWith("GetPropertiesRs") || xmlType.toString().endsWith("SetPropertiesRs")) { for (int n = 0; n < 3; ++n) { if (!alreadyFailed[n]) { BeanPropertyDescriptor propDesc = (BeanPropertyDescriptor) propertyMap.get(_addLocalNames[n]); System.err.println("localName:" + _addLocalNames[n] + ", propDesc:" + propDesc); try { propDesc.set(value, additional[n].getValue()); } catch (Throwable t) { t.printStackTrace(); throw new SAXException(t.getMessage()); }// w ww . jav a2 s . c o m } } } handleMixedContent(); }