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

📄 datasource.java

📁 一个eclipse插件源代码。用于web开发
💻 JAVA
字号:
/*
 * $Header: /home/cvs/WEBPUMP2.0/WebPumpIDE_Src/WebPumpIDE/src/com/webpump/ui/datasource/data/DataSource.java,v 1.1.1.1 2004/07/01 09:07:42 wang_j Exp $
 * $Revision: 1.1.1.1 $
 * $Date: 2004/07/01 09:07:42 $
 *
 * ====================================================================
 *
 * 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.pde.core.*;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import com.webpump.ui.base.data.BaseDataObject;
import com.webpump.ui.base.data.BaseObject;
import com.webpump.ui.perspective.WebpumpIDEPlugin;

/**
 * Class for data object of a html page .
 * 
 * @author zhang_tx
 * @version 2.0.0 2004-2-24
 */
public class DataSource extends BaseDataObject {
    
    private String m_strName = "";
    
    private DataSourceProperty m_objSourceProp = new DataSourceProperty();
    /**all  property information data object of the datasource */
    private Vector m_vPropertyInfo = new Vector();
	String PropertyName[] = {"factory","driverClassName","url","username","password","maxActive","maxIdle","maxWait" };
	String[] strPropertyInfo = new String[2];
	
    /**
     * Parse the DataSource node
     * 
     * @param node the DataSource node 
     * @param lineTable a Hashtable object
     */
    public void parse(Node node, Hashtable lineTable)  {
        
        if (m_vPropertyInfo == null) 
            m_vPropertyInfo = new Vector();
        //get all property nodes    
        NodeList children = node.getChildNodes();
		m_strName = getNodeAttribute(node, "name");
        for (int i = 0; i < children.getLength(); i++) {
            Node child = children.item(i);
            //parse property node
            parseChild(child, m_vPropertyInfo, lineTable);
        }
    }
    
    /**
     * Parse property node and add to vInfo
     * 
     * @param node the property node 
     * @param vInfo a Vector object to contain all sub data object
     * @param lineTable a Hashtable object
     */
    public void parseChild(Node node, Vector vInfo, Hashtable lineTable) {
        String tag = node.getNodeName().toLowerCase();
        
        if (tag.equals("parameter")) {                      
            PropertyInfo objPropertyInfo = new PropertyInfo();
			objPropertyInfo.setParent(this);
			objPropertyInfo.setModel(this.getModel());
            //parse Property node                       
			objPropertyInfo.parse(node, lineTable);
			objPropertyInfo.setInTheModel(true);
            vInfo.add(objPropertyInfo);
        }
    }   
    
    /**
     * Transform DataSource to a string
     * 
     * @return DataSourceString string of DataSource
     */
    public String getDataSourceString() {
        String DataSourceString;
        DataSourceString = "   " + "<Resource name = " + "\"" + WebpumpIDEPlugin.filterXML(m_objSourceProp.getName()) + "\""
                                          + " auth = " + "\"" + WebpumpIDEPlugin.filterXML(m_objSourceProp.getAuthor()) + "\"" 
		                                  + " type = " + "\"" + WebpumpIDEPlugin.filterXML(m_objSourceProp.getSourceType()) + "\"" + "/>" + "\n";
		DataSourceString = "   " + "<ResourceParams name = " + "\"" + WebpumpIDEPlugin.filterXML(m_objSourceProp.getName()) + "\"" + ">" + "\n";
        for (int i = 0; i < m_vPropertyInfo.size(); i++) {            
            DataSourceString += ((PropertyInfo) m_vPropertyInfo.get(i)).getParamString();
        }
        
        DataSourceString = DataSourceString + "   " + "</ResourceParams>" + "\n";
        return DataSourceString;
    }
    
    
    /**
     * Get all property information data object
     * 
     * @return m_vPropertyInfo
     */
    public Vector getvPropertyInfo() {
        return m_vPropertyInfo;
    }
    
    /**
     * Get the type of the datasource
     * 
     * @return m_strSourceType the type of the datasource
     */
    public String toString() {
        return m_objSourceProp.getName()==null?"":m_objSourceProp.getName();
    }   

    /**
     * Add a property info data object to DataSource data object
     * @param objPropertyInfo the property info data object which will be added to DataSource data object
     */
    public void addProperty(PropertyInfo objPropertyInfo) {
        m_vPropertyInfo.add(objPropertyInfo);
        objPropertyInfo.setInTheModel(true);
        objPropertyInfo.setParent(this);
        objPropertyInfo.setModel(this.getModel());
        //   fire structure of the data model changed      
        fireStructureChanged(objPropertyInfo, IModelChangedEvent.INSERT);
    }
    
    /**
     * Remove a Property data object form DataSource data object
     * @param objPropertyInfo the Property info data object which will be removed form DataSource data object
     */
    public void removeProperty(PropertyInfo objPropertyInfo) {
        m_vPropertyInfo.removeElement(objPropertyInfo);
        objPropertyInfo.setInTheModel(false);
        //  fire structure of the data model changed 
        fireStructureChanged(objPropertyInfo, ModelChangedEvent.REMOVE);
    }
    
    public void write(String indent, PrintWriter writer){
		writeComments(writer);
		//Write "<data-source type"
		writer.println(indent + "<Resource name = " + "\"" + WebpumpIDEPlugin.filterXML(m_objSourceProp.getName()) + "\""
                                          + " auth = " + "\"" + WebpumpIDEPlugin.filterXML(m_objSourceProp.getAuthor()) + "\"" 
		                                  + " type = " + "\"" + WebpumpIDEPlugin.filterXML(m_objSourceProp.getSourceType()) + "\"" + "/>");
		writer.println(indent + "<ResourceParams name = " + "\"" + WebpumpIDEPlugin.filterXML(m_objSourceProp.getName()) + "\"" + ">");
		String indent2 = indent + INDENT;
		//Write Children nodes of the present node
		writeChildren(indent2, m_vPropertyInfo, writer);
		//Write "</data-source>"
		writer.println(indent + "</ResourceParams>");
    }
    
	/**
	 * 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);
		}
	}
	
	/**
	 * Return the children nodes which have been stored in m_vPropertyInfo
	 */
	public Object[] getChild()
	{
		if (m_vPropertyInfo==null)
			return new BaseObject[0];		
		return (BaseObject[]) m_vPropertyInfo.toArray(
					new BaseObject[m_vPropertyInfo.size()]);
	}

	/**
	 * set the property info data to the datasource
	 * 
	 * @param PropertyInfos    the property info content to set
	 * @param pos   the info position 
	 */
	public void setPropertyInfo(String PropertyInfos,int pos){
		PropertyInfo temp = (PropertyInfo)m_vPropertyInfo.get(pos);
		strPropertyInfo[0] = PropertyName[pos];
		strPropertyInfo[1] = PropertyInfos;
		temp.setPropertyInfo(strPropertyInfo);
		fireStructureChanged(this, ModelChangedEvent.CHANGE);

	}
	
	/**
	 * set the type of the datasource
	 * 
	 * @param newtype    the new type for the datasource
	 */
	public void setName(String newname){
		m_objSourceProp.setName(newname);
		fireStructureChanged(this, IModelChangedEvent.CHANGE);
	}
	
	/**
	 * set the type of the datasource
	 * 
	 * @param newtype    the new type for the datasource
	 */
	public void setAuthor(String newauth){
		m_objSourceProp.setAuthor(newauth);
		fireStructureChanged(this, IModelChangedEvent.CHANGE);
	}
	
	/**
	 * set the type of the datasource
	 * 
	 * @param newtype    the new type for the datasource
	 */
	public void setType(String newtype){
		m_objSourceProp.setType(newtype);
		fireStructureChanged(this, IModelChangedEvent.CHANGE);
	}
	
	/**
	 * add a property info data to the datasource
	 * 
	 * @param add  the property info data for add
	 */
	private void addPropertyInfo(PropertyInfo add) {
		m_vPropertyInfo.add(add);
		add.setInTheModel(true);
		add.setParent(this);
		add.setModel(this.getModel());		
		fireStructureChanged(add, IModelChangedEvent.CHANGE);
	}

	/**
	 * get all the property info data of the datasource
	 * 
	 */
	public String[] getPropertyInfo(){
		String [] returnstrings = new String[8];
		for(int i=0;i<m_vPropertyInfo.size();i++){
			PropertyInfo temp = (PropertyInfo)m_vPropertyInfo.get(i);
			returnstrings[i] = temp.getValue();
		}
		return returnstrings;
	}
	public void init(){
		for(int i=0;i<8;i++){
			PropertyInfo temp = new PropertyInfo();
			m_vPropertyInfo.add(temp);
			temp.setInTheModel(true);
			temp.setParent(this);
			temp.setModel(this.getModel());
			//   fire structure of the data model changed      
			fireStructureChanged(temp, IModelChangedEvent.INSERT);
			strPropertyInfo[0] = PropertyName[i];
			strPropertyInfo[1] = "";
			if(i == 5){
				strPropertyInfo[1] = "15";
			}
			if(i == 6){
				strPropertyInfo[1] = "1";
			}
			if(i == 7){
				strPropertyInfo[1] = "-1";
			}
			temp.setPropertyInfo(strPropertyInfo);
		}
	}
	/**
	 * @return
	 */
	public DataSourceProperty getSourceProp() {
		return m_objSourceProp;
	}

	/**
	 * @return
	 */
	public String getName() {
		return m_strName;
	}

	/**
	 * @param string
	 */
	public void setSourceName(String string) {
		m_strName = string;
		fireStructureChanged(this, IModelChangedEvent.CHANGE);
	}

	/**
	 * @param property
	 */
	public void setSourceProp(DataSourceProperty property) {
		m_objSourceProp = property;
	}

}

⌨️ 快捷键说明

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