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.mdsal.binding.generator.impl;
10 import static com.google.common.base.Preconditions.checkArgument;
11 import static com.google.common.base.Preconditions.checkState;
13 import java.util.List;
15 import org.opendaylight.mdsal.binding.generator.api.BindingGenerator;
16 import org.opendaylight.mdsal.binding.generator.api.BindingRuntimeGenerator;
17 import org.opendaylight.mdsal.binding.generator.api.BindingRuntimeTypes;
18 import org.opendaylight.mdsal.binding.model.api.Type;
19 import org.opendaylight.yangtools.yang.model.api.Module;
20 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
22 public class BindingGeneratorImpl implements BindingGenerator, BindingRuntimeGenerator {
24 * Resolves generated types from <code>context</code> schema nodes only for
25 * modules specified in <code>modules</code>
27 * Generated types are created for modules, groupings, types, containers,
28 * lists, choices, augments, rpcs, notification, identities.
31 * schema context which contains data about all schema nodes
34 * set of modules for which schema nodes should be generated
36 * @return list of types (usually <code>GeneratedType</code> or
37 * <code>GeneratedTransferObject</code>) which:
39 * <li>are generated from <code>context</code> schema nodes and</li>
40 * <li>are also part of some of the module in <code>modules</code>
43 * @throws IllegalArgumentException
45 * <li>if arg <code>context</code> is null or</li>
46 * <li>if arg <code>modules</code> is null</li>
48 * @throws IllegalStateException
49 * if <code>context</code> contain no modules
52 public List<Type> generateTypes(final SchemaContext context, final Set<Module> modules) {
53 checkContext(context);
54 checkArgument(modules != null, "Set of Modules cannot be NULL.");
55 return new CodegenTypeGenerator(context).toTypes(modules);
59 public BindingRuntimeTypes generateTypeMapping(final SchemaContext context) {
60 checkContext(context);
61 return new RuntimeTypeGenerator(context).toTypeMapping();
64 private static void checkContext(final SchemaContext context) {
65 checkArgument(context != null, "Schema Context reference cannot be NULL.");
66 checkState(context.getModules() != null, "Schema Context does not contain defined modules.");