--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.mdsal.binding2.java.api.generator;
+
+import com.google.common.annotations.Beta;
+import org.opendaylight.mdsal.binding2.java.api.generator.renderers.EnumRenderer;
+import org.opendaylight.mdsal.binding2.model.api.CodeGenerator;
+import org.opendaylight.mdsal.binding2.model.api.Enumeration;
+import org.opendaylight.mdsal.binding2.model.api.Type;
+import org.opendaylight.mdsal.binding2.model.api.UnitName;
+import org.opendaylight.yangtools.concepts.Identifier;
+
+/**
+ * Transformer of the data from the virtual form to JAVA source code. The
+ * result source code represents JAVA enumeration. For generation of the source
+ * code is used the template written in Twirl (Scala based) language.
+ */
+@Beta
+public class EnumGenerator implements CodeGenerator {
+
+ @Override
+ public String generate(Type type) {
+ if (type instanceof Enumeration) {
+ final Enumeration enums = (Enumeration) type;
+ return new EnumRenderer(enums).generateTemplate();
+ }
+ return "";
+ }
+
+ @Override
+ public boolean isAcceptable(Type type) {
+ return type instanceof Enumeration;
+ }
+
+ @Override
+ public Identifier getUnitName(Type type) {
+ return new UnitName(type.getName());
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.mdsal.binding2.java.api.generator;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.Preconditions;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import org.opendaylight.mdsal.binding2.model.api.CodeGenerator;
+import org.opendaylight.mdsal.binding2.model.api.Type;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.sonatype.plexus.build.incremental.BuildContext;
+
+/**
+ * Generates files with JAVA source code for every specified type.
+ */
+@Beta
+public final class GeneratorJavaFile {
+
+ private static final Logger LOG = LoggerFactory.getLogger(GeneratorJavaFile.class);
+
+ /**
+ * List of <code>CodeGenerator</code> instances.
+ */
+ private final List<CodeGenerator> generators = new ArrayList<>();
+
+ /**
+ * Set of <code>Type</code> instances for which the JAVA code is generated.
+ */
+ private final Collection<? extends Type> types;
+
+ /**
+ * BuildContext used for instantiating files
+ */
+ private final BuildContext buildContext;
+
+ /**
+ * Creates instance of this class with the set of <code>types</code> for
+ * which the JAVA code is generated.
+ *
+ * The instances of concrete JAVA code generator are created.
+ *
+ * @param buildContext
+ * build context to use for accessing files
+ * @param types
+ * set of types for which JAVA code should be generated
+ */
+ public GeneratorJavaFile(final BuildContext buildContext, final Collection<? extends Type> types) {
+ this.buildContext = Preconditions.checkNotNull(buildContext);
+ this.types = Preconditions.checkNotNull(types);
+ generators.add(new EnumGenerator());
+ //TODO: finish generators
+// generators.add(new InterfaceGenerator());
+// generators.add(new TOGenerator());
+// generators.add(new BuilderGenerator());
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.mdsal.binding2.java.api.generator.renderers;
+
+import static org.opendaylight.mdsal.binding2.java.api.generator.util.TextTemplateUtil.asJavadoc;
+import static org.opendaylight.mdsal.binding2.java.api.generator.util.TextTemplateUtil.encodeAngleBrackets;
+
+import java.util.LinkedList;
+import java.util.List;
+import org.opendaylight.mdsal.binding2.model.api.Enumeration;
+import org.opendaylight.mdsal.binding2.txt.enumTemplate;
+
+public class EnumRenderer extends BaseRenderer {
+ private final Enumeration enums;
+
+ public EnumRenderer(final Enumeration type) {
+ super(type);
+ enums = type;
+ }
+
+ @Override
+ protected String body() {
+ String importedName = importedName(String.class);
+ return enumTemplate.render(enums, importedName).body();
+ }
+
+ /**
+ * @param enumeration
+ * @return List of enumeration pairs with javadoc
+ */
+ public static String writeEnumeration(final Enumeration enumeration) {
+ final List<CharSequence> strings = new LinkedList<>();
+ if (!enumeration.getValues().isEmpty()) {
+ for (Enumeration.Pair pair : enumeration.getValues()) {
+ final StringBuilder sb = new StringBuilder();
+ sb.append(asJavadoc(encodeAngleBrackets(pair.getDescription())));
+ sb.append("\n");
+ sb.append(pair.getMappedName());
+ sb.append('(');
+ sb.append(pair.getValue());
+ sb.append(", \"");
+ sb.append(pair.getName());
+ sb.append("\")");
+ strings.add(sb);
+ }
+ }
+ return String.join(",\n", strings).concat(";");
+ }
+}
\ No newline at end of file
--- /dev/null
+@*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *@
+
+@import org.opendaylight.mdsal.binding2.java.api.generator.renderers.EnumRenderer.writeEnumeration
+@import org.opendaylight.mdsal.binding2.java.api.generator.util.TextTemplateUtil.formatDataForJavaDoc
+@import org.opendaylight.mdsal.binding2.java.api.generator.util.TextTemplateUtil.wrapToDocumentation
+@import org.opendaylight.mdsal.binding2.model.api.Enumeration
+@import org.opendaylight.mdsal.binding2.model.api.GeneratedType
+
+@(genType: GeneratedType, importedName: String)
+@if(genType != null) {
+@{wrapToDocumentation(formatDataForJavaDoc(genType))}
+public enum @{genType.getName} {
+@{writeEnumeration(genType.asInstanceOf[Enumeration])}
+
+ @{importedName} name;
+ int value;
+ private static final java.util.Map<java.lang.Integer, @{genType.getName}> VALUE_MAP;
+
+ static {
+ final com.google.common.collect.ImmutableMap.Builder<java.lang.Integer, @{genType.getName}> b = com.google.common.collect.ImmutableMap.builder();
+ for (@{genType.getName} enumItem : @{genType.getName}.values())
+ {
+ b.put(enumItem.value, enumItem);
+ }
+
+ VALUE_MAP = b.build();
+ }
+
+ private @{genType.getName}(int value, @{importedName} name) {
+ this.value = value;
+ this.name = name;
+ }
+
+ /**
+ * Returns the name of the enumeration item as it is specified in the input yang.
+ *
+ * @@return the name of the enumeration item as it is specified in the input yang
+ */
+ public @{importedName} getName() {
+ return name;
+ }
+
+ /**
+ * @@return integer value
+ */
+ public int getIntValue() {
+ return value;
+ }
+
+ /**
+ * @@param valueArg
+ * @@return corresponding @{genType.getName} item
+ */
+ public static @{genType.getName} forValue(int valueArg) {
+ return VALUE_MAP.get(valueArg);
+ }
+}
+}
\ No newline at end of file