Updated code generation
[yangtools.git] / code-generator / binding-java-api-generator / src / main / java / org / opendaylight / yangtools / sal / java / api / generator / TOGenerator.java
index 0299b1b64499d1dce5b082b9f5edb2f0b09ddddc..994fd79031caadca7f2e1a4942004ede3aa0098e 100644 (file)
@@ -1,48 +1,53 @@
-/*
- * Copyright (c) 2013 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.yangtools.sal.java.api.generator;
-
-import org.opendaylight.yangtools.sal.binding.model.api.CodeGenerator;
-import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject;
-import org.opendaylight.yangtools.sal.binding.model.api.Type;
-
-/**
- * 
- * Transformator of the data from the virtual form to JAVA source code. The
- * result source code represents JAVA class. For generating of the source code
- * is used the template written in XTEND language.
- * 
- */
-public final class TOGenerator implements CodeGenerator {
-
-    /**
-     * Generates JAVA source code for generated type <code>Type</code>. The code
-     * is generated according to the template source code template which is
-     * written in XTEND language.
-     */
-    @Override
-    public String generate(Type type) {
-        if (type instanceof GeneratedTransferObject) {
-            final GeneratedTransferObject genTO = (GeneratedTransferObject) type;
-            final ClassTemplate template = new ClassTemplate(genTO);
-            return template.generate();
-        }
-        return "";
-    }
-
-    @Override
-    public boolean isAcceptable(Type type) {
-        return type instanceof GeneratedTransferObject;
-    }
-
-    @Override
-    public String getUnitName(Type type) {
-        return type.getName();
-    }
-
-}
+/*\r
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.yangtools.sal.java.api.generator;\r
+\r
+import org.opendaylight.yangtools.sal.binding.model.api.CodeGenerator;\r
+import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject;\r
+import org.opendaylight.yangtools.sal.binding.model.api.Type;\r
+\r
+/**\r
+ * \r
+ * Transformator of the data from the virtual form to JAVA source code. The\r
+ * result source code represents JAVA class. For generating of the source code\r
+ * is used the template written in XTEND language.\r
+ * \r
+ */\r
+public final class TOGenerator implements CodeGenerator {\r
+\r
+    /**\r
+     * Generates JAVA source code for generated type <code>Type</code>. The code\r
+     * is generated according to the template source code template which is\r
+     * written in XTEND language.\r
+     */\r
+    @Override\r
+    public String generate(Type type) {\r
+        if (type instanceof GeneratedTransferObject) {\r
+            final GeneratedTransferObject genTO = (GeneratedTransferObject) type;\r
+            if(genTO.isUnionType()) {\r
+                final UnionTemplate template = new UnionTemplate(genTO);\r
+                return template.generate();\r
+            } else {\r
+                final ClassTemplate template = new ClassTemplate(genTO);\r
+                return template.generate();\r
+            }\r
+        }\r
+        return "";\r
+    }\r
+\r
+    @Override\r
+    public boolean isAcceptable(Type type) {\r
+        return type instanceof GeneratedTransferObject;\r
+    }\r
+\r
+    @Override\r
+    public String getUnitName(Type type) {\r
+        return type.getName();\r
+    }\r
+\r
+}\r