protected void addSchemaElements(List list, XSDSchema schema) { boolean builtInTypesSchema = XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001.equals(schema.getTargetNamespace()); if (builtInTypesSchema && (fFilter & INCLUDE_PRIMITIVES) > 0) { list.addAll(XSDUtils.getAdvancedPrimitives()); return; } if ((fFilter & INCLUDE_ELEMENT_DECLARATIONS) > 0) { list.addAll(schema.getElementDeclarations()); } if ((fFilter & INCLUDE_TYPES) == 0) { return; } List types = schema.getTypeDefinitions(); Iterator i = types.iterator(); boolean bAdd = false; while (i.hasNext()) { XSDTypeDefinition defn = (XSDTypeDefinition) i.next(); bAdd = (((fFilter & INCLUDE_COMPLEX_TYPES) > 0) && (defn instanceof XSDComplexTypeDefinition) || ((fFilter & INCLUDE_SIMPLE_TYPES) > 0) && (defn instanceof XSDSimpleTypeDefinition)); if (bAdd) { list.add(defn); } } }
/** * Content provider for XSDComplexType. It also handles built-in types. * * <p>Expects an XSDSchema as input. */ public class XSDTypeOrElementContentProvider extends AbstractContentProvider { protected static final List xsdPrimitiveTypes = XSDUtils.getAdvancedPrimitives(); protected static final HashSet xsdPrimitiveTypesNames = new HashSet(xsdPrimitiveTypes.size() + 1); public static final int INCLUDE_SIMPLE_TYPES = 0x1; public static final int INCLUDE_COMPLEX_TYPES = 0x2; public static final int INCLUDE_TYPES = INCLUDE_SIMPLE_TYPES | INCLUDE_COMPLEX_TYPES; public static final int INCLUDE_ELEMENT_DECLARATIONS = 0x4; public static final int INCLUDE_PRIMITIVES = 0x8; public static final int INLCUDE_ALL = 0xff; static { Iterator i = xsdPrimitiveTypes.iterator(); while (i.hasNext()) { XSDNamedComponent component = (XSDNamedComponent) i.next(); xsdPrimitiveTypesNames.add(component.getName()); } } private int fFilter = INLCUDE_ALL; public void setFilter(int filter) { fFilter = filter; } public int getFilter() { return fFilter; } /** * Append the schemas that are present in the object passed to the list indicated. This can deal * with WSDL definitions, XSDSchema, and a List or Array of objects that any of those. * * @param input an object that has or is schema definitions. * @param list the list where the schemas are put. */ public void collectElements(Object input, List list) { if (input == null) { return; } if (input instanceof Definition) { Types types = ((Definition) input).getETypes(); if (types == null) { return; } collectElements(types.getSchemas(), list); return; } if (input instanceof XSDSchema) { XSDSchema schema = (XSDSchema) input; addSchemaElements(list, schema); return; } collectComplex(input, list); } protected void addSchemaElements(List list, XSDSchema schema) { boolean builtInTypesSchema = XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001.equals(schema.getTargetNamespace()); if (builtInTypesSchema && (fFilter & INCLUDE_PRIMITIVES) > 0) { list.addAll(XSDUtils.getAdvancedPrimitives()); return; } if ((fFilter & INCLUDE_ELEMENT_DECLARATIONS) > 0) { list.addAll(schema.getElementDeclarations()); } if ((fFilter & INCLUDE_TYPES) == 0) { return; } List types = schema.getTypeDefinitions(); Iterator i = types.iterator(); boolean bAdd = false; while (i.hasNext()) { XSDTypeDefinition defn = (XSDTypeDefinition) i.next(); bAdd = (((fFilter & INCLUDE_COMPLEX_TYPES) > 0) && (defn instanceof XSDComplexTypeDefinition) || ((fFilter & INCLUDE_SIMPLE_TYPES) > 0) && (defn instanceof XSDSimpleTypeDefinition)); if (bAdd) { list.add(defn); } } } /** Helper method for identifying if a given type is a built-in type. */ public static boolean isBuiltInType(XSDTypeDefinition target) { XSDSchema schema = (XSDSchema) target.eContainer(); if (!XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001.equals(schema.getTargetNamespace())) { return false; } return xsdPrimitiveTypesNames.contains(target.getName()); } }