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

📄 safearray.java

📁 用java和windows的word应用的通用编程接口 关联起来
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * Copyright (c) 1999-2004 Sourceforge JACOB Project. All rights reserved.
 * Originator: Dan Adler (http://danadler.com).
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * 1. Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer. 2. Redistributions in
 * binary form must reproduce the above copyright notice, this list of
 * conditions and the following disclaimer in the documentation and/or other
 * materials provided with the distribution. 3. Redistributions in any form must
 * be accompanied by information on how to obtain complete source code for the
 * JACOB software.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */
package com.jacob.com;

/**
 * This creates an array wrapper around Variant objects(?).
 * Lookslike it supports 1 and two dimensional arrays 
 */
public class SafeArray extends JacobObject {
    int m_pV = 0;

    /**
     * constructor
     *
     */
    public SafeArray() {
    }

    /**
     * constructor
     * @param vt
     */
    public SafeArray(int vt) {
        init(vt, new int[] { 0 }, new int[] { -1 });
    }

    /**
     * constructor
     * @param vt
     * @param celems
     */
    public SafeArray(int vt, int celems) {
        init(vt, new int[] { 0 }, new int[] { celems });
    }

    /**
     * @param vt
     * @param celems1
     * @param celems2
     */
    public SafeArray(int vt, int celems1, int celems2) {
        init(vt, new int[] { 0, 0 }, new int[] { celems1, celems2 });
    }

    /**
     * constructor
     * @param vt
     * @param lbounds
     * @param celems
     */
    public SafeArray(int vt, int lbounds[], int celems[]) {
        init(vt, lbounds, celems);
    }

    /**
     *  convert a string to a VT_UI1 array
     * @param s source string
     */
    public SafeArray(String s) {
        char[] ca = s.toCharArray();
        init(Variant.VariantByte, new int[] { 0 }, new int[] { ca.length });
        fromCharArray(ca);
    }

    protected native void init(int vt, int lbounds[], int celems[]);

    /**
     * not impl
     * @return 0
     */
    public int getNumLocks() {
        return 0;
    }

    /**
     * convert a VT_UI1 array to string
     * @return variant byte as a string
     */
    public String asString() {
        if (getvt() != Variant.VariantByte)
            return null;
        char ja[] = toCharArray();
        return new String(ja);
    }

    public native Object clone();

    
    /**
     *  now private so only this object can asccess
     *  was: call this to explicitly release the com object before gc
     * 
     */
    private native void destroy();

    public native int getvt();

    /*
     *  (non-Javadoc)
     * @see java.lang.Object#finalize()
     */
    protected void finalize() {
        safeRelease();
    }
    
    /*
     *  (non-Javadoc)
     * @see com.jacob.com.JacobObject#safeRelease()
     */
    public void safeRelease()
    {
        super.safeRelease();
        if (m_pV != 0){
            destroy();
            m_pV = 0;
        } else {
            // looks like a double release
            if (isDebugEnabled()){debug(this.getClass().getName()+":"+this.hashCode()+" double release");}
        }
    }

    public native void reinit(SafeArray sa);

    public native void reinterpretType(int vt);

    public native int getLBound();

    public native int getLBound(int dim);

    public native int getUBound();

    public native int getUBound(int dim);

    public native int getNumDim();

    public native int getFeatures();

    public native int getElemSize();

    /**
     * populate the safe array from the passed in array of data
     * @param ja
     */
    public native void fromCharArray(char ja[]);

    /**
     * populate the safe array from the passed in array of data
     * @param ja
     */
    public native void fromIntArray(int ja[]);

    /**
     * populate the safe array from the passed in array of data
     * @param ja
     */
    public native void fromShortArray(short ja[]);

    /**
     * populate the safe array from the passed in array of data
     * @param ja
     */
    public native void fromDoubleArray(double ja[]);

    /**
     * populate the safe array from the passed in array of data
     * @param ja
     */
    public native void fromStringArray(String ja[]);

    /**
     * populate the safe array from the passed in array of data
     * @param ja
     */
    public native void fromByteArray(byte ja[]);

    /**
     * populate the safe array from the passed in array of data
     * @param ja
     */
    public native void fromFloatArray(float ja[]);

    /**
     * populate the safe array from the passed in array of data
     * @param ja
     */
    public native void fromBooleanArray(boolean ja[]);

    /**
     * populate the safe array from the passed in array of data
     * @param ja
     */
    public native void fromVariantArray(Variant ja[]);

    /**
     * Retrieves the data from the array cast to a Java data type
     * @return char[] character array contained in this collection
     */
    public native char[] toCharArray();

    /**
     * Retrieves the data from the array cast to a Java data type
     * @return int[] int array contained in this collection
     */
    public native int[] toIntArray();

    /**
     * Retrieves the data from the array cast to a Java data type
     * @return short[] short array contained in this collection
     */
    public native short[] toShortArray();

    /**
     * Retrieves the data from the array cast to a Java data type
     * @return double[] double array contained in this colleciton
     */
    public native double[] toDoubleArray();

    /**
     * Retrieves the data from the array cast to a Java data type
     * @return String[] String array contained in this collecition
     */
    public native String[] toStringArray();

    /**
     * Retrieves the data from the array cast to a Java data type
     * @return byte[] byte array contained in this collecition
     */
    public native byte[] toByteArray();

    /**
     * Retrieves the data from the array cast to a Java data type
     * @return float[] array of float contained in this collection
     */
    public native float[] toFloatArray();

    /**
     * Retrieves the data from the array cast to a Java data type
     * @return boolean[] array of booleans contained in this collection
     */
    public native boolean[] toBooleanArray();

    /**
     * Retrieves the data from the array cast to a Java data type
     * @return Variant[] array of variants contained in this collection
     */
    public native Variant[] toVariantArray();

    /**
     * char access
     * @param sa_idx
     * @return single character rpeesentation
     */
    public native char getChar(int sa_idx);

    /**
     * char access
     * @param sa_idx1
     * @param sa_idx2
     * @return single character repesentation
     */
    public native char getChar(int sa_idx1, int sa_idx2);

    /**
     * char access
     * @param sa_idx
     * @param c
     */
    public native void setChar(int sa_idx, char c);

    /**
     * char access
     * @param sa_idx1
     * @param sa_idx2
     * @param c
     */
    public native void setChar(int sa_idx1, int sa_idx2, char c);

    /**
     * char access
     * @param sa_idx
     * @param nelems
     * @param ja
     * @param ja_start
     */
    public native void getChars(int sa_idx, int nelems, char ja[], int ja_start);

    /**
     * char access
     * @param sa_idx
     * @param nelems
     * @param ja
     * @param ja_start
     */
    public native void setChars(int sa_idx, int nelems, char ja[], int ja_start);

    /**
     * int access
     * @param sa_idx
     * @return int stored in array
     */
    public native int getInt(int sa_idx);

    /**
     * int access
     * @param sa_idx1
     * @param sa_idx2
     * @return int stored in array
     */
    public native int getInt(int sa_idx1, int sa_idx2);

    /**
     * int access
     * @param sa_idx
     * @param c
     */
    public native void setInt(int sa_idx, int c);

    /**
     * int access
     * @param sa_idx1
     * @param sa_idx2
     * @param c
     */
    public native void setInt(int sa_idx1, int sa_idx2, int c);

    /**
     * int access
     * @param sa_idx
     * @param nelems
     * @param ja
     * @param ja_start
     */
    public native void getInts(int sa_idx, int nelems, int ja[], int ja_start);

    /**
     * int access
     * @param sa_idx
     * @param nelems
     * @param ja
     * @param ja_start
     */
    public native void setInts(int sa_idx, int nelems, int ja[], int ja_start);

    /**
     * short access
     * @param sa_idx
     * @return short stored in array
     */
    public native short getShort(int sa_idx);

    /**
     * short access
     * @param sa_idx1
     * @param sa_idx2
     * @return short stored in array
     */

⌨️ 快捷键说明

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