⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jsourcecodewizardprocessor.java

📁 免疫遗传算法java语言版源程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/**
 * IgaLib -> wizard
 * Copyright (C) 2001  Tosiki IGA , IgaLib project member
 *   (http://homepage2.nifty.com/igat/igapyon/index.html)
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package jp.ne.nifty.iga.tosiki.wizard;

import jp.ne.nifty.iga.tosiki.string.*;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * JSourceCodeWizard 偺僿儖僷乕僋儔僗丅僜乕僗僐乕僪僂傿僓乕僪幚峴晹暘<BR>
 * 僜乕僗僐乕僪僂傿僓乕僪傪幚峴偟偰僜乕僗僐乕僪傪惗惉偡傞晹暘偱偡<BR>
 *
 * @author Tosiki IGA
 */
public class JSourceCodeWizardProcessor
{
	/**
	 * 
	 *
	 * @param String strDirectory 彂偒崬傒愭僨傿儗僋僩儕
	 */
	public static final void write(JSourceCodeWizard wizard,JSourceCodeWizardChannel dataChannel,ArrayList vecItem,String strDirectory)
		throws IOException
	{
		IndentWriter indentWriter=new IndentWriter(new OutputStreamWriter(new FileOutputStream(strDirectory+getMyClassName(wizard,dataChannel)+".java")));

		JSourceCodeWizardProcessor.writeHead(wizard,dataChannel,vecItem,indentWriter);
		JSourceCodeWizardField.writeGetSet(wizard,dataChannel,vecItem,indentWriter);
		JSourceCodeWizardField.writeCopy(wizard,dataChannel,vecItem,indentWriter);
		JSourceCodeWizardProcessor.writeBasicFunction(wizard,dataChannel,vecItem,indentWriter);

		JSourceCodeWizardProcessorFunction.writeFunction(wizard,dataChannel,vecItem,indentWriter);

		if(dataChannel.getFunction().getUseSql())
		{
			JSourceCodeWizardProcessorSql.write(wizard,dataChannel,vecItem,indentWriter);
		}

		JSourceCodeWizardProcessor.writeCommonFunction(wizard,dataChannel,vecItem,indentWriter);

		if(dataChannel.getFunction().getUseXml())
		{
			JSourceCodeWizardProcessorXml.writeXmlFunction(wizard,dataChannel,vecItem,indentWriter);
		}

		if(dataChannel.getFunction().getUseCsv())
		{
			new JSourceCodeWizardProcessorCsv().writeFunction(wizard,dataChannel,vecItem,indentWriter);
		}

		if(dataChannel.getFunction().getUseTsv())
		{
			new JSourceCodeWizardProcessorTsv().writeFunction(wizard,dataChannel,vecItem,indentWriter);
		}

		JSourceCodeWizardProcessor.writeTail(wizard,dataChannel,vecItem,indentWriter);

		indentWriter.flush();
		indentWriter.close();
	}

	/**
	 * 僿僢僟掕媊丒曄悢愰尵晹側偳
	 */
	public static final void writeHead(
		JSourceCodeWizard wizard,JSourceCodeWizardChannel dataChannel,ArrayList vecItem,IndentWriter out)
		throws IOException
	{
		out.beginComment();
		out.println(wizard.getString("src.head.comment.define",new Object[]{dataChannel.getName()+" ("+dataChannel.getTitle()+")"}));
		if(dataChannel.getDescription()!=null)out.println(wizard.getString("src.common.description",new Object[]{dataChannel.getDescription()}));
		out.println(dataChannel.getCopyright()+"<BR>");
		out.println("");
		out.println(wizard.getString("src.head.comment.warn.1"));
		out.println(wizard.getString("src.head.comment.warn.2"));
		out.println(wizard.getString("src.head.comment.warn.3"));
		out.endComment();
		out.println("");

		if(dataChannel.getPackage()!=null
		&& dataChannel.getPackage().length()>0)
		{
			out.println("package "+dataChannel.getPackage()+";");
			out.println("");
		}

		for(int index=0;index<dataChannel.getImport().size();index++)
		{
			String strImport=(String)dataChannel.getImport().get(index);
			out.println("import "+strImport+";");
		}
		out.println("import java.io.*;");
		out.println("import java.util.*;");
		out.println("");

		out.beginComment();
		out.println(wizard.getString("src.head.comment.classdefine",new Object[]{dataChannel.getName()+" ("+dataChannel.getTitle()+")"}));
		if(dataChannel.getDescription()!=null)out.println(wizard.getString("src.common.description",new Object[]{dataChannel.getDescription()}));
		out.println("");
		out.println(wizard.getString("src.head.comment.warn.1"));
		out.println(wizard.getString("src.head.comment.warn.2"));
		out.println(wizard.getString("src.head.comment.warn.3"));
		out.println("");
		// useSql偺応崌偼 偙偙偵僥乕僽儖峔憿傪憓擖
		if(dataChannel.getFunction().getUseSql())
		{
			JSourceCodeWizardProcessorSql.writeHeadder(wizard,dataChannel,vecItem,out);
		}
		out.println("");
		out.println("  @author "+dataChannel.getAuthor());
		{
			SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy.MM.dd");
			out.println("  @version "+dateFormat.format(new Date()));
		}
		out.endComment();
		out.println("public class "+getMyClassName(wizard,dataChannel));
		if(dataChannel.getFunction().isUseServlet())
		{
			out.println(1,"extends javax.servlet.http.HttpServlet");
		}
		else if(dataChannel.getFunction().isUseSwing())
		{
			out.println(1,"extends javax.swing.JPanel");
		}
		out.println(1,"implements java.lang.Comparable");
		out.println("{");

		for(int index=0;index<vecItem.size();index++)
		{
			JSourceCodeWizardField item=(JSourceCodeWizardField)vecItem.get(index);
			if(item.getDelegate()!=null
			&& item.getDelegate().length()>0)
			{
				continue;
			}

			out.addIndent(1);
			out.beginComment();
			out.println(item.getName()+"("+item.getTitle()+")<BR>");
			item.printDescriptions(wizard,out);
			out.endComment();

			item.writeDefine(out);

			out.addIndent(-1);

			out.println("");
		}

		{
			out.addIndent(1);
			out.beginComment();
			out.println(wizard.getString("src.wiz.shortname.getter.1"));
			out.println(wizard.getString("src.wiz.shortname.getter.2"));
			out.println(wizard.getString("src.wiz.shortname.getter.3"));
			out.endComment();
			out.println("public static String getWizardShortName()");
			out.println("{");
			out.println(1,"return \""+dataChannel.getName()+"\";");
			out.println("}");
			out.addIndent(-1);

			out.println("");
		}
	}

	public static final void writeTail(
		JSourceCodeWizard wizard,JSourceCodeWizardChannel dataChannel,ArrayList vecItem,IndentWriter out)
		throws IOException
	{
		out.println("}");
	}

	public static final void writeBasicFunction(
		JSourceCodeWizard wizard,JSourceCodeWizardChannel dataChannel,ArrayList vecItem,IndentWriter out)
		throws IOException
	{
		out.addIndent(1);

		out.beginComment();
		out.println(dataChannel.getName()+"("+dataChannel.getTitle()+") 偺昞帵梡暥帤楍偺庢摼<BR>");
		out.println("");
		out.println("  @return 昞帵梡暥帤楍");
		out.endComment();
		out.println("public String getDisplayString()");
		out.println("{");

		out.addIndent(1);

		out.println("StringBuffer strbufDisplay=new StringBuffer();");
		out.println("strbufDisplay.append(\""+dataChannel.getName()+"\");");
		out.println("strbufDisplay.append(\"[\");");

		boolean isFirstColumn=true;
		for(int index=0;index<vecItem.size();index++)
		{
			JSourceCodeWizardField item=(JSourceCodeWizardField)vecItem.get(index);
			if(item.isAvailableSql()==false)continue;
			if(isFirstColumn)
			{
				isFirstColumn=false;
			}
			else
			{
				out.println("strbufDisplay.append(\",\");");
			}
			out.println("strbufDisplay.append(\""+item.getName()+"=\"+get"+getUpper(item.getName())+"());");
		}

		out.println("strbufDisplay.append(\"]\");");

		out.println("return strbufDisplay.toString();");

		out.addIndent(-1);
		out.println("}");
		out.println("");
		out.beginComment();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -