gt: 			if (! attributes.getString("visibility").equals("-1"))
context: package org.argouml.persistence;
  
  import org.argouml.model.uml.UmlFactory;
  
  import java.sql.*;
  import java.io.*;
  import java.util.Properties;
  import javax.swing.*;
  import javax.swing.event.*;
  import javax.swing.tree.*;
  import javax.swing.text.*;
  import javax.swing.table.*;
  import javax.swing.border.*;
  import javax.swing.plaf.metal.MetalLookAndFeel;
  
  import java.util.*;
  
  import ru.novosoft.uml.*;
  import ru.novosoft.uml.model_management.*;
  import ru.novosoft.uml.foundation.core.*;
  import ru.novosoft.uml.foundation.data_types.*;
  import ru.novosoft.uml.foundation.extension_mechanisms.*;
  import ru.novosoft.uml.behavior.use_cases.*;
  
  
  
  /**
   * This class contains the functionality to load a model from a
   * mysql database. At the moment the DB must have the name "uml",
   * otherwise it won't work. Additionally, you need a "db.ini" file
   * in the Argo root-directory or as parameter -Dargo.dbconfig="c:\db.ini"
   *
   * Model information for static structure and use case diagrams can now be stored
   * to a mySQL database. The adaption to any other JDBC capable database should be
   * easy by adjusting the DB-scheme, since ArgoUML contains clean JDBC code. Graphical
   * information is not supported yet.
   *
   * @author Toby Baier <Toby.Baier@gmx.net>
   * @version 1.0
   */
  
  public class DBLoader
  {
      String DBUrl = "jdbc:mysql://";
      String DBName = "";
      String configFile = null;
      Properties props = null;
      static Connection Conn = null;
  
  	HashMap uuid2element = new HashMap();
  	HashMap uuid2ascend = new HashMap();
  
      //  default constructor, reads config file and connects to db.
      public DBLoader ()
      {
  	props = new Properties();
  	configFile =  System.getProperty("argo.dbconfig", "/db.ini");
  	try {
  	    InputStream is = new FileInputStream(configFile);
  	    props.load(is);
  	}	
  	catch (IOException e) {
  	    System.out.println("Could not load DB properties from " + configFile);
  	    System.out.println(e);
  	    errorMessage("Could not load DB properties from " + configFile, e);
  	}
  
  	try {
  	    Class.forName(props.getProperty("driver")).newInstance();	    
  	}
  	catch (Exception e) {
  	    System.out.println("Could not load the database driver!");
  	    System.out.println(e);
  	    errorMessage("Could not load the database driver!",e);
  	}
  
  	String dbURL = "jdbc:mysql://";
  	dbURL += props.getProperty("host") + "/";
  	dbURL += props.getProperty("db");
  	String dbUser = props.getProperty("user");
  	String dbPassword = props.getProperty("password");
  	String dbConnectFormat = props.getProperty("dbConnectFormat");
  
  
   
  	try {
  	    if (dbConnectFormat.equals("1")) {
  		Conn = DriverManager.getConnection(dbURL, dbUser, dbPassword);
  	    } else if (dbConnectFormat.equals("2")) {
  		Conn = DriverManager.getConnection(dbURL + "?user=" + dbUser + ";password=" + dbPassword);
  	    } else if (dbConnectFormat.equals("3")) {
  		Properties connprops = new Properties();
  		connprops.put("user", dbUser);
  		connprops.put("password", dbPassword);
  		Conn = DriverManager.getConnection(dbURL, connprops);
  	    } else if (dbConnectFormat.equals("4")) {
  		Conn = DriverManager.getConnection(dbURL + "?user="
                                                  + dbUser + "&password=" + dbPassword);
  	    } else {
  		errorMessage("Unknown dbConnectFormat choice:" + dbConnectFormat, null);
  	    }
  	}
  
  	catch (Exception e) {
  	    System.out.println("Could not connect to database!");
  	    System.out.println(e);
  	    errorMessage("Could not connect to database!",e);
  	}
      }
  
      /** test whether we can use this DBLoader */
      public boolean hasConnection() {
  	return (Conn != null);
      }
  	
      private void errorMessage(String msg, Exception e) {
  	JOptionPane.showMessageDialog(null, msg, "Database error", JOptionPane.ERROR_MESSAGE);
      }
  	/**
  	 * This method is called from ActionLoadModelFromDb. It's the only 
  	 * public method, the only one you actually need to call to get a MModel
  	 *
  	 * @param modelName The name of the model you want to read from the database
  	 * @return the constructed model
  	 */
      public MModel read(String modelName) {
  		
  		ResultSet rs = null;
  		Statement stmt = null;
  		String uuid = "";
  		
  		try {
  			System.out.println("Loading model: "+modelName);
  			stmt = Conn.createStatement();
              rs = stmt.executeQuery("SELECT uuid FROM tModelElement WHERE name = '" + modelName + "'");
  			if (rs.next())
  				uuid = rs.getString("uuid");
  
  			return readModel(uuid, modelName, stmt);
  		}
  		catch (SQLException E) {
  			System.out.println("error while executing!");
  			System.out.println(E);
  			errorMessage("Error while loading the model from the database!",E);
  		}
  		finally {
  			if (rs != null) { try {rs.close();} catch (SQLException SQLE) {} }	    
  			if (stmt != null) {	try {stmt.close();} catch (SQLException SQLE) {}}
  			if (Conn != null) {	try {Conn.close();}	catch (SQLException SQLE) {}}
  		}
  		return null;
      }
  
  	private MModel readModel(String modelUUID, String modelName, Statement stmt) throws SQLException {
  		System.out.println("Loading model with uuid: "+ modelUUID);
  
  		MModel model = UmlFactory.getFactory().getModelManagement().createModel();
  		model.setName(modelName);
  		model.setUUID(modelUUID);
  
  		ResultSet rs = null;
  
  		//rs = stmt.executeQuery("SELECT * FROM tModelElement WHERE namespace = '" + modelUUID + "'");
  		rs = stmt.executeQuery("SELECT * FROM tModelElement");
  
  		// first, load all classifiers
  		while (rs.next()) {
  			if (rs.getString("UMLClassName").equals("Interface"))
  				readInterface(model, rs.getString("uuid"), rs.getString("name"), rs.getString("namespace"), rs.getString("stereotype"), rs.getString("package"));
  			if (rs.getString("UMLClassName").equals("Class"))
  				readClass(model, rs.getString("uuid"), rs.getString("name"), rs.getString("namespace"), rs.getString("stereotype"), rs.getString("package"));
  			if (rs.getString("UMLClassName").equals("Actor"))
  				readActor(model, rs.getString("uuid"), rs.getString("name"), rs.getString("namespace"), rs.getString("stereotype"), rs.getString("package"));
  			if (rs.getString("UMLClassName").equals("UseCase"))
  				readUseCase(model, rs.getString("uuid"), rs.getString("name"), rs.getString("namespace"), rs.getString("stereotype"), rs.getString("package"));
  			if (rs.getString("UMLClassName").equals("DataType"))
  				readDataType(rs.getString("uuid"), rs.getString("name"));
  		}
  
  		// now add attributes, operations and constraints to classifiers
  		Iterator iter = uuid2element.values().iterator();
  		while (iter.hasNext()) {
  			MClassifier cls = (MClassifier)iter.next();
  			addAttributes(cls, cls.getUUID());
  			addOperations(cls, cls.getUUID());
  		}
  
  		// now construct the AssociationEnds, so the associations can be 
  		// built more easily
  		rs = stmt.executeQuery("SELECT * FROM tModelElement");
  			while (rs.next()) {
  			if (rs.getString("UMLClassName").equals("AssociationEnd"))
  				readAssociationEnd(model, rs.getString("uuid"), rs.getString("name"), rs.getString("namespace"), rs.getString("stereotype"), rs.getString("package"));
  		}
  
  		// last not least add relationships
  		rs = stmt.executeQuery("SELECT * FROM tModelElement");
  			while (rs.next()) {
  			if (rs.getString("UMLClassName").equals("Association"))
  				readAssociation(model, rs.getString("uuid"), rs.getString("name"), rs.getString("namespace"), rs.getString("stereotype"), rs.getString("package"));
  			if (rs.getString("UMLClassName").equals("Generalization"))
  				readGeneralization(model, rs.getString("uuid"), rs.getString("name"), rs.getString("namespace"), rs.getString("stereotype"), rs.getString("package"));
  			if (rs.getString("UMLClassName").equals("Abstraction"))
  				readAbstraction(model, rs.getString("uuid"), rs.getString("name"), rs.getString("namespace"), rs.getString("stereotype"), rs.getString("package"));
  			if (rs.getString("UMLClassName").equals("Usage"))
  				readUsage(model, rs.getString("uuid"), rs.getString("name"), rs.getString("namespace"), rs.getString("stereotype"), rs.getString("package"));
  		}
  
  		return model;
  	}
  
  	private MStereotype readStereotype(String uuid) {return null;}
  
  	private void readClass(MModel model, String classUUID, String name, String ns, String stereotypeUUID, String packageUUID) throws SQLException {
  
  		MClass cls = UmlFactory.getFactory().getCore().createClass();
  		cls.setName(name);
  		cls.setUUID(classUUID);
  		if (ns.equals(model.getUUID()))
  			cls.setNamespace(model);
  		cls.setStereotype(readStereotype(stereotypeUUID));
  
  		uuid2element.put(classUUID, cls);		
  	}
  
  	private void readInterface(MModel model, String interfaceUUID, String name, String ns, String stereotypeUUID, String packageUUID) throws SQLException {
  
  		MInterface me = UmlFactory.getFactory().getCore().createInterface();
  		me.setName(name);
  		me.setUUID(interfaceUUID);
  		if (ns.equals(model.getUUID()))
  			me.setNamespace(model);
  		me.setStereotype(readStereotype(stereotypeUUID));
  
  		uuid2element.put(interfaceUUID, me);
  	}
  
  	private void readActor(MModel model, String actorUUID, String name, String ns, String stereotypeUUID, String packageUUID) throws SQLException {
  
  		MActor actor = UmlFactory.getFactory().getUseCases().createActor();
  		actor.setName(name);
  		actor.setUUID(actorUUID);
  		if (ns.equals(model.getUUID()))
  			actor.setNamespace(model);
  		actor.setStereotype(readStereotype(stereotypeUUID));
  
  		uuid2element.put(actorUUID, actor);		
  	}
  
  	private void readUseCase(MModel model, String ucUUID, String name, String ns, String stereotypeUUID, String packageUUID) throws SQLException {
  
  		MUseCase usecase = UmlFactory.getFactory().getUseCases().createUseCase();
  		usecase.setName(name);
  		usecase.setUUID(ucUUID);
  		if (ns.equals(model.getUUID()))
  			usecase.setNamespace(model);
  		usecase.setStereotype(readStereotype(stereotypeUUID));
  
  		uuid2element.put(ucUUID, usecase);		
  	}
  
  	private void readDataType(String dtUUID, String name) {
  
  		MDataType me = UmlFactory.getFactory().getCore().createDataType();
  		me.setName(name);
  		me.setUUID(dtUUID);
  
  		uuid2element.put(dtUUID, me);
  	}
  
  	private void addAttributes(MClassifier me, String uuid) throws SQLException{
  		System.out.println("Adicionando atributos");
  			
  		String query = "SELECT f.uuid, f.ownerScope, f.visibility, ";
  		query += "sf.multiplicity, sf.changeability, sf.targetScope, sf.type, ";
  		query += "me.name, me.namespace ";
  		query += "FROM tFeature f, tStructuralFeature sf, tModelElement me ";
  		query += "WHERE f.owner = '" + uuid +"' ";
  		query += "AND f.uuid = sf.uuid ";
  		query += "AND f.uuid = me.uuid";
  		Statement stmtCl = Conn.createStatement();
  		ResultSet attributes = stmtCl.executeQuery(query);
  		while (attributes.next()) {
  			MAttribute attr = UmlFactory.getFactory().getCore().createAttribute();
  			attr.setUUID(attributes.getString("uuid"));
  			if (! attributes.getString("ownerScope").equals("-1"))
  				attr.setOwnerScope(MScopeKind.forValue(Integer.parseInt(attributes.getString("ownerScope"))));
  