BUG-1275: move InstanceIdentifierForXmlCodec 42/8542/3
authorRobert Varga <rovarga@cisco.com>
Wed, 2 Jul 2014 10:03:28 +0000 (12:03 +0200)
committerRobert Varga <rovarga@cisco.com>
Wed, 2 Jul 2014 16:17:16 +0000 (18:17 +0200)
Move the class into the appropriate package and makes it a utility class
without an instance.

Change-Id: Ibaa03e5452fb4890815a11592e8a4787844c32f1
Signed-off-by: Robert Varga <rovarga@cisco.com>
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/InstanceIdentifierForXmlCodec.java [moved from yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/codec/InstanceIdentifierForXmlCodec.java with 92% similarity]
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/XmlDocumentUtils.java

@@ -5,7 +5,7 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-package org.opendaylight.yangtools.yang.data.impl.codec;
+package org.opendaylight.yangtools.yang.data.impl.codec.xml;
 
 import com.google.common.base.Preconditions;
 import com.google.common.base.Splitter;
@@ -31,19 +31,18 @@ import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.w3c.dom.Element;
 
-public class InstanceIdentifierForXmlCodec {
+public final class InstanceIdentifierForXmlCodec {
     private static final Pattern PREDICATE_PATTERN = Pattern.compile("\\[(.*?)\\]");
     private static final Splitter SLASH_SPLITTER = Splitter.on('/');
     private static final Splitter COLON_SPLITTER = Splitter.on(':');
     private static final String SQUOTE = "'";
     private static final String DQUOTE = "\"";
 
-    public static final InstanceIdentifierForXmlCodec INSTANCE_IDENTIFIER_FOR_XML_CODEC = new InstanceIdentifierForXmlCodec();
+    private InstanceIdentifierForXmlCodec() {
 
-    protected InstanceIdentifierForXmlCodec() {
     }
 
-    public InstanceIdentifier deserialize(final Element element, final SchemaContext schemaContext) {
+    public static InstanceIdentifier deserialize(final Element element, final SchemaContext schemaContext) {
         Preconditions.checkNotNull(element, "Value of element for deserialization can't be null");
         Preconditions.checkNotNull(schemaContext,
                 "Schema context for deserialization of instance identifier type can't be null");
@@ -68,7 +67,7 @@ public class InstanceIdentifierForXmlCodec {
         return InstanceIdentifier.create(result);
     }
 
-    public Element serialize(final InstanceIdentifier data, final Element element) {
+    public static Element serialize(final InstanceIdentifier data, final Element element) {
         Preconditions.checkNotNull(data, "Variable should contain instance of instance identifier and can't be null");
         Preconditions.checkNotNull(element, "DOM element can't be null");
         Map<String, String> prefixes = new HashMap<>();
@@ -102,7 +101,7 @@ public class InstanceIdentifierForXmlCodec {
         return predicateStartIndex == -1 ? pathPart : pathPart.substring(0, predicateStartIndex);
     }
 
-    private PathArgument toPathArgument(final String xPathArgument, final Element element, final SchemaContext schemaContext) {
+    private static PathArgument toPathArgument(final String xPathArgument, final Element element, final SchemaContext schemaContext) {
         final QName mainQName = toIdentity(xPathArgument, element, schemaContext);
 
         // predicates
@@ -138,7 +137,7 @@ public class InstanceIdentifierForXmlCodec {
 
     }
 
-    public QName toIdentity(final String xPathArgument, final Element element, final SchemaContext schemaContext) {
+    public static QName toIdentity(final String xPathArgument, final Element element, final SchemaContext schemaContext) {
         final String xPathPartTrimmed = getIdAndPrefixAsStr(xPathArgument).trim();
         final Iterator<String> it = COLON_SPLITTER.split(xPathPartTrimmed).iterator();
 
index fe8b825908b3b7c3e9d2eb6f51f58576a69f357e..a389e679b2cbc3a1df76fc50f2e5152fc634219a 100644 (file)
@@ -8,7 +8,13 @@
 package org.opendaylight.yangtools.yang.data.impl.codec.xml;
 
 import static com.google.common.base.Preconditions.checkState;
-import static org.opendaylight.yangtools.yang.data.impl.codec.InstanceIdentifierForXmlCodec.INSTANCE_IDENTIFIER_FOR_XML_CODEC;
+
+import com.google.common.base.Function;
+import com.google.common.base.Objects;
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+import com.google.common.collect.ImmutableList;
 
 import java.net.URI;
 import java.util.List;
@@ -52,13 +58,6 @@ import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.NodeList;
 
-import com.google.common.base.Function;
-import com.google.common.base.Objects;
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-import com.google.common.base.Strings;
-import com.google.common.collect.ImmutableList;
-
 public class XmlDocumentUtils {
 
     private static class ElementWithSchemaContext {
@@ -239,7 +238,7 @@ public class XmlDocumentUtils {
             }
         } else if (baseType instanceof InstanceIdentifierTypeDefinition) {
             if (nodeValue instanceof InstanceIdentifier) {
-                INSTANCE_IDENTIFIER_FOR_XML_CODEC.serialize((InstanceIdentifier)nodeValue,element);
+                InstanceIdentifierForXmlCodec.serialize((InstanceIdentifier)nodeValue,element);
             } else {
                 Object value = nodeValue;
                 logger.debug("Value of {}:{} is not instance of InstanceIdentifier but is {}", baseType.getQName()
@@ -323,9 +322,9 @@ public class XmlDocumentUtils {
         }
 
         if (schema.getType() instanceof org.opendaylight.yangtools.yang.model.util.InstanceIdentifier) {
-            value = INSTANCE_IDENTIFIER_FOR_XML_CODEC.deserialize(xmlElement,schemaCtx);
+            value = InstanceIdentifierForXmlCodec.deserialize(xmlElement,schemaCtx);
         } else if(schema.getType() instanceof IdentityrefTypeDefinition){
-            value = INSTANCE_IDENTIFIER_FOR_XML_CODEC.toIdentity(xmlElement.getTextContent(), xmlElement, schemaCtx);
+            value = InstanceIdentifierForXmlCodec.toIdentity(xmlElement.getTextContent(), xmlElement, schemaCtx);
         }
 
         if (value == null) {
@@ -345,7 +344,7 @@ public class XmlDocumentUtils {
             value = codec.deserialize(text);
         }
         if (schema.getType() instanceof org.opendaylight.yangtools.yang.model.util.InstanceIdentifier) {
-            value = INSTANCE_IDENTIFIER_FOR_XML_CODEC.deserialize(xmlElement,schemaCtx);
+            value = InstanceIdentifierForXmlCodec.deserialize(xmlElement,schemaCtx);
         }
         if (value == null) {
             value = xmlElement.getTextContent();