e4b26e9095c535d34cb6919228c64e7f8d9fee93
[mdsal.git] / binding / mdsal-binding-generator-impl / src / main / java / org / opendaylight / mdsal / binding / generator / util / SourceCodeGeneratorFactory.java
1 /*
2  * Copyright (c) 2014 Brocade Communications 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.mdsal.binding.generator.util;
10
11 /**
12  * Factory class for creating SourceCodeGenerator instances.
13  *
14  * @author Thomas Pantelis
15  */
16 public class SourceCodeGeneratorFactory {
17
18     private static final String GENERATE_CODEC_SOURCE_PROP = "org.opendaylight.yangtools.sal.generateCodecSource";
19
20     private static final SourceCodeGenerator NULL_GENERATOR = new NullSourceCodeGenerator();
21
22     /**
23      * Gets a SourceCodeGenerator instance.
24      * <p>
25      * Generation of source code is controlled by the <i>org.opendaylight.yangtools.sal.generateCodecSource</i>
26      * system property. If set to true, a DefaultSourceCodeGenerator instance is returned, otherwise a
27      * NullSourceCodeGenerator is returned.
28      *
29      * @param generatedSourceDir the directory in which to put generated source files. If null,
30      *     a default is used (see DefaultSourceCodeGenerator).
31      */
32     public SourceCodeGenerator getInstance(final String generatedSourceDir) {
33         boolean generateSource = Boolean.getBoolean(GENERATE_CODEC_SOURCE_PROP);
34         if (generateSource) {
35             return new DefaultSourceCodeGenerator(generatedSourceDir);
36         }
37
38         return NULL_GENERATOR;
39     }
40 }