⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 attachmentsimpl.java

📁 Java有关XML编程需要用到axis 的源代码 把里面bin下的包导入相应的Java工程 进行使用
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        if( null == ret && reference.startsWith(Attachments.CIDprefix)){             //This is a content-id lets see if we have it.                ret = (Part) attachments.get( reference.substring(4));        }        return ret;    }    /**     * This method will return all attachments as a collection.     *     * @return A collection of attachments.     *     * @throws org.apache.axis.AxisFault     */    public java.util.Collection getAttachments()            throws org.apache.axis.AxisFault {        if (_askedForStreams) {            throw new IllegalStateException(Messages.getMessage("concurrentModificationOfStream"));        }        mergeinAttachments();        return new LinkedList(orderedAttachments);    }    /**     * From the complex stream return the root part.     * Today this is SOAP.     *     * @return the root <code>Part</code>     */    public Part getRootPart() {        return soapPart;    }    public void setRootPart(Part newRoot) {        try {            this.soapPart = (SOAPPart) newRoot;            multipart = null;            dimemultipart = null;        } catch (ClassCastException e) {            throw new ClassCastException(Messages.getMessage("onlySOAPParts"));        }    }    /** multipart , cached entries for the stream of attachment that are going to be sent.   */    javax.mail.internet.MimeMultipart multipart = null;    DimeMultiPart dimemultipart = null;    /**     * Get the content length of the stream.     *     * @return the content length of the stream     *     * @throws org.apache.axis.AxisFault     */    public long getContentLength() throws org.apache.axis.AxisFault {        if (_askedForStreams) {            throw new IllegalStateException(Messages.getMessage("concurrentModificationOfStream"));        }        mergeinAttachments();        int sendtype= this.sendtype == SEND_TYPE_NOTSET ? SEND_TYPE_DEFAULT :   this.sendtype;        try {              if(sendtype == SEND_TYPE_MIME || sendtype == SEND_TYPE_MTOM)                 return org.apache.axis.attachments.MimeUtils.getContentLength(                                multipart != null ? multipart : (multipart = org.apache.axis.attachments.MimeUtils.createMP(soapPart.getAsString(), orderedAttachments, getSendType())));              else if (sendtype == SEND_TYPE_DIME)return createDimeMessage().getTransmissionSize();        } catch (Exception e) {            throw AxisFault.makeFault(e);        }        return 0;    }    /**     * Creates the DIME message     *     * @return a DIME part     *     * @throws org.apache.axis.AxisFault if the part could not be built     */    protected DimeMultiPart createDimeMessage() throws org.apache.axis.AxisFault{        int sendtype= this.sendtype == SEND_TYPE_NOTSET ? SEND_TYPE_DEFAULT :   this.sendtype;        if (sendtype == SEND_TYPE_DIME){           if(dimemultipart== null){              dimemultipart= new DimeMultiPart();              dimemultipart.addBodyPart(new DimeBodyPart(                soapPart.getAsBytes(), DimeTypeNameFormat.URI,                "http://schemas.xmlsoap.org/soap/envelope/",                  "uuid:714C6C40-4531-442E-A498-3AC614200295"));              for( java.util.Iterator i= orderedAttachments.iterator();                i.hasNext(); ){                AttachmentPart part= (AttachmentPart)i.next();                    DataHandler dh= AttachmentUtils.                      getActivationDataHandler(part);                    dimemultipart.addBodyPart(new                      DimeBodyPart(dh,part.getContentId()));              }            }        }        return dimemultipart;      }    /**     * Write the content to the stream.     *     * @param os     *     * @throws org.apache.axis.AxisFault     */    public void writeContentToStream(java.io.OutputStream os)            throws org.apache.axis.AxisFault {        int sendtype= this.sendtype == SEND_TYPE_NOTSET ?                          SEND_TYPE_DEFAULT : this.sendtype;        try{        mergeinAttachments();        if(sendtype == SEND_TYPE_MIME || sendtype == SEND_TYPE_MTOM){        org.apache.axis.attachments.MimeUtils.writeToMultiPartStream(os,                (multipart != null)                ? multipart                : (multipart =                   org.apache.axis.attachments.MimeUtils.createMP(                        soapPart.getAsString(), orderedAttachments, getSendType())));        for (java.util.Iterator i = orderedAttachments.iterator();             i.hasNext();) {            AttachmentPart part = (AttachmentPart) i.next();            DataHandler dh =                    AttachmentUtils.getActivationDataHandler(part);            DataSource ds = dh.getDataSource();            if ((ds != null) && (ds instanceof ManagedMemoryDataSource)) {                ((ManagedMemoryDataSource) ds).delete();            }        }        }else if (sendtype == SEND_TYPE_DIME)createDimeMessage().write(os);       }catch(Exception e){ throw org.apache.axis.AxisFault.makeFault(e);}    }    /**     * Gets the content type for the whole stream.     *     * @return the content type for the whole stream     *     * @throws org.apache.axis.AxisFault     */    public String getContentType() throws org.apache.axis.AxisFault {        mergeinAttachments();        int sendtype= this.sendtype == SEND_TYPE_NOTSET ? SEND_TYPE_DEFAULT :               this.sendtype;        if(sendtype == SEND_TYPE_MIME || sendtype == SEND_TYPE_MTOM)          return org.apache.axis.attachments.MimeUtils.getContentType((multipart                  != null)                  ? multipart                  : (multipart =                  org.apache.axis.attachments.MimeUtils.createMP(                          soapPart.getAsString(),                          orderedAttachments, getSendType())));        else return org.apache.axis.Message.MIME_APPLICATION_DIME;    }    /**     * This is the number of attachments.     *     * @return the number of attachments     */    public int getAttachmentCount() {        if (_askedForStreams) {            throw new IllegalStateException(Messages.getMessage("concurrentModificationOfStream"));        }        try {            mergeinAttachments();            // force a serialization of the message so that            // any attachments will be added            soapPart.saveChanges();                        return orderedAttachments.size();        } catch (AxisFault e) {            log.warn(Messages.getMessage("exception00"),e);        }        return 0;    }    /**     * Determine if an object is to be treated as an attchment.     *     * @param value the value that is to be determined if     * its an attachment.     *     * @return True if value should be treated as an attchment.     */    public boolean isAttachment(Object value) {        return AttachmentUtils.isAttachment(value);    }    /**     * Removes all <CODE>AttachmentPart</CODE> objects that have     *   been added to this <CODE>SOAPMessage</CODE> object.     *     *   <P>This method does not touch the SOAP part.</P>     */    public void removeAllAttachments() {        if (_askedForStreams) {            throw new IllegalStateException(Messages.getMessage("concurrentModificationOfStream"));        }        try {            multipart = null;            dimemultipart = null;            mergeinAttachments();            attachments.clear();            orderedAttachments.clear();            stackDataHandler.clear();        } catch (AxisFault af){            log.warn(Messages.getMessage("exception00"),af);        }    }    /**     * Retrieves all the <CODE>AttachmentPart</CODE> objects     * that have header entries that match the specified headers.     * Note that a returned attachment could have headers in     * addition to those specified.     * @param   headers a <CODE>MimeHeaders</CODE>     *     object containing the MIME headers for which to     *     search     * @return an iterator over all attachments that have a header     *     that matches one of the given headers     */    public java.util.Iterator getAttachments(            javax.xml.soap.MimeHeaders headers) {        if (_askedForStreams) {            throw new IllegalStateException(Messages.getMessage("concurrentModificationOfStream"));        }        java.util.Vector vecParts = new java.util.Vector();        java.util.Iterator iterator = GetAttachmentsIterator();        while(iterator.hasNext()){            Part part = (Part) iterator.next();            if(part instanceof AttachmentPart){                if(((AttachmentPart)part).matches(headers)){                    vecParts.add(part);                }            }        }        return vecParts.iterator();    }    /**     * get an iterator over all attachments. This     * @return iterator of Part Objects; some of which may be     * AttachmentPart instances     * @see org.apache.axis.Part     * @see AttachmentPart     */    private java.util.Iterator GetAttachmentsIterator() {        java.util.Iterator iterator = attachments.values().iterator();        return iterator;    }    /**     * Create a new attachment Part in this Message.     * Will actually, and always, return an AttachmentPart.     *     * @return a new attachment Part     *     * @throws org.apache.axis.AxisFault     */    public Part createAttachmentPart() throws org.apache.axis.AxisFault {        return new AttachmentPart();    }    public void setSendType( int sendtype){      if( sendtype < 1)        throw new IllegalArgumentException("");      if( sendtype > SEND_TYPE_MAX )        throw new IllegalArgumentException("");      this.sendtype= sendtype;    }    public int getSendType(){      return sendtype;    }    /**     * dispose of the attachments and their files; do not use the object     * after making this call.     */    public void dispose() {        java.util.Iterator iterator = GetAttachmentsIterator();        while (iterator.hasNext()) {            Part part = (Part) iterator.next();            if (part instanceof AttachmentPart) {                AttachmentPart apart=(AttachmentPart)part;                apart.dispose();            }        }    }    // consider type-safe e-num here?    /**     * Determine how an object typically sent as attachments are to     * be represented. Currently, MIME DIME and NONE are reccognised.     *     * @param value  a String representing a sending type, treated in a     *              case-insensetive manner     * @return an <code>int</code> send type code     */    public static int getSendType(String value) {        if (value.equalsIgnoreCase("MTOM")) return SEND_TYPE_MTOM;        if (value.equalsIgnoreCase("MIME")) return SEND_TYPE_MIME;        if (value.equalsIgnoreCase("DIME")) return SEND_TYPE_DIME;        if (value.equalsIgnoreCase("NONE")) return SEND_TYPE_NONE;        return SEND_TYPE_NOTSET;    }    /**     * For a given sendType value, return a string representation.     *     * @param value  a type code integer     * @return a <code>String</code> representation of <code>value</code>     */    public static String getSendTypeString(int value) {        if (value == SEND_TYPE_MTOM) {            return "MTOM";        }        if (value == SEND_TYPE_MIME) {            return "MIME";        }        if (value == SEND_TYPE_DIME) {            return "DIME";        }        if (value == SEND_TYPE_NONE) {            return "NONE";        }        return null;    }    /**     * Once this method is called, attachments can only be accessed via the InputStreams.     * Any other access to the attachments collection (e.g. via getAttachments()) is     * prohibited and will cause a IllegalStateException to be thrown.     *     * @return All of the attachment streams.     */    public IncomingAttachmentStreams getIncomingAttachmentStreams() {        if (_askedForAttachments) {            throw new IllegalStateException(Messages.getMessage("concurrentModificationOfStream"));        }        _askedForStreams = true;        mpartStream = null; // todo: comment        return _streams;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -