- Hlavní stránka
- Balíky
- Třídy
- Soubory

# src/cz/neubauer/tomas/hazardanalysis/Rizika.java

Zobrazit dokumentaci tohoto souboru.

    00001
    00004 package cz.neubauer.tomas.hazardanalysis;
    00005
    00006 import java.sql.Connection;
    00007 import java.sql.DriverManager;
    00008 import java.sql.SQLException;
    00009 import java.util.Properties;
    00010
    00011 import javax.xml.xpath.XPathConstants;
    00012
    00013 import org.w3c.dom.NodeList;
    00014
    00015 import cz.neubauer.tomas.hazardanalysis.model.XMLReader;
    00016 import cz.neubauer.tomas.hazardanalysis.model.analysis.Analysis;
    00017 import cz.neubauer.tomas.hazardanalysis.model.analysis.AnalysisRecord;
    00018 import cz.neubauer.tomas.hazardanalysis.model.components.Component;
    00019 import cz.neubauer.tomas.hazardanalysis.model.components.ComponentCatalog;
    00020 import cz.neubauer.tomas.hazardanalysis.viewcontroller.MainFrame;
    00021
    00027 public class Rizika {
    00031         private ComponentCatalog componentCatalog;
    00032
    00036         private Connection connection;
    00037
    00043         public Rizika() {
    00044                 try {
    00045                         DriverManager.registerDriver(new com.mysql.jdbc.Driver());
    00046
    00047                         String configurationFile = "conf/db.conf";
    00048
    00049                         String host = (String) XMLReader.readXML(configurationFile,
    00050                                         "/connection/host", XPathConstants.STRING);
    00051                         String port = (String) XMLReader.readXML(configurationFile,
    00052                                         "/connection/port", XPathConstants.STRING);
    00053                         String schema = (String) XMLReader.readXML(configurationFile,
    00054                                         "/connection/schema", XPathConstants.STRING);
    00055                         String username = (String) XMLReader.readXML(configurationFile,
    00056                                         "/connection/username", XPathConstants.STRING);
    00057                         String password = (String) XMLReader.readXML(configurationFile,
    00058                                         "/connection/password", XPathConstants.STRING);
    00059
    00060                         Properties info = new Properties();
    00061                         info.put("user", username);
    00062                         info.put("password", password);
    00063                         info.put("characterEncoding", "utf8");
    00064
    00065                         connection = DriverManager.getConnection("jdbc:mysql://" + host
    00066                                         + ":" + port + "/" + schema + "", info);
    00067
    00068                         componentCatalog = new ComponentCatalog();
    00069                         componentCatalog.loadFromDB(connection);
    00070
    00071                         new MainFrame(this);
    00072                 } catch (SQLException e) {
    00073                         e.printStackTrace();
    00074                 }
    00075         }
    00076
    00083         public static void main(String[] args) {
    00084                 new Rizika();
    00085         }
    00086
    00094         public Analysis createAnalysis(String xmlFileURI) {
    00095                 // nacteni komponent konkretniho diagramu
    00096                 NodeList nl = (NodeList) XMLReader.readXML(xmlFileURI,
    00097                                 "/VisioDocument/Masters/Master/@NameU", XPathConstants.NODESET);
    00098                 if (nl == null) {
    00099                         return null;
    00100                 }
    00101
    00102                 Analysis analysis = new Analysis();
    00103                 String currentComponentNode;
    00104                 Component currentComponent;
    00105                 for (int i = 0; i < nl.getLength(); i++) {
    00106                         currentComponentNode = nl.item(i).getNodeValue();
    00107                         currentComponent = componentCatalog
    00108                                         .getComponentByName(currentComponentNode);
    00109                         if (currentComponent != null) {
    00110                                 AnalysisRecord analysisRecord = new AnalysisRecord(
    00111                                                 currentComponent);
    00112                                 analysis.addAnalysisRecord(analysisRecord);
    00113                         }
    00114                 }
    00115                 return analysis;
    00116         }
    00117
    00123         public ComponentCatalog getComponentCatalog() {
    00124                 return componentCatalog;
    00125         }
    00126
    00132         public Connection getConnection() {
    00133                 return connection;
    00134         }
    00135
    00139         public void refresh() {
    00140                 componentCatalog.loadFromDB(connection);
    00141         }
    00142 }