📄 nodeloader.java
字号:
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
* Created on 2005/3/17
*
* $Author$
* $Date$
* $Revision$
*
*/
package eti.bi.alphaminer.core.Node;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Vector;
import java.util.jar.JarFile;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import eti.bi.alphaminer.operation.operator.NodeInfo;
import eti.bi.alphaminer.operation.operator.OperatorFactory;
import eti.bi.common.System.SysConfig;
import eti.bi.common.System.SysLog;
import eti.bi.exception.SysException;
/**
* @author kjor
*
* TODO To change the template for this generated type comment go to Window -
* Preferences - Java - Code Style - Code Templates
*/
public class NodeLoader {
private static URL m_Definitionurl;
private static String charsetName;
// private static Vector m_OperatorPropertyPanels = new Vector();
private static Vector<Stencil> m_Stencils = new Vector<Stencil>();
private static Hashtable<String, NodeInfo> m_OperatorInfos = new Hashtable<String, NodeInfo>();
/**
* load the system operator
*/
public static void loadNodes() throws SysException {
DefaultHandler aHandler = new NodeSAXHandler(NodeLoader.class.getClassLoader(), SysConfig
.getOperatorImageHome(), SysConfig.getLocaleHomen(),null,-1);
try {
String definitionString = readDefinitionFile();
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();
StringReader aStringReader = new StringReader(definitionString);
saxParser.parse(new InputSource(aStringReader), aHandler);
} catch (SAXException e) {
SysLog.error(null,e);
// TODO
} catch (ParserConfigurationException e) {
SysLog.error(null,e);
} catch (IOException e) {
SysLog.error(null,e);
}
}
/**
* load the operator in specific place
*
* @param definitionString
* the string of the operator.xml
* @param classloader
* class loader
* @param basePath
* base path for image resource
*/
public static void loadNodes(String definitionString, ClassLoader classloader, String imagebasePath, String localePath, JarFile jarfile, int pluginindex)
throws SysException {
DefaultHandler aHandler = new NodeSAXHandler(classloader, imagebasePath, localePath, jarfile,pluginindex);
try {
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();
StringReader aStringReader = new StringReader(definitionString);
saxParser.parse(new InputSource(aStringReader), aHandler);
} catch (SAXException e) {
SysLog.error(null,e);
// TODO
} catch (ParserConfigurationException e) {
SysLog.error(null,e);
} catch (IOException e) {
SysLog.error(null,e);
}
}
public static void setDefinitionUrl(URL definitionUrl, String a_CharsetName) {
m_Definitionurl = definitionUrl;
charsetName = a_CharsetName;
}
public static void reLoad() {
m_Stencils.clear();
m_OperatorInfos.clear();
try {
OperatorFactory.loadOperator();
} catch (SysException e) {
e.printStackTrace();
}
}
public static String readDefinitionFile() throws SysException {
InputStream in = null;
try {
// m_DefinitionFileName =
// SysConfig.getProperty(Constants.OPERATOR_DEFINITION_FILE_KEY);
if(m_Definitionurl==null) {
throw new SysException("No definition file .");
}
in = m_Definitionurl.openStream();
int size = in.available();
int read = 0;
byte[] bytes = new byte[size];
while(read<size) {
read += in.read(bytes, read, size-read);
}
if(charsetName==null) {
return new String(bytes);
}
else {
return new String(bytes,charsetName);
}
} catch (Exception e) {
e.printStackTrace();
throw new SysException("Error getting or parsing the definition file [" + m_Definitionurl.getPath() + "]", e);
} finally {
if(in !=null) {
try {
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
public static void addStencil(Stencil aStencil) {
if(m_Stencils.size()==0) {
m_Stencils.add(aStencil);
return;
}
try {
Iterator<Stencil> iterator = m_Stencils.iterator();
while(iterator.hasNext()) {
Stencil temp = iterator.next();
if(temp.getName().equals(aStencil.getName())&&temp.getDisplayName().equals(aStencil.getDisplayName())) {
Vector<NodeGroup> groups = aStencil.getGroups();
Iterator<NodeGroup> groupsiterator = groups.iterator();
while(groupsiterator.hasNext()) {
addGroup(temp,groupsiterator.next());
}
return;
}
}
m_Stencils.add(aStencil);
}
catch(Exception e) {
e.printStackTrace();
}
}
/**
* @author Xiaojun Chen add a single group into Phase
* @param agroup
* an Operator Group
*/
public static void addGroup(Stencil aStencil, NodeGroup agroup) {
if (agroup == null||aStencil==null) {
return;
}
NodeGroup aNodeGroup = findGroup(aStencil,agroup.getName());
if(aNodeGroup!=null){
addGroup(aNodeGroup,agroup);
return;
}
aStencil.addGroup(agroup);
}
private static void addGroup(NodeGroup nodeGroup,NodeGroup agroup) {
int j=agroup.Nodesize();
for(int i=0;i<j;i++) {
try {
nodeGroup.addNodeInfoID(agroup.getNodeDefinitionID(i));
} catch (SysException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(agroup.getChildrenNodeGroup()==null||agroup.getChildrenNodeGroup().size()<=0) {
return;
}
LinkedList<NodeGroup> secondCchildren = agroup.getChildrenNodeGroup();
if(secondCchildren==null||secondCchildren.size()==0) {
return;
}
Iterator<NodeGroup> iterator2 = secondCchildren.iterator();
LinkedList<NodeGroup> firstCchildren = nodeGroup.getChildrenNodeGroup();
if(firstCchildren==null||firstCchildren.size()==0) {
while(iterator2.hasNext()) {
nodeGroup.addChildrenGroup(iterator2.next());
}
}
else {
while(iterator2.hasNext()) {
Iterator<NodeGroup> iterator1 = firstCchildren.iterator();
NodeGroup tempNodeGroup2 = iterator2.next();
String name = tempNodeGroup2.getName();
boolean flag = false;
while(iterator1.hasNext()) {
NodeGroup tempNodeGroup1 = iterator1.next();
if(tempNodeGroup1.getName().equals(name)) {
addGroup(tempNodeGroup1,tempNodeGroup2);
}
}
if(!flag) {
nodeGroup.addChildrenGroup(tempNodeGroup2);
}
}
}
}
/**
* @author Xiaojun Chen add a single group into Phase
* @param agroup
* an Operator Group
*/
public static void addGroup(NodeGroup agroup) {
if (agroup == null) {
return;
}
NodeGroup aNodeGroup = findGroup(agroup.getName());
if(aNodeGroup!=null){
addGroup(aNodeGroup,agroup);
return;
}
Stencil stencils = m_Stencils.get(m_Stencils.size()-1);
stencils.addGroup(agroup);
}
private static NodeGroup findGroup(String name) {
int size = m_Stencils.size();
NodeGroup aNodeGroup = null;
int i=0;
for(i=0;i<size;i++) {
aNodeGroup = findGroup(m_Stencils.get(i),name);
if(aNodeGroup!=null) {
return aNodeGroup;
}
}
return null;
}
private static NodeGroup findGroup(Stencil aStencil,String name) {
Vector<NodeGroup> groups = aStencil.getGroups();
int size = groups.size();
NodeGroup group;
for(int i=0;i<size;i++) {
group = groups.get(i);
if(group.getName().equals(name)) {
return group;
}
group = findGroup(group,name);
if(group!=null) {
return group;
}
}
return null;
}
private static NodeGroup findGroup(NodeGroup aNodeGroup,String name) {
if(aNodeGroup==null) {
return null;
}
LinkedList<NodeGroup> children = aNodeGroup.getChildrenNodeGroup();
if(children==null||children.size()==0) {
return null;
}
Iterator<NodeGroup> iterator = children.iterator();
NodeGroup nodeGroup = null;
while(iterator.hasNext()) {
nodeGroup = iterator.next();
if(nodeGroup.getName().equals(name)) {
return nodeGroup;
}
nodeGroup = findGroup(nodeGroup,name);
if(nodeGroup!=null) {
return nodeGroup;
}
}
return null;
}
public static Vector<Stencil> getStencils() {
return m_Stencils;
}
public static Stencil getLastStencil() {
if(m_Stencils==null) {
return null;
}
return m_Stencils.get(m_Stencils.size()-1);
}
@SuppressWarnings("unchecked")
public static void addNodeInfo(NodeInfo aNodeInfo) {
m_OperatorInfos.put(aNodeInfo.getDefinitionID(), aNodeInfo);
}
public static NodeInfo getNodeInfo(String aNodeDefinitionID) {
return m_OperatorInfos.get(aNodeDefinitionID);
}
public static String format(String str) {
// if(locale.getLanguage().equals(locale.CHINA.getLanguage())){
try {
str = new String(str.getBytes("ISO-8859-1"), "GB2312");
} catch (UnsupportedEncodingException e) {
// log.error("Unsupported encoding exception!"+e);
}
// }
return str;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -