Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* Fixes issues introduced in eclipse-ee4j#1734 (NPE / auto-ack on non wanted classes)
* Fixing issues eclipse-ee4j#1756 (for eclipse-ee4j#1734 PR)

(cherry picked from commit 731a5f0)
  • Loading branch information
laurentschoelens authored and lukasj committed Oct 9, 2023
1 parent 2352161 commit adc839c
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 @@ -156,6 +156,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 @@ -314,6 +315,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 @@ -145,35 +145,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 com.sun.xml.bind.api.impl.NameConverter;
import com.sun.xml.bind.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, 2021 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 @@ -368,9 +368,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 @@ -384,8 +384,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 @@ -641,7 +642,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 @@ -440,8 +440,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 adc839c

Please sign in to comment.