📄 deserializationcontext.java
字号:
} // If we still have no luck, check to see if there's an arrayType // (itemType for SOAP 1.2) attribute, in which case this is almost // certainly an array. if (typeQName == null && attrs != null) { String encURI = getSOAPConstants().getEncodingURI(); String itemType = getSOAPConstants().getAttrItemType(); for (int i = 0; i < attrs.getLength(); i++) { if (encURI.equals(attrs.getURI(i)) && itemType.equals(attrs.getLocalName(i))) { return new QName(encURI, "Array"); } } } return typeQName; } /** * Convenenience method that returns true if the value is nil * (due to the xsi:nil) attribute. * @param attrs are the element attributes. * @return true if xsi:nil is true */ public boolean isNil(Attributes attrs) { return JavaUtils.isTrueExplicitly( Constants.getValue(attrs, Constants.QNAMES_NIL), false); } /** * Get a Deserializer which can turn a given xml type into a given * Java type */ public final Deserializer getDeserializer(Class cls, QName xmlType) { if (xmlType == null) return null; DeserializerFactory dserF = null; Deserializer dser = null; try { dserF = (DeserializerFactory) getTypeMapping(). getDeserializer(cls, xmlType); } catch (JAXRPCException e) { log.error(Messages.getMessage("noFactory00", xmlType.toString())); } if (dserF != null) { try { dser = (Deserializer) dserF.getDeserializerAs(Constants.AXIS_SAX); } catch (JAXRPCException e) { log.error(Messages.getMessage("noDeser00", xmlType.toString())); } } return dser; } /** * Convenience method to get the Deserializer for a specific * java class from its meta data. * @param cls is the Class used to find the deserializer * @return Deserializer */ public Deserializer getDeserializerForClass(Class cls) { if (cls == null) { cls = destClass; } if (cls == null) { return null; }// if (cls.isArray()) {// cls = cls.getComponentType();// } if (javax.xml.rpc.holders.Holder.class.isAssignableFrom(cls)) { try { cls = cls.getField("value").getType(); } catch (Exception e) { } } Deserializer dser = null; QName type = getTypeMapping().getTypeQName(cls); dser = getDeserializer(cls, type); if (dser != null) return dser; try { Method method = MethodCache.getInstance().getMethod(cls, DESERIALIZER_METHOD, DESERIALIZER_CLASSES); if (method != null) { TypeDesc typedesc = TypeDesc.getTypeDescForClass(cls); if (typedesc != null) { dser = (Deserializer) method.invoke(null, new Object[] {getEncodingStyle(), cls, typedesc.getXmlType()}); } } } catch (Exception e) { log.error(Messages.getMessage("noDeser00", cls.getName())); } return dser; } /** * Allows the destination class to be set so that downstream * deserializers like ArrayDeserializer can pick it up when * deserializing its components using getDeserializerForClass * @param destClass is the Class of the component to be deserialized */ public void setDestinationClass(Class destClass) { this.destClass = destClass; } /** * Allows the destination class to be retrieved so that downstream * deserializers like ArrayDeserializer can pick it up when * deserializing its components using getDeserializerForClass * @return the Class of the component to be deserialized */ public Class getDestinationClass() { return destClass; } /** * Convenience method to get the Deserializer for a specific * xmlType. * @param xmlType is QName for a type to deserialize * @return Deserializer */ public final Deserializer getDeserializerForType(QName xmlType) { return getDeserializer(null, xmlType); } /** * Get the TypeMapping for this DeserializationContext */ public TypeMapping getTypeMapping() { if (msgContext == null || msgContext.getTypeMappingRegistry() == null) { return (TypeMapping) new org.apache.axis.encoding.TypeMappingRegistryImpl().getTypeMapping( null); } TypeMappingRegistry tmr = msgContext.getTypeMappingRegistry(); return (TypeMapping) tmr.getTypeMapping(getEncodingStyle()); } /** * Get the TypeMappingRegistry we're using. * @return TypeMapping or null */ public TypeMappingRegistry getTypeMappingRegistry() { return msgContext.getTypeMappingRegistry(); } /** * Get the MessageElement for the indicated id (where id is the #value of an href) * If the MessageElement has not been processed, the MessageElement will * be returned. If the MessageElement has been processed, the actual object * value is stored with the id and this routine will return null. * @param id is the value of an href attribute * @return MessageElement or null */ public MessageElement getElementByID(String id) { if((idMap != null)) { IDResolver resolver = (IDResolver)idMap.get(id); if(resolver != null) { Object ret = resolver.getReferencedObject(id); if (ret instanceof MessageElement) return (MessageElement)ret; } } return null; } /** * Gets the MessageElement or actual Object value associated with the href value. * The return of a MessageElement indicates that the referenced element has * not been processed. If it is not a MessageElement, the Object is the * actual deserialized value. * In addition, this method is invoked to get Object values via Attachments. * @param href is the value of an href attribute (or an Attachment id) * @return MessageElement other Object or null */ public Object getObjectByRef(String href) { Object ret= null; if(href != null){ if((idMap != null)){ IDResolver resolver = (IDResolver)idMap.get(href); if(resolver != null) ret = resolver.getReferencedObject(href); } if( null == ret && !href.startsWith("#")){ //Could this be an attachment? Message msg= null; if(null != (msg=msgContext.getCurrentMessage())){ Attachments attch= null; if( null != (attch= msg.getAttachmentsImpl())){ try{ ret= attch.getAttachmentByReference(href); }catch(AxisFault e){ throw new RuntimeException(e.toString() + JavaUtils.stackToString(e)); } } } } } return ret; } /** * Add the object associated with this id (where id is the value of an id= attribute, * i.e. it does not start with #). * This routine is called to associate the deserialized object * with the id specified on the XML element. * @param id (id name without the #) * @param obj is the deserialized object for this id. */ public void addObjectById(String id, Object obj) { // The resolver uses the href syntax as the key. String idStr = '#' + id; if ((idMap == null) || (id == null)) return ; IDResolver resolver = (IDResolver)idMap.get(idStr); if (resolver == null) return ; resolver.addReferencedObject(idStr, obj); return; } /** * During deserialization, an element with an href=#id<int> * may be encountered before the element defining id=id<int> is * read. In these cases, the getObjectByRef method above will * return null. The deserializer is placed in a table keyed * by href (a fixup table). After the element id is processed, * the deserializer is informed of the value so that it can * update its target(s) with the value. * @param href (#id syntax) * @param dser is the deserializer of the element */ public void registerFixup(String href, Deserializer dser) { if (fixups == null) fixups = new HashMap(); Deserializer prev = (Deserializer) fixups.put(href, dser); // There could already be a deserializer in the fixup list // for this href. If so, the easiest way to get all of the // targets updated is to move the previous deserializers // targets to dser. if (prev != null && prev != dser) { dser.moveValueTargets(prev); if (dser.getDefaultType() == null) { dser.setDefaultType(prev.getDefaultType()); } } } /** * Register the MessageElement with this id (where id is id= form without the #) * This routine is called when the MessageElement with an id is read. * If there is a Deserializer in our fixup list (described above), * the 'fixup' deserializer is given to the MessageElement. When the * MessageElement is completed, the 'fixup' deserializer is informed and * it can set its targets. * @param id (id name without the #) * @param elem is the MessageElement */ public void registerElementByID(String id, MessageElement elem) { if (localIDs == null) localIDs = new LocalIDResolver(); String absID = '#' + id; localIDs.addReferencedObject(absID, elem); registerResolverForID(absID, localIDs); if (fixups != null) { Deserializer dser = (Deserializer)fixups.get(absID); if (dser != null) { elem.setFixupDeserializer(dser); } } } /** * Each id can have its own kind of resolver. This registers a * resolver for the id. */ public void registerResolverForID(String id, IDResolver resolver) { if ((id == null) || (resolver == null)) { // ??? Throw nullPointerException? return; } if (idMap == null) idMap = new HashMap(); idMap.put(id, resolver); } /** * Return true if any ids are being tracked by this DeserializationContext * * @return true if any ides are being tracked by this DeserializationContext */ public boolean hasElementsByID() { return idMap == null ? false : idMap.size() > 0; } /** * Get the current position in the record. */ public int getCurrentRecordPos() { if (recorder == null) return -1; return recorder.getLength() - 1; } /** * Get the start of the mapping position */ public int getStartOfMappingsPos() { if (startOfMappingsPos == -1) { return getCurrentRecordPos() + 1; } return startOfMappingsPos; } /** * Push the MessageElement into the recorder */ public void pushNewElement(MessageElement elem) { if (debugEnabled) { log.debug("Pushing element " + elem.getName()); } if (!doneParsing && (recorder != null)) { recorder.newElement(elem); } try { if(curElement != null) elem.setParentElement(curElement); } catch (Exception e) { /* * The only checked exception that may be thrown from setParent * occurs if the parent already has an explicit object value, * which should never occur during deserialization. */ log.fatal(Messages.getMessage("exception00"), e); } curElement = elem; if (elem.getRecorder() != recorder) recorder = elem.getRecorder(); } /**************************************************************** * Management of sub-handlers (deserializers) */ public void pushElementHandler(SOAPHandler handler) { if (debugEnabled) { log.debug(Messages.getMessage("pushHandler00", "" + handler)); } if (topHandler != null) pushedDownHandlers.add(topHandler); topHandler = handler; } /** Replace the handler at the top of the stack. * * This is only used when we have a placeholder Deserializer * for a referenced object which doesn't know its type until we * hit the referent. */ public void replaceElementHandler(SOAPHandler handler) { topHandler = handler; } public SOAPHandler popElementHandler() { SOAPHandler result = topHandler; int size = pushedDownHandlers.size(); if (size > 0) { topHandler = (SOAPHandler) pushedDownHandlers.remove(size-1); } else { topHandler = null; } if (debugEnabled) { if (result == null) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -