import java.io.IOException;
/**
+ * @deprecated class will be removed in Lithium release
+ *
* This class parses JSON elements from a gson JsonReader. It disallows multiple elements of the same name unlike the
* default gson JsonParser."
*/
+@Deprecated
public class JsonParser {
- public JsonElement parse(JsonReader reader) throws JsonIOException, JsonSyntaxException {
+ public JsonElement parse(final JsonReader reader) throws JsonIOException, JsonSyntaxException {
// code copied from gson's JsonParser and Stream classes
- boolean lenient = reader.isLenient();
+ final boolean lenient = reader.isLenient();
reader.setLenient(true);
boolean isEmpty = true;
try {
reader.peek();
isEmpty = false;
return read(reader);
- } catch (EOFException e) {
+ } catch (final EOFException e) {
if (isEmpty) {
return JsonNull.INSTANCE;
}
// The stream ended prematurely so it is likely a syntax error.
throw new JsonSyntaxException(e);
- } catch (MalformedJsonException e) {
+ } catch (final MalformedJsonException e) {
throw new JsonSyntaxException(e);
- } catch (IOException e) {
+ } catch (final IOException e) {
throw new JsonIOException(e);
- } catch (NumberFormatException e) {
+ } catch (final NumberFormatException e) {
throw new JsonSyntaxException(e);
} catch (StackOverflowError | OutOfMemoryError e) {
throw new JsonParseException("Failed parsing JSON source: " + reader + " to Json", e);
}
}
- public JsonElement read(JsonReader in) throws IOException {
+ public JsonElement read(final JsonReader in) throws IOException {
switch (in.peek()) {
case STRING:
return new JsonPrimitive(in.nextString());
case NUMBER:
- String number = in.nextString();
+ final String number = in.nextString();
return new JsonPrimitive(new LazilyParsedNumber(number));
case BOOLEAN:
return new JsonPrimitive(in.nextBoolean());
in.nextNull();
return JsonNull.INSTANCE;
case BEGIN_ARRAY:
- JsonArray array = new JsonArray();
+ final JsonArray array = new JsonArray();
in.beginArray();
while (in.hasNext()) {
array.add(read(in));
in.endArray();
return array;
case BEGIN_OBJECT:
- JsonObject object = new JsonObject();
+ final JsonObject object = new JsonObject();
in.beginObject();
while (in.hasNext()) {
final String childName = in.nextName();
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+/**
+ * @deprecated class will be removed in Lithium release
+ */
@Provider
@Consumes({ Draft02.MediaTypes.DATA + RestconfService.JSON, Draft02.MediaTypes.OPERATION + RestconfService.JSON,
MediaType.APPLICATION_JSON })
WebApplicationException {
try {
return JsonToCompositeNodeReader.read(entityStream);
- } catch (Exception e) {
+ } catch (final Exception e) {
LOG.debug("Error parsing json input", e);
throw new RestconfDocumentedException("Error parsing input: " + e.getMessage(), ErrorType.PROTOCOL,
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+/**
+ * @deprecated class will be removed in Lithium release
+ */
+@Deprecated
class JsonToCompositeNodeReader {
private static final Logger LOG = LoggerFactory.getLogger(JsonToCompositeNodeReader.class);
private static final Splitter COLON_SPLITTER = Splitter.on(':');
}
public static CompositeNodeWrapper read(final InputStream entityStream) throws UnsupportedFormatException {
- JsonParser parser = new JsonParser();
+ final JsonParser parser = new JsonParser();
- JsonElement rootElement = parser.parse(new JsonReader(new InputStreamReader(entityStream)));
+ final JsonElement rootElement = parser.parse(new JsonReader(new InputStreamReader(entityStream)));
if (rootElement.isJsonNull()) {
// no content, so return null to indicate no input
return null;
throw new UnsupportedFormatException("Root element of Json has to be Object");
}
- Set<Entry<String, JsonElement>> entrySetsOfRootJsonObject = rootElement.getAsJsonObject().entrySet();
+ final Set<Entry<String, JsonElement>> entrySetsOfRootJsonObject = rootElement.getAsJsonObject().entrySet();
if (entrySetsOfRootJsonObject.size() != 1) {
throw new UnsupportedFormatException("Json Object should contain one element");
}
- Entry<String, JsonElement> childEntry = entrySetsOfRootJsonObject.iterator().next();
- String firstElementName = childEntry.getKey();
- JsonElement firstElementType = childEntry.getValue();
+ final Entry<String, JsonElement> childEntry = entrySetsOfRootJsonObject.iterator().next();
+ final String firstElementName = childEntry.getKey();
+ final JsonElement firstElementType = childEntry.getValue();
if (firstElementType.isJsonObject()) {
// container in yang
return createStructureWithRoot(firstElementName, firstElementType.getAsJsonObject());
if (firstElementType.isJsonArray()) {
// list in yang
if (firstElementType.getAsJsonArray().size() == 1) {
- JsonElement firstElementInArray = firstElementType.getAsJsonArray().get(0);
+ final JsonElement firstElementInArray = firstElementType.getAsJsonArray().get(0);
if (firstElementInArray.isJsonObject()) {
return createStructureWithRoot(firstElementName, firstElementInArray.getAsJsonObject());
}
}
private static CompositeNodeWrapper createStructureWithRoot(final String rootObjectName, final JsonObject rootObject) {
- CompositeNodeWrapper firstNode = new CompositeNodeWrapper(getNamespaceFor(rootObjectName),
+ final CompositeNodeWrapper firstNode = new CompositeNodeWrapper(getNamespaceFor(rootObjectName),
getLocalNameFor(rootObjectName));
- for (Entry<String, JsonElement> childOfFirstNode : rootObject.entrySet()) {
+ for (final Entry<String, JsonElement> childOfFirstNode : rootObject.entrySet()) {
addChildToParent(childOfFirstNode.getKey(), childOfFirstNode.getValue(), firstNode);
}
return firstNode;
private static void addChildToParent(final String childName, final JsonElement childType,
final CompositeNodeWrapper parent) {
if (childType.isJsonObject()) {
- CompositeNodeWrapper child = new CompositeNodeWrapper(getNamespaceFor(childName),
+ final CompositeNodeWrapper child = new CompositeNodeWrapper(getNamespaceFor(childName),
getLocalNameFor(childName));
parent.addValue(child);
- for (Entry<String, JsonElement> childOfChild : childType.getAsJsonObject().entrySet()) {
+ for (final Entry<String, JsonElement> childOfChild : childType.getAsJsonObject().entrySet()) {
addChildToParent(childOfChild.getKey(), childOfChild.getValue(), child);
}
} else if (childType.isJsonArray()) {
parent.addValue(new EmptyNodeWrapper(getNamespaceFor(childName), getLocalNameFor(childName)));
} else {
- for (JsonElement childOfChildType : childType.getAsJsonArray()) {
+ for (final JsonElement childOfChildType : childType.getAsJsonArray()) {
addChildToParent(childName, childOfChildType, parent);
}
}
} else if (childType.isJsonPrimitive()) {
- JsonPrimitive childPrimitive = childType.getAsJsonPrimitive();
- String value = childPrimitive.getAsString().trim();
+ final JsonPrimitive childPrimitive = childType.getAsJsonPrimitive();
+ final String value = childPrimitive.getAsString().trim();
parent.addValue(new SimpleNodeWrapper(getNamespaceFor(childName), getLocalNameFor(childName),
resolveValueOfElement(value)));
} else {
if (Iterators.size(it) == 1) {
try {
return URI.create(maybeURI);
- } catch (IllegalArgumentException e) {
+ } catch (final IllegalArgumentException e) {
LOG.debug("Value {} couldn't be interpreted as URI.", maybeURI);
}
}
private static Object resolveValueOfElement(final String value) {
// it could be instance-identifier Built-In Type
if (!value.isEmpty() && value.charAt(0) == '/') {
- IdentityValuesDTO resolvedValue = RestUtil.asInstanceIdentifier(value, new PrefixMapingFromJson());
+ final IdentityValuesDTO resolvedValue = RestUtil.asInstanceIdentifier(value, new PrefixMapingFromJson());
if (resolvedValue != null) {
return resolvedValue;
}
}
// it could be identityref Built-In Type therefore it is necessary to look at value as module_name:local_name
- URI namespace = getNamespaceFor(value);
+ final URI namespace = getNamespaceFor(value);
if (namespace != null) {
return new IdentityValuesDTO(namespace.toString(), getLocalNameFor(value), null, value);
}
import org.opendaylight.yangtools.yang.data.api.CompositeNode;
import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
+/**
+ * @deprecated class will be removed in Lithium release
+ */
@Provider
@Produces({ Draft02.MediaTypes.API + RestconfService.JSON, Draft02.MediaTypes.DATA + RestconfService.JSON,
Draft02.MediaTypes.OPERATION + RestconfService.JSON, MediaType.APPLICATION_JSON })
public void writeTo(final StructuredData t, final Class<?> type, final Type genericType, final Annotation[] annotations,
final MediaType mediaType, final MultivaluedMap<String, Object> httpHeaders, final OutputStream entityStream)
throws IOException, WebApplicationException {
- CompositeNode data = t.getData();
+ final CompositeNode data = t.getData();
if (data == null) {
throw new RestconfDocumentedException(Response.Status.NOT_FOUND);
}
- JsonWriter writer = new JsonWriter(new OutputStreamWriter(entityStream, Charsets.UTF_8));
+ final JsonWriter writer = new JsonWriter(new OutputStreamWriter(entityStream, Charsets.UTF_8));
if (t.isPrettyPrintMode()) {
writer.setIndent(" ");
} else {
writer.setIndent("");
}
- JsonMapper jsonMapper = new JsonMapper(t.getMountPoint());
+ final JsonMapper jsonMapper = new JsonMapper(t.getMountPoint());
jsonMapper.write(writer, data, (DataNodeContainer) t.getSchema());
writer.flush();
}
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
+/**
+ * @deprecated class will be removed in Lithium release
+ */
@Provider
@Produces({ Draft02.MediaTypes.API + RestconfService.XML, Draft02.MediaTypes.DATA + RestconfService.XML,
Draft02.MediaTypes.OPERATION + RestconfService.XML, MediaType.APPLICATION_XML, MediaType.TEXT_XML })
final Transformer ret;
try {
ret = FACTORY.newTransformer();
- } catch (TransformerConfigurationException e) {
+ } catch (final TransformerConfigurationException e) {
LOG.error("Failed to instantiate XML transformer", e);
throw new IllegalStateException("XML encoding currently unavailable", e);
}
final Annotation[] annotations, final MediaType mediaType,
final MultivaluedMap<String, Object> httpHeaders, final OutputStream entityStream) throws IOException,
WebApplicationException {
- CompositeNode data = t.getData();
+ final CompositeNode data = t.getData();
if (data == null) {
throw new RestconfDocumentedException(Response.Status.NOT_FOUND);
}
} else {
trans.setOutputProperty(OutputKeys.INDENT, "no");
}
- } catch (RuntimeException e) {
+ } catch (final RuntimeException e) {
throw new RestconfDocumentedException(e.getMessage(), ErrorType.TRANSPORT, ErrorTag.OPERATION_FAILED);
}
final Document domTree = new XmlMapper().write(data, (DataNodeContainer) t.getSchema());
try {
trans.transform(new DOMSource(domTree), new StreamResult(entityStream));
- } catch (TransformerException e) {
+ } catch (final TransformerException e) {
LOG.error("Error during translation of Document to OutputStream", e);
throw new RestconfDocumentedException(e.getMessage(), ErrorType.TRANSPORT, ErrorTag.OPERATION_FAILED);
}
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+/**
+ * @deprecated class will be removed in Lithium release
+ */
@Provider
@Consumes({ Draft02.MediaTypes.DATA + RestconfService.XML, Draft02.MediaTypes.OPERATION + RestconfService.XML,
MediaType.APPLICATION_XML, MediaType.TEXT_XML })
@Override
public Node<?> readFrom(final Class<Node<?>> type, final Type genericType, final Annotation[] annotations,
- MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream)
+ final MediaType mediaType, final MultivaluedMap<String, String> httpHeaders, final InputStream entityStream)
throws IOException, WebApplicationException {
- XmlToCompositeNodeReader xmlReader = new XmlToCompositeNodeReader();
+ final XmlToCompositeNodeReader xmlReader = new XmlToCompositeNodeReader();
try {
return xmlReader.read(entityStream);
} catch (XMLStreamException | UnsupportedFormatException e) {
package org.opendaylight.controller.sal.rest.impl;
import static com.google.common.base.Preconditions.checkArgument;
-
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.opendaylight.controller.sal.restconf.impl.SimpleNodeWrapper;
import org.opendaylight.yangtools.yang.data.api.Node;
+/**
+ * @deprecated class will be removed in Lithium release
+ */
@Deprecated
public class XmlToCompositeNodeReader {
eventReader = xmlInputFactory.createXMLEventReader(entityStream);
if (eventReader.hasNext()) {
- XMLEvent element = eventReader.peek();
+ final XMLEvent element = eventReader.peek();
if (element.isStartDocument()) {
eventReader.nextEvent();
}
private boolean isSimpleNodeEvent(final XMLEvent event) throws XMLStreamException {
checkArgument(event != null, "XML Event cannot be NULL!");
if (event.isStartElement()) {
- XMLEvent innerEvent = skipCommentsAndWhitespace();
+ final XMLEvent innerEvent = skipCommentsAndWhitespace();
if (innerEvent != null && (innerEvent.isCharacters() || innerEvent.isEndElement())) {
return true;
}
private boolean isCompositeNodeEvent(final XMLEvent event) throws XMLStreamException {
checkArgument(event != null, "XML Event cannot be NULL!");
if (event.isStartElement()) {
- XMLEvent innerEvent = skipCommentsAndWhitespace();
+ final XMLEvent innerEvent = skipCommentsAndWhitespace();
if (innerEvent != null) {
if (innerEvent.isStartElement()) {
return true;
private XMLEvent skipCommentsAndWhitespace() throws XMLStreamException {
while (eventReader.hasNext()) {
- XMLEvent event = eventReader.peek();
+ final XMLEvent event = eventReader.peek();
if (event.getEventType() == XMLStreamConstants.COMMENT) {
eventReader.nextEvent();
continue;
}
if (event.isCharacters()) {
- Characters chars = event.asCharacters();
+ final Characters chars = event.asCharacters();
if (chars.isWhiteSpace()) {
eventReader.nextEvent();
continue;
private NodeWrapper<? extends Node<?>> resolveSimpleNodeFromStartElement(final StartElement startElement)
throws XMLStreamException {
checkArgument(startElement != null, "Start Element cannot be NULL!");
- String data = getValueOf(startElement);
+ final String data = getValueOf(startElement);
if (data == null) {
return new EmptyNodeWrapper(getNamespaceFor(startElement), getLocalNameFor(startElement));
}
}
private URI getNamespaceFor(final StartElement startElement) {
- String namespaceURI = startElement.getName().getNamespaceURI();
+ final String namespaceURI = startElement.getName().getNamespaceURI();
return namespaceURI.isEmpty() ? null : URI.create(namespaceURI);
}
private Object resolveValueOfElement(final String value, final StartElement startElement) {
// it could be instance-identifier Built-In Type
if (value.startsWith("/")) {
- IdentityValuesDTO iiValue = RestUtil.asInstanceIdentifier(value, new RestUtil.PrefixMapingFromXml(
+ final IdentityValuesDTO iiValue = RestUtil.asInstanceIdentifier(value, new RestUtil.PrefixMapingFromXml(
startElement));
if (iiValue != null) {
return iiValue;
}
}
// it could be identityref Built-In Type
- String[] namespaceAndValue = value.split(":");
+ final String[] namespaceAndValue = value.split(":");
if (namespaceAndValue.length == 2) {
- String namespace = startElement.getNamespaceContext().getNamespaceURI(namespaceAndValue[0]);
+ final String namespace = startElement.getNamespaceContext().getNamespaceURI(namespaceAndValue[0]);
if (namespace != null && !namespace.isEmpty()) {
return new IdentityValuesDTO(namespace, namespaceAndValue[1], namespaceAndValue[0], value);
}
import org.opendaylight.yangtools.yang.data.api.SimpleNode;
import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
+/**
+ * @deprecated class will be removed in Lithium release
+ */
+@Deprecated
public final class CompositeNodeWrapper implements NodeWrapper<CompositeNode>, CompositeNode {
private MutableCompositeNode compositeNode;
name = new QName(namespace, localName);
}
- List<Node<?>> nodeValues = new ArrayList<>(values.size());
- for (NodeWrapper<?> nodeWrapper : values) {
+ final List<Node<?>> nodeValues = new ArrayList<>(values.size());
+ for (final NodeWrapper<?> nodeWrapper : values) {
nodeValues.add(nodeWrapper.unwrap());
}
compositeNode = NodeFactory.createMutableCompositeNode(name, null, nodeValues, null, null);
import org.opendaylight.yangtools.yang.data.api.Node;
import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
+/**
+ * @deprecated class will be removed in Lithium release
+ */
+@Deprecated
public final class EmptyNodeWrapper implements NodeWrapper<Node<?>>, Node<Void> {
private Node<?> unwrapped;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.Node;
+/**
+ * @deprecated class will be removed in Lithium release
+ */
+@Deprecated
public interface NodeWrapper<T extends Node<?>> {
void setQname(QName name);
import org.opendaylight.yangtools.yang.data.api.SimpleNode;
import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
+/**
+ * @deprecated class will be removed in Lithium release
+ */
+@Deprecated
public final class SimpleNodeWrapper implements NodeWrapper<SimpleNode<?>>, SimpleNode<Object> {
private SimpleNode<Object> simpleNode;
import org.opendaylight.yangtools.yang.data.api.CompositeNode;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+/**
+ * @deprecated class will be removed in Lithium release
+ */
+@Deprecated
public class StructuredData {
private final CompositeNode data;
this.data = data;
this.schema = schema;
this.mountPoint = mountPoint;
- this.prettyPrintMode = preattyPrintMode;
+ prettyPrintMode = preattyPrintMode;
}
public CompositeNode getData() {