This removes users of getChildren() in favor of getValue().
Change-Id: I1b871b46cd3af04dba1d286f386e43148308fbe1
Signed-off-by: Robert Varga <rovarga@cisco.com>
for (Map.Entry<QName, Object> predicate : predicates.getKeyValues().entrySet()) {
newNodes.add(new SimpleNodeTOImpl<Object>(predicate.getKey(), null, predicate.getValue()));
}
- newNodes.addAll(ret.getChildren());
+ newNodes.addAll(ret.getValue());
return new CompositeNodeTOImpl(last.getNodeType(), null, newNodes);
}
return ret;
*/
public class LazyNodeToNodeMap {
- private Map<Node<?>, Node<?>> node2node = new HashMap<>();
+ private final Map<Node<?>, Node<?>> node2node = new HashMap<>();
private CompositeNode originalRoot;
private MutableCompositeNode mutableRoot;
* @param originalNode
* @return mutable twin
*/
- public Node<?> getMutableEquivalent(Node<?> originalNode) {
+ public Node<?> getMutableEquivalent(final Node<?> originalNode) {
Node<?> mutableNode = node2node.get(originalNode);
if (mutableNode == null) {
addPathMembers(originalNode);
/**
* @param originalNode
*/
- private void addPathMembers(Node<?> originalNode) {
+ private void addPathMembers(final Node<?> originalNode) {
Stack<Node<?>> jobQueue = new Stack<>();
jobQueue.push(originalNode);
while (!jobQueue.isEmpty()) {
mutableEquivalent = nodeMutant;
// tidy up children
- if (nodeMutant.getChildren() == null) {
+ if (nodeMutant.getValue() == null) {
nodeMutant.setValue(new ArrayList<Node<?>>());
}
- for (Node<?> originalChildNode : ((CompositeNode) node2add).getChildren()) {
+ for (Node<?> originalChildNode : ((CompositeNode) node2add).getValue()) {
MutableNode<?> mutableChild = (MutableNode<?>) node2node.get(originalChildNode);
fixChildrenRef(nodeMutant, mutableChild);
}
- if (nodeMutant.getChildren() != null && !nodeMutant.getChildren().isEmpty()) {
+ if (nodeMutant.getValue() != null && !nodeMutant.getValue().isEmpty()) {
nodeMutant.init();
}
* @param nodeMutant
* @param mutableChild
*/
- private static void fixChildrenRef(MutableCompositeNode nodeMutant,
- MutableNode<?> mutableChild) {
+ private static void fixChildrenRef(final MutableCompositeNode nodeMutant,
+ final MutableNode<?> mutableChild) {
if (mutableChild != null) {
- if (!nodeMutant.getChildren().contains(mutableChild)) {
- nodeMutant.getChildren().add(mutableChild);
+ if (!nodeMutant.getValue().contains(mutableChild)) {
+ nodeMutant.getValue().add(mutableChild);
}
CompositeNode parentOfChild = mutableChild.getParent();
if (parentOfChild == null) {
* @param value
* @return simple node modification, based on given qname, value and parent
*/
- public static <T> SimpleNode<T> createImmutableSimpleNode(QName qName,
- CompositeNode parent, T value) {
+ public static <T> SimpleNode<T> createImmutableSimpleNode(final QName qName,
+ final CompositeNode parent, final T value) {
return createImmutableSimpleNode(qName, parent, value, null);
}
* @param original originating node, if available
* @return simple node modification, based on given qname, value and parent
*/
- public static <T> MutableSimpleNode<T> createMutableSimpleNode(QName qName,
- CompositeNode parent, Object value, ModifyAction modifyAction, SimpleNode<T> original) {
+ public static <T> MutableSimpleNode<T> createMutableSimpleNode(final QName qName,
+ final CompositeNode parent, final Object value, final ModifyAction modifyAction, final SimpleNode<T> original) {
@SuppressWarnings("unchecked")
MutableSimpleNodeTOImpl<T> simpleNodeTOImpl =
new MutableSimpleNodeTOImpl<T>(qName, parent, (T) value, modifyAction);
* @param value
* @return composite node modification, based on given qname, value (children), parent and modifyAction
*/
- public static CompositeNode createImmutableCompositeNode(QName qName,
- CompositeNode parent, List<Node<?>> value) {
+ public static CompositeNode createImmutableCompositeNode(final QName qName,
+ final CompositeNode parent, final List<Node<?>> value) {
return createImmutableCompositeNode(qName, parent, value, null);
}
* @param original originating node, if available
* @return composite node modification, based on given qName, value (children), parent and modifyAction
*/
- public static MutableCompositeNode createMutableCompositeNode(QName qName,
- CompositeNode parent, List<Node<?>> valueArg, ModifyAction modifyAction, CompositeNode original) {
+ public static MutableCompositeNode createMutableCompositeNode(final QName qName,
+ final CompositeNode parent, final List<Node<?>> valueArg, final ModifyAction modifyAction, final CompositeNode original) {
List<Node<?>> value = valueArg;
if (value == null) {
value = new ArrayList<>();
* @param modifyAction
* @return simple node modification, based on given qname, value, parent and modifyAction
*/
- public static <T> SimpleNode<T> createImmutableSimpleNode(QName qName,
- CompositeNode parent, T value, ModifyAction modifyAction) {
+ public static <T> SimpleNode<T> createImmutableSimpleNode(final QName qName,
+ final CompositeNode parent, final T value, final ModifyAction modifyAction) {
SimpleNodeTOImpl<T> simpleNodeModTOImpl =
new SimpleNodeTOImpl<T>(qName, parent, value, modifyAction);
return simpleNodeModTOImpl;
* @param modifyAction
* @return composite node modification, based on given qname, value (children), parent and modifyAction
*/
- public static CompositeNode createImmutableCompositeNode(QName qName,
- CompositeNode parent, List<Node<?>> value, ModifyAction modifyAction) {
+ public static CompositeNode createImmutableCompositeNode(final QName qName,
+ final CompositeNode parent, final List<Node<?>> value, final ModifyAction modifyAction) {
CompositeNodeTOImpl compositeNodeModTOImpl =
new CompositeNodeTOImpl(qName, parent, value, modifyAction);
return compositeNodeModTOImpl;
* @return copy of given node, parent and value are the same, but parent
* has no reference to this copy
*/
- public static <T> SimpleNode<T> copyNode(SimpleNode<T> node) {
+ public static <T> SimpleNode<T> copyNode(final SimpleNode<T> node) {
SimpleNode<T> twinNode = createImmutableSimpleNode(
node.getNodeType(), node.getParent(), node.getValue());
return twinNode;
* @return copy of given node, parent and value are the same, but parent
* has no reference to this copy
*/
- public static <T> MutableSimpleNode<T> copyNodeAsMutable(SimpleNode<T> node) {
+ public static <T> MutableSimpleNode<T> copyNodeAsMutable(final SimpleNode<T> node) {
MutableSimpleNode<T> twinNode = createMutableSimpleNode(
node.getNodeType(), node.getParent(), node.getValue(),
node.getModificationAction(), null);
* @return copy of given node, parent and children are the same, but parent and children
* have no reference to this copy
*/
- public static CompositeNode copyNode(CompositeNode node, Node<?>... children) {
+ public static CompositeNode copyNode(final CompositeNode node, final Node<?>... children) {
CompositeNode twinNode = createImmutableCompositeNode(
node.getNodeType(), node.getParent(), Arrays.asList(children), node.getModificationAction());
return twinNode;
* @return copy of given node, parent and children are the same, but parent and children
* have no reference to this copy
*/
- public static CompositeNode copyNode(CompositeNode node) {
- return copyNode(node, node.getChildren().toArray(new Node<?>[0]));
+ public static CompositeNode copyNode(final CompositeNode node) {
+ return copyNode(node, node.getValue().toArray(new Node<?>[0]));
}
/**
* will be stored
* @return copy of given node and all subnodes recursively
*/
- public static MutableCompositeNode copyDeepAsMutable(CompositeNode node,
- Map<Node<?>, Node<?>> originalToCopyArg) {
+ public static MutableCompositeNode copyDeepAsMutable(final CompositeNode node,
+ final Map<Node<?>, Node<?>> originalToCopyArg) {
Map<Node<?>, Node<?>> originalToCopy = originalToCopyArg;
if (originalToCopy == null) {
MutableCompositeNode mutableNode = job.getValue();
mutableNode.setValue(new ArrayList<Node<?>>());
- for (Node<?> child : originalNode.getChildren()) {
+ for (Node<?> child : originalNode.getValue()) {
Node<?> mutableAscendant = null;
if (child instanceof CompositeNode) {
MutableCompositeNode newMutable =
+child.getClass().getName());
}
- mutableNode.getChildren().add(mutableAscendant);
+ mutableNode.getValue().add(mutableAscendant);
originalToCopy.put(child, mutableAscendant);
}
mutableNode.init();
* will be stored
* @return copy of given node and all subnodes recursively
*/
- public static CompositeNode copyDeepAsImmutable(CompositeNode node,
- Map<Node<?>, Node<?>> originalToCopyArg) {
+ public static CompositeNode copyDeepAsImmutable(final CompositeNode node,
+ final Map<Node<?>, Node<?>> originalToCopyArg) {
Stack<CompositeNode> jobQueue = new Stack<>();
jobQueue.push(node);
while (!jobQueue.isEmpty()) {
CompositeNode jobNode = jobQueue.peek();
if (!originalToCopy.isEmpty()
- && originalToCopy.keySet().containsAll(jobNode.getChildren())) {
+ && originalToCopy.keySet().containsAll(jobNode.getValue())) {
jobQueue.pop();
- List<Node<?>> newChildren = NodeUtils.collectMapValues(jobNode.getChildren(), originalToCopy);
+ List<Node<?>> newChildren = NodeUtils.collectMapValues(jobNode.getValue(), originalToCopy);
CompositeNode nodeCopy = createImmutableCompositeNode(jobNode.getNodeType(), null,
newChildren, jobNode.getModificationAction());
NodeUtils.fixChildrenRelation(nodeCopy);
originalToCopy.put(jobNode, nodeCopy);
} else {
- for (Node<?> child : jobNode.getChildren()) {
+ for (Node<?> child : jobNode.getValue()) {
if (child instanceof SimpleNode<?>) {
originalToCopy.put(child, createImmutableSimpleNode(
child.getNodeType(), null, child.getValue(),
/**
* @author michal.rehak
- *
+ *
*/
public class NodeModificationBuilderImpl implements NodeModificationBuilder {
- private SchemaContext context;
+ private final SchemaContext context;
- private Set<MutableNode<?>> changeLog;
- private LazyNodeToNodeMap originalToMutable;
+ private final Set<MutableNode<?>> changeLog;
+ private final LazyNodeToNodeMap originalToMutable;
/**
* @param context
*/
- public NodeModificationBuilderImpl(SchemaContext context) {
+ public NodeModificationBuilderImpl(final SchemaContext context) {
this.context = context;
originalToMutable = new LazyNodeToNodeMap();
changeLog = new HashSet<>();
* @param modNode
* @param action
*/
- private void addModificationToLog(MutableNode<?> modNode, ModifyAction action) {
+ private void addModificationToLog(final MutableNode<?> modNode, final ModifyAction action) {
modNode.setModifyAction(action);
changeLog.add(modNode);
}
@Override
- public void addNode(MutableSimpleNode<?> newNode) {
+ public void addNode(final MutableSimpleNode<?> newNode) {
NodeUtils.fixParentRelation(newNode);
addModificationToLog(newNode, ModifyAction.CREATE);
}
@Override
- public void addNode(MutableCompositeNode newNode) {
+ public void addNode(final MutableCompositeNode newNode) {
NodeUtils.fixParentRelation(newNode);
addModificationToLog(newNode, ModifyAction.CREATE);
}
@Override
- public void replaceNode(MutableSimpleNode<?> replacementNode) {
+ public void replaceNode(final MutableSimpleNode<?> replacementNode) {
addModificationToLog(replacementNode, ModifyAction.REPLACE);
}
@Override
- public void replaceNode(MutableCompositeNode replacementNode) {
+ public void replaceNode(final MutableCompositeNode replacementNode) {
addModificationToLog(replacementNode, ModifyAction.REPLACE);
}
@Override
- public void deleteNode(MutableCompositeNode deadNode) {
+ public void deleteNode(final MutableCompositeNode deadNode) {
addModificationToLog(deadNode, ModifyAction.DELETE);
}
@Override
- public void deleteNode(MutableSimpleNode<?> deadNode) {
+ public void deleteNode(final MutableSimpleNode<?> deadNode) {
addModificationToLog(deadNode, ModifyAction.DELETE);
}
@Override
- public void removeNode(MutableSimpleNode<?> deadNode) {
+ public void removeNode(final MutableSimpleNode<?> deadNode) {
addModificationToLog(deadNode, ModifyAction.REMOVE);
}
@Override
- public void removeNode(MutableCompositeNode deadNode) {
+ public void removeNode(final MutableCompositeNode deadNode) {
addModificationToLog(deadNode, ModifyAction.REMOVE);
}
@Override
- public void mergeNode(MutableCompositeNode alteredNode) {
+ public void mergeNode(final MutableCompositeNode alteredNode) {
addModificationToLog(alteredNode, ModifyAction.MERGE);
}
// try to add key subnode to wanted list
List<QName> supportedKeys = listSchema.getKeyDefinition();
CompositeNode outlawOriginal = ((MutableCompositeNode) outlaw).getOriginal();
- for (Node<?> outlawOriginalChild : outlawOriginal.getChildren()) {
+ for (Node<?> outlawOriginalChild : outlawOriginal.getValue()) {
if (supportedKeys.contains(outlawOriginalChild.getNodeType())) {
originalToMutable.getMutableEquivalent(outlawOriginalChild);
}
* @param focusedDescendant
* @return set of parents and focusedAncestor itself
*/
- private static Set<Node<?>> collectSelfAndAllParents(Node<?> focusedDescendant) {
+ private static Set<Node<?>> collectSelfAndAllParents(final Node<?> focusedDescendant) {
Set<Node<?>> family = new HashSet<>();
Node<?> tmpNode = focusedDescendant;
while (tmpNode != null) {
* @return mutable version of given node
*/
@Override
- public Node<?> getMutableEquivalent(Node<?> originalNode) {
+ public Node<?> getMutableEquivalent(final Node<?> originalNode) {
return originalToMutable.getMutableEquivalent(originalNode);
}
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
-import com.google.common.collect.Maps;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.CompositeNode;
import org.opendaylight.yangtools.yang.data.api.ModifyAction;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
/**
* @author michal.rehak
* @param node
* @return node path up till root node
*/
- public static String buildPath(Node<?> node) {
+ public static String buildPath(final Node<?> node) {
List<String> breadCrumbs = new ArrayList<>();
Node<?> tmpNode = node;
while (tmpNode != null) {
* @return dom tree, containing same node structure, yang nodes are
* associated to dom nodes as user data
*/
- public static org.w3c.dom.Document buildShadowDomTree(CompositeNode treeRootNode) {
+ public static org.w3c.dom.Document buildShadowDomTree(final CompositeNode treeRootNode) {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
org.w3c.dom.Document doc = null;
try {
jointPlace.appendChild(itemEl);
if (item instanceof CompositeNode) {
- for (Node<?> child : ((CompositeNode) item).getChildren()) {
+ for (Node<?> child : ((CompositeNode) item).getValue()) {
jobQueue.push(new SimpleEntry<org.w3c.dom.Node, Node<?>>(itemEl, child));
}
}
* @throws XPathExpressionException
*/
@SuppressWarnings("unchecked")
- public static <T> T findNodeByXpath(org.w3c.dom.Document doc, String xpathEx) throws XPathExpressionException {
+ public static <T> T findNodeByXpath(final org.w3c.dom.Document doc, final String xpathEx) throws XPathExpressionException {
T userNode = null;
XPathFactory xPathfactory = XPathFactory.newInstance();
XPath xpath = xPathfactory.newXPath();
* @return map of children, where key = qName and value is list of children
* groupped by qName
*/
- public static Map<QName, List<Node<?>>> buildNodeMap(List<Node<?>> value) {
+ public static Map<QName, List<Node<?>>> buildNodeMap(final List<Node<?>> value) {
Map<QName, List<Node<?>>> nodeMapTmp = Maps.newLinkedHashMap();
if (value == null) {
throw new IllegalStateException("nodeList should not be null or empty");
* @param context
* @return map of lists, where key = path; value = {@link DataSchemaNode}
*/
- public static Map<String, ListSchemaNode> buildMapOfListNodes(SchemaContext context) {
+ public static Map<String, ListSchemaNode> buildMapOfListNodes(final SchemaContext context) {
Map<String, ListSchemaNode> mapOfLists = new HashMap<>();
Stack<DataSchemaNode> jobQueue = new Stack<>();
* @param qNamesPath
* @return path
*/
- private static String schemaPathToPath(List<QName> qNamesPath) {
+ private static String schemaPathToPath(final List<QName> qNamesPath) {
List<String> pathSeed = new ArrayList<>();
for (QName qNameItem : qNamesPath) {
pathSeed.add(qNameItem.getLocalName());
*
* @param newNode
*/
- public static void fixParentRelation(Node<?> newNode) {
+ public static void fixParentRelation(final Node<?> newNode) {
if (newNode.getParent() != null) {
- List<Node<?>> siblings = newNode.getParent().getChildren();
+ List<Node<?>> siblings = newNode.getParent().getValue();
if (!siblings.contains(newNode)) {
siblings.add(newNode);
}
*
* @param parentNode
*/
- public static void fixChildrenRelation(CompositeNode parentNode) {
- if (parentNode.getChildren() != null) {
- for (Node<?> child : parentNode.getChildren()) {
+ public static void fixChildrenRelation(final CompositeNode parentNode) {
+ if (parentNode.getValue() != null) {
+ for (Node<?> child : parentNode.getValue()) {
if (child instanceof AbstractNodeTO<?>) {
((AbstractNodeTO<?>) child).setParent(parentNode);
}
* @param dataMap
* @return list of values of map, found by given keys
*/
- public static <T, K> List<K> collectMapValues(List<T> keys, Map<T, K> dataMap) {
+ public static <T, K> List<K> collectMapValues(final List<T> keys, final Map<T, K> dataMap) {
List<K> valueSubList = new ArrayList<>();
for (T key : keys) {
valueSubList.add(dataMap.get(key));
* @param nodes
* @return list of children in list of appropriate type
*/
- public static List<Node<?>> buildChildrenList(Node<?>... nodes) {
+ public static List<Node<?>> buildChildrenList(final Node<?>... nodes) {
return Lists.newArrayList(nodes);
}
* XML as {@link InputStream}. The output of the operation SHOULD be root
* <code>CompositeNode</code> or <code>SimpleElement</code> depends by which
* element XML begins. The XML header is omitted by XML parser.
- *
+ *
* @author Lukas Sedlak
- *
+ *
* @see CompositeNode
* @see SimpleNode
* @see Node
* output of the operation SHOULD be root <code>CompositeNode</code> or
* <code>SimpleElement</code> depends on element that XML document begins.
* The XML header is omitted by XML parser.
- *
+ *
* @param inputStream
* XML Input Stream
* @return root <code>Node</code> element conformant to XML start element in
if (newNode != null) {
processingQueue.push(newNode);
if (compParentNode != null) {
- compParentNode.getChildren().add(newNode);
+ compParentNode.getValue().add(newNode);
}
}
} else if (event.isEndElement()) {
* characters value. If the SimpleNode is composed only by empty XML tag
* (i.e. {@code <emptyTag />} or {@code<emptyTag></emptyTag>}) the result
* will be also <code>true</code>.
- *
+ *
* @param event
* actual XMLEvent that is processed
* @return <code>true</code> only and only if the XMLEvent Start Element is
* Simple element tag and contains character values or is empty XML
* tag.
* @throws XMLStreamException
- *
+ *
* @see SimpleNode
*/
private static boolean isSimpleNodeEvent(final XMLEvent event) throws XMLStreamException {
* contains 1..N XML child elements. (i.e. {@code <compositeNode>
* <simpleNode>data</simpleNode>
* </compositeNode>})
- *
+ *
* @param event
* actual XMLEvent that is processed
* @return <code>true</code> only if XML Element contains 1..N child
* elements, otherwise returns <code>false</code>
* @throws XMLStreamException
- *
+ *
* @see CompositeNode
*/
private static boolean isCompositeNodeEvent(final XMLEvent event) throws XMLStreamException {
/**
* Creates and returns <code>SimpleNode</code> instance from actually
* processed XML Start Element.
- *
+ *
* @param startElement
* actual XML Start Element that is processed
* @param parent
* @return <code>new SimpleNode</code> instance from actually processed XML
* Start Element
* @throws XMLStreamException
- *
+ *
* @see SimpleNode
*/
private static SimpleNode<String> resolveSimpleNodeFromStartElement(final StartElement startElement,
- CompositeNode parent) throws XMLStreamException {
+ final CompositeNode parent) throws XMLStreamException {
checkArgument(startElement != null, "Start Element cannot be NULL!");
String data = null;
/**
* Creates and returns <code>MutableCompositeNode</code> instance from
* actually processed XML Start Element.
- *
+ *
* @param startElement
* actual XML Start Element that is processed
* @param parent
* Parent CompositeNode
* @return <code>new MutableCompositeNode</code> instance from actually
* processed XML Start Element
- *
+ *
* @see CompositeNode
* @see MutableCompositeNode
*/
private static MutableCompositeNode resolveCompositeNodeFromStartElement(final StartElement startElement,
- CompositeNode parent) {
+ final CompositeNode parent) {
checkArgument(startElement != null, "Start Element cannot be NULL!");
return NodeFactory.createMutableCompositeNode(resolveElementQName(startElement), parent,
/**
* Extract and retrieve XML Element QName to OpenDaylight QName.
- *
+ *
* @param element
* Start Element
* @return QName instance composed of <code>elements</code> Namespace and
* Local Part.
- *
+ *
* @see QName
*/
private static QName resolveElementQName(final StartElement element) {
Element element;
SchemaContext schemaContext;
- ElementWithSchemaContext(Element element,SchemaContext schemaContext) {
+ ElementWithSchemaContext(final Element element,final SchemaContext schemaContext) {
this.schemaContext = schemaContext;
this.element = element;
}
private static final XmlCodecProvider DEFAULT_XML_VALUE_CODEC_PROVIDER = new XmlCodecProvider() {
@Override
- public TypeDefinitionAwareCodec<Object, ? extends TypeDefinition<?>> codecFor(TypeDefinition<?> baseType) {
+ public TypeDefinitionAwareCodec<Object, ? extends TypeDefinition<?>> codecFor(final TypeDefinition<?> baseType) {
return TypeDefinitionAwareCodec.from(baseType);
}
};
* @return new instance of XML Document
* @throws UnsupportedDataTypeException
*/
- public static Document toDocument(CompositeNode data, DataNodeContainer schema, XmlCodecProvider codecProvider)
+ public static Document toDocument(final CompositeNode data, final DataNodeContainer schema, final XmlCodecProvider codecProvider)
throws UnsupportedDataTypeException {
Preconditions.checkNotNull(data);
Preconditions.checkNotNull(schema);
* @return new instance of XML Document
* @throws UnsupportedDataTypeException
*/
- public static Document toDocument(CompositeNode data, XmlCodecProvider codecProvider)
+ public static Document toDocument(final CompositeNode data, final XmlCodecProvider codecProvider)
throws UnsupportedDataTypeException {
Preconditions.checkNotNull(data);
return doc;
}
- private static Element createXmlRootElement(Document doc, Node<?> data, SchemaNode schema,
- XmlCodecProvider codecProvider) throws UnsupportedDataTypeException {
+ private static Element createXmlRootElement(final Document doc, final Node<?> data, final SchemaNode schema,
+ final XmlCodecProvider codecProvider) throws UnsupportedDataTypeException {
Element itemEl = createElementFor(doc, data);
if (data instanceof SimpleNode<?>) {
if (schema instanceof LeafListSchemaNode) {
}
}
} else { // CompositeNode
- for (Node<?> child : ((CompositeNode) data).getChildren()) {
+ for (Node<?> child : ((CompositeNode) data).getValue()) {
DataSchemaNode childSchema = null;
if (schema != null) {
childSchema = findFirstSchemaForNode(child, ((DataNodeContainer) schema).getChildNodes());
return itemEl;
}
- public static Element createElementFor(Document doc, Node<?> data) {
+ public static Element createElementFor(final Document doc, final Node<?> data) {
QName dataType = data.getNodeType();
Element ret;
if (dataType.getNamespace() != null) {
return ret;
}
- public static void writeValueByType(Element element, SimpleNode<?> node, TypeDefinition<?> type,
- DataSchemaNode schema, XmlCodecProvider codecProvider) {
+ public static void writeValueByType(final Element element, final SimpleNode<?> node, final TypeDefinition<?> type,
+ final DataSchemaNode schema, final XmlCodecProvider codecProvider) {
Object nodeValue = node.getValue();
writeValueByType(element, type, codecProvider, nodeValue);
}
- public static void writeValueByType(Element element, TypeDefinition<?> type, XmlCodecProvider codecProvider, Object nodeValue) {
+ public static void writeValueByType(final Element element, final TypeDefinition<?> type, final XmlCodecProvider codecProvider, final Object nodeValue) {
TypeDefinition<?> baseType = resolveBaseTypeFrom(type);
if (baseType instanceof IdentityrefTypeDefinition) {
if (nodeValue instanceof QName) {
}
- public final static TypeDefinition<?> resolveBaseTypeFrom(TypeDefinition<?> type) {
+ public final static TypeDefinition<?> resolveBaseTypeFrom(final TypeDefinition<?> type) {
TypeDefinition<?> superType = type;
while (superType.getBaseType() != null) {
superType = superType.getBaseType();
return superType;
}
- private static final DataSchemaNode findFirstSchemaForNode(Node<?> node, Set<DataSchemaNode> dataSchemaNode) {
+ private static final DataSchemaNode findFirstSchemaForNode(final Node<?> node, final Set<DataSchemaNode> dataSchemaNode) {
if (dataSchemaNode != null && node != null) {
for (DataSchemaNode dsn : dataSchemaNode) {
if (node.getNodeType().getLocalName().equals(dsn.getQName().getLocalName())) {
return null;
}
- public static Node<?> toDomNode(Element xmlElement, Optional<DataSchemaNode> schema,
- Optional<XmlCodecProvider> codecProvider) {
+ public static Node<?> toDomNode(final Element xmlElement, final Optional<DataSchemaNode> schema,
+ final Optional<XmlCodecProvider> codecProvider) {
if (schema.isPresent()) {
return toNodeWithSchema(xmlElement, schema.get(), codecProvider.or(DEFAULT_XML_VALUE_CODEC_PROVIDER));
}
return toDomNode(xmlElement);
}
- public static CompositeNode fromElement(Element xmlElement) {
+ public static CompositeNode fromElement(final Element xmlElement) {
CompositeNodeBuilder<ImmutableCompositeNode> node = ImmutableCompositeNode.builder();
node.setQName(qNameFromElement(xmlElement));
return node.toInstance();
}
- public static QName qNameFromElement(Element xmlElement) {
+ public static QName qNameFromElement(final Element xmlElement) {
String namespace = xmlElement.getNamespaceURI();
String localName = xmlElement.getLocalName();
return QName.create(namespace != null ? URI.create(namespace) : null, null, localName);
}
- private static Node<?> toNodeWithSchema(Element xmlElement, DataSchemaNode schema, XmlCodecProvider codecProvider,SchemaContext schemaCtx) {
+ private static Node<?> toNodeWithSchema(final Element xmlElement, final DataSchemaNode schema, final XmlCodecProvider codecProvider,final SchemaContext schemaCtx) {
checkQName(xmlElement, schema.getQName());
if (schema instanceof DataNodeContainer) {
return toCompositeNodeWithSchema(xmlElement, schema.getQName(), (DataNodeContainer) schema, codecProvider,schemaCtx);
return null;
}
- private static Node<?> toNodeWithSchema(Element xmlElement, DataSchemaNode schema, XmlCodecProvider codecProvider) {
+ private static Node<?> toNodeWithSchema(final Element xmlElement, final DataSchemaNode schema, final XmlCodecProvider codecProvider) {
return toNodeWithSchema(xmlElement, schema, codecProvider, null);
}
- protected static Node<?> toSimpleNodeWithType(Element xmlElement, LeafSchemaNode schema,
- XmlCodecProvider codecProvider,SchemaContext schemaCtx) {
+ protected static Node<?> toSimpleNodeWithType(final Element xmlElement, final LeafSchemaNode schema,
+ final XmlCodecProvider codecProvider,final SchemaContext schemaCtx) {
TypeDefinitionAwareCodec<? extends Object, ? extends TypeDefinition<?>> codec = codecProvider.codecFor(schema.getType());
String text = xmlElement.getTextContent();
Object value = null;
return new SimpleNodeTOImpl<>(schema.getQName(), null, value, modifyAction.orNull());
}
- private static Node<?> toSimpleNodeWithType(Element xmlElement, LeafListSchemaNode schema,
- XmlCodecProvider codecProvider,SchemaContext schemaCtx) {
+ private static Node<?> toSimpleNodeWithType(final Element xmlElement, final LeafListSchemaNode schema,
+ final XmlCodecProvider codecProvider,final SchemaContext schemaCtx) {
TypeDefinitionAwareCodec<? extends Object, ? extends TypeDefinition<?>> codec = codecProvider.codecFor(schema.getType());
String text = xmlElement.getTextContent();
Object value = null;
return new SimpleNodeTOImpl<>(schema.getQName(), null, value, modifyAction.orNull());
}
- private static Node<?> toCompositeNodeWithSchema(Element xmlElement, QName qName, DataNodeContainer schema,
- XmlCodecProvider codecProvider,SchemaContext schemaCtx) {
+ private static Node<?> toCompositeNodeWithSchema(final Element xmlElement, final QName qName, final DataNodeContainer schema,
+ final XmlCodecProvider codecProvider,final SchemaContext schemaCtx) {
List<Node<?>> values = toDomNodes(xmlElement, Optional.fromNullable(schema.getChildNodes()),schemaCtx);
Optional<ModifyAction> modifyAction = getModifyOperationFromAttributes(xmlElement);
return ImmutableCompositeNode.create(qName, values, modifyAction.orNull());
public static final QName OPERATION_ATTRIBUTE_QNAME = QName.create(URI.create("urn:ietf:params:xml:ns:netconf:base:1.0"), null, "operation");
- public static Optional<ModifyAction> getModifyOperationFromAttributes(Element xmlElement) {
+ public static Optional<ModifyAction> getModifyOperationFromAttributes(final Element xmlElement) {
Attr attributeNodeNS = xmlElement.getAttributeNodeNS(OPERATION_ATTRIBUTE_QNAME.getNamespace().toString(), OPERATION_ATTRIBUTE_QNAME.getLocalName());
- if(attributeNodeNS == null)
- return Optional.absent();
+ if(attributeNodeNS == null) {
+ return Optional.absent();
+ }
ModifyAction action = ModifyAction.fromXmlValue(attributeNodeNS.getValue());
Preconditions.checkArgument(action.isOnElementPermitted(), "Unexpected operation %s on %s", action, xmlElement);
return Optional.of(action);
}
- private static void checkQName(Element xmlElement, QName qName) {
+ private static void checkQName(final Element xmlElement, final QName qName) {
checkState(Objects.equal(xmlElement.getNamespaceURI(), qName.getNamespace().toString()));
checkState(qName.getLocalName().equals(xmlElement.getLocalName()));
}
- public static final Optional<DataSchemaNode> findFirstSchema(QName qname, Set<DataSchemaNode> dataSchemaNode) {
+ public static final Optional<DataSchemaNode> findFirstSchema(final QName qname, final Set<DataSchemaNode> dataSchemaNode) {
if (dataSchemaNode != null && !dataSchemaNode.isEmpty() && qname != null) {
for (DataSchemaNode dsn : dataSchemaNode) {
if (qname.isEqualWithoutRevision(dsn.getQName())) {
return Optional.absent();
}
- public static Node<?> toDomNode(Document doc) {
+ public static Node<?> toDomNode(final Document doc) {
return toDomNode(doc.getDocumentElement());
}
- private static Node<?> toDomNode(Element element) {
+ private static Node<?> toDomNode(final Element element) {
QName qname = qNameFromElement(element);
ImmutableList.Builder<Node<?>> values = ImmutableList.<Node<?>> builder();
return ImmutableCompositeNode.create(qname, values.build());
}
- public static List<Node<?>> toDomNodes(final Element element, final Optional<Set<DataSchemaNode>> context,SchemaContext schemaCtx) {
+ public static List<Node<?>> toDomNodes(final Element element, final Optional<Set<DataSchemaNode>> context,final SchemaContext schemaCtx) {
return forEachChild(element.getChildNodes(),schemaCtx, new Function<ElementWithSchemaContext, Optional<Node<?>>>() {
@Override
- public Optional<Node<?>> apply(ElementWithSchemaContext input) {
+ public Optional<Node<?>> apply(final ElementWithSchemaContext input) {
if (context.isPresent()) {
QName partialQName = qNameFromElement(input.getElement());
Optional<DataSchemaNode> schemaNode = findFirstSchema(partialQName, context.get());
* Element with equal notification QName defined in XML Document.
*/
public static CompositeNode notificationToDomNodes(final Document document,
- final Optional<Set<NotificationDefinition>> notifications, SchemaContext schemaCtx) {
+ final Optional<Set<NotificationDefinition>> notifications, final SchemaContext schemaCtx) {
if (notifications.isPresent() && (document != null) && (document.getDocumentElement() != null)) {
final NodeList originChildNodes = document.getDocumentElement().getChildNodes();
for (int i = 0; i < originChildNodes.getLength(); i++) {
return Optional.<NotificationDefinition>absent();
}
- private static final <T> List<T> forEachChild(NodeList nodes, SchemaContext schemaContext, Function<ElementWithSchemaContext, Optional<T>> forBody) {
+ private static final <T> List<T> forEachChild(final NodeList nodes, final SchemaContext schemaContext, final Function<ElementWithSchemaContext, Optional<T>> forBody) {
ImmutableList.Builder<T> ret = ImmutableList.<T> builder();
for (int i = 0; i < nodes.getLength(); i++) {
org.w3c.dom.Node child = nodes.item(i);
Assert.assertEquals(2, lazyN2N.getKeyNodes().size());
Assert.assertEquals(mutableTree, subMutant.getParent());
- Assert.assertEquals(mutableTree.getChildren().size(), 1);
- Assert.assertEquals(mutableTree.getChildren().iterator().next(), subMutant);
+ Assert.assertEquals(mutableTree.getValue().size(), 1);
+ Assert.assertEquals(mutableTree.getValue().iterator().next(), subMutant);
}
/**
.getLogger(MyNodeBuilder.class);
private URI qnNamespace;
- private String qnPrefix;
- private Date qnRevision;
+ private final String qnPrefix;
+ private final Date qnRevision;
private CompositeNode rootNode;
/**
* @param baseQName
*/
- private MyNodeBuilder(QName baseQName) {
+ private MyNodeBuilder(final QName baseQName) {
qnNamespace = baseQName.getNamespace();
qnPrefix = baseQName.getPrefix();
qnRevision = baseQName.getRevision();
}
@Override
- protected void setParent(Object parent, Object child) {
+ protected void setParent(final Object parent, final Object child) {
// do nothing
if (child instanceof AbstractNodeTO<?>) {
((AbstractNodeTO<?>) child).setParent((CompositeNode) parent);
}
@Override
- protected Object createNode(Object name) {
+ protected Object createNode(final Object name) {
MutableCompositeNode newNode = NodeFactory.createMutableCompositeNode(
createQName(name), getCurrentNode(), null, null, null);
NodeUtils.fixParentRelation(newNode);
}
@Override
- protected Object createNode(Object name, @SuppressWarnings("rawtypes") Map attributes) {
+ protected Object createNode(final Object name, @SuppressWarnings("rawtypes") final Map attributes) {
ModifyAction modifyAction = processAttributes(attributes);
MutableCompositeNode newNode = NodeFactory.createMutableCompositeNode(
createQName(name), getCurrentNode(), null, modifyAction, null);
@Override
- protected Object createNode(Object name, @SuppressWarnings("rawtypes") Map attributes, Object value) {
+ protected Object createNode(final Object name, @SuppressWarnings("rawtypes") final Map attributes, final Object value) {
ModifyAction modifyAction = processAttributes(attributes);
SimpleNode<Object> newNode = NodeFactory.createImmutableSimpleNode(
createQName(name), (CompositeNode) getCurrent(), value, modifyAction);
* @param attributes
* @return
*/
- private ModifyAction processAttributes(@SuppressWarnings("rawtypes") Map attributes) {
+ private ModifyAction processAttributes(@SuppressWarnings("rawtypes") final Map attributes) {
LOG.debug("attributes:" + attributes);
ModifyAction modAction = null;
}
@Override
- protected Object createNode(Object name, Object value) {
+ protected Object createNode(final Object name, final Object value) {
SimpleNode<Object> newNode = NodeFactory.createImmutableSimpleNode(createQName(name), (CompositeNode) getCurrent(), value);
NodeUtils.fixParentRelation(newNode);
return newNode;
}
- private QName createQName(Object localName) {
+ private QName createQName(final Object localName) {
LOG.debug("qname for: "+localName);
return new QName(qnNamespace, qnRevision, qnPrefix, (String) localName);
}
}
@Override
- protected Object postNodeCompletion(Object parent, Object node) {
+ protected Object postNodeCompletion(final Object parent, final Object node) {
Node<?> nodeRevisited = (Node<?>) node;
LOG.debug("postNodeCompletion at: \n "+ nodeRevisited+"\n "+parent);
if (nodeRevisited instanceof MutableCompositeNode) {
rootNode = (CompositeNode) nodeRevisited;
} else {
NodeUtils.fixParentRelation(nodeRevisited);
- nodeRevisited.getParent().getChildren().remove(mutant);
+ nodeRevisited.getParent().getValue().remove(mutant);
}
}
*/
@Test
public void testImmutableNodes() throws Exception {
- Assert.assertEquals(2, network.getChildren().size());
+ Assert.assertEquals(2, network.getValue().size());
CompositeNode tpList = NodeUtils.findNodeByXpath(networkShadow,
NodeHelper.AddNamespaceToPattern(
"//{0}node[{0}node-id/text()='nodeId_19']/{0}termination-points", ns));
Document shadowConfig = NodeUtils.buildShadowDomTree(root);
NodeHelper.compareXmlTree(shadowConfig, "./mutableNodesConfig.xml", getClass());
- Assert.assertEquals(1, root.getChildren().size());
+ Assert.assertEquals(1, root.getValue().size());
Assert.assertEquals(1, ifNode.getSimpleNodesByName("name").size());
Assert.assertEquals(1, ifNode.getSimpleNodesByName("mtu").size());
Assert.assertEquals(2, topNode.getCompositesByName("interface").size());
" </network-elements>\n" +
"</network>";
- private static String domTreeString(Document domTree) throws TransformerException {
+ private static String domTreeString(final Document domTree) throws TransformerException {
TransformerFactory transformerFact = TransformerFactory.newInstance();
transformerFact.setAttribute("indent-number", 4);
Transformer transformer = transformerFact.newTransformer();
* @param out
* @throws Exception
*/
- private static void dumpDoc(Document domTree, PrintStream out) throws Exception {
+ private static void dumpDoc(final Document domTree, final PrintStream out) throws Exception {
out.println(domTreeString(domTree));
}
- public static void dumpDoc(Document domTree, Logger logger) throws TransformerException {
+ public static void dumpDoc(final Document domTree, final Logger logger) throws TransformerException {
logger.info("{}", domTreeString(domTree));
}
* @param qName
* @return example tree, see {@link #NETWORK_XML}
*/
- public static CompositeNode buildTestConfigTree(QName qName) {
+ public static CompositeNode buildTestConfigTree(final QName qName) {
List<Node<?>> value = new ArrayList<Node<?>>();
value.add(NodeFactory.createImmutableSimpleNode(new QName(qName, "element-id"), null, "ntElementId_09"));
CompositeNode ntElementNode1 = NodeFactory.createImmutableCompositeNode(new QName(qName, "network-element"), null, value);
/**
* @param parentNode
*/
- public static void assignParentToChildren(CompositeNode parentNode) {
- for (Node<?> child : parentNode.getChildren()) {
+ public static void assignParentToChildren(final CompositeNode parentNode) {
+ for (Node<?> child : parentNode.getValue()) {
((AbstractNodeTO<?>) child).setParent(parentNode);
}
}
* @return tree root
* @throws Exception
*/
- public static CompositeNode loadConfigByGroovy(String scriptName) throws Exception {
+ public static CompositeNode loadConfigByGroovy(final String scriptName) throws Exception {
InputStream configStream = NodeHelper.class.getResourceAsStream(scriptName);
Binding binding = new Binding();
GroovyShell gShell = new GroovyShell(binding);
* @param nsArg , e.g.: <pre>{"uri:ns1", "uri:ns2"}</pre>
* @return pattern with namespaces: <pre>//uri:ns1:network/uri:ns2:xx[text() = ''sss'']"</pre>
*/
- public static String AddNamespaceToPattern(String pattern, Object... nsArg) {
+ public static String AddNamespaceToPattern(final String pattern, final Object... nsArg) {
Object[] ns = nsArg;
String patternNs = pattern.replaceAll("'", "''");
if (ns == null) {
* @throws SAXException
* @throws IOException
*/
- public static void compareXmlTree(Document tree, String xmlFile, Class<?> clazz) throws Exception,
+ public static void compareXmlTree(final Document tree, final String xmlFile, final Class<?> clazz) throws Exception,
SAXException, IOException {
ByteArrayOutputStream actualRaw = new ByteArrayOutputStream();
dumpDoc(tree, new PrintStream(actualRaw));
CompositeNode topology = network.getCompositesByName("topologies").iterator().next()
.getCompositesByName("topology").iterator().next();
- Map<QName, List<Node<?>>> nodeMap = NodeUtils.buildNodeMap(topology.getChildren());
+ Map<QName, List<Node<?>>> nodeMap = NodeUtils.buildNodeMap(topology.getValue());
Assert.assertEquals(3, nodeMap.size());
}
NodeHelper.compareXmlTree(shadowTree, "./config02g-shadow.xml", getClass());
}
- private static void checkFamilyBinding(CompositeNode treeRoot) throws Exception {
+ private static void checkFamilyBinding(final CompositeNode treeRoot) throws Exception {
Stack<CompositeNode> jobQueue = new Stack<>();
jobQueue.push(treeRoot);
while (!jobQueue.isEmpty()) {
CompositeNode job = jobQueue.pop();
- for (Node<?> child : job.getChildren()) {
+ for (Node<?> child : job.getValue()) {
if (child instanceof CompositeNode) {
jobQueue.push((CompositeNode) child);
}
public class XmlTreeBuilderTest {
private InputStream inputStream;
-
+
/**
* Perform pre-test initialization
- *
+ *
* @throws Exception
*/
@Before
}
assertNotNull(rootNode);
assertTrue(rootNode instanceof CompositeNode);
-
+
CompositeNode compRootNode = (CompositeNode)rootNode;
- assertNotNull(compRootNode.getChildren());
-
+ assertNotNull(compRootNode.getValue());
+
SimpleNode<String> methodName = null;
SimpleNode<String> emptyTag = null;
CompositeNode params = null;
- for (final Node<?> childNode : compRootNode.getChildren()) {
+ for (final Node<?> childNode : compRootNode.getValue()) {
if (childNode instanceof SimpleNode) {
if ("emptyTag".equals(childNode.getNodeType().getLocalName())) {
emptyTag = (SimpleNode<String>) childNode;
} else if ("methodName".equals(childNode.getNodeType().getLocalName())) {
methodName = (SimpleNode<String>) childNode;
}
-
+
} else if (childNode instanceof CompositeNode) {
params = (CompositeNode) childNode;
}
}
-
+
assertNotNull(methodName);
assertNotNull(params);
assertTrue(emptyTag.getValue().isEmpty());
assertEquals(methodName.getValue(), "getDeviceEquipment");
-
+
String deviceId = null;
String deviceIP = null;
- for (final Node<?> param : params.getChildren()) {
+ for (final Node<?> param : params.getValue()) {
if (param instanceof CompositeNode) {
- final Node<?> valueNode = ((CompositeNode) param).getChildren().get(0);
-
+ final Node<?> valueNode = ((CompositeNode) param).getValue().get(0);
+
assertTrue(valueNode instanceof CompositeNode);
final CompositeNode value = (CompositeNode) valueNode;
- final Node<?> stringNode = value.getChildren().get(0);
+ final Node<?> stringNode = value.getValue().get(0);
assertTrue(stringNode instanceof SimpleNode);
-
+
final SimpleNode<String> string = (SimpleNode<String>) stringNode;
if ("DeviceID123".equals(string.getValue())) {
deviceId = string.getValue();
}
}
}
-
+
assertNotNull(deviceId);
assertNotNull(deviceIP);
}
-
+
@Test
public void nodeMapInCompositeNodeTest() {
Node<?> rootNode = null;
} catch (XMLStreamException e) {
e.printStackTrace();
}
-
+
CompositeNode compRootNode = (CompositeNode)rootNode;
List<CompositeNode> params = compRootNode.getCompositesByName("params");
assertEquals(1, params.size());