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

📄 variant.java

📁 java 与COM组件的连接桥
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
     *
     */
    public void putEmpty(){
    	// verify we aren't released yet
    	getvt();
    	putVariantEmpty();
    }
    
    /**
     * Sets the type to VariantDispatch and sets the value to null
     * Equivalent to VB's nothing
     */
    private native void putVariantNothing();
    
    /**
     * Sets the type to VariantDispatch and sets the value to null
     * Equivalent to VB's nothing
     */
    public void putNothing(){
    	// verify we aren't released yet
    	getvt();
    	putVariantNothing();
    }

    private native int getVariantError();

    /**
     * @return double return the error value held in this variant (fails on other types?)
     * @throws IllegalStateException if variant is not of the requested type
     */
    public int getError(){
    	if (this.getvt() == VariantError){
    		return getVariantError();
    	} else {
    		throw new IllegalStateException(
    				"getError() only legal on Variants of type VariantError, not "+this.getvt());
    	}
    }

    
    private native void putVariantError(int in);
    
    /**
     * puts an error code (I think) into the variant and sets the type
     * @param in
     */
    public void putError(int in){
    	// verify we aren't released yet
    	getvt();
    	putVariantError(in);
    }

    private native double getVariantDouble();

    /**
     * @return double return the double value held in this variant (fails on other types?)
     * @throws IllegalStateException if variant is not of the requested type
     */
    public double getDouble(){
    	if (this.getvt() == VariantDouble){
    		return getVariantDouble();
    	} else {
    		throw new IllegalStateException(
    				"getDouble() only legal on Variants of type VariantDouble, not "+this.getvt());
    	}
    }

    
    private native void putVariantCurrency(long in);
    
    /**
     * puts a value in as a currency and sets the variant type
     * @param in
     */
    public void putCurrency(long in){
    	// verify we aren't released yet
    	getvt();
    	putVariantCurrency(in);
    }

    /** 
     * Puts an object into the Variant -- converts to Dispatch.
     * Acts as a cover for putVariantDispatch();
     * This primarily exists to support jacobgen.
     * This should be deprecated.
     * @see Variant#putDispatch(Dispatch) 
     * @deprecated should use putDispatch()  
     * */
    public void putObject(Object in){ 
    	// this should verify in instanceof Dispatch
    	putVariantDispatch(in); }
    
    /**
     * the JNI implementation for putDispatch() so that 
     * we can screen the incoming dispatches in putDispatch() before this
     * is invoked
     * @param in should be a dispatch object
     */
    private native void putVariantDispatch(Object in);

    private native void putVariantDouble(double in);
    
    public void putDouble(double in){
    	// verify we aren't released yet
    	getvt();
    	putVariantDouble(in);
    }

    /**
     * 
     * @return the value in this Variant as a long, null if not a long
     */
    private native long getVariantCurrency();
    
    /**
     * 
     * @return returns the currency value as a long, throws exception if not a currency type
     * @throws IllegalStateException if variant is not of the requested type
     */
    public long getCurrency(){
    	if (this.getvt() == VariantCurrency){
    		return getVariantCurrency();
    	} else {
    		throw new IllegalStateException(
    				"getCurrency() only legal on Variants of type VariantCurrency, not "+this.getvt());
    	}
    }

    private native void putVariantFloatRef(float in);
    
    /**
     * pushes a float into the variant and sets the type
     * @param in
     */
    public void putFloatRef(float in){
    	// verify we aren't released yet
    	getvt();
    	putVariantFloatRef(in);
    }

    private native void putVariantCurrencyRef(long in);
    
    /**
     * pushes a long into the variant as currency and sets the type
     * @param in
     */
    public void putCurrencyRef(long in){
    	// verify we aren't released yet
    	getvt();
    	putVariantCurrencyRef(in);
    }

    private native void putVariantErrorRef(int in);
    
    /**
     * pushes an error code into the variant by ref and sets the type
     * @param in
     */
    public void putErrorRef(int in){
    	// verify we aren't released yet
    	getvt();
    	putVariantErrorRef(in);
    }

    private native void putVariantBooleanRef(boolean in);

    /**
     * pushes a boolean into the variant by ref and sets the type of the variant to boolean
     * @param in 
     */
    public void putBooleanRef(boolean in){
    	// verify we aren't released yet
    	getvt();
    	putVariantBooleanRef(in);
    }
    
    /**
     * Just a cover for putObject().
     * We shouldn't accept any old random object.
     * This has been left in to support jacobgen.
     * This should be deprecated.
     * @param in
     * @deprecated
     */
    public void putObjectRef(Object in) {
        putObject(in);
    }

    private native void putVariantByteRef(byte in);

    /**
     * pushes a byte into the variant by ref and sets the type
     * @param in
     */
    public void putByteRef(byte in){
    	// verify we aren't released yet
    	getvt();
    	putVariantByteRef(in);
    }
    /**
     * Native method that actually extracts a string value from the variant
     * @return
     */
    private native String getVariantString();
    
    /**
     * 
     * @return string contents of the variant.
     * @throws IllegalStateException if this variant is not of type String
     */
    public String getString(){
    	if (getvt() == Variant.VariantString){
    		return getVariantString();
    	} else {
    		throw new IllegalStateException(
    				"getString() only legal on Variants of type VariantString, not "+this.getvt());
    	}
    }

    private native void putVariantString(String in);

    /**
     * put a string into the variant and set its type
     * @param in
     */
    public void putString(String in){
    	// verify we aren't released yet
    	getvt();
    	putVariantString(in);
    }
    
    private native float getVariantFloatRef();

    /**
     * 
     * @return returns the float value, throws exception if not a currency type
     * @throws IllegalStateException if variant is not of the requested type
     */
    public float getFloatRef(){
    	if ((this.getvt() & VariantFloat) == VariantFloat &&
        		(this.getvt() & VariantByref) == VariantByref) {
        		return getVariantFloatRef();
		} else {
			throw new IllegalStateException(
					"getFloatRef() only legal on byRef Variants of type VariantFloat, not "+this.getvt());
		}
	}


    private native long getVariantCurrencyRef();

    /**
     * 
     * @return returns the currency value as a long, throws exception if not a currency type
     * @throws IllegalStateException if variant is not of the requested type
     */
    public long getCurrencyRef(){
    	if ((this.getvt() & VariantCurrency) == VariantCurrency &&
        		(this.getvt() & VariantByref) == VariantByref) {
        		return getVariantCurrencyRef();
		} else {
			throw new IllegalStateException(
					"getCurrencyRef() only legal on byRef Variants of type VariantCurrency, not "+this.getvt());
		}
	}


    private native int getVariantErrorRef();

    /**
     * 
     * @return returns the error value as an int, throws exception if not a currency type
     * @throws IllegalStateException if variant is not of the requested type
     */
    public int getErrorRef(){
    	if ((this.getvt() & VariantError) == VariantError &&
        		(this.getvt() & VariantByref) == VariantByref) {
        		return getVariantErrorRef();
		} else {
			throw new IllegalStateException(
					"getErrorRef() only legal on byRef Variants of type VariantError, not "+this.getvt());
		}
	}


    private native boolean getVariantBooleanRef();
    
    /**
     * public cover for native method
     * @return the boolean from a booleanRef
     * @throws IllegalStateException if variant is not of the requested type
     */
    public boolean getBooleanRef(){
    	if ((this.getvt() & VariantBoolean) == VariantBoolean &&
        		(this.getvt() & VariantByref) == VariantByref) {
        		return getVariantBooleanRef();
		} else {
			throw new IllegalStateException(
					"getBooleanRef() only legal on byRef Variants of type VariantBoolean, not "+this.getvt());
		}
	}

    private native byte getVariantByteRef();

    /**
     * public cover for native method
     * @return the byte from a booleanRef
     * @throws IllegalStateException if variant is not of the requested type
     */
    public byte getByteRef(){
    	if ((this.getvt() & VariantByte) == VariantByte &&
        		(this.getvt() & VariantByref) == VariantByref) {
        		return getVariantByteRef();
		} else {
			throw new IllegalStateException(
					"getByteRef() only legal on byRef Variants of type VariantByte, not "+this.getvt());
		}
	}

    
    /**
     * attempts to return the contents of this variant as a float
     * (after possible conversion)
     * @deprecated should use changeType() and getFloat() instead
     * @return float
     */
    public float toFloat(){
    	changeType(Variant.VariantFloat);
    	return getFloat();
    }

    private native SafeArray toVariantSafeArray(boolean deepCopy);

    /**
     * By default toSafeArray makes a deep copy due to the fact that this
     * Variant owns the embedded SafeArray and will destroy it when it gc's
     * calls toSafeArray(true).
     */
    public SafeArray toSafeArray() {
    	// verify we haven't been released yet
    	getvt();
        return toSafeArray(true);
    }
    
    /**
     * This lets folk turn into a safe array without a deep copy.
     * Shoudl this API be public?
     * @param deepCopy
     * @return SafeArray constructed
     */
    public SafeArray toSafeArray(boolean deepCopy){
    	// verify we haven't been released yet
    	getvt();
    	return toVariantSafeArray(deepCopy);
    }

    private native void putVariantSafeArrayRef(SafeArray in);

    /**
     * have no idea...
     * @param in
     */
    public void putSafeArrayRef(SafeArray in){
    	// verify we haven't been released yet
    	getvt();
    	putVariantSafeArrayRef(in);
    }
    
    private native void putVariantSafeArray(SafeArray in);


    /**
     * have no idea...
     * @param in
     */
    public void putSafeArray(SafeArray in){
    	// verify we haven't been released yet
    	getvt();
    	putVariantSafeArray(in);
    }
    
    /**
     * sets the type to VT_ERROR and the error message to DISP_E_PARAMNOTFOIUND
     * */
    private native void putVariantNoParam();
    
    /**
     * sets the type to VT_ERROR and the error message to DISP_E_PARAMNOTFOIUND
     * */
    public void putNoParam(){
    	// verify we aren't released yet
    	getvt();
    	putVariantNoParam();
    }

    /**
     * sets the type to VT_ERROR and the error message to DISP_E_PARAMNOTFOIUND
     * @deprecated replaced by putNoParam()
     * */
    public void noParam(){
    	putNoParam();
    }
    /**
     * @deprecated superceded by SafeArray
     * @throws com.jacob.com.NotImplementedException
     */ 
    public void putCharArray(Object in) {
        throw new NotImplementedException("Not implemented");
    }

    /**
     * 
     * @return returns the value as a float if the type is of type float
     */
    private native float getVariantFloat();

    /**
     * @return returns the value as a float if the type is of type float
     * @throws IllegalStateException if variant is not of the requested type
     */
    public float getFloat(){
    	if (this.getvt() == VariantFloat){
    		return getVariantFloat();
    	} else {
    		throw new IllegalStateException(
    				"getFloat() only legal on Variants of type VariantFloat, not "+this.getvt());
    	}
    }

    
    /**
     * fills the Variant with a float and sets the type to float
     * @param in
     */
    private native void putVariantFloat(float in);

    /**
     * fills the Variant with a float and sets the type to float
     * @param in
     */
    public void putFloat(float in){
    	// verify we haven't been released yet
    	getvt();
    	putVariantFloat(in);
    }
    
    /**
     * Dispatch and dispatchRef are treated the same
     * This is a cover for putVariantDispatch().  
     * Dispatch and dispatchRef are treated the same
     * @param in
     */
    public void putDispatchRef(Dispatch in) {
        putVariantDispatch(in);
    }

    /**
     * Dispatch and dispatchRef are treated the same
     * This is just a cover for toDispatch() with a flag check

⌨️ 快捷键说明

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