2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.data.operations;
10 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
11 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
13 import com.google.common.base.Optional;
15 final class LeafNodeModification implements Modification<LeafSchemaNode, LeafNode<?>> {
18 public Optional<LeafNode<?>> modify(LeafSchemaNode schema, Optional<LeafNode<?>> actualNode,
19 Optional<LeafNode<?>> modificationNode, OperationStack operationStack) throws DataModificationException {
21 operationStack.enteringNode(modificationNode);
23 Optional<LeafNode<?>> result;
25 // Returns either actual node, modification node or empty in case of removal
26 switch (operationStack.getCurrentOperation()) {
28 result = modificationNode.isPresent() ? modificationNode : actualNode;
32 DataModificationException.DataExistsException.check(schema.getQName(), actualNode, null);
35 result = modificationNode;
39 DataModificationException.DataMissingException.check(schema.getQName(), actualNode);
42 result = Optional.absent();
50 throw new UnsupportedOperationException(String.format("Unable to perform operation: %s on: %s, unknown", operationStack.getCurrentOperation(), schema));
54 operationStack.exitingNode(modificationNode);