/** * Return the most specific type below xsd:anySimpleType that this type is derived from. */ private XSTypeDefinition getFoundingType() { XSTypeDefinition founding = typeDeclaration; XSTypeDefinition parent = founding.getBaseType(); if ( parent == null ) // it is xsd:anySimpleType return founding; while (parent.getBaseType() != null) { founding = parent; parent = parent.getBaseType(); } return founding; }
public boolean derivedFromType(XSTypeDefinition ancestor, short derivation) { // REVISIT: implement according to derivation // ancestor is null, return false if (ancestor == null) { return false; } // extract the actual XSTypeDefinition if the given ancestor is a delegate. while (ancestor instanceof XSSimpleTypeDelegate) { ancestor = ((XSSimpleTypeDelegate) ancestor).type; } // ancestor is anyType, return true // anyType is the only type whose base type is itself if (ancestor.getBaseType() == ancestor) { return true; } // recursively get base, and compare it with ancestor XSTypeDefinition type = this; while (type != ancestor && // compare with ancestor type != fAnySimpleType) { // reached anySimpleType type = type.getBaseType(); } return type == ancestor; }
public TypeDefinition getBaseType() { // TODO: Cache per-model?? if (baseType == null && xsTypeDefinition.getBaseType() != null) baseType = createTypeDefinition(xsTypeDefinition.getBaseType()); return baseType; }
public static boolean isExtensionOf(XSTypeDefinition type, XSTypeDefinition baseType) { if (type.equals(baseType)) { return true; } XSTypeDefinition parent = type.getBaseType(); if (parent == null) return false; if (parent == type) { return false; } return isExtensionOf(parent, baseType); }
String generateTypeHierarchy( XSTypeDefinition type, String indent ) { String s = "\n" + indent + "-> '" + type.getName() + "' (" + type.getNamespace() + "'): "; switch ( type.getTypeCategory() ) { case XSTypeDefinition.SIMPLE_TYPE: { s += "simple"; break; } case XSTypeDefinition.COMPLEX_TYPE: { s += "complex"; break; } default: { // cannot happen } } if ( type.getBaseType() != null && type.getBaseType() != type ) { s += generateTypeHierarchy( type.getBaseType(), " " + indent ); } return s; }
public boolean derivedFromType(XSTypeDefinition ancestor, short derivationMethod) { // ancestor is null, retur false if (ancestor == null) return false; // ancestor is anyType, return true if (SchemaGrammar.isAnyType(ancestor)) return true; // recursively get base, and compare it with ancestor XSTypeDefinition type = this; while (type != ancestor && // compare with ancestor type != SchemaGrammar.fAnySimpleType && // reached anySimpleType !SchemaGrammar.isAnyType(type)) { // reached anyType type = type.getBaseType(); } return type == ancestor; }
public boolean derivedFrom(String ancestorNS, String ancestorName, short derivation) { // REVISIT: implement according to derivation // ancestor is null, retur false if (ancestorName == null) return false; // ancestor is anyType, return true if (URI_SCHEMAFORSCHEMA.equals(ancestorNS) && ANY_TYPE.equals(ancestorName)) { return true; } // recursively get base, and compare it with ancestor XSTypeDefinition type = this; while (!(ancestorName.equals(type.getName()) && ((ancestorNS == null && type.getNamespace() == null) || (ancestorNS != null && ancestorNS.equals(type.getNamespace())))) && // compare with ancestor type != fAnySimpleType) { // reached anySimpleType type = type.getBaseType(); } return type != fAnySimpleType; }
public static boolean isSchemaTypesIdentical(XSTypeDefinition typeDefn1, XSTypeDefinition typeDefn2) { boolean typesIdentical = false; String type1Name = typeDefn1.getName(); String type2Name = typeDefn2.getName(); if (("anyType".equals(type1Name) && "anyType".equals(type2Name)) || ("anySimpleType".equals(type1Name) && "anySimpleType".equals(type2Name))) { typesIdentical = true; } if (!typesIdentical && isURIEqual(typeDefn1.getNamespace(), typeDefn2.getNamespace())) { // if targetNamespace of types are same, then check for equality of type names and of the base type if ((type1Name == null && type2Name == null) || (type1Name != null && type1Name.equals(type2Name)) && (isSchemaTypesIdentical(typeDefn1.getBaseType(), typeDefn2.getBaseType()))) { typesIdentical = true; } } return typesIdentical; } // isSchemaTypesIdentical
private short getXercesXSDTypeCodeFor$value(XSTypeDefinition elementType) { if (Constants.NS_XMLSCHEMA.equals(elementType.getNamespace())) { short typeCode = -100; // dummy initializer boolean isxsd11Type = false; // the below 'if else' clauses are written to process few special cases handling few of schema types within PsychoPath XPath engine final String elementTypeName = elementType.getName(); if ("dayTimeDuration".equals(elementTypeName)) { typeCode = PsychoPathTypeHelper.DAYTIMEDURATION_DT; isxsd11Type = true; } else if ("yearMonthDuration".equals(elementTypeName)) { typeCode = PsychoPathTypeHelper.YEARMONTHDURATION_DT; isxsd11Type = true; } return (isxsd11Type) ? typeCode : ((XSSimpleTypeDefinition) elementType).getBuiltInKind(); } else { return getXercesXSDTypeCodeFor$value(elementType.getBaseType()); } } // getXercesXSDTypeCodeFor$value
private int getBaseType(XSTypeDefinition std) { if (std == null) { return XQItemType.XQBASETYPE_ANYSIMPLETYPE; } if (xs_ns.equals(std.getNamespace())) { QName qn = new QName(std.getNamespace(), std.getName()); int type = getBaseTypeForTypeName(qn); logger.trace("getBaseType; returning {} for type {}", type, std.getName()); return type; } return getBaseType(std.getBaseType()); }
public boolean derivedFrom(String ancestorNS, String ancestorName, short derivationMethod) { // ancestor is null, retur false if (ancestorName == null) return false; // ancestor is anyType, return true if (ancestorNS != null && ancestorNS.equals(SchemaSymbols.URI_SCHEMAFORSCHEMA) && ancestorName.equals(SchemaSymbols.ATTVAL_ANYTYPE)) { return true; } // recursively get base, and compare it with ancestor XSTypeDefinition type = this; while (!(ancestorName.equals(type.getName()) && ((ancestorNS == null && type.getNamespace() == null) || (ancestorNS != null && ancestorNS.equals(type.getNamespace())))) && // compare with ancestor type != SchemaGrammar.fAnySimpleType && // reached anySimpleType !SchemaGrammar.isAnyType(type)) { // reached anyType type = (XSTypeDefinition)type.getBaseType(); } return type != SchemaGrammar.fAnySimpleType && !SchemaGrammar.isAnyType(type); }
/** * DOM Level 3 * Checks if a type is derived from another by restriction. See: * http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#TypeInfo-isDerivedFrom * * @param ancestorNS * The namspace of the ancestor type declaration * @param ancestorName * The name of the ancestor type declaration * @param type * The reference type definition * * @return boolean True if the type is derived by restriciton for the * reference type */ private boolean isDerivedByRestriction (String ancestorNS, String ancestorName, XSTypeDefinition type) { XSTypeDefinition oldType = null; while (type != null && type != oldType) { if ((ancestorName.equals(type.getName())) && ((ancestorNS != null && ancestorNS.equals(type.getNamespace())) || (type.getNamespace() == null && ancestorNS == null))) { return true; } oldType = type; type = type.getBaseType(); } return false; }
private static String getSimpleTypesString(XSTypeDefinition et) { StringBuffer typesHierarchy = new StringBuffer(); while (et != null && !"anySimpleType".equals(et.getName()) && !"anyType".equals(et.getName()) && et.getNamespace() != null) { typesHierarchy.append(et.getNamespace().substring(et.getNamespace().lastIndexOf("/") + 1)) .append(":") .append(et.getName()) .append(";"); if (et instanceof XSSimpleType) { XSSimpleType simpleType = (XSSimpleType) et; if (simpleType.getVariety() == XSSimpleTypeDefinition.VARIETY_LIST || simpleType.getVariety() == XSSimpleTypeDefinition.VARIETY_UNION) { XSObjectList list = simpleType.getMemberTypes(); if (list.getLength() > 0) { typesHierarchy.append("{"); for (int i = 0; i < list.getLength(); i++) { typesHierarchy.append(getSimpleTypesString((XSTypeDefinition) list.item(i))); } typesHierarchy.append("}"); } } } et = et.getBaseType(); } return typesHierarchy.toString(); }
type = type.getBaseType();
/** * Create a new JBossXSTypeDefinition * while reading data from a XSTypeDefinition * * @param xt */ public JBossXSTypeDefinition(XSTypeDefinition xt) { super(xt.getName(), xt.getNamespace()); setAnonymous(xt.getAnonymous()); XSTypeDefinition xbase = xt.getBaseType(); if (xbase != null) { if (xbase instanceof JBossXSTypeDefinition == false && !("anyType".equals(xbase.getName()))) baseType = new JBossXSTypeDefinition(xbase); } }
private XSElementDecl findLocallyDeclaredType(QName element, XSCMValidator currentCM, XSTypeDefinition baseType) { XSElementDecl elemDecl = null; if (currentCM != null) { elemDecl = currentCM.findMatchingElemDecl(element, fSubGroupHandler); } if (elemDecl == null) { if (baseType.getTypeCategory() != XSTypeDefinition.SIMPLE_TYPE && baseType != SchemaGrammar.getXSAnyType(fSchemaVersion)) { currentCM = ((XSComplexTypeDecl) baseType).getContentModel(fCMBuilder); return findLocallyDeclaredType(element, currentCM, baseType.getBaseType()); } } return elemDecl; }
private boolean getDBMethods(XSTypeDefinition typed, XSTypeDefinition typeb, OneSubGroup methods, short schemaVersion) { short dMethod = 0, bMethod = 0; while (typed != typeb && !SchemaGrammar.isAnyType(typed)) { if (typed.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) dMethod |= ((XSComplexTypeDecl)typed).fDerivedBy; else dMethod |= XSConstants.DERIVATION_RESTRICTION; typed = typed.getBaseType(); // type == null means the current type is anySimpleType, // whose base type should be anyType if (typed == null) typed = SchemaGrammar.getXSAnyType(schemaVersion); if (typed.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) bMethod |= ((XSComplexTypeDecl)typed).fBlock; } // No derivation relation, or blocked, return false if (typed != typeb || (dMethod & bMethod) != 0) return false; // Remember the derivation methods and blocks, return true. methods.dMethod = dMethod; methods.bMethod = bMethod; return true; }
private void addBaseTypeParts(XSTypeDefinition baseType, List<XSParticle> xsparts) { if (baseType == null) throw MESSAGES.illegalNullArgumentInSchemaMapping("baseType"); if (XSTypeDefinition.COMPLEX_TYPE == baseType.getTypeCategory()) { XSTypeDefinition btype = baseType.getBaseType(); if (btype != null) addBaseTypeParts(btype, xsparts); //Recurse //Just add the particles from this basetype as a ModelGroup sequence XSParticle part = ((XSComplexTypeDefinition)baseType).getParticle(); XSTerm term = part.getTerm(); if (term instanceof XSModelGroup) { JBossXSParticle p = new JBossXSParticle(); p.setTerm(term); xsparts.add(p); } } }
XSTypeDefinition ancestorType = baseSchemaType.getBaseType();
base = base.getBaseType();