📄 variant.java
字号:
/*
* 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;
/**
* The multi-format data type used for all call backs and most communications
* between Java and COM. It provides a single class that can handle all data
* types
*/
public class Variant extends JacobObject implements java.io.Serializable {
/**
* Use this constant for optional parameters
*/
public final static com.jacob.com.Variant DEFAULT;
/**
* Same than {@link #DEFAULT}
*/
public final static com.jacob.com.Variant VT_MISSING;
static {
com.jacob.com.Variant vtMissing = new com.jacob.com.Variant();
vtMissing.noParam();
DEFAULT = vtMissing;
VT_MISSING = vtMissing;
}
/**
* Use for true/false variant parameters
*/
public final static com.jacob.com.Variant VT_TRUE = new com.jacob.com.Variant(
true);
/**
* Use for true/false variant parameters
*/
public final static com.jacob.com.Variant VT_FALSE = new com.jacob.com.Variant(
false);
/**
* Pointer to MS struct.
*/
int m_pVariant = 0;
/** variant's type is empty : equivalent to VB Nothing */
public static final short VariantEmpty = 0;
/** variant's type is null : equivalent to VB Null */
public static final short VariantNull = 1;
/** variant's type is short */
public static final short VariantShort = 2;
/** variant's type is int */
public static final short VariantInt = 3;
/** variant's type is float */
public static final short VariantFloat = 4;
/** variant's type is double */
public static final short VariantDouble = 5;
/** variant's type is currency */
public static final short VariantCurrency = 6;
/** variant's type is date */
public static final short VariantDate = 7;
/** variant's type is string */
public static final short VariantString = 8;
/** variant's type is dispatch */
public static final short VariantDispatch = 9;
/** variant's type is error */
public static final short VariantError = 10;
/** variant's type is boolean */
public static final short VariantBoolean = 11;
/** variant's type is variant it encapsulate another variant */
public static final short VariantVariant = 12;
/** variant's type is object */
public static final short VariantObject = 13;
/** variant's type is byte */
public static final short VariantByte = 17;
/** @todo */
public static final short VariantTypeMask = 4095;
/** variant's type is array */
public static final short VariantArray = 8192;
/** variant's type is a reference (to IDispatch?) */
public static final short VariantByref = 16384;
/** @return the value of this variant as an int */
public native int toInt();
/** @return the value of this variant as a date */
public native double toDate();
/** @return the value of this variant as boolean */
public native boolean toBoolean();
/** @return the value of this variant as an enumeration (java style) */
public native EnumVariant toEnumVariant();
/** As far as I can tell : this does absolutely nothing */
public native void getNull();
/** Set this Variant's type to VT_NULL (the VB equivalent of NULL) */
public native void putNull();
/**
* @deprecated No longer used
* @return null !
*/
public native Variant cloneIndirect();
/** @return the content of this variant as a double */
public native double toDouble();
/**
* @return the content of this variant as a long reprensenting a monetary
* amount
*/
public native long toCurrency();
/**
* @deprecated superceded by SafeArray
* @param in
* doesn't matter because this method does nothing
* @throws com.jacob.com.ComFailException
*/
public void putVariantArray(Variant[] in) {
throw new ComFailException("Not implemented");
}
/**
* @deprecated superceded by SafeArray
* @return never returns
* @throws com.jacob.com.ComFailException
*/
public Variant[] getVariantArray() {
throw new ComFailException("Not implemented");
}
/**
* @deprecated superceded by SafeArray
* @param in
* doesn't matter because this method does nothing
* @throws com.jacob.com.ComFailException
*/
public void putByteArray(Object in) {
throw new ComFailException("Not implemented");
}
/**
* set the content of this variant to a short (VT_I2|VT_BYREF)
* @param in
*/
public native void putShortRef(short in);
/**
* set the content of this variant to an int (VT_I4|VT_BYREF)
* @param in
*/
public native void putIntRef(int in);
/**
* set the content of this variant to a double (VT_R8|VT_BYREF)
* @param in
*/
public native void putDoubleRef(double in);
/**
* set the content of this variant to a date (VT_DATE|VT_BYREF)
* @param in
*/
public native void putDateRef(double in);
/**
* set the content of this variant to a string (VT_BSTR|VT_BYREF)
* @param in
*/
public native void putStringRef(String in);
/**
* get the content of this variant as a short
* @return short
*/
public native short getShortRef();
/**
* get the content of this variant as an int
* @return int
*/
public native int getIntRef();
/**
* set the content of this variant to a short (VT_I2)
* @param in
*/
public native void putShort(short in);
/**
* get the content of this variant as a short
* @return short
*/
public native short getShort();
/**
* get the content of this variant as a double
* @return double
*/
public native double getDoubleRef();
/**
* get the content of this variant as a double representing a date
* @return double
*/
public native double getDateRef();
/**
* get the content of this variant as a string
* @return String
*/
public native String getStringRef();
/**
* @return never returns anything
* @throws com.jacob.com.ComFailException
* @deprecated superceded by SafeArray
*/
public Object toCharArray() {
throw new ComFailException("Not implemented");
}
/**
* Clear the content of this variant
*/
public native void VariantClear();
/**
* @return the content of this variant as a Dispatch object
*/
public native Dispatch toDispatch();
/**
* this returns null
* @return ?? comment says null?
*/
public native Object clone();
/**
* attempts to return the content of this variant as a string
* @return String
*/
public native String toString();
/**
* return the int value held in this variant (fails on other types?)
* @return int
*/
public native int getInt();
/**
* return the date (as a double) value held in this variant (fails on other
* types?)
* @return double
*/
public native double getDate();
/**
* set the value of this variant
* @param in
*/
public native void putInt(int in);
/**
* set the value of this variant
* @param in
*/
public native void putDate(double in);
/**
* attempts to return the content of this variant as a double
* @return byte
*/
public native byte toByte();
/**
* same as {@link #toDispatch()}
* @return this object as a dispatch
*/
public Object getDispatch() {
return toDispatch();
}
/**
* same as {@link #putObject(Object)}
* @param in
*/
public void putDispatch(Object in) {
putObject(in);
}
public native boolean getBoolean();
public native byte getByte();
public native void putBoolean(boolean in);
public native void putByte(byte in);
public native int toError();
public Object toObject() {
return toDispatch();
}
public native void getEmpty();
public native void putEmpty();
public native int getError();
public native void putError(int in);
public native double getDouble();
public Object getObject() {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -