Skip to content

Commit

Permalink
Fixes for #1756 (#1766)
Browse files Browse the repository at this point in the history
* Fixes issues introduced in #1734 (NPE / auto-ack on non wanted classes)
* Fixing issues #1756 (for #1734 PR)
  • Loading branch information
laurentschoelens committed Oct 9, 2023
1 parent 8526f2d commit 731a5f0
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 50 deletions.
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 @@ -44,6 +44,7 @@
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.XSAttributeDecl;
import com.sun.xml.xsom.XSAttributeUse;
import com.sun.xml.xsom.XSComponent;
import com.sun.xml.xsom.XSDeclaration;
Expand Down Expand Up @@ -355,7 +356,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 +383,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

0 comments on commit 731a5f0

Please sign in to comment.