Separate out RootModificationApplyOperation
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / tree / AlwaysFailOperation.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.data.impl.schema.tree;
9
10 import java.util.Optional;
11 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
12 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode;
13 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.Version;
14
15 /**
16  * An implementation of apply operation which fails to do anything, consistently. An instance of this class is used by
17  * the data tree if it does not have a SchemaContext attached and hence cannot perform anything meaningful.
18  */
19 final class AlwaysFailOperation extends NonApplyDelegatedModificationApplyOperation {
20     static final ModificationApplyOperation INSTANCE = new AlwaysFailOperation();
21
22     private AlwaysFailOperation() {
23
24     }
25
26     @Override
27     ModificationApplyOperation delegate() {
28         throw ise();
29     }
30
31     @Override
32     Optional<TreeNode> apply(final ModifiedNode modification, final Optional<TreeNode> currentMeta,
33             final Version version) {
34         throw ise();
35     }
36
37     @Override
38     void checkApplicable(final ModificationPath path, final NodeModification modification,
39             final Optional<TreeNode> current, final Version version) throws DataValidationFailedException {
40         throw ise();
41     }
42
43     private static IllegalStateException ise() {
44         return new IllegalStateException("Schema Context is not available.");
45     }
46 }