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;
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;
*
* @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());
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);
id = identifier;
}
- return new Simple(id, source);
+ return new Simple(id, source, symbolicName);
}
/**
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
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;
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
return identifier;
}
+ @Override
+ public Optional<String> getSymbolicName() {
+ return Optional.ofNullable(symbolicName);
+ }
+
@Override
protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
return toStringHelper.add("source", source);
return xmlSchemaSource.getIdentifier();
}
+ @Override
+ public Optional<String> getSymbolicName() {
+ return xmlSchemaSource.getSymbolicName();
+ }
+
@Override
protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
return toStringHelper.add("xmlSchemaSource", xmlSchemaSource);