public static int commitGUIConfigurationTransaction( XMLTreeForConfiguration xtfcXMLTreeForConfiguration, Vector vFunctionalities) { TreeVisit tvConfigurationTreeVisit; TreeVisitToGetConfigurationFile tvgcTreeVisitToGetConfigurationFile; String sConfigurationFile; URL uXML; String sConfigurationLockFile; BufferedWriter bwBufferedWriter; File fFile; tvgcTreeVisitToGetConfigurationFile = new TreeVisitToGetConfigurationFile(vFunctionalities); tvConfigurationTreeVisit = new TreeVisit(tvgcTreeVisitToGetConfigurationFile); if (tvConfigurationTreeVisit.inOrderVisit(xtfcXMLTreeForConfiguration.getXMLTopTreeComponent()) != 0) { JOptionPane.showMessageDialog( null, "inOrderVisit failed", "ConfigurationTransaction", JOptionPane.ERROR_MESSAGE); return 1; } sConfigurationFile = tvgcTreeVisitToGetConfigurationFile.getConfigurationFile(); System.out.println("commitGUIConfigurationTransaction: " + sConfigurationFile); uXML = xtfcXMLTreeForConfiguration.getXML(); try { bwBufferedWriter = new BufferedWriter(new FileWriter(URLDecoder.decode(uXML.getFile(), "UTF-8"))); bwBufferedWriter.write(sConfigurationFile, 0, sConfigurationFile.length()); bwBufferedWriter.close(); System.out.println( "commitGUIConfigurationTransaction: file written (" + URLDecoder.decode(uXML.getFile(), "UTF-8") + ")"); } catch (IOException e) { JOptionPane.showMessageDialog( null, "Operation on BufferedWriter failed (3)", "ConfigurationTransaction", JOptionPane.ERROR_MESSAGE); return 2; } sConfigurationLockFile = new String(uXML.getFile() + ".lck"); try { fFile = new File(URLDecoder.decode(sConfigurationLockFile, "UTF-8")); System.out.println("File. delete: " + URLDecoder.decode(sConfigurationLockFile, "UTF-8")); } catch (IOException e) { JOptionPane.showMessageDialog( null, "URLDecoder.decode failed", "ConfigurationTransaction", JOptionPane.ERROR_MESSAGE); return 1; } if (fFile.delete() == false) { JOptionPane.showMessageDialog( null, "fFile.delete on " + sConfigurationLockFile + " failed", "ConfigurationTransaction", JOptionPane.ERROR_MESSAGE); return 3; } return 0; }
public void realize(XMLTree xtXMLTree) { try { TreeComponent tcSiteTreeComponent; TreeComponent tcSiteTreeComponentParent; TreeComponent tcXMLTopTreeComponent; TreeVisit tvTreeVisit; TreeVisitToFindTreeComponent tvftcTreeVisitToFindTreeComponent; TreeComponent tcSiteToRemoveTreeComponent; tcSiteTreeComponent = xtXMLTree.getSelectedTreeComponent(); if (tcSiteTreeComponent.getChildCount() != 0) { JOptionPane.showMessageDialog( null, "The site is not empty", "DeleteSite", JOptionPane.ERROR_MESSAGE); return; } if (JOptionPane.showOptionDialog( null, "Are you sure?", "DeleteSite", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null) == 1) return; if (ConfigurationTransaction.beginGUIConfigurationTransaction( _xtfcXMLTreeForConfiguration.getXML().getFile(), _pProperties.getProperty("login")) != 0) { JOptionPane.showMessageDialog( null, "beginGUIConfigurationTransaction failed", "DeleteSite", JOptionPane.ERROR_MESSAGE); return; } tcSiteTreeComponentParent = (TreeComponent) tcSiteTreeComponent.getParent(); xtXMLTree.setSelectedTreeComponent(tcSiteTreeComponentParent); tcSiteTreeComponentParent.remove(tcSiteTreeComponent); tcSiteTreeComponentParent.refreshSubTree(); // XMLTreeForContents tcXMLTopTreeComponent = _xtfcXMLTreeForContents.getXMLTopTreeComponent(); tvftcTreeVisitToFindTreeComponent = new TreeVisitToFindTreeComponent( "Site", tcSiteTreeComponent.getAttributeValue("Identifier")); tvTreeVisit = new TreeVisit(tvftcTreeVisitToFindTreeComponent); if (tvTreeVisit.preOrderVisit(tcXMLTopTreeComponent) != 0) { JOptionPane.showMessageDialog( null, "preOrderVisit failed", "DeleteSite", JOptionPane.ERROR_MESSAGE); if (ConfigurationTransaction.rollbackGUIConfigurationTransaction( _xtfcXMLTreeForConfiguration.getXML().getFile()) != 0) { JOptionPane.showMessageDialog( null, "rollbackGUIConfigurationTransaction failed", "DeleteSite", JOptionPane.ERROR_MESSAGE); } return; } if ((tcSiteToRemoveTreeComponent = tvftcTreeVisitToFindTreeComponent.getTreeComponentFound()) == null) { JOptionPane.showMessageDialog( null, "TreeComponent not found (TagName: Site, Identifier: " + tcSiteTreeComponent.getAttributeValue("Identifier") + ")", "DeleteSite", JOptionPane.ERROR_MESSAGE); if (ConfigurationTransaction.rollbackGUIConfigurationTransaction( _xtfcXMLTreeForConfiguration.getXML().getFile()) != 0) { JOptionPane.showMessageDialog( null, "rollbackGUIConfigurationTransaction failed", "DeleteSite", JOptionPane.ERROR_MESSAGE); } return; } tcXMLTopTreeComponent.remove(tcSiteToRemoveTreeComponent); tcXMLTopTreeComponent.refreshSubTree(); // XMLTreeForMonitor tcXMLTopTreeComponent = _xtfmXMLTreeForMonitor.getXMLTopTreeComponent(); tvftcTreeVisitToFindTreeComponent = new TreeVisitToFindTreeComponent( "Site", tcSiteTreeComponent.getAttributeValue("Identifier")); tvTreeVisit = new TreeVisit(tvftcTreeVisitToFindTreeComponent); if (tvTreeVisit.preOrderVisit(tcXMLTopTreeComponent) != 0) { JOptionPane.showMessageDialog( null, "preOrderVisit failed", "DeleteSite", JOptionPane.ERROR_MESSAGE); if (ConfigurationTransaction.rollbackGUIConfigurationTransaction( _xtfcXMLTreeForConfiguration.getXML().getFile()) != 0) { JOptionPane.showMessageDialog( null, "rollbackGUIConfigurationTransaction failed", "DeleteSite", JOptionPane.ERROR_MESSAGE); } return; } if ((tcSiteToRemoveTreeComponent = tvftcTreeVisitToFindTreeComponent.getTreeComponentFound()) == null) { JOptionPane.showMessageDialog( null, "TreeComponent not found (TagName: Site, Identifier: " + tcSiteTreeComponent.getAttributeValue("Identifier") + ")", "DeleteSite", JOptionPane.ERROR_MESSAGE); if (ConfigurationTransaction.rollbackGUIConfigurationTransaction( _xtfcXMLTreeForConfiguration.getXML().getFile()) != 0) { JOptionPane.showMessageDialog( null, "rollbackGUIConfigurationTransaction failed", "DeleteSite", JOptionPane.ERROR_MESSAGE); } return; } tcXMLTopTreeComponent.remove(tcSiteToRemoveTreeComponent); tcXMLTopTreeComponent.refreshSubTree(); if (ConfigurationTransaction.commitGUIConfigurationTransaction( _xtfcXMLTreeForConfiguration, _xtfcXMLTreeForConfiguration.getFunctionalities()) != 0) { JOptionPane.showMessageDialog( null, "commitGUIConfigurationTransaction failed", "DeleteSite", JOptionPane.ERROR_MESSAGE); return; } } catch (Exception e) { JOptionPane.showMessageDialog( null, "DeleteSite ERROR: " + e, "DeleteSite", JOptionPane.ERROR_MESSAGE); if (ConfigurationTransaction.rollbackGUIConfigurationTransaction( _xtfcXMLTreeForConfiguration.getXML().getFile()) != 0) { JOptionPane.showMessageDialog( null, "rollbackGUIConfigurationTransaction failed", "DeleteSite", JOptionPane.ERROR_MESSAGE); } return; } }