List of usage examples for org.xml.sax SAXException SAXException
public SAXException(Exception e)
From source file:org.apache.axis.encoding.ser.VectorDeserializer.java
/** * onStartChild is called on each child element. * * @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.//from www .java 2 s . c o m */ public SOAPHandler onStartChild(String namespace, String localName, String prefix, Attributes attributes, DeserializationContext context) throws SAXException { if (log.isDebugEnabled()) { log.debug("Enter: VectorDeserializer::onStartChild()"); } if (attributes == null) throw new SAXException(Messages.getMessage("noType01")); // If the xsi:nil attribute, set the value to null and return since // there is nothing to deserialize. if (context.isNil(attributes)) { setChildValue(null, new Integer(curIndex++)); return null; } // Get the type QName itemType = context.getTypeFromAttributes(namespace, localName, attributes); // Get the deserializer Deserializer dSer = null; if (itemType != null) { dSer = context.getDeserializerForType(itemType); } if (dSer == null) { dSer = new DeserializerImpl(); } // When the value is deserialized, inform us. // Need to pass the index because multi-ref stuff may // result in the values being deserialized in a different order. dSer.registerValueTarget(new DeserializerTarget(this, new Integer(curIndex))); curIndex++; if (log.isDebugEnabled()) { log.debug("Exit: VectorDeserializer::onStartChild()"); } // Let the framework know that we aren't complete until this guy // is complete. addChildDeserializer(dSer); return (SOAPHandler) dSer; }
From source file:org.apache.axis.message.BodyBuilder.java
public void startElement(String namespace, String localName, String prefix, Attributes attributes, DeserializationContext context) throws SAXException { SOAPConstants soapConstants = context.getSOAPConstants(); if (soapConstants == SOAPConstants.SOAP12_CONSTANTS && attributes.getValue(Constants.URI_SOAP12_ENV, Constants.ATTR_ENCODING_STYLE) != null) { AxisFault fault = new AxisFault(Constants.FAULT_SOAP12_SENDER, null, Messages.getMessage("noEncodingStyleAttrAppear", "Body"), null, null, null); throw new SAXException(fault); }/*www. j a v a 2s. c om*/ // make a new body element if (!context.isDoneParsing()) { if (!context.isProcessingRef()) { if (myElement == null) { try { myElement = new SOAPBody(namespace, localName, prefix, attributes, context, envelope.getSOAPConstants()); } catch (AxisFault axisFault) { throw new SAXException(axisFault); } } context.pushNewElement(myElement); } envelope.setBody((SOAPBody) myElement); } }
From source file:org.apache.axis.message.BodyBuilder.java
public SOAPHandler onStartChild(String namespace, String localName, String prefix, Attributes attributes, DeserializationContext context) throws SAXException { SOAPBodyElement element = null; if (log.isDebugEnabled()) { log.debug("Enter: BodyBuilder::onStartChild()"); }/*from w w w . ja v a2 s. c o m*/ QName qname = new QName(namespace, localName); SOAPHandler handler = null; /** We're about to create a body element. So we really need * to know at this point if this is an RPC service or not. It's * possible that no one has set the service up until this point, * so if that's the case we should attempt to set it based on the * namespace of the first root body element. Setting the * service may (should?) result in setting the service * description, which can then tell us what to create. */ boolean isRoot = true; String root = attributes.getValue(Constants.URI_DEFAULT_SOAP_ENC, Constants.ATTR_ROOT); if ((root != null) && root.equals("0")) isRoot = false; MessageContext msgContext = context.getMessageContext(); OperationDesc[] operations = null; try { if (msgContext != null) { operations = msgContext.getPossibleOperationsByQName(qname); } // If there's only one match, set it in the MC now if ((operations != null) && (operations.length == 1)) msgContext.setOperation(operations[0]); } catch (org.apache.axis.AxisFault e) { // SAXException is already known to this method, so I // don't have an exception-handling propogation explosion. throw new SAXException(e); } Style style = operations == null ? Style.RPC : operations[0].getStyle(); SOAPConstants soapConstants = context.getSOAPConstants(); /** Now we make a plain SOAPBodyElement IF we either: * a) have an non-root element, or * b) have a non-RPC service */ if (localName.equals(Constants.ELEM_FAULT) && namespace.equals(soapConstants.getEnvelopeURI())) { try { element = new SOAPFault(namespace, localName, prefix, attributes, context); } catch (AxisFault axisFault) { throw new SAXException(axisFault); } element.setEnvelope(context.getEnvelope()); handler = new SOAPFaultBuilder((SOAPFault) element, context); } else if (!gotRPCElement) { if (isRoot && (style != Style.MESSAGE)) { gotRPCElement = true; try { element = new RPCElement(namespace, localName, prefix, attributes, context, operations); } catch (org.apache.axis.AxisFault e) { // SAXException is already known to this method, so I // don't have an exception-handling propogation explosion. // throw new SAXException(e); } // Only deserialize this way if there is a unique operation // for this QName. If there are overloads, // we'll need to start recording. If we're making a high- // fidelity recording anyway, don't bother (for now). if (msgContext != null && !msgContext.isHighFidelity() && (operations == null || operations.length == 1)) { ((RPCElement) element).setNeedDeser(false); boolean isResponse = false; if (msgContext.getCurrentMessage() != null && Message.RESPONSE.equals(msgContext.getCurrentMessage().getMessageType())) isResponse = true; handler = new RPCHandler((RPCElement) element, isResponse); if (operations != null) { ((RPCHandler) handler).setOperation(operations[0]); msgContext.setOperation(operations[0]); } } } } if (element == null) { if ((style == Style.RPC) && soapConstants == SOAPConstants.SOAP12_CONSTANTS) { throw new SAXException(Messages.getMessage("onlyOneBodyFor12")); } try { element = new SOAPBodyElement(namespace, localName, prefix, attributes, context); } catch (AxisFault axisFault) { throw new SAXException(axisFault); } if (element.getFixupDeserializer() != null) handler = (SOAPHandler) element.getFixupDeserializer(); } if (handler == null) handler = new SOAPHandler(); handler.myElement = element; //context.pushNewElement(element); if (log.isDebugEnabled()) { log.debug("Exit: BodyBuilder::onStartChild()"); } return handler; }
From source file:org.apache.axis.message.HeaderBuilder.java
public void startElement(String namespace, String localName, String prefix, Attributes attributes, DeserializationContext context) throws SAXException { SOAPConstants soapConstants = context.getSOAPConstants(); if (soapConstants == SOAPConstants.SOAP12_CONSTANTS && attributes.getValue(Constants.URI_SOAP12_ENV, Constants.ATTR_ENCODING_STYLE) != null) { AxisFault fault = new AxisFault(Constants.FAULT_SOAP12_SENDER, null, Messages.getMessage("noEncodingStyleAttrAppear", "Header"), null, null, null); throw new SAXException(fault); }/*from ww w . ja v a 2s. c o m*/ if (!context.isDoneParsing()) { if (myElement == null) { try { myElement = new SOAPHeader(namespace, localName, prefix, attributes, context, envelope.getSOAPConstants()); } catch (AxisFault axisFault) { throw new SAXException(axisFault); } envelope.setHeader((SOAPHeader) myElement); } context.pushNewElement(myElement); } }
From source file:org.apache.axis.message.HeaderBuilder.java
public SOAPHandler onStartChild(String namespace, String localName, String prefix, Attributes attributes, DeserializationContext context) throws SAXException { try {// ww w .ja va 2s. c o m header = new SOAPHeaderElement(namespace, localName, prefix, attributes, context); } catch (AxisFault axisFault) { throw new SAXException(axisFault); } SOAPHandler handler = new SOAPHandler(); handler.myElement = header; return handler; }
From source file:org.apache.axis.message.MessageElement.java
/** * replay the sax events to a handler/* w w w. j a v a 2 s. c o m*/ * @param handler * @throws SAXException */ public void publishToHandler(ContentHandler handler) throws SAXException { if (recorder == null) { throw new SAXException(Messages.getMessage("noRecorder00")); } recorder.replay(startEventIndex, endEventIndex, handler); }
From source file:org.apache.axis.message.MessageElement.java
/** * replay the sax events to a SAX content handles * @param handler//from w ww . j a v a 2s . c om * @throws SAXException */ public void publishContents(ContentHandler handler) throws SAXException { if (recorder == null) { throw new SAXException(Messages.getMessage("noRecorder00")); } recorder.replay(startContentsIndex, endEventIndex - 1, handler); }
From source file:org.apache.axis.message.RPCHandler.java
/** * Register the start of a parameter (child element of the method call * element).//from w w w . ja va 2 s . c o m * * Our job here is to figure out a) which parameter this is (based on * the QName of the element or its position), and b) what type it is * (based on the xsi:type attribute or operation metadata) so we can * successfully deserialize it. */ public SOAPHandler onStartChild(String namespace, String localName, String prefix, Attributes attributes, DeserializationContext context) throws SAXException { if (log.isDebugEnabled()) { log.debug("Enter: RPCHandler.onStartChild()"); } if (!context.isDoneParsing()) { try { context.pushNewElement(new MessageElement(namespace, localName, prefix, attributes, context)); } catch (AxisFault axisFault) { throw new SAXException(axisFault); } } MessageElement curEl = context.getCurElement(); QName type = null; QName qname = new QName(namespace, localName); ParameterDesc paramDesc = null; SOAPConstants soapConstants = context.getSOAPConstants(); if (soapConstants == SOAPConstants.SOAP12_CONSTANTS && Constants.QNAME_RPC_RESULT.equals(qname)) { // TODO: fix it ... now we just skip it return new DeserializerImpl(); } // Create a new param if not the same element if (currentParam == null || !currentParam.getQName().getNamespaceURI().equals(namespace) || !currentParam.getQName().getLocalPart().equals(localName)) { currentParam = new RPCParam(namespace, localName, null); rpcElem.addParam(currentParam); } // Grab xsi:type attribute if present, on either this element or // the referent (if it's an href). MessageElement.getType() will // automatically dig through to the referent if necessary. type = curEl.getType(); if (type == null) { type = context.getTypeFromAttributes(namespace, localName, attributes); } if (log.isDebugEnabled()) { log.debug(Messages.getMessage("typeFromAttr00", "" + type)); } Class destClass = null; // If we have an operation descriptor, try to associate this parameter // with the appropriate ParameterDesc if (operation != null) { // Try by name first if (isResponse) { paramDesc = operation.getOutputParamByQName(qname); } else { paramDesc = operation.getInputParamByQName(qname); } // If that didn't work, try position // FIXME : Do we need to be in EITHER named OR positional // mode? I.e. will it screw us up to find something // by position if we've already looked something up // by name? I think so... if (paramDesc == null) { if (isResponse) { paramDesc = operation.getReturnParamDesc(); } else { paramDesc = operation.getParameter(rpcElem.getParams().size() - 1); } } if (paramDesc == null) { throw new SAXException(Messages.getMessage("noParmDesc")); } // Make sure that we don't find body parameters that should // be in the header if (!isHeaderElement && ((isResponse && paramDesc.isOutHeader()) || (!isResponse && paramDesc.isInHeader()))) { throw new SAXException(Messages.getMessage("expectedHeaderParam", paramDesc.getQName().toString())); } destClass = paramDesc.getJavaType(); if ((destClass != null) && (destClass.isArray())) { context.setDestinationClass(destClass); } // Keep the association so we can use it later // (see RPCProvider.processMessage()) currentParam.setParamDesc(paramDesc); if (type == null) { type = paramDesc.getTypeQName(); } } if (type != null && type.equals(XMLType.AXIS_VOID)) { Deserializer nilDSer = new DeserializerImpl(); return (SOAPHandler) nilDSer; } // If the nil attribute is set, just // return the base DeserializerImpl. // Register the value target to set the value // on the RPCParam. This is necessary for cases like // <method> // <foo>123</foo> // <foo>456</foo> // <foo xsi:nil="true" /> // </method> // so that a list of 3 items is created. // Failure to register the target would result in the last // item not being added to the list if (context.isNil(attributes)) { Deserializer nilDSer = new DeserializerImpl(); nilDSer.registerValueTarget(new RPCParamTarget(currentParam)); return (SOAPHandler) nilDSer; } Deserializer dser = null; if ((type == null) && (namespace != null) && (!namespace.equals(""))) { dser = context.getDeserializerForType(qname); } else { dser = context.getDeserializer(destClass, type); // !!! if (dser == null && destClass != null && destClass.isArray() && operation.getStyle() == Style.DOCUMENT) { dser = context.getDeserializerForClass(destClass); } // !!! } if (dser == null) { if (type != null) { dser = context.getDeserializerForType(type); if (null != destClass && dser == null && Element.class.isAssignableFrom(destClass)) { //If a DOM element is expected, as last resort always allow direct mapping // of parameter's SOAP xml to a DOM element. Support of literal parms by default. dser = context.getDeserializerForType(Constants.SOAP_ELEMENT); } if (dser == null) { dser = context.getDeserializerForClass(destClass); } if (dser == null) { throw new SAXException(Messages.getMessage("noDeser01", localName, "" + type)); } if (paramDesc != null && paramDesc.getJavaType() != null) { // If we have an xsi:type, make sure it makes sense // with the current paramDesc type Class xsiClass = context.getTypeMapping().getClassForQName(type); if (null != xsiClass && !JavaUtils.isConvertable(xsiClass, destClass)) { throw new SAXException("Bad types (" + xsiClass + " -> " + destClass + ")"); // FIXME! } } } else { dser = context.getDeserializerForClass(destClass); if (dser == null) { dser = new DeserializerImpl(); } } } dser.setDefaultType(type); dser.registerValueTarget(new RPCParamTarget(currentParam)); if (log.isDebugEnabled()) { log.debug("Exit: RPCHandler.onStartChild()"); } return (SOAPHandler) dser; }
From source file:org.apache.axis.message.SAXOutputter.java
public void characters(char[] p1, int p2, int p3) throws SAXException { if (log.isDebugEnabled()) { log.debug("SAXOutputter.characters ['" + new String(p1, p2, p3) + "']"); }/* w w w . j a v a 2 s .c om*/ try { if (!isCDATA) { context.writeChars(p1, p2, p3); } else { context.writeString(new String(p1, p2, p3)); } } catch (IOException e) { throw new SAXException(e); } }
From source file:org.apache.axis.message.SAXOutputter.java
public void ignorableWhitespace(char[] p1, int p2, int p3) throws SAXException { try {/*from w w w . ja v a 2s .c om*/ context.writeChars(p1, p2, p3); } catch (IOException e) { throw new SAXException(e); } }