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

📄 xmlbeans.java

📁 代码是一个分类器的实现,其中使用了部分weka的源代码。可以将项目导入eclipse运行
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
    m_CurrentNode = node;        result   = null;    children = XMLDocument.getChildTags(node);    fontname = "";    style    = 0;    size     = 0;    for (i = 0; i < children.size(); i++) {      child = (Element) children.get(i);      name  = child.getAttribute(ATT_NAME);      if (name.equals(VAL_NAME))        name = (String) invokeReadFromXML(child);      else if (name.equals(VAL_STYLE))        style = readIntFromXML(child);      else if (name.equals(VAL_SIZE))        size = readIntFromXML(child);      else        System.out.println("WARNING: '" + name            + "' is not a recognized name for " + node.getAttribute(ATT_NAME) + "!");    }        result = new Font(fontname, style, size);    return result;  }  /**   * adds the given Point 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 writePoint(Element parent, Object o, String name)      throws Exception {        Element     node;    Point       p;    // for debugging only    if (DEBUG)       trace(new Throwable(), name);        m_CurrentNode = parent;        p    = (Point) o;    node = addElement(parent, name, p.getClass().getName(), false);    writeDoubleToXML(node, p.getX(), VAL_X);    writeDoubleToXML(node, p.getY(), VAL_Y);        return node;  }  /**   * builds the Point 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 readPoint(Element node) throws Exception {    Object      result;    Vector      children;    Element     child;    int         i;    double      x;    double      y;    String      name;    // for debugging only    if (DEBUG)       trace(new Throwable(), node.getAttribute(ATT_NAME));    m_CurrentNode = node;        result   = null;    children = XMLDocument.getChildTags(node);    x        = 0;    y        = 0;    for (i = 0; i < children.size(); i++) {      child = (Element) children.get(i);      name  = child.getAttribute(ATT_NAME);      if (name.equals(VAL_X))        x = readDoubleFromXML(child);      else if (name.equals(VAL_Y))        y = readDoubleFromXML(child);      else        System.out.println("WARNING: '" + name            + "' is not a recognized name for " + node.getAttribute(ATT_NAME) + "!");    }        result = new Point();    ((Point) result).setLocation(x, y);    return result;  }  /**   * adds the given ColorUIResource 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 writeColorUIResource(Element parent, Object o, String name)      throws Exception {        Element           node;    ColorUIResource   resource;    // for debugging only    if (DEBUG)       trace(new Throwable(), name);        m_CurrentNode = parent;        resource = (ColorUIResource) o;    node     = addElement(parent, name, resource.getClass().getName(), false);    invokeWriteToXML(node, new Color(resource.getRGB()), VAL_COLOR);        return node;  }  /**   * builds the ColorUIResource 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 readColorUIResource(Element node) throws Exception {    Object      result;    Vector      children;    Element     child;    int         i;    String      name;    Color       color;    // for debugging only    if (DEBUG)       trace(new Throwable(), node.getAttribute(ATT_NAME));    m_CurrentNode = node;        result   = null;    children = XMLDocument.getChildTags(node);    color    = null;    for (i = 0; i < children.size(); i++) {      child = (Element) children.get(i);      name  = child.getAttribute(ATT_NAME);      if (name.equals(VAL_COLOR))        color = (Color) invokeReadFromXML(child);      else        System.out.println("WARNING: '" + name            + "' is not a recognized name for " + node.getAttribute(ATT_NAME) + "!");    }        result = new ColorUIResource(color);    return result;  }  /**   * adds the given FontUIResource 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 writeFontUIResource(Element parent, Object o, String name)      throws Exception {        Element           node;    FontUIResource    resource;    // for debugging only    if (DEBUG)       trace(new Throwable(), name);        m_CurrentNode = parent;        resource = (FontUIResource) o;    node     = addElement(parent, name, resource.getClass().getName(), false);    invokeWriteToXML(node, new Font(resource.getName(), resource.getStyle(), resource.getSize()), VAL_COLOR);        return node;  }  /**   * builds the FontUIResource 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 readFontUIResource(Element node) throws Exception {    Object      result;    Vector      children;    Element     child;    int         i;    String      name;    Font        font;    // for debugging only    if (DEBUG)       trace(new Throwable(), node.getAttribute(ATT_NAME));    m_CurrentNode = node;        result   = null;    children = XMLDocument.getChildTags(node);    font     = null;    for (i = 0; i < children.size(); i++) {      child = (Element) children.get(i);      name  = child.getAttribute(ATT_NAME);      if (name.equals(VAL_FONT))        font = (Font) invokeReadFromXML(child);      else        System.out.println("WARNING: '" + name            + "' is not a recognized name for " + node.getAttribute(ATT_NAME) + "!");    }        result = new FontUIResource(font);    return result;  }  /**   * adds the given BeanInstance 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 writeBeanInstance(Element parent, Object o, String name)      throws Exception {        Element         node;    BeanInstance    beaninst;    // for debugging only    if (DEBUG)       trace(new Throwable(), name);        m_CurrentNode = parent;        beaninst = (BeanInstance) o;    node     = addElement(parent, name, beaninst.getClass().getName(), false);    writeIntToXML(node, m_BeanInstances.indexOf(beaninst), VAL_ID);    writeIntToXML(node, beaninst.getX() + beaninst.getWidth()  / 2, VAL_X);   // x is thought to be in the center?    writeIntToXML(node, beaninst.getY() + beaninst.getHeight() / 2, VAL_Y);   // y is thought to be in the center?    invokeWriteToXML(node, beaninst.getBean(), VAL_BEAN);        return node;  }  /**   * builds the BeanInstance 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 readBeanInstance(Element node) throws Exception {    Object          result;    Vector          children;    Element         child;    String          name;    int             i;    int             x;    int             y;    int             id;    Object          bean;    BeanVisual      visual;    BeanInstance    beaninst;    // for debugging only    if (DEBUG)       trace(new Throwable(), node.getAttribute(ATT_NAME));    m_CurrentNode = node;        result   = null;    children = XMLDocument.getChildTags(node);    id       = -1;    x        = 0;    y        = 0;    bean     = null;    for (i = 0; i < children.size(); i++) {      child = (Element) children.get(i);      name  = child.getAttribute(ATT_NAME);      if (name.equals(VAL_ID))        id = readIntFromXML(child);      else if (name.equals(VAL_X))        x = readIntFromXML(child);      else if (name.equals(VAL_Y))        y = readIntFromXML(child);      else if (name.equals(VAL_BEAN))        bean = invokeReadFromXML(child);      else        System.out.println("WARNING: '" + name            + "' is not a recognized name for " + node.getAttribute(ATT_NAME) + "!");    }        result   = new BeanInstance(m_BeanLayout, bean, x, y);    beaninst = (BeanInstance) result;        // set parent of BeanVisual    if (beaninst.getBean() instanceof weka.gui.beans.Visible) {      visual = ((Visible) beaninst.getBean()).getVisual();      visual.setSize(visual.getPreferredSize());      if (visual.getParent() == null) {        ((JPanel) beaninst.getBean()).add(visual);      }    }        // no IDs -> get next null position    if (id == -1) {      for (i = 0; i < m_BeanInstances.size(); i++) {        if (m_BeanInstances.get(i) == null) {          id = ((Integer) m_BeanInstancesID.get(i)).intValue();          break;        }      }    }    // get position for id    i = m_BeanInstancesID.indexOf(new Integer(id));    // keep track of the BeanInstances for reading the connections later on    m_BeanInstances.set(i, result);    // no current MetaBean    m_CurrentMetaBean = null;        return result;  }  /**   * adds the given BeanConncetion 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 writeBeanConnection(Element parent, Object o, String name)    throws Exception {        Element           node;    BeanConnection    beanconn;    int               source;    int               target;    int               sourcePos;    int               targetPos;    // for debugging only    if (DEBUG)       trace(new Throwable(), name);        m_CurrentNode = parent;        beanconn = (BeanConnection) o;    node     = null;    // get position    sourcePos = m_BeanInstances.indexOf(beanconn.getSource());    targetPos = m_BeanInstances.indexOf(beanconn.getTarget());        // get id (if Connection is from a Bean in the UserToolBar, it's not listed! -> ignore it)    if ( (sourcePos > -1) && (targetPos > -1) ) {      source = ((Integer) m_BeanInstancesID.get(sourcePos)).intValue();      target = ((Integer) m_BeanInstancesID.get(targetPos)).intValue();    }    else {       source = -1;       target = -1;    }        // connection exists in the layout?    if ( (source > -1) && (target > -1) ) {      node = addElement(parent, name, beanconn.getClass().getName(), false);        writeIntToXML(node, source, VAL_SOURCEID);      writeIntToXML(node, target, VAL_TARGETID);      invokeWriteToXML(node, beanconn.getEventName(), VAL_EVENTNAME);      writeBooleanToXML(node, beanconn.isHidden(), VAL_HIDDEN);    }        return node;  }  /**   * builds the BeanConnection 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 readBeanConnection(Element node) throws Exception {    Object                  result;    Vector                  children;    Element                 child;    String                  name;    int                     i;    int                     source;    int                     target;    int                     sourcePos;    int                     targetPos;    String                  event;    boolean                 hidden;    // for debugging only    if (DEBUG)       trace(new Throwable(), node.getAttribute(ATT_NAME));    m_CurrentNode = node;        result   = null;    children = XMLDocument.getChildTags(node);    source   = 0;    target   = 0;    event    = "";    hidden   = false;    for (i = 0; i < children.size(); i++) {      child = (Element) children.get(i);      name  = child.getAttribute(ATT_NAME);      if (name.equals(VAL_SOURCEID))        source = readIntFromXML(child);      else if (name.equals(VAL_TARGETID))        target = readIntFromXML(child);      else if (name.equals(VAL_EVENTNAME))        event = (String) invokeReadFromXML(child);      else if (name.equals(VAL_HIDDEN))        hidden = readBooleanFromXML(child);      else        System.out.println("WARNING: '" + name            + "' is not a recognized name for " + node.getAttribute(ATT_NAME) + "!");    }    // get position of id    sourcePos = m_BeanInstancesID.indexOf(new Integer(source));    targetPos = m_BeanInstancesID.indexOf(new Integer(target));        // do we currently ignore the connections?    // Note: necessary because of the MetaBeans    if (m_IgnoreBeanConnections) {      addBeanConnectionRelation(m_CurrentMetaBean, sourcePos + "," + targetPos + "," + event + "," + hidden);      return result;    }    // generate it normally    result = createBeanConnection(sourcePos, targetPos, event, hidden);    return result;  }    /**   * adds the given Loader (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 writeBeanLoader(Element parent, Object o, String name)

⌨️ 快捷键说明

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