Add hooking into NormalizedNodeParsers.
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / transform / base / parser / ExtensibleParser.java
1 /*
2  * Copyright (c) 2015 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
9 package org.opendaylight.yangtools.yang.data.impl.schema.transform.base.parser;
10
11 import java.util.Map;
12 import javax.annotation.Nullable;
13 import org.opendaylight.yangtools.yang.common.QName;
14 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
15 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
16 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeBuilder;
17 import org.opendaylight.yangtools.yang.data.impl.schema.transform.ToNormalizedNodeParser;
18
19 /**
20  * Extensible parser allows its subclasses to customize the building process of normalized nodes
21  *
22  * @param <P>
23  * @param <E>
24  * @param <N>
25  * @param <S>
26  */
27 public interface ExtensibleParser<P extends YangInstanceIdentifier.PathArgument, E, N extends NormalizedNode<P, ?>, S>
28         extends ToNormalizedNodeParser<E, N, S> {
29
30     /**
31      * Provide building strategy
32      */
33     BuildingStrategy<P, N> getBuildingStrategy();
34
35     /**
36      * Building strategy serves as a set of hooks into the parsing process.
37      *
38      * @param <P>
39      * @param <N>
40      */
41     interface BuildingStrategy<P extends YangInstanceIdentifier.PathArgument, N extends NormalizedNode<P, ?>> {
42
43         /**
44          * Build normalized node from its builder
45          *
46          * @param builder filled builder for node
47          * @return built normalized node or null if the node should not be built
48          */
49         @Nullable N build(NormalizedNodeBuilder<P, ?, N> builder);
50
51         /**
52          * Hook for subclasses to handle attributes associated with current node. This is called before the build method
53          * and allows subclasses to react to node's attributes e.g. modification operation
54          *
55          * @param attributes attributes for node
56          * @param containerBuilder builder created for node. Can be modified according to attributes e.g. remove attribute
57          */
58         void prepareAttributes(Map<QName, String> attributes, NormalizedNodeBuilder<P, ?, N> containerBuilder);
59     }
60 }