|
Glassfish example source code file (TextClassWriter.java)
The Glassfish TextClassWriter.java source code/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright (c) 2010 Oracle and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development * and Distribution License("CDDL") (collectively, the "License"). You * may not use this file except in compliance with the License. You can * obtain a copy of the License at * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html * or packager/legal/LICENSE.txt. See the License for the specific * language governing permissions and limitations under the License. * * When distributing the software, include this License Header Notice in each * file and include the License file at packager/legal/LICENSE.txt. * * GPL Classpath Exception: * Oracle designates this particular file as subject to the "Classpath" * exception as provided by Oracle in the GPL Version 2 section of the License * file that accompanied this code. * * Modifications: * If applicable, add the following below the License Header, with the fields * enclosed by brackets [] replaced by your own identifying information: * "Portions Copyright [year] [name of copyright owner]" * * Contributor(s): * If you wish your version of this file to be governed by only the CDDL or * only the GPL Version 2, indicate your decision by adding "[Contributor] * elects to include this software in this distribution under the [CDDL or GPL * Version 2] license." If you don't indicate a single choice of license, a * recipient has the option to distribute your version of this file under * either the CDDL, the GPL Version 2 or to extend the choice of license to * its licensees as provided above. However, if you add GPL Version 2 code * and therefore, elected the GPL Version 2 license, then the option applies * only if the new code is made subject to such option by the copyright * holder. */ package org.glassfish.admin.rest.generator; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.Writer; import java.util.List; /** * @author Mitesh Meswani */ public class TextClassWriter implements ClassWriter { Writer writer; /** * @param className Name of class to be generated * @param generationDir Absolute location where it needs to be generated * @param baseClassName * @param resourcePath */ public TextClassWriter(File generationDir, String className, String baseClassName, String resourcePath) throws IOException { File file = new File(generationDir, className + ".java"); file.createNewFile(); FileWriter fstream = new FileWriter(file); writer = new BufferedWriter(fstream); writeCopyRightHeader(); writePackageHeader(); writeImportStatements(); if(resourcePath != null) { writer.write("@Path(\"/" + resourcePath + "/\")\n"); } writer.write("public class " + className + " extends " + baseClassName + " {\n\n"); } private void writePackageHeader() throws IOException { writer.write("package org.glassfish.admin.rest.resources.generated;\n"); } private void writeCopyRightHeader() throws IOException { writer.write("/*\n"); writer.write(" * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.\n"); writer.write(" *\n"); writer.write(" * Copyright (c) 2009-2010 Oracle and/or its affiliates. All rights reserved.\n"); writer.write(" *\n"); writer.write(" * The contents of this file are subject to the terms of either the GNU\n"); writer.write(" * General Public License Version 2 only (\"GPL\") or the Common Development\n"); writer.write(" * and Distribution License(\"CDDL\") (collectively, the \"License\"). You\n"); writer.write(" * may not use this file except in compliance with the License. You can\n"); writer.write(" * obtain a copy of the License at\n"); writer.write(" * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html\n"); writer.write(" * or packager/legal/LICENSE.txt. See the License for the specific\n"); writer.write(" * language governing permissions and limitations under the License.\n"); writer.write(" *\n"); writer.write(" * When distributing the software, include this License Header Notice in each\n"); writer.write(" * file and include the License file at packager/legal/LICENSE.txt.\n"); writer.write(" *\n"); writer.write(" * GPL Classpath Exception:\n"); writer.write(" * Oracle designates this particular file as subject to the \"Classpath\"\n"); writer.write(" * exception as provided by Oracle in the GPL Version 2 section of the License\n"); writer.write("* file that accompanied this code.\n"); writer.write(" *\n"); writer.write(" * Modifications:\n"); writer.write(" * If applicable, add the following below the License Header, with the fields\n"); writer.write(" * enclosed by brackets [] replaced by your own identifying information:\n"); writer.write(" * \"Portions Copyright [year] [name of copyright owner]\"\n"); writer.write(" *\n"); writer.write(" * Contributor(s):\n"); writer.write(" * If you wish your version of this file to be governed by only the CDDL or\n"); writer.write(" * only the GPL Version 2, indicate your decision by adding \"[Contributor]\n"); writer.write(" * elects to include this software in this distribution under the [CDDL or GPL\n"); writer.write(" * Version 2] license.\" If you don't indicate a single choice of license, a\n"); writer.write(" * recipient has the option to distribute your version of this file under\n"); writer.write(" * either the CDDL, the GPL Version 2 or to extend the choice of license to\n"); writer.write(" * its licensees as provided above. However, if you add GPL Version 2 code\n"); writer.write(" * and therefore, elected the GPL Version 2 license, then the option applies\n"); writer.write(" * only if the new code is made subject to such option by the copyright\n"); writer.write(" * holder.\n"); writer.write(" */\n"); writer.write("\n"); } private void writeImportStatements() throws IOException { writer.write("import javax.ws.rs.Path;\n"); writer.write("import javax.ws.rs.PathParam;\n"); writer.write("import org.glassfish.admin.rest.resources.*;\n"); writer.write("import org.glassfish.admin.rest.resources.custom.*;\n"); } @Override public void createCommandResourceConstructor(String commandResourceClassName, String commandName, String httpMethod, boolean linkedToParent, CommandResourceMetaData.ParameterMetaData[] commandParams, String commandDisplayName, String commandAction) { try { writer.write(" public " + commandResourceClassName + "() {\n"); writer.write(" super(\n"); writer.write(" \"" + commandResourceClassName + "\",\n"); writer.write(" \"" + commandName + "\",\n"); writer.write(" \"" + httpMethod + "\",\n"); if (!httpMethod.equals("GET")) { writer.write(" \"" + commandAction + "\",\n"); writer.write(" \"" + commandDisplayName + "\",\n"); } writer.write(" " + linkedToParent + ");\n"); writer.write(" }\n"); if (commandParams != null) { writer.write("@Override\n"); writer.write("protected java.util.HashMap<String, String> getCommandParams() {\n"); writer.write("\tjava.util.HashMap<String, String> hm = new java.util.HashMap Other Glassfish examples (source code examples)Here is a short list of links related to this Glassfish TextClassWriter.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.