X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fconfig%2Fyang-jmx-generator-plugin%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fyangjmxgenerator%2Fplugin%2Fftl%2Fdirectives%2FTypeDeclarationDirective.java;fp=opendaylight%2Fconfig%2Fyang-jmx-generator-plugin%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fyangjmxgenerator%2Fplugin%2Fftl%2Fdirectives%2FTypeDeclarationDirective.java;h=0000000000000000000000000000000000000000;hb=cd0a18d48f5e8b6ff208b6633e05ee003979218e;hp=42556c243e76e5f5f001018e0943299044ea991a;hpb=ef6bd770f1366f84fdbc7ab19fa649953b36197b;p=controller.git diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/directives/TypeDeclarationDirective.java b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/directives/TypeDeclarationDirective.java deleted file mode 100644 index 42556c243e..0000000000 --- a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/directives/TypeDeclarationDirective.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * 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.controller.config.yangjmxgenerator.plugin.ftl.directives; - -import java.io.IOException; -import java.io.Writer; -import java.util.Collection; -import java.util.Map; - -import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.TypeDeclaration; - -import com.google.common.base.Preconditions; - -import freemarker.core.Environment; -import freemarker.ext.beans.StringModel; -import freemarker.template.TemplateDirectiveBody; -import freemarker.template.TemplateDirectiveModel; -import freemarker.template.TemplateException; -import freemarker.template.TemplateModel; - -/** - * Add type declaration to freemarker template. - */ -public class TypeDeclarationDirective implements TemplateDirectiveModel { - - private static final String OBJECT = "object"; - - @Override - public void execute(Environment env, Map params, TemplateModel[] loopVars, - TemplateDirectiveBody body) throws TemplateException, IOException { - Object object = params.get(OBJECT); - Preconditions.checkNotNull(object, "Null type declaration"); - - object = ((StringModel) object).getWrappedObject(); - Preconditions.checkArgument( - object instanceof TypeDeclaration, - "Type declaration should be instance of " - + TypeDeclaration.class + " but was " - + object.getClass()); - - TypeDeclaration type = (TypeDeclaration) object; - - Writer out = env.getOut(); - StringBuilder build = new StringBuilder("public "); - if (type.isAbstract()) - build.append("abstract "); - if (type.isFinal()) - build.append("final "); - build.append(type.getType() + " "); - build.append(type.getName() + " "); - - generateExtendOrImplement(build, "extends", type.getExtended()); - - generateExtendOrImplement(build, "implements", type.getImplemented()); - - build.append(System.lineSeparator()); - out.write(build.toString().toCharArray()); - } - - private void generateExtendOrImplement(StringBuilder build, String prefix, - Collection elements) { - if (elements.isEmpty()) - return; - - build.append(prefix + " "); - - for (String extended : elements) { - build.append(extended); - build.append(", "); - } - build.deleteCharAt(build.length() - 1); - build.deleteCharAt(build.length() - 1); - } - -}