package beanspack; import java.beans.*; import javax.xml.parsers.*; import org.w3c.dom.*; import toolspack.*; /** * Bean di supporto alla gestione degli eventi dei bean installati nell'infrastruttura. * Contiene un documento actionXML settabile da parte di altri bean; ad ogni modifica * di questo documento tutti i bean registrati come listener ne vengono notificati e possono * rispondere con un veto che viene quindi girato al bean che ha tentato di settare actionXML. * Il documento actionXML deve avere radice * * Questo componente fornisce inoltre supporto al logging e contiene un documentBuilder * per fornire agli altri bean nuovi documenti DOM * I metodi sono synchronized perché questo bean può essere utilizzato anche come * applicationBean, quindi deve gestire la concorrenza. * Tutti i metodi di questa classe fanno parte dell'interfaccia ISupportBean. * @author Stefano Ricciarelli * @version 1.2 - Date: 28-06-2002 */ public class SupportBean implements ISupportBean { private Document actionXML; //Transient significa che è escluso da serializzazione private transient PropertyChangeSupport propertyChangeListeners = new PropertyChangeSupport(this); private transient VetoableChangeSupport vetoableChangeListeners = new VetoableChangeSupport(this); private DocumentBuilder documentBuilder; public SupportBean() { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); try { documentBuilder = factory.newDocumentBuilder(); } catch (Exception ex) { } actionXML = getNewDocument(); Element action = actionXML.createElement("action"); action.setAttribute("beanName", ""); action.setAttribute("actionName", ""); actionXML.appendChild(action); } /** * Metodo con cui settare il documeto actionXML di questo bean * @param actionXML il documento con cui si vuole settare actionXML di questo bean * @throws PropertyVetoException l'eventuale veto ricevuto da altri bean in risposta * all'inizitiva di modifica di actionXML */ public synchronized void setActionXML(Document actionXML) throws PropertyVetoException { Document oldActionXML = this.actionXML; vetoableChangeListeners.fireVetoableChange("actionXML", oldActionXML, actionXML); this.actionXML = actionXML; propertyChangeListeners.firePropertyChange("actionXML", oldActionXML, actionXML); } //Seguono i metodi che wrappano il Logger rendendo così disponibili le sue funzionalità //ai componenti installati nell'infrastruttura public synchronized Document getNewDocument() { return documentBuilder.newDocument(); } public void DOMtoXMLfile(Document dom, String fileName) { Logger.DOMtoXMLfile(dom, fileName); } public void appendErrorXML(Document doc) { Logger.appendErrorXML(doc); } public void appendErrorXML(Document doc, String root) { Logger.appendErrorXML(doc, root); } public void appendErrorXML(Node node) { Logger.appendErrorXML(node); } public void appendErrorXML(Node node, String root) { Logger.appendErrorXML(node, root); } public void print(Object o, String s) { Logger.print(o, s); } public void print(String s) { Logger.print(s); } //Seguono i metodi che gestiscono l'aggiunta/rimozione di Listener public synchronized void removePropertyChangeListener(PropertyChangeListener l) { propertyChangeListeners.removePropertyChangeListener(l); } public synchronized void addPropertyChangeListener(PropertyChangeListener l) { propertyChangeListeners.addPropertyChangeListener(l); } public synchronized void removeVetoableChangeListener(VetoableChangeListener l) { vetoableChangeListeners.removeVetoableChangeListener(l); } public synchronized void addVetoableChangeListener(VetoableChangeListener l) { vetoableChangeListeners.addVetoableChangeListener(l); } }