📄 xmlbeans.java
字号:
throws Exception { Element node; weka.gui.beans.Loader loader; // for debugging only if (DEBUG) trace(new Throwable(), name); m_CurrentNode = parent; loader = (weka.gui.beans.Loader) o; node = addElement(parent, name, loader.getClass().getName(), false); invokeWriteToXML(node, loader.getLoader(), VAL_LOADER); invokeWriteToXML(node, loader.getBeanContext(), VAL_BEANCONTEXT); return node; } /** * adds the given Saver (a bean) to a DOM structure. * * @param parent the parent of this object, e.g. the class this object is a member of * @param o the Object to describe in XML * @param name the name of the object * @return the node that was created * @throws Exception if the DOM creation fails */ public Element writeBeanSaver(Element parent, Object o, String name) throws Exception { Element node; weka.gui.beans.Saver saver; // for debugging only if (DEBUG) trace(new Throwable(), name); m_CurrentNode = parent; saver = (weka.gui.beans.Saver) o; node = addElement(parent, name, saver.getClass().getName(), false); invokeWriteToXML(node, saver.getSaver(), VAL_SAVER); return node; } /** * adds the given Loader to a DOM structure. * * @param parent the parent of this object, e.g. the class this object is a member of * @param o the Object to describe in XML * @param name the name of the object * @return the node that was created * @throws Exception if the DOM creation fails */ public Element writeLoader(Element parent, Object o, String name) throws Exception { Element node; weka.core.converters.Loader loader; File file; boolean known; // for debugging only if (DEBUG) trace(new Throwable(), name); m_CurrentNode = parent; loader = (weka.core.converters.Loader) o; node = addElement(parent, name, loader.getClass().getName(), false); known = true; file = null; // file if (loader instanceof weka.core.converters.AbstractFileLoader) file = ((weka.core.converters.AbstractFileLoader) loader).retrieveFile(); else known = false; if (!known) System.out.println("WARNING: unknown loader class '" + loader.getClass().getName() + "' - cannot retrieve file!"); // only save it, if it's a real file! if ( (file == null) || (file.isDirectory()) ) invokeWriteToXML(node, "", VAL_FILE); else invokeWriteToXML(node, file.getAbsolutePath(), VAL_FILE); return node; } /** * builds the Loader from the given DOM node. * * @param node the associated XML node * @return the instance created from the XML description * @throws Exception if instantiation fails */ public Object readLoader(Element node) throws Exception { Object result; Vector children; Element child; int i; String name; String file; File fl; // for debugging only if (DEBUG) trace(new Throwable(), node.getAttribute(ATT_NAME)); m_CurrentNode = node; result = Class.forName(node.getAttribute(ATT_CLASS)).newInstance(); children = XMLDocument.getChildTags(node); file = ""; for (i = 0; i < children.size(); i++) { child = (Element) children.get(i); name = child.getAttribute(ATT_NAME); if (name.equals(VAL_FILE)) file = (String) invokeReadFromXML(child); else readFromXML(result, name, child); } if (file.equals("")) file = null; // set file only, if it exists if (file != null) { fl = new File(file); if (fl.exists()) ((weka.core.converters.AbstractFileLoader) result).setSource(fl); else System.out.println("WARNING: The file '" + file + "' does not exist!"); } return result; } /** * adds the given Saver to a DOM structure. * * @param parent the parent of this object, e.g. the class this object is a member of * @param o the Object to describe in XML * @param name the name of the object * @return the node that was created * @throws Exception if the DOM creation fails */ public Element writeSaver(Element parent, Object o, String name) throws Exception { Element node; weka.core.converters.Saver saver; File file; String prefix; String dir; boolean known; // for debugging only if (DEBUG) trace(new Throwable(), name); m_CurrentNode = parent; saver = (weka.core.converters.Saver) o; node = addElement(parent, name, saver.getClass().getName(), false); known = true; file = null; prefix = ""; dir = ""; // file if (saver instanceof weka.core.converters.AbstractFileSaver) { file = ((weka.core.converters.AbstractFileSaver) saver).retrieveFile(); prefix = ((weka.core.converters.AbstractFileSaver) saver).filePrefix(); dir = ((weka.core.converters.AbstractFileSaver) saver).retrieveDir(); } else { known = false; } if (!known) System.out.println("WARNING: unknown saver class '" + saver.getClass().getName() + "' - cannot retrieve file!"); // only save it, if it's a real file! if ( (file == null) || (file.isDirectory()) ) { invokeWriteToXML(node, "", VAL_FILE); invokeWriteToXML(node, dir, VAL_DIR); invokeWriteToXML(node, prefix, VAL_PREFIX); } else { invokeWriteToXML(node, file.getAbsolutePath(), VAL_FILE); invokeWriteToXML(node, "", VAL_DIR); invokeWriteToXML(node, "", VAL_PREFIX); } return node; } /** * builds the Saver from the given DOM node. * * @param node the associated XML node * @return the instance created from the XML description * @throws Exception if instantiation fails */ public Object readSaver(Element node) throws Exception { Object result; Vector children; Element child; int i; String name; String file; String dir; String prefix; // for debugging only if (DEBUG) trace(new Throwable(), node.getAttribute(ATT_NAME)); m_CurrentNode = node; result = Class.forName(node.getAttribute(ATT_CLASS)).newInstance(); children = XMLDocument.getChildTags(node); file = null; dir = null; prefix = null; for (i = 0; i < children.size(); i++) { child = (Element) children.get(i); name = child.getAttribute(ATT_NAME); if (name.equals(VAL_FILE)) file = (String) invokeReadFromXML(child); else if (name.equals(VAL_DIR)) dir = (String) invokeReadFromXML(child); else if (name.equals(VAL_PREFIX)) prefix = (String) invokeReadFromXML(child); else readFromXML(result, name, child); } if ( (file != null) && (file.length() == 0) ) file = null; if (file != null) { ((weka.core.converters.AbstractFileSaver) result).setFile(new File(file)); } else if ( (dir != null) && (prefix != null) ) { ((weka.core.converters.AbstractFileSaver) result).setDir(dir); ((weka.core.converters.AbstractFileSaver) result).setFilePrefix(prefix); } return result; } /** * adds the given BeanVisual to a DOM structure. * * @param parent the parent of this object, e.g. the class this object is a member of * @param o the Object to describe in XML * @param name the name of the object * @return the node that was created * @throws Exception if the DOM creation fails */ public Element writeBeanVisual(Element parent, Object o, String name) throws Exception { Element node; BeanVisual visual; // for debugging only if (DEBUG) trace(new Throwable(), name); m_CurrentNode = parent; visual = (BeanVisual) o; node = writeToXML(parent, o, name); // add icon paths invokeWriteToXML(node, visual.getIconPath(), VAL_ICONPATH); invokeWriteToXML(node, visual.getAnimatedIconPath(), VAL_ANIMATEDICONPATH); return node; } /** * builds the BeanVisual from the given DOM node. * * @param node the associated XML node * @return the instance created from the XML description * @throws Exception if instantiation fails */ public Object readBeanVisual(Element node) throws Exception { Object result; Vector children; Element child; int i; String name; String text; String iconPath; String animIconPath; // for debugging only if (DEBUG) trace(new Throwable(), node.getAttribute(ATT_NAME)); m_CurrentNode = node; result = null; children = XMLDocument.getChildTags(node); text = ""; iconPath = ""; animIconPath = ""; // find text for (i = 0; i < children.size(); i++) { child = (Element) children.get(i); name = child.getAttribute(ATT_NAME); if (name.equals(VAL_TEXT)) text = (String) invokeReadFromXML(child); else if (name.equals(VAL_ICONPATH)) iconPath = (String) invokeReadFromXML(child); else if (name.equals(VAL_ANIMATEDICONPATH)) animIconPath = (String) invokeReadFromXML(child); } result = new BeanVisual(text, iconPath, animIconPath); // set rest of properties for (i = 0; i < children.size(); i++) readFromXML(result, node.getAttribute(ATT_NAME), (Element) children.get(i)); return result; } /** * returns the IDs for the given BeanInstances, i.e., the stored IDs * in m_BeanInstancesID, based on m_BeanInstances * * @param beans the beans to retrieve the IDs for * @return the IDs for the given BeanInstances * @see #m_BeanInstances * @see #m_BeanInstancesID */ protected Vector getIDsForBeanInstances(Vector beans) { Vector result; int i; int pos; result = new Vector(); for (i = 0; i < beans.size(); i++) { pos = m_BeanInstances.indexOf(beans.get(i)); result.add(m_BeanInstancesID.get(pos)); } return result; } /** * adds the given MetaBean to a DOM structure. * * @param parent the parent of this object, e.g. the class this object is a member of * @param o the Object to describe in XML * @param name the name of the object * @return the node that was created * @throws Exception if the DOM creation fails */ public Element writeMetaBean(Element parent, Object o, String name) throws Exception { Element node; MetaBean meta; // for debugging only if (DEBUG) trace(new Throwable(), name); m_CurrentNode = parent; meta = (MetaBean) o; node = writeToXML(parent, o, name); invokeWriteToXML(node, getIDsForBeanInstances(meta.getBeansInInputs()), VAL_INPUTSID); invokeWriteToXML(node, getIDsForBeanInstances(meta.getBeansInOutputs()), VAL_OUTPUTSID); return node; } /** * returns a vector with references to BeanInstances according to the IDs * in the given Vector. * @param ids contains the IDs of the BeanInstances * @return the corresponding BeanInstances * @see #m_BeanInstances * @see #m_BeanInstancesID */ protected Vector getBeanInstancesForIDs(Vector ids) { Vector result; int i; int pos; result = new Vector(); for (i = 0; i < ids.size(); i++) { pos = m_BeanInstancesID.indexOf(ids.get(i)); result.add(m_BeanInstances.get(pos)); } return result; } /** * builds the MetaBean from the given DOM node. * * @param node the associated XML node * @return the instance created from the XML description * @throws Exception if instantiation fails */ public Object readMetaBean(Element node) throws Exception { Object result; Vector children; Element child; int i; String name; Vector inputs; Vector outputs; Vector coords; MetaBean bean; // for debugging only if (DEBUG) trace(new Throwable(), node.getAttribute(ATT_NAME)); m_CurrentNode = node; result = new MetaBean(); children = XMLDocument.getChildTags(node); inputs = new Vector(); outputs = new Vector(); coords = new Vector(); // the current MetaBean m_CurrentMetaBean = (MetaBean) result; for (i = 0; i < children.size(); i++) { child = (Element) children.get(i); name = child.getAttribute(ATT_NAME); if (name.equals(VAL_ASSOCIATEDCONNECTIONS)) ((MetaBean) result).setAssociatedConnections((Vector) invokeReadFromXML(child)); else if (name.equals(VAL_INPUTSID)) inputs = (Vector) invokeReadFromXML(child); else if (name.equals(VAL_OUTPUTSID)) outputs = (Vector) invokeReadFromXML(child); else if (name.equals(VAL_SUBFLOW)) ((MetaBean) result).setSubFlow((Vector) invokeReadFromXML(child)); else if (name.equals(VAL_ORIGINALCOORDS)) coords = (Vector) invokeReadFromXML(child); else if (name.equals(VAL_INPUTS)) System.out.println("INFO: '" + name + "' will be restored later."); else if (name.equals(VAL_OUTPUTS)) System.out.println("INFO: '" + name + "' will be restored later."); else readFromXML(result, name, child); } bean = (MetaBean) result; // set inputs and outputs, after the beans have been instantiated bean.setInputs(getBeanInstancesForIDs(inputs)); bean.setOutputs(getBeanInstancesForIDs(outputs)); bean.setOriginalCoords(coords); return result; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -