<artifactId>yang-data-impl</artifactId>
<version>2.0.3</version>
</dependency>
-
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>dom4j</groupId>
+ <artifactId>dom4j</artifactId>
+ <version>1.6.1</version>
+ </dependency>
+ <dependency>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ <version>2.7</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.ccsdk.sli.plugins</groupId>
+ <artifactId>restapi-call-node-provider</artifactId>
+ <version>0.3.0-SNAPSHOT</version>
+ </dependency>
</dependencies>
</project>
*/
public class Annotation {
+ /**
+ * Name of the annotation.
+ */
private String name;
+
+ /**
+ * Value of the annotation.
+ */
private String value;
/**
* Representation of data format.
*/
public enum DataFormat {
+
+ /**
+ * XML data format.
+ */
XML,
+
+ /**
+ * JSON data format.
+ */
JSON
}
*/
public abstract class DataFormatSerializer {
+ /**
+ * Data format type of the serializer.
+ */
private DataFormat dataFormat;
+
+ /**
+ * Data format serializer context.
+ */
private DataFormatSerializerContext serializerContext;
/**
* Creates an instance of data format serializer.
*
- * @param dataFormat type of data format
- * @param serializerContext data format serializer context
+ * @param d type of data format
+ * @param s data format serializer context
*/
- protected DataFormatSerializer(DataFormat dataFormat,
- DataFormatSerializerContext serializerContext) {
- this.dataFormat = dataFormat;
- this.serializerContext = serializerContext;
+ protected DataFormatSerializer(DataFormat d,
+ DataFormatSerializerContext s) {
+ this.dataFormat = d;
+ this.serializerContext = s;
}
/**
package org.onap.ccsdk.sli.plugins.yangserializers.dfserializer;
+import org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.PropertiesNodeSerializer;
+
import java.util.Map;
/**
*/
public class DataFormatSerializerContext {
+ /**
+ * Data format listener.
+ */
private Listener listener;
+
+ /**
+ * URI corresponding to the instance identifier.
+ */
private String uri;
+
+ /**
+ * Protocol annotation.
+ */
private Map<String, String> protocolAnnotation;
+ /**
+ * Properties node serializer.
+ */
+ private PropertiesNodeSerializer propNodeSerializer;
+
/**
* Creates an instance of data format serializer context.
*
- * @param listener data format listener
- * @param uri URI corresponding to instance identifier
- * @param protocolAnnotation protocol annotations
+ * @param l data format listener
+ * @param u URI corresponding to instance identifier
+ * @param p protocol annotations
+ * @param s properties node serializer
*/
- public DataFormatSerializerContext(Listener listener, String uri,
- Map<String, String> protocolAnnotation) {
- this.listener = listener;
- this.uri = uri;
- this.protocolAnnotation = protocolAnnotation;
+ public DataFormatSerializerContext(Listener l, String u,
+ Map<String, String> p,
+ PropertiesNodeSerializer s) {
+ listener = l;
+ uri = u;
+ protocolAnnotation = p;
+ propNodeSerializer = s;
}
/**
- * Retruns data format listener.
+ * Returns the data format listener.
*
* @return data format listener
*/
}
/**
- * Returns URI.
+ * Returns the URI.
*
* @return URI
*/
}
/**
- * Returns protocol annotations.
+ * Returns the protocol annotations.
*
* @return protocol annotations
*/
public Map<String, String> getProtocolAnnotation() {
return protocolAnnotation;
}
+
+ /**
+ * Returns the properties node serializer.
+ *
+ * @return properties node serializer
+ */
+ public PropertiesNodeSerializer getPropNodeSerializer() {
+ return propNodeSerializer;
+ }
}
\ No newline at end of file
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - CCSDK
+ * ================================================================================
+ * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.ccsdk.sli.plugins.yangserializers.dfserializer;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.NodeType;
+
+
+/**
+ * Representation of default implementation of JSON listener.
+ */
+public class DefaultJsonListener implements JsonListener {
+
+ /**
+ * Serializer helper to convert to properties node.
+ */
+ private SerializerHelper serializerHelper;
+
+ /**
+ * Name of the current JSON node.
+ */
+ private String name;
+
+ /**
+ * Module name of the current JSON node.
+ */
+ private String modName;
+
+ /**
+ * Creates an instance of default json listener with its serializer helper.
+ *
+ * @param serializerHelper serializer helper
+ */
+ public DefaultJsonListener(SerializerHelper serializerHelper) {
+ this.serializerHelper = serializerHelper;
+ }
+
+ @Override
+ public void enterJsonNode(String nodeName, JsonNode node, NodeType nodeType) {
+ //TODO: Implementation code.
+ }
+
+ @Override
+ public void exitJsonNode(JsonNode node) {
+ //TODO: Implementation code.
+ }
+
+ @Override
+ public SerializerHelper serializerHelper() {
+ return serializerHelper;
+ }
+
+}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - CCSDK
+ * ================================================================================
+ * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.ccsdk.sli.plugins.yangserializers.dfserializer;
+
+import com.fasterxml.jackson.databind.JsonNode;
+
+/**
+ * Implementation of JSON walker to walk through the nodes and process it.
+ */
+public class DefaultJsonWalker implements JsonWalker {
+
+ @Override
+ public void walk(JsonListener listener, JsonNode jsonNode) {
+ //TODO: Implementation code.
+ }
+
+ /**
+ * Processes single instance node or leaf, by adding the node to from
+ * JSON and walking through all its children recursively.
+ *
+ * @param key JSON name
+ * @param value JSON node
+ * @param listener JSON listener
+ */
+ private void processSingleNode(String key, JsonNode value,
+ JsonListener listener) {
+ //TODO: Implementation code.
+ }
+
+ /**
+ * Processes multi instance node or leaf, by adding the node to from JSON
+ * and walking through all its instance recursively.
+ *
+ * @param key JSON name
+ * @param value JSON node
+ * @param listener JSON listener
+ */
+ private void processMultiNodes(String key, JsonNode value,
+ JsonListener listener) {
+ //TODO: Implementation code.
+ }
+}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - CCSDK
+ * ================================================================================
+ * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.ccsdk.sli.plugins.yangserializers.dfserializer;
+
+import org.dom4j.Element;
+
+/**
+ * Representation of default implementation of XML listener.
+ */
+public class DefaultXmlListener implements XmlListener {
+
+ /**
+ * Serializer helper to convert to properties node.
+ */
+ private SerializerHelper serializerHelper;
+
+ /**
+ * Creates an instance of default XML listener with its serializer helper.
+ *
+ * @param serializerHelper serializer helper
+ */
+ public DefaultXmlListener(SerializerHelper serializerHelper) {
+ this.serializerHelper = serializerHelper;
+ }
+
+ @Override
+ public void enterXmlElement(Element element, XmlNodeType nodeType) {
+ //TODO: Implementation code.
+ }
+
+ @Override
+ public void exitXmlElement(Element element) {
+ //TODO: Implementation code.
+ }
+
+ @Override
+ public SerializerHelper serializerHelper() {
+ return serializerHelper;
+ }
+ }
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - CCSDK
+ * ================================================================================
+ * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.ccsdk.sli.plugins.yangserializers.dfserializer;
+
+import org.dom4j.Element;
+
+/**
+ * Implementation of XML walker to walk through the nodes and process it.
+ */
+public class DefaultXmlWalker implements XmlWalker {
+
+ @Override
+ public void walk(XmlListener listener, Element xmlElement) {
+ //TODO: Implementation code.
+ }
+}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - CCSDK
+ * ================================================================================
+ * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.ccsdk.sli.plugins.yangserializers.dfserializer;
+
+/**
+ * Represents the data format listener factory which will return JSON or XML
+ * listener according to the serializer helper.
+ */
+public final class DfListenerFactory {
+
+ /**
+ * Returns the instance of the data format listener factory.
+ *
+ * @return instance of the data format listener factory
+ */
+ public static DfListenerFactory instance() {
+ return DfListenerFactory.LazyHolder.INSTANCE;
+ }
+
+ /**
+ * Bill pugh singleton pattern. Instance will not be instantiated until
+ * the lazy holder class is loaded via a call to the instance of method
+ * below.
+ */
+ private static class LazyHolder {
+ private static final DfListenerFactory INSTANCE =
+ new DfListenerFactory();
+ }
+
+ /**
+ * Returns the data format listener by deciding it based on the format of
+ * the parameter.
+ *
+ * @param serHelper serializer helper
+ * @param params parameters
+ * @return data format listener
+ */
+ public Listener getListener(SerializerHelper serHelper,
+ YangParameters params) {
+ Listener listener;
+ switch (params.format) {
+ case JSON:
+ listener = new DefaultJsonListener(serHelper);
+ break;
+
+ case XML:
+ listener = new DefaultXmlListener(serHelper);
+ break;
+
+ //TODO: DataFormat Exception code to be added.
+ default:
+ throw new IllegalArgumentException("In correct format");
+ }
+ return listener;
+ }
+}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - CCSDK
+ * ================================================================================
+ * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.ccsdk.sli.plugins.yangserializers.dfserializer;
+
+/**
+ * Represents the data format serializer factory which will return JSON or XML
+ * serializer according to the serializer context.
+ */
+public final class DfSerializerFactory {
+
+ /**
+ * Returns the instance of the data format serializer factory.
+ *
+ * @return instance of the data format serializer factory
+ */
+ public static DfSerializerFactory instance() {
+ return DfSerializerFactory.LazyHolder.INSTANCE;
+ }
+
+ /**
+ * Bill pugh singleton pattern. Instance will not be instantiated until
+ * the lazy holder class is loaded via a call to the instance of method
+ * below.
+ */
+ private static class LazyHolder {
+ private static final DfSerializerFactory INSTANCE =
+ new DfSerializerFactory();
+ }
+
+ /**
+ * Returns the data format serializer by deciding it based on the format of
+ * the parameter.
+ *
+ * @param serCtx serializer context
+ * @param params parameters
+ * @return data format serializer
+ */
+ public DataFormatSerializer getSerializer(DataFormatSerializerContext
+ serCtx,
+ YangParameters params) {
+ DataFormatSerializer serializer;
+ switch (params.format) {
+ case JSON:
+ serializer = new JsonSerializer(serCtx);
+ break;
+
+ case XML:
+ serializer = new XmlSerializer(serCtx);
+ break;
+
+ //TODO: DataFormat Exception code to be added.
+ default:
+ throw new IllegalArgumentException("In correct format");
+ }
+ return serializer;
+ }
+}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - CCSDK
+ * ================================================================================
+ * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.ccsdk.sli.plugins.yangserializers.dfserializer;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.NodeType;
+
+/**
+ * Abstraction of an entity which provides call back methods, which in turn
+ * are called by JSON walker while walking the JSON tree. This interface
+ * needs to be implemented by protocol, implementing listener based call
+ * while doing JSON walk.
+ */
+public interface JsonListener extends Listener {
+
+ /**
+ * Call back invoked during JSON node entry. All other related
+ * information can be obtained from the JSON node.
+ *
+ * @param nodeName JSON node name
+ * @param node JSON node
+ * @param nodeType JSON node type
+ */
+ void enterJsonNode(String nodeName, JsonNode node, NodeType nodeType);
+
+ /**
+ * Call back invoked during JSON node exit. All the related information
+ * can be obtained from the JSON node.
+ *
+ * @param node JSON node
+ */
+ void exitJsonNode(JsonNode node);
+}
import java.util.List;
import java.util.Map;
+import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormat.JSON;
+
/**
- * Representation of JSON serializer.
+ * Representation of JSON serializer which encodes properties to JSON and
+ * decodes properties from JSON with the data format serializer.
*/
public class JsonSerializer extends DataFormatSerializer {
* @param serializerContext data format serializer context
*/
protected JsonSerializer(DataFormatSerializerContext serializerContext) {
- super(DataFormat.JSON, serializerContext);
+ super(JSON, serializerContext);
}
@Override
- public String encode(Map<String, String> param, Map<String, List<Annotation>> annotations) {
+ public String encode(Map<String, String> param,
+ Map<String, List<Annotation>> annotations) {
+ //TODO: Implementation code.
return null;
}
@Override
public Map<String, String> decode(String dataFormatBody) {
+ //TODO: Implementation code.
return null;
}
}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - CCSDK
+ * ================================================================================
+ * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.ccsdk.sli.plugins.yangserializers.dfserializer;
+
+import com.fasterxml.jackson.databind.JsonNode;
+
+/**
+ * Abstraction of an entity which provides interface for JSON walk. This
+ * interface serves as a common tool for anyone who needs to parse the JSON
+ * node with depth-first algorithm.
+ */
+public interface JsonWalker {
+
+ /**
+ * Walks the JSON data tree. Protocols implement JSON listener service
+ * and walks the JSON tree with input as implemented object. JSON walker
+ * provides call back to the implemented methods.
+ *
+ * @param listener JSON listener implemented by the protocol
+ * @param jsonNode root node of the JSON data tree
+ */
+ void walk(JsonListener listener, JsonNode jsonNode);
+}
package org.onap.ccsdk.sli.plugins.yangserializers.dfserializer;
-import java.util.Map;
+import org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.NodeType;
+import org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.PropertiesNode;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
/**
- * Representation of MDSAL based schema helper.
+ * Representation of MDSAL based serializer helper, which adds properties
+ * node to the properties tree based on its types.
*/
-public class MdsalSerializerHelper extends SerializerHelper<SchemaNode> {
+public class MdsalSerializerHelper extends SerializerHelper<SchemaNode, SchemaContext> {
- protected MdsalSerializerHelper(SchemaNode node, String uri) {
- super(node, uri);
- }
+ /**
+ * Current properties node.
+ */
+ private PropertiesNode propNode;
- @Override
- public SchemaNode getRootContext() {
- return null;
+ /**
+ * Current schema node.
+ */
+ private SchemaNode curSchemaNode;
+
+
+ /**
+ * Creates MDSAL serializer helper with root schema node, schema context
+ * and URI.
+ *
+ * @param n schema node of the URI's last node
+ * @param c schema context
+ * @param u URI of the request
+ */
+ protected MdsalSerializerHelper(SchemaNode n, SchemaContext c,
+ String u) {
+ super(n, c, u);
}
@Override
- public SchemaNode getCurContext() {
- return null;
+ protected SchemaNode getSchemaNode() {
+ return schemaNode;
}
@Override
- public SchemaNode getChildContext(SchemaNode schemaNode, String name, String namespace) {
- return null;
+ protected SchemaContext getSchemaCtx() {
+ return schemaCtx;
}
@Override
- public NodeType getNodeType(SchemaNode schemaNode) {
- return null;
+ protected SchemaNode getCurSchema() {
+ return curSchemaNode;
}
@Override
- public void addNode(String name, String namespace, String value, String valNamespace, NodeType type) {
+ protected void addNode(String name, String nameSpace, String value,
+ String valNameSpace, NodeType type) {
+ //TODO: Implementation code.
}
@Override
- public void exitNode() {
+ protected void exitNode() {
+ //TODO: Implementation code.
}
@Override
- public Map<String, String> getProperties() {
+ protected PropertiesNode getPropertiesNode() {
+ //TODO: Implementation code.
return null;
}
}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - CCSDK
+ * ================================================================================
+ * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.ccsdk.sli.plugins.yangserializers.dfserializer;
+
+import com.google.gson.stream.JsonWriter;
+import org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.PropertiesNode;
+import org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.PropertiesNodeListener;
+
+import java.io.Writer;
+
+/**
+ * Representation of JSON implementation of properties node listener.
+ */
+public class PropertiesNodeJsonListener implements PropertiesNodeListener{
+
+ /**
+ * JSON writer to write the JSON data format.
+ */
+ private JsonWriter jsonWriter;
+
+ /**
+ * Writer to write the JSON.
+ */
+ private Writer writer;
+
+ /**
+ * Creates the properties node JSON listener by instantiating and
+ * indenting the writer.
+ */
+ public PropertiesNodeJsonListener() {
+ }
+
+ @Override
+ public void start(PropertiesNode node) {
+ //TODO: Implementation code.
+ }
+
+ @Override
+ public void end(PropertiesNode node) {
+ //TODO: Implementation code.
+ }
+
+ @Override
+ public void enterPropertiesNode(PropertiesNode node) {
+ //TODO: Implementation code.
+ }
+
+ @Override
+ public void exitPropertiesNode(PropertiesNode node) {
+ //TODO: Implementation code.
+ }
+}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - CCSDK
+ * ================================================================================
+ * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.ccsdk.sli.plugins.yangserializers.dfserializer;
+
+import org.dom4j.Element;
+import org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.PropertiesNode;
+import org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.PropertiesNodeListener;
+
+import java.io.Writer;
+import java.util.Stack;
+
+/**
+ * Representation of XML implementation of properties node listener.
+ */
+public class PropertiesNodeXmlListener implements PropertiesNodeListener {
+
+ /**
+ * XML data from the element.
+ */
+ private String xmlData;
+
+ /**
+ * Root element of the XML document.
+ */
+ private Element rootElement;
+
+ /**
+ * Writer to write the XML.
+ */
+ private Writer writer;
+
+ /**
+ * XML element stack to store the elements.
+ */
+ private final Stack<Element> elementStack = new Stack<>();
+
+ /**
+ * Creates the properties node XML listener.
+ */
+ public PropertiesNodeXmlListener() {
+ }
+
+ @Override
+ public void start(PropertiesNode node) {
+ //TODO: Implementation code.
+ }
+
+ @Override
+ public void end(PropertiesNode node) {
+ //TODO: Implementation code.
+ }
+
+ @Override
+ public void enterPropertiesNode(PropertiesNode node) {
+ //TODO: Implementation code.
+ }
+
+ @Override
+ public void exitPropertiesNode(PropertiesNode node) {
+ //TODO: Implementation code.
+ }
+}
package org.onap.ccsdk.sli.plugins.yangserializers.dfserializer;
-import java.util.Map;
+import org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.NodeType;
+import org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.PropertiesNode;
/**
* Abstraction of an entity which helps the data format serializers to obtain
* schema context details and to build properties from data.
*
* @param <T> type of schema node
+ * @param <P> type of schema context
*/
-public abstract class SerializerHelper<T> {
+public abstract class SerializerHelper<T, P> {
- private T rootSchema;
- private String rootURI;
+ /**
+ * Schema node of the last element in the URI.
+ */
+ protected T schemaNode;
- protected SerializerHelper(T t, String uri) {
- rootSchema = t;
- }
+ /**
+ * Root schema context.
+ */
+ protected P schemaCtx;
+
+ /**
+ * Root URI.
+ */
+ protected String rootUri;
/**
- * Returns root schema context node.
+ * Creates an instance of the serializer helper with the schema node,
+ * schema context and the URI.
*
- * @return root schema context node
+ * @param t schema node
+ * @param p schema context
+ * @param u root URI
*/
- protected abstract T getRootContext();
+ protected SerializerHelper(T t, P p, String u) {
+ schemaNode = t;
+ schemaCtx = p;
+ rootUri = u;
+ }
/**
- * Returns current schema context node.
+ * Returns schema node of the last element in the URI.
*
- * @return current schema context node
+ * @return schema node
*/
- protected abstract T getCurContext();
+ protected abstract T getSchemaNode();
/**
- * Returns child schema context node.
+ * Returns the root schema context.
*
- * @return child schema context node
+ * @return schema context
*/
- protected abstract T getChildContext(T t, String name, String namespace);
+ protected abstract P getSchemaCtx();
/**
- * Returns type of node
- * @param t node
- * @return node type
+ * Returns the current schema context node.
+ *
+ * @return current schema context node
*/
- protected abstract NodeType getNodeType(T t);
+ protected abstract T getCurSchema();
/**
- * Adds a node to current tree.
+ * Adds a node to the properties node tree.
*
- * @param name name of node
- * @param namespace namespace of node, it can be either module name or
- * namespace, null indicates parent namespace
- * @param value value of node, in case it's leaf/leaf-list node
- * @param valNamespace value namespace for identityref, could be module
- * name or namespace
- * @param type type of node if known like in case of JSON
+ * @param name name of the node
+ * @param nameSpace name space of the node, it can be either module
+ * name or namespace; null indicates parent namespace
+ * @param value value of the node; applicable for leaf/leaf-list node
+ * @param valNameSpace value namespace for identityref, could be module
+ * name or namespace
+ * @param type type of node if known like in case of JSON
*/
- protected abstract void addNode(String name, String namespace, String value,
- String valNamespace, NodeType type);
+ protected abstract void addNode(String name, String nameSpace, String value,
+ String valNameSpace, NodeType type);
/**
- * Exits the node, in case if it's leaf node add to properties map.
+ * Exits the node, in case if it's leaf node then it adds to the properties
+ * map.
*/
protected abstract void exitNode();
/**
- * Returns the properties built corresponding to data.
+ * Returns the built properties corresponding to the data.
*
- * @return properties map
+ * @return properties node.
*/
- protected abstract Map<String, String> getProperties();
+ protected abstract PropertiesNode getPropertiesNode();
}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - CCSDK
+ * ================================================================================
+ * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.ccsdk.sli.plugins.yangserializers.dfserializer;
+
+import org.dom4j.Element;
+
+/**
+ * Abstraction of an entity which provides call back methods, which in turn
+ * are called by XML walker while walking the XML tree. This interface needs
+ * to be implemented by protocol implementing listener based call while doing
+ * XML walk.
+ */
+public interface XmlListener extends Listener {
+
+ /**
+ * Callback invoked during a node entry. All the related information
+ * about the node can be obtained from the element.
+ *
+ * @param element current XML element
+ * @param nodeType node type of the element
+ */
+ void enterXmlElement(Element element, XmlNodeType nodeType);
+
+ /**
+ * Callback invoked during a node exit. All the related information about
+ * the node can be obtained from the element.
+ *
+ * @param element current xml element.
+ */
+ void exitXmlElement(Element element);
+}
package org.onap.ccsdk.sli.plugins.yangserializers.dfserializer;
/**
- * Representation of type of data node.
+ * Represents the XML node type.
*/
-public enum NodeType {
- SINGLE_INSTANCE,
- MULTI_INSTANCE,
- SINGLE_INSTANCE_LEAF,
- MULTI_INSTANCE_LEAF
+public enum XmlNodeType {
+
+ /**
+ * Object XML node type.
+ */
+ OBJECT_NODE,
+
+ /**
+ * Text XML node type.
+ */
+ TEXT_NODE
}
import java.util.List;
import java.util.Map;
+import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormat.XML;
+
/**
- * Representation of XML serializer.
+ * Representation of XML serializer which encodes properties to XML and
+ * decodes properties from XML with the data format serializer.
*/
public class XmlSerializer extends DataFormatSerializer {
* @param serializerContext data format serializer context
*/
protected XmlSerializer(DataFormatSerializerContext serializerContext) {
- super(DataFormat.XML, serializerContext);
+ super(XML, serializerContext);
}
@Override
- public String encode(Map<String, String> param, Map<String, List<Annotation>> annotations) {
+ public String encode(Map<String, String> param,
+ Map<String, List<Annotation>> annotations) {
+ //TODO: Implementation code.
return null;
}
@Override
public Map<String, String> decode(String dataFormatBody) {
+ //TODO: Implementation code.
return null;
}
}
\ No newline at end of file
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - CCSDK
+ * ================================================================================
+ * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.ccsdk.sli.plugins.yangserializers.dfserializer;
+
+import org.dom4j.Element;
+
+/**
+ * Abstraction of an entity which provides interface for XML walk. This
+ * interface serves as a common tool for anyone who needs to parse the XML
+ * node with depth-first algorithm.
+ */
+public interface XmlWalker {
+
+ /**
+ * Walks the XML data tree. Protocols implement XML listener service and
+ * walks the XML tree with input as implemented object. XML walker
+ * provides call back to the implemented methods.
+ *
+ * @param listener XML listener implemented by the protocol
+ * @param xmlElement root element of the XML data tree
+ */
+ void walk(XmlListener listener, Element xmlElement);
+}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - CCSDK
+ * ================================================================================
+ * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.ccsdk.sli.plugins.yangserializers.dfserializer;
+
+import org.onap.ccsdk.sli.plugins.restapicall.Parameters;
+
+/**
+ * Representation of the YANG parameters for the restconf api call node.
+ */
+public class YangParameters extends Parameters {
+
+ /**
+ * Creates an instance of the YANG parameters.
+ */
+ public YangParameters() {
+ super();
+ }
+
+ /**
+ * Directory path of the YANG file.
+ */
+ public String dirPath;
+}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - CCSDK
+ * ================================================================================
+ * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.ccsdk.sli.plugins.yangserializers.pnserializer;
+
+import java.util.Map;
+
+/**
+ * Implementation of properties node walker which helps in forming a new tree from properties node.
+ *
+ * @param <T> node child of properties node.
+ */
+public class DefaultPropertiesNodeWalker<T extends NodeChild> implements PropertiesNodeWalker {
+
+ @Override
+ public void walk(PropertiesNodeListener listener,
+ PropertiesNode propertiesNode) {
+ listener.start(propertiesNode);
+ walkChildNode(listener, propertiesNode);
+ listener.end(propertiesNode);
+ }
+
+ /**
+ * Walks the children node from the parent node.
+ *
+ * @param listener properties node listener
+ * @param propertiesNode properties node
+ */
+ public void walkChildNode(PropertiesNodeListener listener,
+ PropertiesNode propertiesNode) {
+ Map<String, T> children = getChildren(propertiesNode);
+ if (children != null) {
+ for (Map.Entry<String, T> entry : children.entrySet()) {
+ PropertiesNode node = ((PropertiesNode) entry.getValue());
+ listener.enterPropertiesNode(node);
+ walkChildNode(listener, node);
+ listener.exitPropertiesNode(node);
+ }
+ }
+ }
+
+ /**
+ * Returns the children node according to the property node type.
+ *
+ * @param value property node
+ * @return property node children
+ */
+ private Map<String,T> getChildren(PropertiesNode value) {
+ if (value instanceof RootNode) {
+ return ((RootNode) value).children();
+ }
+ switch (value.nodeType()) {
+ case SINGLE_INSTANCE_NODE:
+ return ((InnerNode) value).children();
+ case MULTI_INSTANCE_HOLDER_NODE:
+ return ((Map<String, T>) ((ListHolderNode) value).children());
+ case MULTI_INSTANCE_NODE:
+ return ((Map<String, T>) ((MultiInstanceNode) value)
+ .children());
+ case MULTI_INSTANCE_LEAF_HOLDER_NODE:
+ return ((Map<String, T>) ((LeafListHolderNode) value)
+ .children());
+ case SINGLE_INSTANCE_LEAF_NODE:
+ case MULTI_INSTANCE_LEAF_NODE:
+ return null;
+ default:
+ throw new IllegalArgumentException("No more types allowed");
+ }
+ }
+}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - CCSDK
+ * ================================================================================
+ * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.ccsdk.sli.plugins.yangserializers.pnserializer;
+
+/**
+ * Abstraction of properties node listener.
+ */
+public interface PropertiesNodeListener {
+
+ /**
+ * Pre-configurations required before starting the walking.
+ *
+ * @param node properties node
+ */
+ void start(PropertiesNode node);
+
+ /**
+ * Post-configurations required after starting the walking.
+ *
+ * @param node properties node
+ */
+ void end(PropertiesNode node);
+
+ /**
+ * Enters the properties node.
+ *
+ * @param node properties node
+ */
+ void enterPropertiesNode(PropertiesNode node);
+
+ /**
+ * Enters the properties node.
+ *
+ * @param node properties node
+ */
+ void exitPropertiesNode(PropertiesNode node);
+}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - CCSDK
+ * ================================================================================
+ * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.ccsdk.sli.plugins.yangserializers.pnserializer;
+
+/**
+ * Abstraction of properties node walker
+ */
+public interface PropertiesNodeWalker {
+
+ /**
+ * Walks the properties node with the listener.
+ *
+ * @param listener properties node listener.
+ * @param propertiesNode properties node
+ */
+ void walk(PropertiesNodeListener listener, PropertiesNode propertiesNode);
+}