Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for #1756 #1766

Merged
merged 4 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ public boolean run(Outline model, Options opt, ErrorHandler errorHandler) throws

group.scd("x-schema::"+(tns.equals("")?"":"tns"));
group._attribute("if-exists", true);
group._attribute("auto-acknowledge", true);
SchemaBindings schemaBindings = group.schemaBindings();
schemaBindings.map(false);
if (ps.packageNames.size() == 1) {
Expand Down Expand Up @@ -337,6 +338,7 @@ public OutlineAdaptor(XSComponent schemaComponent, OutlineType outlineType,
private void buildBindings(Bindings bindings) {
bindings.scd(schemaComponent.apply(SCD));
bindings._attribute("if-exists", true);
bindings._attribute("auto-acknowledge", true);
outlineType.bindingsBuilder.build(this, bindings);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,35 +141,43 @@ private void apply(Collection<? extends XSComponent> contextNode) {
errorReceiver.error( itr.next().getLocator(), Messages.format(Messages.ERR_SCD_MATCHED_MULTIPLE_NODES_SECOND) );
}

// apply bindings to the target
for (Element binding : bindings) {
for (Element item : DOMUtils.getChildElements(binding)) {
String localName = item.getLocalName();

if ("bindings".equals(localName))
continue; // this should be already in Target.bindings of some SpecVersion.

try {
new DOMForestScanner(forest).scan(item,loader);
BIDeclaration decl = (BIDeclaration)unmarshaller.getResult();

// add this binding to the target
XSAnnotation ann = target.getAnnotation(true);
BindInfo bi = (BindInfo)ann.getAnnotation();
if(bi==null) {
bi = new BindInfo();
ann.setAnnotation(bi);
Ring old = Ring.begin();
try {
// apply bindings to the target
for (Element binding : bindings) {
for (Element item : DOMUtils.getChildElements(binding)) {
String localName = item.getLocalName();

if ("bindings".equals(localName))
continue; // this should be already in Target.bindings of some SpecVersion.

try {
new DOMForestScanner(forest).scan(item,loader);
BIDeclaration decl = (BIDeclaration)unmarshaller.getResult();

// add this binding to the target
XSAnnotation ann = target.getAnnotation(true);
BindInfo bi = (BindInfo)ann.getAnnotation();
if(bi==null) {
bi = new BindInfo();
ann.setAnnotation(bi);
}
bi.addDecl(decl);
if (src.getAttributeNode("auto-acknowledge") != null) {
target.visit(Ring.get(AcknowledgePluginCustomizationBinder.class));
}
} catch (SAXException e) {
// the error should have already been reported.
} catch (JAXBException e) {
// if validation didn't fail, then unmarshalling can't go wrong
throw new AssertionError(e);
}
bi.addDecl(decl);
target.visit(Ring.get(AcknowledgePluginCustomizationBinder.class));
} catch (SAXException e) {
// the error should have already been reported.
} catch (JAXBException e) {
// if validation didn't fail, then unmarshalling can't go wrong
throw new AssertionError(e);
}
}
} finally {
Ring.end(old);
}

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,9 @@
import com.sun.tools.xjc.reader.xmlschema.bindinfo.BindInfo;
import com.sun.tools.xjc.util.CodeModelClassFactory;
import com.sun.tools.xjc.util.ErrorReceiverFilter;
import com.sun.xml.xsom.*;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use single class imports, please

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, and fixed IDE config 😄

import org.glassfish.jaxb.core.api.impl.NameConverter;
import org.glassfish.jaxb.core.v2.util.XmlFactory;
import com.sun.xml.xsom.XSAnnotation;
import com.sun.xml.xsom.XSAttributeUse;
import com.sun.xml.xsom.XSComponent;
import com.sun.xml.xsom.XSDeclaration;
import com.sun.xml.xsom.XSParticle;
import com.sun.xml.xsom.XSSchema;
import com.sun.xml.xsom.XSSchemaSet;
import com.sun.xml.xsom.XSSimpleType;
import com.sun.xml.xsom.XSTerm;
import com.sun.xml.xsom.XSType;
import com.sun.xml.xsom.XSWildcard;
import com.sun.xml.xsom.util.XSFinder;

import org.xml.sax.Locator;
Expand Down Expand Up @@ -355,7 +345,7 @@ private void processPackageJavadoc( XSSchema s ) {
*/
public BindInfo getOrCreateBindInfo( XSComponent schemaComponent ) {

BindInfo bi = _getBindInfoReadOnly(schemaComponent);
BindInfo bi = _getBindInfoReadOnly(schemaComponent, false);
if(bi!=null) return bi;

// XSOM is read-only, so we cannot add new annotations.
Expand All @@ -382,44 +372,69 @@ public BindInfo getOrCreateBindInfo( XSComponent schemaComponent ) {
* will be returned.
*/
public BindInfo getBindInfo( XSComponent schemaComponent ) {
BindInfo bi = _getBindInfoReadOnly(schemaComponent);
BindInfo bi = _getBindInfoReadOnly(schemaComponent, false);
if(bi!=null) return bi;
else return emptyBindInfo;
}
/**
* Gets the documentation object associated to a schema component.
*
* @return
* return the documentation tag for the given component, null if none found
*/
public String getDocumentation( XSComponent schemaComponent ) {
BindInfo bi = _getBindInfoReadOnly(schemaComponent, true);
if (bi != null) {
String doc = bi.getDocumentation();
return doc == null ? null : doc.trim();
}
return null;
}

/**
* Gets the BindInfo object associated to a schema component.
*
* @return
* null if no bind info is associated to this schema component.
*/
private BindInfo _getBindInfoReadOnly( XSComponent schemaComponent ) {
private BindInfo _getBindInfoReadOnly( XSComponent schemaComponent, boolean extended ) {

BindInfo bi = externalBindInfos.get(schemaComponent);
if(bi!=null) return bi;

XSAnnotation annon = _getXSAnnotation(schemaComponent);
if(annon!=null) {
bi = (BindInfo)annon.getAnnotation();
if(bi!=null) {
if(bi.getOwner()==null)
bi.setOwner(this,schemaComponent);
return bi;
}
XSAnnotation annon = _getXSAnnotation(schemaComponent, extended);
if (annon != null) {
return (BindInfo) annon.getAnnotation();
}

return null;
}

private XSAnnotation _getXSAnnotation(XSComponent schemaComponent) {
private XSAnnotation _getXSAnnotation(XSComponent schemaComponent, boolean extended) {
XSAnnotation annon = schemaComponent.getAnnotation();
if (annon != null) {
return annon;
return enhanceBindInfo(annon, schemaComponent);
}
if (schemaComponent instanceof XSParticle) {
annon = ((XSParticle) schemaComponent).getTerm().getAnnotation();
} else if (schemaComponent instanceof XSAttributeUse) {
annon = ((XSAttributeUse) schemaComponent).getDecl().getAnnotation();
if (extended) {
if (schemaComponent instanceof XSParticle) {
XSTerm term = ((XSParticle) schemaComponent).getTerm();
return enhanceBindInfo(term.getAnnotation(), term);
} else if (schemaComponent instanceof XSAttributeUse) {
XSAttributeDecl decl = ((XSAttributeUse) schemaComponent).getDecl();
return enhanceBindInfo(decl.getAnnotation(), decl);
}
}
return null;
}

private XSAnnotation enhanceBindInfo(XSAnnotation annon, XSComponent schemaComponent) {
if (annon != null) {
BindInfo bi = (BindInfo) annon.getAnnotation();
if (bi != null) {
if (bi.getOwner() == null) {
bi.setOwner(this, schemaComponent);
}
}
}
return annon;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 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
Expand Down Expand Up @@ -366,9 +366,10 @@ public void queueBuild( XSComponent sc, CElement bean ) {
private void addSchemaFragmentJavadoc( CClassInfo bean, XSComponent sc ) {

// first, pick it up from <documentation> if any.
String doc = builder.getBindInfo(sc).getDocumentation();
if(doc!=null)
String doc = builder.getDocumentation(sc);
if (doc != null) {
append(bean, doc);
}

// then the description of where this component came from
Locator loc = sc.getLocator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,9 @@ private TypeUse find( XSSimpleType type ) {
}

String documentation = "";
if (info.getDocumentation() != null && info.getDocumentation().length() > 0) {
documentation = info.getDocumentation().trim();
String extDocumentation = builder.getDocumentation(type);
if (extDocumentation != null) {
documentation = extDocumentation;
}

// see if this type should be mapped to a type-safe enumeration by default.
Expand Down Expand Up @@ -648,7 +649,7 @@ private List<CEnumConstant> buildCEnumConstants(XSRestrictionSimpleType type, bo

for( XSFacet facet : type.getDeclaredFacets(XSFacet.FACET_ENUMERATION)) {
String name=null;
String mdoc=builder.getBindInfo(facet).getDocumentation().trim();
String mdoc= builder.getDocumentation(facet);

if(!enums.add(facet.getValue().value))
continue; // ignore the 2nd occasion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,7 @@ public CPropertyInfo createElementOrReferenceProperty(
* Common finalization of {@link CPropertyInfo} for the create***Property methods.
*/
private <T extends CPropertyInfo> T wrapUp(T prop, XSComponent source) {
prop.javadoc = concat(javadoc,
getBuilder().getBindInfo(source).getDocumentation());
prop.javadoc = concat(javadoc, getBuilder().getDocumentation(source));
if (prop.javadoc == null) {
prop.javadoc = "";
} else {
Expand Down