Bug 6859 #3 Binding generator v1 refactoring
[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(String generatedSourceDir) {
33
34         boolean generateSource = Boolean.valueOf(System.getProperty( GENERATE_CODEC_SOURCE_PROP, "false"));
35         if(generateSource) {
36             return new DefaultSourceCodeGenerator(generatedSourceDir);
37         }
38
39         return NULL_GENERATOR;
40     }
41 }