Refactor mdsal-binding-generator artifacts
[mdsal.git] / binding / mdsal-binding-generator / src / main / java / org / opendaylight / mdsal / binding / yang / types / BaseYangTypesProvider.java
1 /*
2  * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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.mdsal.binding.yang.types;
9
10 import org.eclipse.jdt.annotation.NonNull;
11 import org.opendaylight.mdsal.binding.model.api.Restrictions;
12 import org.opendaylight.mdsal.binding.model.api.Type;
13 import org.opendaylight.mdsal.binding.model.ri.BaseYangTypes;
14 import org.opendaylight.mdsal.binding.model.ri.Types;
15 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
16 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
17
18 @Deprecated(forRemoval = true)
19 final class BaseYangTypesProvider implements TypeProvider {
20     static final @NonNull BaseYangTypesProvider INSTANCE = new BaseYangTypesProvider();
21
22     private BaseYangTypesProvider() {
23         // Hidden on purpose
24     }
25
26     /**
27      * Searches <code>Type</code> value to which is YANG <code>type</code>
28      * mapped.
29      *
30      * @param type
31      *            type definition representation of YANG type
32      * @return java <code>Type</code> representation of <code>type</code>.
33      *         If <code>type</code> isn't found then <code>null</code> is
34      *         returned.
35      */
36     @Override
37     public Type javaTypeForSchemaDefinitionType(final TypeDefinition<?> type, final SchemaNode parentNode,
38             final boolean lenientRelativeLeafrefs) {
39         return type == null ? null : BaseYangTypes.javaTypeForYangType(type.getQName().getLocalName());
40     }
41
42     @Override
43     public Type javaTypeForSchemaDefinitionType(final TypeDefinition<?> type, final SchemaNode parentNode,
44             final Restrictions restrictions, final boolean lenientRelativeLeafrefs) {
45         final String typeName = type.getQName().getLocalName();
46         final Type mapped = BaseYangTypes.javaTypeForYangType(typeName);
47         return mapped == null || restrictions == null ? mapped : Types.restrictedType(mapped, restrictions);
48     }
49 }