xmlcomplexchoice.java
来自「jawe的最新版本,基于Java的图形化工作流编辑器。图形化工作流编辑器 。使用」· Java 代码 · 共 185 行
JAVA
185 行
package org.enhydra.shark.xpdl;import java.util.ArrayList;import java.util.Iterator;/** * Class that represents choice of complex elements from XML schema. * * @author Sasa Bojanic */public abstract class XMLComplexChoice extends XMLElement { protected ArrayList choices; protected XMLElement choosen; protected transient boolean cachesInitialized=false; public XMLComplexChoice(XMLComplexElement parent, String name, boolean isRequired) { super(parent, name, isRequired); fillChoices(); } public void setValue(String v) {// throw new RuntimeException("Can't set value for this type of element!"); } public void makeAs (XMLElement el) { super.makeAs(el); XMLComplexChoice cce=(XMLComplexChoice)el; int chsnind=cce.choices.indexOf(cce.getChoosen()); XMLElement newChsn=(XMLElement)choices.get(chsnind); newChsn.makeAs(cce.getChoosen()); this.setChoosen(newChsn);// Iterator it1=this.choices.iterator();// Iterator it2=cce.choices.iterator();// int chsnind=cce.choices.indexOf(cce.getChoosen());//// while (it1.hasNext() && it2.hasNext()) {// XMLElement e1=(XMLElement)it1.next();// XMLElement e2=(XMLElement)it2.next();// e1.makeAs(e2);// }// this.setChoosen((XMLElement)choices.get(chsnind)); } /** * Overrides super-method to set this element and all of its * choice elements read only value to the one specified. */ public void setReadOnly (boolean ro) { super.setReadOnly(ro); for (int i = 0; i < choices.size(); i++) { ((XMLElement) choices.get(i)).setReadOnly(ro); } } public void setNotifyListeners (boolean notify) { super.setNotifyListeners(notify); for (int i = 0; i < choices.size(); i++) { ((XMLElement) choices.get(i)).setNotifyListeners(notify); } } public void setNotifyMainListeners (boolean notify) { super.setNotifyMainListeners(notify); for (int i = 0; i < choices.size(); i++) { ((XMLElement) choices.get(i)).setNotifyMainListeners(notify); } } /** * Initializes caches in read-only mode. If mode is not read-only, * throws RuntimeException. */ public void initCaches () { if (!isReadOnly) { throw new RuntimeException("Caches can be initialized only in read-only mode!"); } clearCaches(); Iterator it=choices.iterator(); while (it.hasNext()) { XMLElement el=(XMLElement)it.next(); if (el instanceof XMLBaseForCollectionAndComplex) { ((XMLBaseForCollectionAndComplex)el).initCaches(); } else if (el instanceof XMLComplexChoice) { ((XMLComplexChoice)el).initCaches(); } } cachesInitialized=true; } public void clearCaches () { Iterator it=choices.iterator(); while (it.hasNext()) { XMLElement el=(XMLElement)it.next(); if (el instanceof XMLBaseForCollectionAndComplex) { ((XMLBaseForCollectionAndComplex)el).clearCaches(); } else if (el instanceof XMLComplexChoice) { ((XMLComplexChoice)el).clearCaches(); } } cachesInitialized=false; } public boolean isEmpty() { return (choosen instanceof XMLEmptyChoiceElement); } /** * The possible choices - instances of XMLElement class. * * @return the possible choices for this element. */ public ArrayList getChoices() { return choices; } public XMLElement getChoosen() { return choosen; } public void setChoosen(XMLElement ch) { if (isReadOnly) { throw new RuntimeException("Can't set the value of read only element!"); } if (!choices.contains(ch)) { throw new RuntimeException("Incorrect value! The possible values are: " + choices); } boolean notify=false; XMLElement oldChoosen=choosen; if (this.choosen == null || !this.choosen.equals(ch)) { notify=true; } this.choosen = ch; if (notify && (notifyMainListeners || notifyListeners)) { XMLElementChangeInfo info=createInfo(oldChoosen, choosen, null, XMLElementChangeInfo.UPDATED); if (notifyListeners) { notifyListeners(info); } if (notifyMainListeners) { notifyMainListeners(info); } } } protected abstract void fillChoices (); public Object clone() { XMLComplexChoice d = (XMLComplexChoice) super.clone(); d.choices = new ArrayList(); d.choosen = null; d.cachesInitialized=false; Iterator it=choices.iterator(); while (it.hasNext()) { XMLElement c=(XMLElement)it.next(); XMLElement cloned = (XMLElement) c.clone(); d.choices.add(cloned); cloned.setParent(d); if (d.choosen==null && this.choosen!=null && this.choosen.equals(c)) { d.choosen = cloned; } } return d; } public boolean equals (Object e) { boolean equals=super.equals(e); if (equals) { XMLComplexChoice el=(XMLComplexChoice)e; equals=(this.choices.equals(el.choices)); // System.out.println(" XMLComplexChoice choices equal - "+equals); equals=equals && !((choices==null && el.choices!=null) || (choices!=null && el.choices==null)); // System.out.println(" XMLComplexChoice choosen equal - "+equals); } return equals; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?