/** * Return a collection of all types referenced by the attributes (XSDFeatures) of source. This * method is non-recursive (i.e. the list only contains direct references, not * references-of-references) Will not return null, but may return an empty set. This will not * return a BO reference if the file has been deleted (or just doesn't exist). * * @param source The complex type to examine for references * @return a Collection of XSDComplexTypeDefinition instances -- no duplicates */ public static Collection<XSDTypeDefinition> getReferencedTypes(XSDComplexTypeDefinition source) { if (source == null) { return Collections.emptySet(); } List<XSDTypeDefinition> results = new ArrayList<XSDTypeDefinition>(); XSDFeature element = null; XSDComplexTypeDefinition elementType = null; for (Iterator<XSDParticleContent> i = getChildElements(source).iterator(); i.hasNext(); ) { element = (XSDFeature) i.next(); elementType = getResolvedComplexType(element); if (elementType != null && !results.contains(elementType) && !XSDConstants.isSchemaForSchemaNamespace(elementType.getTargetNamespace())) results.add(elementType); } return results; }
/** * Return a collection of all types referenced by the attributes (XSDFeatures) of source. This * method is non-recursive (i.e. the list only contains direct references, not * references-of-references) Will not return null, but may return an empty set. This will return a * BO reference if the file has been deleted (or just doesn't exist). * * @param source The complex type to examine for references * @param includeAnonymous if true, the returned list will include anonymous inlined types as * well. These are not technically "referenced", however it allows this method to be used as a * way to get all non-primitive types used in any way by source * @return a Collection of XSDTypeDefinition (could be complex or simple type) instances -- no * duplicates */ public static Collection<XSDTypeDefinition> getAllReferencedTypes( XSDComplexTypeDefinition source, boolean includeAnonymous) { if (source == null) { return Collections.emptySet(); } List<XSDTypeDefinition> results = new ArrayList<XSDTypeDefinition>(); XSDTypeDefinition elementType = null; for (Iterator<XSDParticleContent> i = getChildElements(source).iterator(); i.hasNext(); ) { XSDFeature next = (XSDFeature) i.next(); elementType = getResolvedType(next); // Only add non-null, non-duplicate, non-primitive types. If includeAnonymous is false, // anonymous types should be filtered out as well if (elementType != null && !results.contains(elementType) && !XSDConstants.isSchemaForSchemaNamespace(elementType.getTargetNamespace()) && (includeAnonymous || elementType.eContainer() != next)) { results.add(elementType); } } return results; }