com.sun.tools.xjc.reader.xmlschema.AcknowledgePluginCustomizationBinder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jaxb-xjc Show documentation
Show all versions of jaxb-xjc Show documentation
JAXB Binding Compiler. Contains source code needed for binding customization files into java sources.
In other words: the *tool* to generate java classes for the given xml representation.
/*
* Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package com.sun.tools.xjc.reader.xmlschema;
import com.sun.tools.xjc.reader.xmlschema.bindinfo.BIDeclaration;
import com.sun.tools.xjc.reader.xmlschema.bindinfo.BIXPluginCustomization;
import com.sun.tools.xjc.reader.xmlschema.bindinfo.BindInfo;
import com.sun.xml.xsom.*;
import com.sun.xml.xsom.visitor.XSSimpleTypeVisitor;
import com.sun.xml.xsom.visitor.XSVisitor;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
/**
* Mark as acknowledge every BIXPluginCustomization
* seen in XSComponent and sub-tree.
*/
public class AcknowledgePluginCustomizationBinder extends BindingComponent implements XSVisitor, XSSimpleTypeVisitor {
private final Set visitedComponents = new HashSet<>();
public AcknowledgePluginCustomizationBinder() {
}
/**
* Acknowledge plugin customizations on this component
* and returns true if this is the first time this
* component is visited.
*/
private boolean acknowledge( XSComponent c ) {
if (!visitedComponents.add(c)) {
return false; // already processed
}
XSAnnotation ann = c.getAnnotation(false);
if (ann != null && ann.getAnnotation() instanceof BindInfo) {
for (BIDeclaration decl : ((BindInfo) ann.getAnnotation()).getDecls()) {
if (decl instanceof BIXPluginCustomization) {
decl.markAsAcknowledged();
}
}
}
return true;
}
@Override
public void annotation(XSAnnotation ann) {
}
@Override
public void attGroupDecl(XSAttGroupDecl decl) {
if (acknowledge(decl)) {
attContainer(decl);
}
}
@Override
public void attributeDecl(XSAttributeDecl decl) {
if (acknowledge(decl)) {
decl.getType().visit((XSSimpleTypeVisitor) this);
}
}
@Override
public void attributeUse(XSAttributeUse use) {
if (acknowledge(use)) {
use.getDecl().visit(this);
}
}
@Override
public void complexType(XSComplexType type) {
if (acknowledge(type)) {
// don't need to acknowledge the base type -- it must be global, thus
// it is covered already
type.getContentType().visit(this);
attContainer(type);
}
}
private void attContainer( XSAttContainer cont ) {
for (Iterator extends XSAttGroupDecl> itr = cont.iterateAttGroups(); itr.hasNext(); ) {
itr.next().visit(this);
}
for (Iterator extends XSAttributeUse> itr = cont.iterateDeclaredAttributeUses(); itr.hasNext(); ) {
itr.next().visit(this);
}
XSWildcard wc = cont.getAttributeWildcard();
if (wc!=null) {
wc.visit(this);
}
}
@Override
public void schema(XSSchema schema) {
acknowledge(schema);
}
@Override
public void facet(XSFacet facet) {
acknowledge(facet);
}
@Override
public void notation(XSNotation notation) {
acknowledge(notation);
}
@Override
public void wildcard(XSWildcard wc) {
acknowledge(wc);
}
@Override
public void modelGroupDecl(XSModelGroupDecl decl) {
if (acknowledge(decl)) {
decl.getModelGroup().visit(this);
}
}
@Override
public void modelGroup(XSModelGroup group) {
if (acknowledge(group)) {
for ( int i=0; i