static SchemaType findBaseType(SchemaType sType) { while (sType.getFullJavaName() == null) sType = sType.getBaseType(); return sType; }
private SchemaType closestBuiltin(SchemaType sType) { while (!sType.isBuiltinType()) sType = sType.getBaseType(); return sType; }
public boolean isSkippedAnonymousType() { SchemaType outerType = getOuterType(); return ((outerType == null) ? false : (outerType.getBaseType() == this || outerType.getContentBasedOnType() == this)); }
/** * Since not all schema types have java types, this skips * over any that don't and gives you the nearest java base type. */ String findJavaType ( SchemaType sType ) { while ( sType.getFullJavaName() == null ) sType = sType.getBaseType(); return sType.getFullJavaName(); }
private boolean derivedFromInteger( SchemaType type ) { int btc = type.getBuiltinTypeCode(); while (btc == SchemaType.BTC_NOT_BUILTIN) { type = type.getBaseType(); btc = type.getBuiltinTypeCode(); } // This depends on the ordering of the constant values, which is not ideal but is easier return btc >= SchemaType.BTC_INTEGER && btc <= SchemaType.BTC_UNSIGNED_BYTE; }
/** * This method will get the base type for the schema type */ private static QName getClosestName(SchemaType sType) { while (sType.getName() == null) sType = sType.getBaseType(); return sType.getName(); }
public boolean isInstanceOf(SchemaType type) { SchemaType myType; if (type.getSimpleVariety() != SchemaType.UNION) { for (myType = instanceType(); myType != null; myType = myType.getBaseType()) if (type == myType) return true; return false; } else { Set ctypes = new HashSet(Arrays.asList(type.getUnionConstituentTypes())); for (myType = instanceType(); myType != null; myType = myType.getBaseType()) if (ctypes.contains(myType)) return true; return false; } }
static void addAnonymousTypesFromRedefinition(SchemaType sType, List result) { while (((SchemaTypeImpl)sType).isRedefinition() && (sType.getDerivationType() == SchemaType.DT_EXTENSION || sType.isSimpleType())) { sType = sType.getBaseType(); SchemaType[] newAnonTypes = sType.getAnonymousTypes(); if (newAnonTypes.length > 0) result.addAll(Arrays.asList(newAnonTypes)); } } }
private boolean hasBase(SchemaType sType) { boolean hasBase; SchemaType baseEnumType = sType.getBaseEnumType(); if (baseEnumType.isAnonymousType() && baseEnumType.isSkippedAnonymousType()) { if (sType.getContentBasedOnType() != null) hasBase = sType.getContentBasedOnType().getBaseType() != baseEnumType; else hasBase = sType.getBaseType() != baseEnumType; } else hasBase = baseEnumType != sType; return hasBase; }
private SchemaProperty[] getDerivedProperties(SchemaType sType) { // We have to see if this is redefined, because if it is we have // to include all properties associated to its supertypes QName name = sType.getName(); if (name != null && name.equals(sType.getBaseType().getName())) { SchemaType sType2 = sType.getBaseType(); // Walk all the redefined types and record any properties // not present in sType, because the redefined types do not // have a generated class to represent them SchemaProperty[] props = sType.getDerivedProperties(); Map propsByName = new LinkedHashMap(); for (int i = 0; i < props.length; i++) propsByName.put(props[i].getName(), props[i]); while (sType2 != null && name.equals(sType2.getName())) { props = sType2.getDerivedProperties(); for (int i = 0; i < props.length; i++) if (!propsByName.containsKey(props[i].getName())) propsByName.put(props[i].getName(), props[i]); sType2 = sType2.getBaseType(); } return (SchemaProperty[]) propsByName.values().toArray(new SchemaProperty[0]); } else return sType.getDerivedProperties(); }
/** * Return the simple type for schema type. If the schema type is already * simple, just return it. If it is a complex type with simple content, * return the simple type it extends. */ static SchemaType getSimpleType(SchemaType st) { assert st.isSimpleType() || st.getContentType() == SchemaType.SIMPLE_CONTENT : st + " does not have simple content."; while (! st.isSimpleType() ) st = st.getBaseType(); return st; }
private static boolean checkAllDerivationsForRestriction(SchemaType baseType, SchemaType derivedType, Collection errors, XmlObject context) { boolean allDerivationsAreRestrictions = true; SchemaType currentType = derivedType; // XMLBEANS-66: if baseType is a union, check restriction is of one of the constituant types Set possibleTypes = null; if (baseType.getSimpleVariety() == SchemaType.UNION) possibleTypes = new HashSet(Arrays.asList(baseType.getUnionConstituentTypes())); // run up the types hierarchy from derived Type to base Type and make sure that all are derived by // restriction. If any are not then this is not a valid restriction. while (!baseType.equals(currentType) && possibleTypes != null && !possibleTypes.contains(currentType)) { if (currentType.getDerivationType() == SchemaType.DT_RESTRICTION) { currentType = currentType.getBaseType(); } else { allDerivationsAreRestrictions = false; errors.add(XmlError.forObject(XmlErrorCodes.PARTICLE_RESTRICTION_NAME_AND_TYPE$TYPE_RESTRICTED, new Object[] { printType(derivedType), printType(baseType), printType(currentType) }, context)); break; } } return allDerivationsAreRestrictions; }
String getBaseClass(SchemaType sType) { SchemaType baseType = findBaseType(sType.getBaseType()); switch (sType.getSimpleVariety()) { case SchemaType.NOT_SIMPLE: // non-simple-content: inherit from base type impl if (!XmlObject.type.equals(baseType)) return baseType.getFullJavaImplName(); return "org.apache.xmlbeans.impl.values.XmlComplexContentImpl"; case SchemaType.ATOMIC: // We should only get called for restrictions assert(! sType.isBuiltinType()); return getAtomicRestrictionType(sType); case SchemaType.LIST: return "org.apache.xmlbeans.impl.values.XmlListImpl"; case SchemaType.UNION: return "org.apache.xmlbeans.impl.values.XmlUnionImpl"; default: throw new IllegalStateException(); } }
private static XmlObject[] _typedArray(XmlObject[] input) { if (input.length == 0) return input; SchemaType commonType = input[0].schemaType(); if (commonType.equals(XmlObject.type) || commonType.isNoType()) return input; for (int i = 1; i < input.length; i++) { if (input[i].schemaType().isNoType()) return input; commonType = commonType.getCommonBaseType(input[i].schemaType()); if (commonType.equals(XmlObject.type)) return input; } Class desiredClass = commonType.getJavaClass(); while (desiredClass == null) { commonType = commonType.getBaseType(); if (XmlObject.type.equals(commonType)) return input; desiredClass = commonType.getJavaClass(); } XmlObject[] result = (XmlObject[])Array.newInstance(desiredClass, input.length); System.arraycopy(input, 0, result, 0, input.length); return result; }
for (SchemaType sType = this; result == null; sType = sType.getBaseType()) result = ((SchemaTypeImpl)sType).createUnattachedSubclass(this);
void printNestedInnerTypes(SchemaType sType, SchemaTypeSystem system) throws IOException { boolean redefinition = sType.getName() != null && sType.getName().equals(sType.getBaseType().getName()); while (sType != null) { SchemaType[] anonTypes = sType.getAnonymousTypes(); for (int i = 0; i < anonTypes.length; i++) { if (anonTypes[i].isSkippedAnonymousType()) printNestedInnerTypes(anonTypes[i], system); else printInnerType(anonTypes[i], system); } // For redefinition other than by extension for complex types, go ahead and print // the anonymous types in the base if (!redefinition || (sType.getDerivationType() != SchemaType.DT_EXTENSION && !sType.isSimpleType())) break; sType = sType.getBaseType(); } }
void printNestedTypeImpls(SchemaType sType, SchemaTypeSystem system) throws IOException { boolean redefinition = sType.getName() != null && sType.getName().equals(sType.getBaseType().getName()); while (sType != null) { SchemaType[] anonTypes = sType.getAnonymousTypes(); for (int i = 0; i < anonTypes.length; i++) { if (anonTypes[i].isSkippedAnonymousType()) printNestedTypeImpls(anonTypes[i], system); else printInnerTypeImpl(anonTypes[i], system, true); } // For redefinition by extension, go ahead and print the anonymous // types in the base if (!redefinition || (sType.getDerivationType() != SchemaType.DT_EXTENSION && !sType.isSimpleType())) break; sType = sType.getBaseType(); } } }
public boolean isAssignableFrom(SchemaType type) { if (type == null || type.isNoType()) return true; if (isNoType()) return false; if (getSimpleVariety() == UNION) { SchemaType[] members = getUnionMemberTypes(); for (int i = 0; i < members.length; i++) if (members[i].isAssignableFrom(type)) return true; } int depth = ((SchemaTypeImpl)type).getBaseDepth() - getBaseDepth(); if (depth < 0) return false; while (depth > 0) { type = type.getBaseType(); depth -= 1; } return (type != null && type.equals(this)); }
String baseInterface = findJavaType(sType.getBaseType());
else if (getOuterType() == null) return "noouter"; else if (getOuterType().getBaseType() == this) prefix = "B="; else if (getOuterType().getContentBasedOnType() == this)