Using ANT 1.6 API only.
diff --git a/plugins/org.eclipse.gmf.xpand.ant/src-ant/org/eclipse/gmf/internal/xpand/ant/MetamodelRegistry.java b/plugins/org.eclipse.gmf.xpand.ant/src-ant/org/eclipse/gmf/internal/xpand/ant/MetamodelRegistry.java
index 7f20d36..d74cb1f 100644
--- a/plugins/org.eclipse.gmf.xpand.ant/src-ant/org/eclipse/gmf/internal/xpand/ant/MetamodelRegistry.java
+++ b/plugins/org.eclipse.gmf.xpand.ant/src-ant/org/eclipse/gmf/internal/xpand/ant/MetamodelRegistry.java
@@ -14,6 +14,7 @@
 import java.util.ArrayList;
 import java.util.Collection;
 
+import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.types.DataType;
 
 public class MetamodelRegistry extends DataType {
@@ -29,7 +30,11 @@
 
 	public Collection<Metamodel> getMetamodels() {
 		if (isReference()) {
-			return ((MetamodelRegistry) getCheckedRef()).getMetamodels();
+			Object referencedObject = getRefid().getReferencedObject();
+			if (referencedObject instanceof MetamodelRegistry) {
+				return ((MetamodelRegistry) referencedObject).getMetamodels();
+			}
+            throw new BuildException(getRefid() + " doesn\'t denote a " + getDataTypeName());
 		}
 		return myMetamodels;
 	}