* <element name='foo' type='t' /> to <element ref='foo' />.
*
* This is possible if we already have such declaration to begin with.
*/
private boolean canBeDirectElementRef(TypeRef<T, C> t, QName tn, TypeInfo parentInfo) {
Element te = null;
ClassInfo ci = null;
QName targetTagName = null;
if(t.isNillable() || t.getDefaultValue()!=null) {
// can't put those attributes on <element ref>
return false;
}
if (t.getTarget() instanceof Element) {
te = (Element) t.getTarget();
targetTagName = te.getElementName();
if (te instanceof ClassInfo) {
ci = (ClassInfo)te;
}
}
String nsUri = tn.getNamespaceURI();
if ((!nsUri.equals(uri) && nsUri.length()>0) && (!((parentInfo instanceof ClassInfo) && (((ClassInfo)parentInfo).getTypeName() == null)))) {
return true;
}
// there's a circular reference from an anonymous subtype to a global element
if ((ci != null) && ((targetTagName != null) && (te.getScope() == null))) {
if (targetTagName.getLocalPart().equals(tn.getLocalPart())) {
return true;
}
}