import java.util.Date;
import java.util.Iterator;
import java.util.List;
+import javax.annotation.Nullable;
import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
import org.opendaylight.netconf.md.sal.rest.schema.SchemaExportContext;
private static final Logger LOG = LoggerFactory.getLogger(ParserIdentifier.class);
+ private ParserIdentifier() {
+ throw new UnsupportedOperationException("Util class.");
+ }
+
/**
* Make {@link InstanceIdentifierContext} from identifier.
*
* - {@link SchemaContext}
* @return {@link InstanceIdentifierContext}
*/
- public static InstanceIdentifierContext<?> toInstanceIdentifier(final String identifier,
+ public static InstanceIdentifierContext<?> toInstanceIdentifier(@Nullable final String identifier,
final SchemaContext schemaContext) {
final YangInstanceIdentifier deserialize;
- if (identifier.contains(RestconfConstants.MOUNT)) {
+ if (identifier != null && identifier.contains(RestconfConstants.MOUNT)) {
final String mountPointId = identifier.substring(0, identifier.indexOf("/" + RestconfConstants.MOUNT));
deserialize = IdentifierCodec.deserialize(mountPointId, schemaContext);
} else {
return new InstanceIdentifierContext<SchemaNode>(deserialize, child.getDataSchemaNode(), null, schemaContext);
}
+ /**
+ * Make {@link String} from {@link YangInstanceIdentifier}
+ *
+ * @param instanceIdentifier
+ * @param schemaContext
+ * @return
+ */
+ public static String stringFromYangInstanceIdentifier(final YangInstanceIdentifier instanceIdentifier,
+ final SchemaContext schemaContext) {
+ return IdentifierCodec.serialize(instanceIdentifier, schemaContext);
+ }
+
/**
* Make a {@link QName} from identifier
*
* @return {@link QName}
*/
public static QName makeQNameFromIdentifier(final String identifier) {
+ // check if more than one slash is not used as path separator
+ if (identifier.contains(
+ String.valueOf(RestconfConstants.SLASH).concat(String.valueOf(RestconfConstants.SLASH)))) {
+ LOG.debug("URI has bad format. It should be \'moduleName/yyyy-MM-dd\' " + identifier);
+ throw new RestconfDocumentedException(
+ "URI has bad format. End of URI should be in format \'moduleName/yyyy-MM-dd\'", ErrorType.PROTOCOL,
+ ErrorTag.INVALID_VALUE);
+ }
+
final int mountIndex = identifier.indexOf(RestconfConstants.MOUNT);
String moduleNameAndRevision = "";
if (mountIndex >= 0) {
- moduleNameAndRevision = identifier.substring(mountIndex + RestconfConstants.MOUNT.length());
+ moduleNameAndRevision = identifier.substring(mountIndex + RestconfConstants.MOUNT.length())
+ .replaceFirst(String.valueOf(RestconfConstants.SLASH), "");
} else {
moduleNameAndRevision = identifier;
}
- final Splitter splitter = Splitter.on("/").omitEmptyStrings();
+ final Splitter splitter = Splitter.on(RestconfConstants.SLASH);
final Iterable<String> split = splitter.split(moduleNameAndRevision);
- final List<String> pathArgs = Lists.<String> newArrayList(split);
- if (pathArgs.size() < 2) {
+ final List<String> pathArgs = Lists.newArrayList(split);
+ if (pathArgs.size() != 2) {
LOG.debug("URI has bad format. It should be \'moduleName/yyyy-MM-dd\' " + identifier);
throw new RestconfDocumentedException(
"URI has bad format. End of URI should be in format \'moduleName/yyyy-MM-dd\'", ErrorType.PROTOCOL,
final StringBuilder pathBuilder = new StringBuilder();
while (componentIter.hasNext()) {
final String current = componentIter.next();
- pathBuilder.append("/");
- pathBuilder.append(current);
+
if (RestconfConstants.MOUNT.equals(current)) {
+ pathBuilder.append("/");
+ pathBuilder.append(RestconfConstants.MOUNT);
break;
}
+
+ if (pathBuilder.length() != 0) {
+ pathBuilder.append("/");
+ }
+
+ pathBuilder.append(current);
}
final InstanceIdentifierContext<?> point = ParserIdentifier
.toInstanceIdentifier(pathBuilder.toString(), schemaContext);