How to test if item value is DateTime in Java

I have an item value that may or may not be of type DateTime; sometimes it is a null “” string.

How in JAVA do I test for this? For instance, the following does not work when

if (doc.getItemValueString(“DateTimeField”).compareTo(“”) == 0){}

because getITemValueString always returns “” if the item is a date.

Subject: How to test if item value is DateTime in Java

You can use the getItemValue() method of the Document class and just test the return value (see below). Or you could just write a wrapper class/method that uses the getItemValueDateTimeArray() method and catch the exceptions.dgg

public class JavaAgent extends AgentBase {

private Session nsess;

public void NotesMain() {

	try {

		this.nsess = super.getSession();

		AgentContext agentContext = this.nsess.getAgentContext();

		Document adocTmp = agentContext.getDocumentContext();



		java.util.AbstractCollection acolValues = adocTmp.getItemValue("$Revisions"); /* should return DateTime objects */

// java.util.AbstractCollection acolValues = adocTmp.getItemValue(“FUBARed”); /* won’t return DateTime objects*/

		if (acolValues.isEmpty()) {

			System.out.println("We have an empty collection - nothing to do!");

		} else {

			java.util.Iterator ait = acolValues.iterator();

			while (ait.hasNext()) {

				Object aobjVal = ait.next();

				if (aobjVal instanceof lotus.domino.DateTime) {

					System.out.println("Got a DateTime object: " + aobjVal);

					((DateTime) aobjVal).recycle();

				} else {

					System.out.println("Got another object: " + aobjVal.getClass().getName());

				}

			}

		}

	} catch (NotesException ne) {

		System.out.println(new StringBuffer(64).append("NotesException ").append(ne.id).append(" - ").append(ne.text));

		ne.printStackTrace();

	} finally {

		try {

			this.nsess.recycle();

			this.nsess = null;

		} catch (NotesException ne) {

			ne.printStackTrace();

		}

		System.runFinalization();

		System.gc();

	}

}

}