module.java

来自「一个eclipse插件源代码。用于web开发」· Java 代码 · 共 286 行

JAVA
286
字号
/*
 * $Header: /home/cvs/WEBPUMP2.0/WebPumpIDE_Src/WebPumpIDE/src/com/webpump/ui/gefmodule/model/Module.java,v 1.2 2004/12/29 09:45:30 wang_j Exp $
 * $Revision: 1.2 $
 * $Date: 2004/12/29 09:45:30 $
 *
 * ====================================================================
 *
 * The NanJing HopeRun(IT-FOREST) Software License, Version 2.0.0
 *
 * Copyright 2003-2004 by NanJing HopeRun(IT-FOREST) Information System Co., Ltd, CHINA and
 *                        IT Forest Corporation
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * HopeRun(IT-FOREST) Information System Co., Ltd, CHINA and IT Forest Corporation.
 * You shall not disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into with
 * HopeRun(IT-FOREST) Information System Co., Ltd, CHINA and IT Forest Corporation.
 */

package com.webpump.ui.gefmodule.model;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Vector;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.swt.graphics.Image;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

import com.webpump.ui.gefmodule.util.SourceDOMParser;


/**
 * Class for Module
 * 
 * @author shi_l
 * @version 2.0.0 2004-5-30
 */
public class Module extends ModelSubpart {

	/**children*/
	private Vector m_vChildren;

	/**count*/
	private static int count;

	/**
	 * constructor
	 *
	 */
	public Module() {
		
		m_vChildren = new Vector();
	}

	/**
	 * get children
	 * @return m_vChildren Vector
	 */
	public Vector getChildren() {
		return m_vChildren;
	}

	/**
	 * add child
	 * @param child ModelElement
	 */
	public void addChild(ModelElement child) {
		addChild(child, -1);
	}

	/**
	 * add child
	 * @param child ModelElement
	 *        index int
	 */
	public void addChild(ModelElement child, int index) {
		if (index >= 0)
			m_vChildren.add(index, child);
		else
			m_vChildren.add(child);
		fireStructureChange(CHILDREN, child);
	}

	/**
	 * remove child
	 * @param child ModelElement
	 */
	public void removeChild(ModelElement child) {
		m_vChildren.remove(child);
		fireStructureChange(CHILDREN, child);
	}

	/**
	 * get icon image
	 * @return image
	 */
	public Image getIconImage() {
		return null;
	}

	/**
	 * get new id
	 * @return id String
	 */
	protected String getNewID() {
		return Integer.toString(count++);
	}

	/**
	 * write
	 * @param writer PrintWriter
	 */
	public void write(PrintWriter writer , String strCharset) {
		
				
		writer.println("<?xml version=\"1.0\" encoding=\""+strCharset+"\"?>");
		writer.println("<module-config>");
		writer.println("<pages>");
		for (int i = 0; i < m_vChildren.size(); i++) {
			if (m_vChildren.get(i) instanceof Page) {
				((Page) m_vChildren.get(i)).write(writer);
			}

		}
		writer.println("</pages>");
		writer.println("<tasks>");
		for (int i = 0; i < m_vChildren.size(); i++) {
			if (m_vChildren.get(i) instanceof Page) {
				((Page) m_vChildren.get(i)).writeSourceTask(writer);
			}
		}
		writer.println("</tasks>");
		writer.println("</module-config>");
	}

	/**
	 * load
	 * @param stream InputStream
	 * @throws CoreException
	 */
	public void load(InputStream stream) throws CoreException {
		SourceDOMParser parser = new SourceDOMParser();

		try {
			InputSource source = new InputSource(stream);

			parser.parse(source);
			processDocument(parser.getDocument());
			//		   loaded = true;

		} catch (SAXException e) {
		} catch (IOException e) {
			//   PDECore.logException(e);
			System.out.println(e.toString());
		} catch (Exception e) {
			System.out.println(e.toString());
		}
	}

	/**
	 * process document
	 * @param doc Document
	 */
	public void processDocument(Document doc) {
		//处历larse得到的Document

		//得到Node
		Node rootNode = doc.getDocumentElement();

		//从根节点开始解?
		parse(rootNode);
	}

	/**
	 * parse
	 * @param node Node
	 */
	public void parse(Node node) {
		//解析节?
		String tag = node.getNodeName().toLowerCase();
		if (tag.equals("module-config")) {
			//解析到模型元素

			//得到子节?
			NodeList children = node.getChildNodes();

			for (int i = 0; i < children.getLength(); i++) {
				//解析各个子节?
				Node child = children.item(i);
				parseChild(child);
			}
		}
	}

	/**
	 * parse child
	 * @param node Node
	 */
	public void parseChild(Node node) {
		//解析节?
		String tag = node.getNodeName().toLowerCase();
		if (tag.equals("pages")) {
			//解析到模型元素

			//得到子节?
			NodeList children = node.getChildNodes();

			for (int i = 0; i < children.getLength(); i++) {
				//解析各个子节?
				Node child = children.item(i);
				parsePage(child);
			}
		} else if (tag.equals("tasks")) {
			NodeList children = node.getChildNodes();

			for (int i = 0; i < children.getLength(); i++) {
				//解析各个子节?
				Node child = children.item(i);
				parseTask(child);
			}
		}
	}

	/**
	 * parse page
	 * @param child Node
	 */
	protected void parsePage(Node child) {
		//解析单个子节?
		String tag = child.getNodeName().toLowerCase();
		if (tag.toLowerCase().equals("page")) {
			//如果是Page元素
			Page page = new Page();
			//铁赜页?

			page.parse(child);
			//铁赜页?
			addChild(page);
		}
	}

	/**
	 * parse task
	 * @param child Node
	 */
	protected void parseTask(Node child) {
		String tag = child.getNodeName().toLowerCase();
		if (tag.toLowerCase().equals("task")) {
			//如果是Page元素
			Task task = new Task();
			//铁赜页?

			task.parse(child, m_vChildren);
		}
	}
	/*	
		protected void parseNode(Node child) {
			//解析单个子节?
			String tag = child.getNodeName().toLowerCase();
			if (tag.toLowerCase().equals("page")) {
				//如果是Page元素
				Page page = new Page();
				//铁赜页?
	
				page.parse(child);
				//铁赜页?
				addChild(page);
			}
			if (tag.toLowerCase().equals("task")) {
				//如果是Page元素
				Task task = new Task();
				//铁赜页?
	
				task.parse(child, m_vChildren);
			}
		}
	*/
}

⌨️ 快捷键说明

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