sourcelist.java

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

JAVA
216
字号
/*
 * $Header: /home/cvs/WEBPUMP2.0/WebPumpIDE_Src/WebPumpIDE/src/com/webpump/ui/datasource/data/SourceList.java,v 1.1.1.1 2004/07/01 09:07:43 wang_j Exp $
 * $Revision: 1.1.1.1 $
 * $Date: 2004/07/01 09:07:43 $
 *
 * ====================================================================
 *
 * 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.datasource.data;

import java.io.PrintWriter;
import java.util.Hashtable;
import java.util.Vector;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.pde.core.IModelChangedEvent;
import org.eclipse.pde.core.IWritable;
import org.eclipse.pde.core.ModelChangedEvent;
import org.w3c.dom.*;
import com.webpump.ui.base.data.BaseDataObject;

/**
 * Class for data object of all datasource .
 * 
 * @author zhang_tx
 * @version 2.0.0 2004-2-24
 */
public class SourceList extends BaseDataObject {
    
    /** all datasource data object*/        
    private Vector m_vSource;
    
    private Vector m_vSourceProp;

	final static String INDENT = "   ";
    /**
     * Parse the root node of datasource.xml 
     * @param node thr root node
     * @param lineTable a Hashtable object
     */
    public void parse(Node node, Hashtable lineTable)  {
        bindSourceLocation(node, lineTable);
        if(node.getNodeName().toLowerCase().equals("context")){
			if (m_vSource == null) 
			m_vSource = new Vector();
			m_vSourceProp = new Vector();
			//get child nodes
			NodeList children = node.getChildNodes();
        
			for (int i = 0; i < children.getLength(); i++) {
				Node child = children.item(i);            
				//parse child node
				parseChild(child, m_vSource, m_vSourceProp, lineTable) ;
			}
			for (int i = 0; i < m_vSource.size(); i++ ){
				DataSource currentSource = (DataSource)m_vSource.get(i);
				String sourceName = currentSource.getName();
				for(int j = 0; j < m_vSourceProp.size(); j++ ){
					if(((DataSourceProperty)m_vSourceProp.get(j)).getName().equals(sourceName)){
						currentSource.setSourceProp((DataSourceProperty)m_vSourceProp.get(j));
					}
				}
			}
        }

    }
    
    
    /**
     * parse datasource node and add to vInfo
     * @param node the htmlpage node
     * @param vInfo a Vector object to contain all sub data object
     * @param lineTable a Hashtable object
     */
    public void parseChild(Node node, Vector vInfo, Vector vProp, Hashtable lineTable) {
        String tag = node.getNodeName();
        if (tag.equals("ResourceParams")) {                    
            DataSource objPage = new DataSource();
            objPage.setParent(this);
            objPage.setModel(this.getModel()); 
            objPage.setInTheModel(true);
            // parse datasource node
			objPage.parse(node,lineTable);
            vInfo.add(objPage);
        }
		if (tag.equals("Resource")) {                    
			DataSourceProperty objProp = new DataSourceProperty();
			objProp.setParent(this);
			objProp.setModel(this.getModel()); 
			objProp.setInTheModel(true);
			// parse datasource node
			objProp.parse(node,lineTable);
			vProp.add(objProp);
		}   
    }

    
    /**
     * Transform the SourceList object to a string 
     * 
     * @return SourceListString string of SourceList 
     */
    public String getSourceListString() {
        String SourceListString;
        
        SourceListString = "<Context>\n";        
        for (int i = 0; i<m_vSource.size(); i++) {
            SourceListString += ((DataSource) m_vSource.get(i)).getDataSourceString();
        }        
        SourceListString += "</Context>";
        
        return SourceListString;
    }
    
 
	/**
	 * Write this node in "datasource.xml"
	 * @param indent
	 * @param writer
	 */
	public void write(String indent, PrintWriter writer) {
		writeComments(writer);
		//write "<data-sources>" in "datasource.xml"
		writer.println(indent + "<Context>");
		writeComments(writer);
		String indent2 = indent + INDENT;		
		//Write Children nodes of the present node
		writeChildren(indent2, m_vSource, writer);
		writer.println(indent + "</Context>");
	}

	/**
	 * Write all children nodes of the present node
	 * @param indent
	 * @param children
	 * @param writer
	 */
	protected void writeChildren(
		String indent,
		Vector children,
		PrintWriter writer) {
		//Search all the children nodes of the present node and write each of them using their own write method	
		for (int i = 0; i < children.size(); i++) {
			IWritable writable = (IWritable) children.get(i);
			writable.write(indent, writer);
		}
	}
   
    /**
     * Get m_vSource
     * @return m_vSource 
     */
    public Vector getvSource() {
        return m_vSource;
    }
	/**
	 * Restore the Property
	 * @param name
	 * @param oldValue
	 * @param newValue
	 */
	public void restoreProperty(String name, Object oldValue, Object newValue)
		throws CoreException {
		super.restoreProperty(name, oldValue, newValue);
	}
	
	/**
	 * Return the children nodes which have been stored in m_vPropertyInfo
	 */
	public Object[] getChild()
	{
		return m_vSource.toArray();
	}
	
	
	public String toString(){
		return "Context";
	}
	
	/**
	 * Add a datasource data object to SourceList data object
	 * @param objDataSource   datasource data object which will be added to SourceList data object
	 */
	public void addDataSource(DataSource objDataSource)
	{
		m_vSource.add(objDataSource);
		objDataSource.setInTheModel(true);
		objDataSource.setParent(this);
		objDataSource.setModel(this.getModel());		
		fireStructureChanged(objDataSource, IModelChangedEvent.INSERT);
	}
	
	/**
	 * remove a datasource data object from the SourceList data object
	 * @param objDataSource   datasource data object which will be added to SourceList data object
	 */
	public void remove(DataSource objDataSource)
	{
		m_vSource.removeElement(objDataSource);
		objDataSource.setInTheModel(false);
	    fireStructureChanged(objDataSource, ModelChangedEvent.REMOVE);
	}	
}

⌨️ 快捷键说明

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