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
9 package org.opendaylight.controller.config.yangjmxgenerator.plugin.gofactory;
11 import com.google.common.base.Optional;
12 import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.FtlTemplate;
13 import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Annotation;
14 import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Constructor;
15 import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Field;
16 import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Method;
17 import org.opendaylight.controller.config.yangjmxgenerator.plugin.java.FullyQualifiedName;
18 import org.opendaylight.controller.config.yangjmxgenerator.plugin.java.GeneratedObject;
19 import org.opendaylight.controller.config.yangjmxgenerator.plugin.java.GeneratedObjectBuilder;
20 import org.opendaylight.controller.config.yangjmxgenerator.plugin.java.JavaFileInputBuilder;
22 public class GenericGeneratedObjectFactory {
24 public GeneratedObject toGeneratedObject(FtlTemplate template, Optional<String> copyright) {
25 JavaFileInputBuilder b = new JavaFileInputBuilder();
26 b.setHeader(template.getHeaderString());
27 b.setFqn(new FullyQualifiedName(template.getPackageName(), template.getTypeDeclaration().getName()));
28 b.setClassJavaDoc(template.getMaybeJavadoc());
29 for (Annotation annotation : template.getAnnotations()) {
30 b.addClassAnnotation(annotation);
33 for (String extended : template.getTypeDeclaration().getExtended()) {
34 b.addExtendsFQN(FullyQualifiedName.fromString(extended));
36 for (String implemented : template.getTypeDeclaration().getImplemented()) {
37 b.addImplementsFQN(FullyQualifiedName.fromString(implemented));
39 b.setCopyright(copyright);
40 b.setTypeName(template.getTypeDeclaration().toTypeName());
42 for (Field field : template.getFields()) {
43 b.addToBody(field.toString());
46 for (Constructor constructor : template.getConstructors()) {
47 b.addToBody(constructor.toString());
50 for (Method method : template.getMethods()) {
51 b.addToBody(method.toString());
53 return new GeneratedObjectBuilder(b.build()).toGeneratedObject();