📄 xmlbeans.java
字号:
int id; int n; Element child; m_BeanInstances = new Vector(); m_BeanInstancesID = new Vector(); // get all BeanInstance nodes list = document.getElementsByTagName("*"); clsName = BeanInstance.class.getName(); for (i = 0; i < list.getLength(); i++) { node = (Element) list.item(i); // is it a BeanInstance? if (node.getAttribute(ATT_CLASS).equals(clsName)) { children = XMLDocument.getChildTags(node); id = m_BeanInstancesID.size(); // get id-tag (if available) for (n = 0; n < children.size(); n++) { child = (Element) children.get(n); if (child.getAttribute(ATT_NAME).equals(VAL_ID)) id = readIntFromXML((Element) child); } m_BeanInstancesID.add(new Integer(id)); } } m_BeanInstances.setSize(m_BeanInstancesID.size()); // set MetaBean to null m_CurrentMetaBean = null; // no BeanConnections -> see readPostProcess(Object) m_IgnoreBeanConnections = true; // reset BeanConnection-Relations m_BeanConnectionRelation = new Hashtable(); return document; } /** * puts the given BeanConnection onto the next null in the given Vector, * or at the end of the list, if no null is found. * (during the de-serializing, no BeanConnections are set, only nulls) * @param conn the connection to add to the list * @param list the list to add the BeanConnection to */ protected void setBeanConnection(BeanConnection conn, Vector list) { int i; boolean added; added = false; for (i = 0; i < list.size(); i++) { if (list.get(i) == null) { list.set(i, conn); added = true; break; } } if (!added) list.add(conn); } /** * generates a connection based on the given parameters * @param sourcePos the source position in the m_BeanInstances vector * @param targetPos the target position in the m_BeanInstances vector * @param event the name of the event, i.e., the connection * @param hidden true if the connection is hidden * @return the generated BeanConnection * @throws Exception if something goes wrong */ protected BeanConnection createBeanConnection(int sourcePos, int targetPos, String event, boolean hidden) throws Exception { BeanConnection result; BeanInfo compInfo; EventSetDescriptor[] esds; int i; BeanInstance instSource; BeanInstance instTarget; result = null; // was there a connection? if ( (sourcePos == -1) || (targetPos == -1) ) return result; instSource = (BeanInstance) m_BeanInstances.get(sourcePos); instTarget = (BeanInstance) m_BeanInstances.get(targetPos); compInfo = Introspector.getBeanInfo(((BeanInstance) m_BeanInstances.get(sourcePos)).getBean().getClass()); esds = compInfo.getEventSetDescriptors(); for (i = 0; i < esds.length; i++) { if (esds[i].getName().equals(event)) { result = new BeanConnection(instSource, instTarget, esds[i]); ((BeanConnection) result).setHidden(hidden); break; } } return result; } /** * rebuilds all the connections for a certain key in the hashtable. * for the ones being part of a MetaBean, no new instance is built, but only * the reference to the actual BeanConnection set. * @param deserialized the deserialized knowledgeflow * @param key the key of the hashtable to rebuild all connections for * @throws Exception if something goes wrong */ protected void rebuildBeanConnections(Vector deserialized, Object key) throws Exception { int i; int n; int sourcePos; int targetPos; String event; boolean hidden; Vector conns; BeanConnection conn; StringTokenizer tok; Vector beanconns; conns = (Vector) m_BeanConnectionRelation.get(key); // no connections? if (conns == null) return; for (n = 0; n < conns.size(); n++) { tok = new StringTokenizer(conns.get(n).toString(), ","); conn = null; sourcePos = Integer.parseInt(tok.nextToken()); targetPos = Integer.parseInt(tok.nextToken()); event = tok.nextToken(); hidden = stringToBoolean(tok.nextToken()); // regular connection? -> new instance // or MetaBean from user toolbar if ( (!(key instanceof MetaBean)) || (getDataType() == DATATYPE_USERCOMPONENTS)) { conn = createBeanConnection(sourcePos, targetPos, event, hidden); } // MetaBean? -> find BeanConnection else { beanconns = BeanConnection.getConnections(); for (i = 0; i < beanconns.size(); i++) { conn = (BeanConnection) beanconns.get(i); if ( (conn.getSource() == (BeanInstance) m_BeanInstances.get(sourcePos)) && (conn.getTarget() == (BeanInstance) m_BeanInstances.get(targetPos)) && (conn.getEventName().equals(event)) ) { break; } conn = null; } } // add the connection to the corresponding list/MetaBean if (key instanceof MetaBean) setBeanConnection(conn, ((MetaBean) key).getAssociatedConnections()); else setBeanConnection(conn, (Vector) deserialized.get(INDEX_BEANCONNECTIONS)); } } /** * removes the given meta beans from the layout, since they're only listed * in the user toolbar * * @param metabeans the list of MetaBeans in the user toolbar */ protected void removeUserToolBarBeans(Vector metabeans) { int i; int n; MetaBean meta; Vector subflow; BeanInstance beaninst; for (i = 0; i < metabeans.size(); i++) { meta = (MetaBean) metabeans.get(i); subflow = meta.getSubFlow(); for (n = 0; n < subflow.size(); n++) { beaninst = (BeanInstance) subflow.get(n); beaninst.removeBean(m_BeanLayout); } } } /** * additional post-processing can happen in derived classes after reading * from XML. re-builds the BeanConnections. * * @param o the object to perform some additional processing on * @return the processed object * @throws Exception if post-processing fails */ protected Object readPostProcess(Object o) throws Exception { Enumeration enm; Vector deserialized; Object key; deserialized = (Vector) super.readPostProcess(o); // rebuild the actual connections rebuildBeanConnections(deserialized, REGULAR_CONNECTION); // rebuild the references in the MetaBeans enm = m_BeanConnectionRelation.keys(); while (enm.hasMoreElements()) { key = enm.nextElement(); // skip the regular connections if (!(key instanceof MetaBean)) continue; rebuildBeanConnections(deserialized, key); } // remove MetaBean and subflow from BeanInstance (not part of the flow!) if (getDataType() == DATATYPE_USERCOMPONENTS) removeUserToolBarBeans(deserialized); return deserialized; } /** * returns the relation for the given MetaBean, for the regular connections, * null has to be used * @param meta the MetaBean (or null for regular connections) to retrieve * the connections for * @return the associated connections * @see #REGULAR_CONNECTION */ protected Vector getBeanConnectionRelation(MetaBean meta) { Vector result; Object key; if (meta == null) key = REGULAR_CONNECTION; else key = meta; // not yet in there? if (!m_BeanConnectionRelation.containsKey(key)) { m_BeanConnectionRelation.put(key, new Vector()); } result = (Vector) m_BeanConnectionRelation.get(key); return result; } /** * adds the given connection-relation for the specified MetaBean (or null in * case of regular connections) * @param meta the MetaBean (or null for regular connections) to add * the relationship for * @param connection the connection relation to add */ protected void addBeanConnectionRelation(MetaBean meta, String connection) { Vector relations; Object key; relations = getBeanConnectionRelation(meta); // add relation relations.add(connection); // update if (meta == null) key = REGULAR_CONNECTION; else key = meta; m_BeanConnectionRelation.put(key, relations); } /** * adds the given Color 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 writeColor(Element parent, Object o, String name) throws Exception { Element node; Color color; // for debugging only if (DEBUG) trace(new Throwable(), name); m_CurrentNode = parent; color = (Color) o; node = addElement(parent, name, color.getClass().getName(), false); writeIntToXML(node, color.getRed(), VAL_RED); writeIntToXML(node, color.getGreen(), VAL_GREEN); writeIntToXML(node, color.getBlue(), VAL_BLUE); return node; } /** * builds the Color 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 readColor(Element node) throws Exception { Object result; Vector children; Element child; int i; int red; int green; int blue; String name; // for debugging only if (DEBUG) trace(new Throwable(), node.getAttribute(ATT_NAME)); m_CurrentNode = node; result = null; children = XMLDocument.getChildTags(node); red = 0; green = 0; blue = 0; for (i = 0; i < children.size(); i++) { child = (Element) children.get(i); name = child.getAttribute(ATT_NAME); if (name.equals(VAL_RED)) red = readIntFromXML(child); else if (name.equals(VAL_GREEN)) green = readIntFromXML(child); else if (name.equals(VAL_BLUE)) blue = readIntFromXML(child); else System.out.println("WARNING: '" + name + "' is not a recognized name for " + node.getAttribute(ATT_NAME) + "!"); } result = new Color(red, green, blue); return result; } /** * adds the given Dimension 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 writeDimension(Element parent, Object o, String name) throws Exception { Element node; Dimension dim; // for debugging only if (DEBUG) trace(new Throwable(), name); m_CurrentNode = parent; dim = (Dimension) o; node = addElement(parent, name, dim.getClass().getName(), false); writeDoubleToXML(node, dim.getWidth(), VAL_WIDTH); writeDoubleToXML(node, dim.getHeight(), VAL_HEIGHT); return node; } /** * builds the Dimension 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 readDimension(Element node) throws Exception { Object result; Vector children; Element child; int i; double width; double height; String name; // for debugging only if (DEBUG) trace(new Throwable(), node.getAttribute(ATT_NAME)); m_CurrentNode = node; result = null; children = XMLDocument.getChildTags(node); width = 0; height = 0; for (i = 0; i < children.size(); i++) { child = (Element) children.get(i); name = child.getAttribute(ATT_NAME); if (name.equals(VAL_WIDTH)) width = readDoubleFromXML(child); else if (name.equals(VAL_HEIGHT)) height = readDoubleFromXML(child); else System.out.println("WARNING: '" + name + "' is not a recognized name for " + node.getAttribute(ATT_NAME) + "!"); } result = new Dimension(); ((Dimension) result).setSize(width, height); return result; } /** * adds the given Font 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 writeFont(Element parent, Object o, String name) throws Exception { Element node; Font font; // for debugging only if (DEBUG) trace(new Throwable(), name); m_CurrentNode = parent; font = (Font) o; node = addElement(parent, name, font.getClass().getName(), false); invokeWriteToXML(node, font.getName(), VAL_NAME); writeIntToXML(node, font.getStyle(), VAL_STYLE); writeIntToXML(node, font.getSize(), VAL_SIZE); return node; } /** * builds the Font 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 readFont(Element node) throws Exception { Object result; Vector children; Element child; int i; int style; int size; String name; String fontname; // for debugging only if (DEBUG) trace(new Throwable(), node.getAttribute(ATT_NAME));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -