// Level level = TreeWalker.setLogging(s_logger.getLevel());
Set foundset = Collections.EMPTY_SET;
if (m_includes != null || m_excludes != null) {
foundset = new HashSet();
}
TreeWalker wlkr = new TreeWalker(null, new SchemaContextTracker());
for (Iterator iter = globals.iterator(); iter.hasNext();) {
OpenAttrBase global = (OpenAttrBase)iter.next();
if (global instanceof INamed) {
// set up the basic global definition extension
GlobalExtension exten = new GlobalExtension(m_extension, global);
String name = ((INamed)global).getName();
boolean exclude = exclset.contains(name);
exten.setRemoved(exclude);
if (exclude) {
foundset.add(name);
}
boolean include = inclset.contains(name);
exten.setIncluded(include);
if (include) {
foundset.add(name);
}
// initialize extensions for full tree of non-excluded global definition components
if (!exten.isRemoved()) {
extendGlobal(builder, wlkr, exten);
} else if (global.type() == SchemaBase.SIMPLETYPE_TYPE ||
global.type() == SchemaBase.COMPLEXTYPE_TYPE) {
setReplacement(((INamed)global).getQName(), null);
}
}
}
// TreeWalker.setLogging(level);
// report any names not found
if (foundset.size() < exclset.size() + inclset.size()) {
Set mergeset = new HashSet();
mergeset.addAll(exclset);
mergeset.addAll(inclset);
for (Iterator iterator = mergeset.iterator(); iterator.hasNext();) {
String name = (String)iterator.next();
if (!foundset.contains(name)) {
vctx.addWarning("Name '" + name + "' not found in schema", this);
}
}
}
// use child customizations to amend the generated extensions
int size = getChildren().size();
for (int i = 0; i < size; i++) {
ComponentCustom custom = (ComponentCustom)getChildren().get(i);
SchemaPath path = custom.buildPath(vctx);
if (path != null) {
if (path.isWildStart()) {
vctx.addError("Top level customizations cannot use wildcard as first step", custom);
} else {
// match only the first path step
OpenAttrBase match = path.partialMatchUnique(0, 0, m_schema);
if (s_logger.isDebugEnabled()) {
if (match == null) {
s_logger.debug("No global schema component found for customization " + custom);
} else {
s_logger.debug("Matched customization " + custom + " to global schema component "
+ SchemaUtils.describeComponent(match));
}
}
if (match != null) {
String name = ((INamed)match).getName();
GlobalExtension exten = (GlobalExtension)match.getExtension();
if (custom.isExcluded()) {
// check if customization applies to descendant of global definition component
if (path.getPathLength() == 1) {
// force exclude if generation skipped by customization
if (exten.isIncluded()) {
vctx.addWarning("Name '" + name
+ "' is on include list for schema, but excluded by customization", custom);
}
exten.setIncluded(false);
exten.setRemoved(true);
} else {
// apply customization to target component extension(s)
applyRemainingCustomizationPath(path, match, custom, vctx);
}
} else {
// check for customization for global excluded at schema level
if (exten.isRemoved()) {
vctx.addWarning("Name '" + name
+ "' is on excludes list for schema, but has a customization", custom);
exten.setRemoved(false);
extendGlobal(builder, wlkr, exten);
}
// check if customization applies to descendant of global definition component
if (path.getPathLength() > 1) {
applyRemainingCustomizationPath(path, match, custom, vctx);
} else {
custom.apply((ComponentExtension)match.getExtension(), vctx);
}
}
}
}
}
}
// flag extensions for facets to be removed from schema
SchemaVisitor visitor = new FacetRemoverVisitor(this);
for (Iterator iter = globals.iterator(); iter.hasNext();) {
OpenAttrBase global = (OpenAttrBase)iter.next();
ComponentExtension exten = (ComponentExtension)global.getExtension();
if (exten != null && !exten.isRemoved()) {
wlkr.walkElement(global, visitor);
}
}
}