X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=yang%2Fyang-repo-api%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fmodel%2Frepo%2Fapi%2FYinDomSchemaSource.java;h=bac0786482f3424be89ad591ac487e1b7d7f37b9;hb=bf25c16c89625837be48ee685184707339f487ff;hp=d32ccd06899dd69eedfc49eade2cc157ce5adc50;hpb=c562c0ce956b098e91205ff0fb609f82f5b9ea57;p=yangtools.git diff --git a/yang/yang-repo-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/YinDomSchemaSource.java b/yang/yang-repo-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/YinDomSchemaSource.java index d32ccd0689..bac0786482 100644 --- a/yang/yang-repo-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/YinDomSchemaSource.java +++ b/yang/yang-repo-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/YinDomSchemaSource.java @@ -16,6 +16,7 @@ import static org.opendaylight.yangtools.yang.model.api.YangStmtMapping.SUBMODUL import com.google.common.base.MoreObjects; import com.google.common.base.MoreObjects.ToStringHelper; +import java.util.Optional; import javax.xml.transform.Source; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; @@ -24,7 +25,6 @@ import javax.xml.transform.dom.DOMSource; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.common.Revision; import org.opendaylight.yangtools.yang.common.YangConstants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -52,16 +52,17 @@ public abstract class YinDomSchemaSource implements YinXmlSchemaSource { * * @param identifier Schema source identifier * @param source W3C DOM source + * @param symbolicName Source symbolic name * @return A new {@link YinDomSchemaSource} instance. */ public static @NonNull YinDomSchemaSource create(final @NonNull SourceIdentifier identifier, - final @NonNull DOMSource source) { + final @NonNull DOMSource source, final @Nullable String symbolicName) { final Node root = source.getNode().getFirstChild(); final String rootNs = root.getNamespaceURI(); if (rootNs == null) { // Let whoever is using this deal with this - return new Simple(identifier, source); + return new Simple(identifier, source, symbolicName); } final QName qname = QName.create(rootNs, root.getLocalName()); @@ -80,15 +81,14 @@ public abstract class YinDomSchemaSource implements YinXmlSchemaSource { REVISION_STMT.getLocalName()); if (revisions.getLength() == 0) { // FIXME: is module name important (as that may have changed) - return new Simple(identifier, source); + return new Simple(identifier, source, symbolicName); } final Element revisionStmt = (Element) revisions.item(0); final Attr dateAttr = revisionStmt.getAttributeNode(REVISION_ARG); checkArgument(dateAttr != null, "No revision statement argument found in %s", revisionStmt); - final SourceIdentifier parsedId = RevisionSourceIdentifier.create(nameAttr.getValue(), - Revision.of(dateAttr.getValue())); + final SourceIdentifier parsedId = new SourceIdentifier(nameAttr.getValue(), dateAttr.getValue()); final SourceIdentifier id; if (!parsedId.equals(identifier)) { LOG.debug("Changed identifier from {} to {}", identifier, parsedId); @@ -97,7 +97,7 @@ public abstract class YinDomSchemaSource implements YinXmlSchemaSource { id = identifier; } - return new Simple(id, source); + return new Simple(id, source, symbolicName); } /** @@ -125,7 +125,8 @@ public abstract class YinDomSchemaSource implements YinXmlSchemaSource { throws TransformerException { final YinDomSchemaSource cast = castSchemaSource(xmlSchemaSource); return cast != null ? cast : - create(xmlSchemaSource.getIdentifier(), transformSource(xmlSchemaSource.getSource())); + create(xmlSchemaSource.getIdentifier(), transformSource(xmlSchemaSource.getSource()), + xmlSchemaSource.getSymbolicName().orElse(null)); } @Override @@ -166,7 +167,8 @@ public abstract class YinDomSchemaSource implements YinXmlSchemaSource { final Source source = xmlSchemaSource.getSource(); if (source instanceof DOMSource) { - return create(xmlSchemaSource.getIdentifier(), (DOMSource) source); + return create(xmlSchemaSource.getIdentifier(), (DOMSource) source, + xmlSchemaSource.getSymbolicName().orElse(null)); } return null; @@ -175,10 +177,13 @@ public abstract class YinDomSchemaSource implements YinXmlSchemaSource { private static final class Simple extends YinDomSchemaSource { private final @NonNull SourceIdentifier identifier; private final @NonNull DOMSource source; + private final String symbolicName; - Simple(final @NonNull SourceIdentifier identifier, final @NonNull DOMSource source) { + Simple(final @NonNull SourceIdentifier identifier, final @NonNull DOMSource source, + final @Nullable String symbolicName) { this.identifier = requireNonNull(identifier); this.source = requireNonNull(source); + this.symbolicName = symbolicName; } @Override @@ -191,6 +196,11 @@ public abstract class YinDomSchemaSource implements YinXmlSchemaSource { return identifier; } + @Override + public Optional getSymbolicName() { + return Optional.ofNullable(symbolicName); + } + @Override protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) { return toStringHelper.add("source", source); @@ -230,6 +240,11 @@ public abstract class YinDomSchemaSource implements YinXmlSchemaSource { return xmlSchemaSource.getIdentifier(); } + @Override + public Optional getSymbolicName() { + return xmlSchemaSource.getSymbolicName(); + } + @Override protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) { return toStringHelper.add("xmlSchemaSource", xmlSchemaSource);