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

📄 variant.java

📁 java与windows的com桥,可以用来操作所有的com程序如word或者excel等
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
	 * This would have returned null if the value was VT_EMPTY or if it wasn't
	 * so it would have always returned the same value.
	 * 
	 * @deprecated method never did anything
	 */
	@Deprecated
	public void getEmpty() {
	}

	/**
	 * @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());
		}
	}

	/**
	 * 
	 * @return returns the error value as an int, throws exception if not a
	 *         Error 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());
		}
	}

	/**
	 * @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());
		}
	}

	/**
	 * 
	 * @return returns the float value, throws exception if not a Float 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());
		}
	}

	/**
	 * return the int value held in this variant if it is an int or a short.
	 * Throws for other types.
	 * 
	 * @return int contents of the windows memory
	 * @throws IllegalStateException
	 *             if variant is not of the requested type
	 */
	public int getInt() {
		if (this.getvt() == VariantInt) {
			return getVariantInt();
		} else if (this.getvt() == VariantShort) {
			return getVariantShort();
		} else {
			throw new IllegalStateException(
					"getInt() only legal on Variants of type VariantInt, not "
							+ this.getvt());
		}
	}

	/**
	 * get the content of this variant as an int
	 * 
	 * @return int
	 * @throws IllegalStateException
	 *             if variant is not of the requested type
	 */
	public int getIntRef() {
		if ((this.getvt() & VariantInt) == VariantInt
				&& (this.getvt() & VariantByref) == VariantByref) {
			return getVariantIntRef();
		} else {
			throw new IllegalStateException(
					"getIntRef() only legal on byRef Variants of type VariantInt, not "
							+ this.getvt());
		}
	}

	/**
	 * returns the windows time contained in this Variant to a Java Date. should
	 * return null if this is not a date Variant SF 959382
	 * 
	 * @return java.util.Date returns the date if this is a VariantDate != 0,
	 *         null if it is a VariantDate == 0 and throws an
	 *         IllegalStateException if this isn't a date.
	 * @throws IllegalStateException
	 *             if variant is not of the requested type
	 */
	public Date getJavaDate() {
		Date returnDate = null;
		if (getvt() == VariantDate) {
			double windowsDate = getDate();
			if (windowsDate != 0) {
				returnDate = DateUtilities.convertWindowsTimeToDate(getDate());
			}
		} else {
			throw new IllegalStateException(
					"getJavaDate() only legal on Variants of type VariantDate, not "
							+ this.getvt());
		}
		return returnDate;
	}

	/**
	 * returns the windows time contained in this Variant to a Java Date should
	 * return null if this is not a date reference Variant SF 959382
	 * 
	 * @return java.util.Date
	 */
	public Date getJavaDateRef() {
		double windowsDate = getDateRef();
		if (windowsDate == 0) {
			return null;
		} else {
			return DateUtilities.convertWindowsTimeToDate(windowsDate);
		}
	}

	/**
	 * 64 bit Longs only available on x64. 64 bit long support added 1.14
	 * 
	 * @return returns the value as a long, throws exception if not a Long
	 *         type..
	 * @throws IllegalStateException
	 *             if variant is not of the requested type
	 */
	public long getLong() {
		if (this.getvt() == VariantLongInt) {
			return getVariantLong();
		} else {
			throw new IllegalStateException(
					"getLong() only legal on Variants of type VariantLongInt, not "
							+ this.getvt());
		}
	}

	/**
	 * 64 bit Longs only available on x64. 64 bit long support added 1.14
	 * 
	 * @return returns the value as a long, throws exception if not a long type
	 * @throws IllegalStateException
	 *             if variant is not of the requested type
	 */
	public long getLongRef() {
		if ((this.getvt() & VariantLongInt) == VariantLongInt
				&& (this.getvt() & VariantByref) == VariantByref) {
			return getVariantLongRef();
		} else {
			throw new IllegalStateException(
					"getLongRef() only legal on byRef Variants of type VariantLongInt, not "
							+ this.getvt());
		}
	}

	/**
	 * This method would have returned null if the type was VT_NULL. But because
	 * we return null if the data is not of the right type, this method should
	 * have always returned null
	 * 
	 * @deprecated method never did anything
	 */
	@Deprecated
	public void getNull() {
	}

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

	/**
	 * get the content of this variant as an int
	 * 
	 * @return int
	 * @throws IllegalStateException
	 *             if variant is not of the requested type
	 */
	public short getShortRef() {
		if ((this.getvt() & VariantShort) == VariantShort
				&& (this.getvt() & VariantByref) == VariantByref) {
			return getVariantShortRef();
		} else {
			throw new IllegalStateException(
					"getShortRef() only legal on byRef Variants of type VariantShort, not "
							+ this.getvt());
		}
	}

	/**
	 * 
	 * @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());
		}
	}

	/**
	 * gets the content of the variant as a string ref
	 * 
	 * @return String retrieved from the COM area.
	 * @throws IllegalStateException
	 *             if variant is not of the requested type
	 */
	public String getStringRef() {
		if ((this.getvt() & VariantString) == VariantString
				&& (this.getvt() & VariantByref) == VariantByref) {
			return getVariantStringRef();
		} else {
			throw new IllegalStateException(
					"getStringRef() only legal on byRef Variants of type VariantString, not "
							+ this.getvt());
		}
	}

	/**
	 * Used to get the value from a windows type of VT_VARIANT or a jacob
	 * Variant type of VariantVariant. Added 1.12 pre 6 - VT_VARIANT support is
	 * at an alpha level
	 * 
	 * @return Object a java Object that represents the content of the enclosed
	 *         Variant
	 */
	public Object getVariant() {
		if ((this.getvt() & VariantVariant) == VariantVariant
				&& (this.getvt() & VariantByref) == VariantByref) {
			if (JacobObject.isDebugEnabled()) {
				JacobObject.debug("About to call getVariantVariant()");
			}
			Variant enclosedVariant = new Variant();
			int enclosedVariantMemory = getVariantVariant();
			enclosedVariant.m_pVariant = enclosedVariantMemory;
			Object enclosedVariantAsJava = enclosedVariant.toJavaObject();
			// zero out the reference to the underlying windows memory so that
			// it is still only owned in one place by one java object
			// (this object of type VariantVariant)
			// enclosedVariant.putEmpty(); // don't know if this would have had
			// side effects
			if (JacobObject.isDebugEnabled()) {
				JacobObject
						.debug("Zeroing out enclosed Variant's ref to windows memory");
			}
			enclosedVariant.m_pVariant = 0;
			return enclosedVariantAsJava;
		} else {
			throw new IllegalStateException(
					"getVariant() only legal on Variants of type VariantVariant, not "
							+ this.getvt());
		}
	}

	/**
	 * @deprecated superseded by SafeArray
	 * @return never returns anything
	 * @throws com.jacob.com.NotImplementedException
	 */
	@Deprecated
	public Variant[] getVariantArray() {
		throw new NotImplementedException("Not implemented");
	}

	/**
	 * @return the Variant Array that represents the data in the Variant
	 * @deprecated superseded by SafeArray
	 * @throws com.jacob.com.NotImplementedException
	 */
	@Deprecated
	public Variant[] getVariantArrayRef() {
		throw new NotImplementedException("Not implemented");
	}

	/**
	 * 
	 * @return the value in this Variant as a boolean, null if not a boolean
	 */
	private native boolean getVariantBoolean();

	private native boolean getVariantBooleanRef();

	/**
	 * @return the value in this Variant as a byte, null if not a byte
	 */
	private native byte getVariantByte();

	/**
	 * @return the value in this Variant as a byte, null if not a byte
	 */
	private native byte getVariantByteRef();

	/**
	 * @return the value in this Variant as a long, null if not a long
	 */
	private native long getVariantCurrency();

	/**
	 * @return the value in this Variant as a long, null if not a long
	 */
	private native long getVariantCurrencyRef();

	/**
	 * @return double return the date (as a double) value held in this variant
	 *         (fails on other types?)
	 */
	private native double getVariantDate();

	/**
	 * get the content of this variant as a double representing a date
	 * 
	 * @return double
	 */
	private native double getVariantDateRef();

	/**
	 * @return the value in this Variant as a decimal, null if not a decimal
	 */
	private native Object getVariantDec();

	/**
	 * @return the value in this Variant (byref) as a decimal, null if not a
	 *         decimal
	 */
	private native Object getVariantDecRef();

	/**
	 * @return double get the content of this variant as a double
	 */
	private native double getVariantDouble();

	/**
	 * @return double get the content of this variant as a double
	 */
	private native double getVariantDoubleRef();

	private native int getVariantError();

	private native int getVariantErrorRef();

	/**
	 * @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
	 */
	private native float getVariantFloatRef();

	/**
	 * @return the int value held in this variant (fails on other types?)
	 */
	private native int getVariantInt();

	/**
	 * @return the int value held in this variant (fails on other types?)
	 */
	private native int getVariantIntRef();

	/**
	 * @return the value in this Variant as a long, null if not a long
	 */
	private native long getVariantLong();

	/**
	 * @return the value in this Variant as a long, null if not a long
	 */
	private native long getVariantLongRef();

	/**
	 * get the content of this variant as a short
	 * 
	 * @return short
	 */
	private native short getVariantShort();

	/**
	 * @return short the content of this variant as a short
	 */
	private native short getVariantShortRef();

	/**
	 * Native method that actually extracts a string value from the variant
	 * 
	 * @return
	 */
	private native String getVariantString();

	/**
	 * @return String the content of this variant as a string
	 */
	private native String getVariantStringRef();

	/**
	 * Returns the variant type via a native method call
	 * 
	 * @return short one of the VT_xx types
	 */
	private native short getVariantType();

	/**
	 * Returns the variant type via a native method call. Added 1.12 pre 6 -
	 * VT_VARIANT support is at an alpha level
	 * 
	 * @return Variant one of the VT_Variant types
	 */
	private native int getVariantVariant();

	/**
	 * Reports the type of the underlying Variant object
	 * 
	 * @return returns the variant type as a short, one of the Variantxxx values
	 *         defined as statics in this class. returns VariantNull if not
	 *         initialized
	 * @throws IllegalStateException
	 *             if there is no underlying windows data structure
	 */
	public short getvt() {
		if (m_pVariant != 0) {
			return getVariantType();
		} else {
			throw new IllegalStateException("uninitialized Variant");
		}
	}

	/**
	 * initializes the COM Variant and puts its reference in this instance
	 */
	protected native void init();

	/**
	 * 
	 * @return returns true if the variant is considered null
	 * @throws IllegalStateException
	 *             if there is no underlying windows memory
	 */
	public boolean isNull() {
		getvt();
		return isVariantConsideredNull();
	}

	/**
	 * is the variant null or empty or error or null dispatch
	 * 
	 * @return true if it is null or false if not
	 */
	private native boolean isVariantConsideredNull();

	/**
	 * sets the type to VT_ERROR and the error message to DISP_E_PARAMNOTFOIUND
	 * 
	 * @deprecated replaced by putNoParam()
	 */
	@Deprecated
	public void noParam() {
		putNoParam();
	}

	/**
	 * returns true if the passed in Variant is a constant that should not be
	 * freed
	 * 
	 * @param pVariant
	 * @return boolean that is true if Variant is a type of constant, VT_FALSE,
	 *         VT_TRUE, VT_MISSING, DEFAULT
	 */
	protected boolean objectIsAConstant(Variant pVariant) {
		if (pVariant == VT_FALSE || pVariant == VT_TRUE
				|| pVariant == VT_MISSING || pVariant == DEFAULT) {
			return true;
		} else {
			return false;
		}

	}

	/**
	 * puts a boolean into the variant and sets it's type
	 * 
	 * @param in
	 *            the new value
	 */
	public void putBoolean(boolean in) {
		// verify we aren't released yet
		getvt();
		putVariantBoolean(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);
	}

	/**
	 * pushes a byte into the varaint and sets the type
	 * 
	 * @param in
	 */
	public void putByte(byte in) {

⌨️ 快捷键说明

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