Remove RevisionSourceIdentifier
[yangtools.git] / yang / yang-repo-api / src / main / java / org / opendaylight / yangtools / yang / model / repo / api / YinDomSchemaSource.java
index d32ccd06899dd69eedfc49eade2cc157ce5adc50..bac0786482f3424be89ad591ac487e1b7d7f37b9 100644 (file)
@@ -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<String> 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<String> getSymbolicName() {
+            return xmlSchemaSource.getSymbolicName();
+        }
+
         @Override
         protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
             return toStringHelper.add("xmlSchemaSource", xmlSchemaSource);