X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-rest-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frestconf%2Fimpl%2FRestCodec.java;h=952b6ce1bb0345823e6794bf378a92865c3bf5cf;hb=ab7bfb1d8a4f5c0fb800074c9a8f12caeb35925c;hp=40fba88356e89f924e6c2903e7460102a74d818c;hpb=1f3ee2a2588512476704f3bf1c3528753ad453d5;p=controller.git diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/RestCodec.java b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/RestCodec.java index 40fba88356..952b6ce1bb 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/RestCodec.java +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/RestCodec.java @@ -2,6 +2,7 @@ package org.opendaylight.controller.sal.restconf.impl; import java.net.URI; +import org.opendaylight.controller.sal.core.api.mount.MountInstance; import org.opendaylight.controller.sal.rest.impl.RestUtil; import org.opendaylight.controller.sal.restconf.impl.IdentityValuesDTO.IdentityValue; import org.opendaylight.yangtools.concepts.Codec; @@ -20,8 +21,8 @@ public class RestCodec { private RestCodec() { } - public static final Codec from(TypeDefinition typeDefinition) { - return new ObjectCodec(typeDefinition); + public static final Codec from(TypeDefinition typeDefinition, MountInstance mountPoint) { + return new ObjectCodec(typeDefinition, mountPoint); } @SuppressWarnings("rawtypes") @@ -29,13 +30,18 @@ public class RestCodec { private final Logger logger = LoggerFactory.getLogger(RestCodec.class); - public static final Codec IDENTITYREF_DEFAULT_CODEC = new IdentityrefCodecImpl(); public static final Codec LEAFREF_DEFAULT_CODEC = new LeafrefCodecImpl(); + private final Codec identityrefCodec; - private TypeDefinition type; + private final TypeDefinition type; - private ObjectCodec(TypeDefinition typeDefinition) { + private ObjectCodec(TypeDefinition typeDefinition, MountInstance mountPoint) { type = RestUtil.resolveBaseTypeFrom(typeDefinition); + if (type instanceof IdentityrefTypeDefinition) { + identityrefCodec = new IdentityrefCodecImpl(mountPoint); + } else { + identityrefCodec = null; + } } @SuppressWarnings("unchecked") @@ -43,7 +49,7 @@ public class RestCodec { public Object deserialize(Object input) { try { if (type instanceof IdentityrefTypeDefinition) { - return IDENTITYREF_DEFAULT_CODEC.deserialize(input); + return identityrefCodec.deserialize(input); } else if (type instanceof LeafrefTypeDefinition) { return LEAFREF_DEFAULT_CODEC.deserialize(input); } else { @@ -71,7 +77,7 @@ public class RestCodec { public Object serialize(Object input) { try { if (type instanceof IdentityrefTypeDefinition) { - return IDENTITYREF_DEFAULT_CODEC.serialize(input); + return identityrefCodec.serialize(input); } else if (type instanceof LeafrefTypeDefinition) { return LEAFREF_DEFAULT_CODEC.serialize(input); } else { @@ -98,6 +104,12 @@ public class RestCodec { public static class IdentityrefCodecImpl implements IdentityrefCodec { + private final MountInstance mountPoint; + + public IdentityrefCodecImpl(MountInstance mountPoint) { + this.mountPoint = mountPoint; + } + @Override public IdentityValuesDTO serialize(QName data) { return new IdentityValuesDTO(data.getNamespace().toString(), data.getLocalName(), data.getPrefix()); @@ -107,13 +119,18 @@ public class RestCodec { public QName deserialize(IdentityValuesDTO data) { IdentityValue valueWithNamespace = data.getValuesWithNamespaces().get(0); String namespace = valueWithNamespace.getNamespace(); - URI validNamespace = ControllerContext.getInstance().findNamespaceByModule(namespace); + URI validNamespace; + if (mountPoint != null) { + validNamespace = ControllerContext.getInstance().findNamespaceByModuleName(mountPoint, namespace); + } else { + validNamespace = ControllerContext.getInstance().findNamespaceByModuleName(namespace); + } if (validNamespace == null) { validNamespace = URI.create(namespace); } return QName.create(validNamespace, null, valueWithNamespace.getValue()); } - + } public static class LeafrefCodecImpl implements LeafrefCodec {