Example usage for java.lang Exception getClass

List of usage examples for java.lang Exception getClass

Introduction

In this page you can find the example usage for java.lang Exception getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:model.SQLiteModel.java

public static void printTable(List<Map<String, String>> data) {
    Set<String> columnNames = new HashSet<String>();
    try {/* w w w . j a va2s. c  o m*/
        for (String columnName : data.get(0).keySet()) {
            System.out.print(columnName + "\t");
            columnNames.add(columnName);
        }
        System.out.println();
        for (Map<String, String> h : data) {
            for (String columnName : columnNames) {
                System.out.print(h.get(columnName) + "\t");
            }
            System.out.println();
        }
    } catch (Exception e) {
        System.err.println(e.getClass().getName() + ": " + e.getMessage());
    }
}

From source file:model.SQLiteModel.java

public static void update(String query) {
    //query = StringEscapeUtils.escapeJavaScript(query);
    //System.out.println(query);
    Statement stmt = null;//  ww  w .ja  v  a  2  s  . co  m
    try {

        stmt = c.createStatement();
        if (stmt.executeUpdate(query) == 0) {
            writeLineToLog("Records created successfully");
        }

        stmt.close();
    } catch (Exception e) {
        System.err.println(e.getClass().getName() + ": " + e.getMessage());
        System.out.println("Unsuccessful update query: " + query);
        writeLineToLog("Unsuccessful update query: " + query);
    }
}

From source file:model.SQLiteModel.java

public static String[][] getFirstMetadata(int assertionId) {
    String query = "SELECT metadatum, metadata_type, frequency,"
            + "(SELECT concept FROM concepts as c WHERE m.conceptId=c.conceptId) AS concept"
            + " FROM metadata as m " + "WHERE assertionId = " + assertionId + " AND conceptId = ("
            + "SELECT concept1Id FROM assertions as a " + "WHERE a.assertionId = m.assertionId);";
    List<Map<String, String>> data = select(query);
    String[][] tableData = null;//  ww  w  .j  a  va2s .  co  m
    try {
        tableData = new String[data.size()][4];
        for (int i = 0; i < data.size(); i++) {
            tableData[i][0] = data.get(i).get("concept");
            tableData[i][1] = data.get(i).get("metadatum");
            tableData[i][2] = data.get(i).get("metadata_type");
            tableData[i][3] = data.get(i).get("frequency");
        }
    } catch (Exception e) {
        System.err.println(e.getClass().getName() + ": " + e.getMessage());
    }
    return tableData;
}

From source file:model.SQLiteModel.java

public static String[][] getSecondMetadata(int assertionId) {
    String query = "SELECT metadatum, metadata_type, frequency,"
            + "(SELECT concept FROM concepts as c WHERE m.conceptId=c.conceptId) AS concept"
            + " FROM metadata as m " + "WHERE assertionId = " + assertionId + " AND conceptId = ("
            + "SELECT concept2Id FROM assertions as a " + "WHERE a.assertionId = m.assertionId);";
    List<Map<String, String>> data = select(query);
    String[][] tableData = null;//  w  ww  .ja  v  a 2 s .  c o  m
    try {
        tableData = new String[data.size()][4];
        for (int i = 0; i < data.size(); i++) {
            tableData[i][0] = data.get(i).get("concept");
            tableData[i][1] = data.get(i).get("metadatum");
            tableData[i][2] = data.get(i).get("metadata_type");
            tableData[i][3] = data.get(i).get("frequency");
        }
    } catch (Exception e) {
        System.err.println(e.getClass().getName() + ": " + e.getMessage());
    }
    return tableData;
}

From source file:model.SQLiteModel.java

public static Object[][] getMetadata() {
    String query = "SELECT metadatumId, metadatum, metadata_type, frequency, (" + "SELECT concept "
            + "FROM concepts as c " + "WHERE c.conceptId = m.conceptId) as concept," + "assertionId "
            + "FROM  metadata as m";
    List<Map<String, String>> data = select(query);
    Object[][] tableData = null;/*from ww w.  j av a2 s  .  co  m*/
    try {
        tableData = new Object[data.size()][6];
        for (int i = 0; i < data.size(); i++) {
            tableData[i][0] = Integer.parseInt(data.get(i).get("metadatumId"));
            tableData[i][1] = data.get(i).get("metadatum");
            tableData[i][2] = data.get(i).get("metadata_type");
            tableData[i][3] = Integer.parseInt(data.get(i).get("frequency"));
            tableData[i][4] = data.get(i).get("concept");
            tableData[i][5] = Integer.parseInt(data.get(i).get("assertionId"));
        }
    } catch (Exception e) {
        System.err.println(e.getClass().getName() + ": " + e.getMessage());
    }
    return tableData;
}

From source file:model.SQLiteModel.java

public static Object[][] getAssertions() {
    String query = "SELECT assertionId, relation, "
            + "(SELECT concept FROM concepts WHERE conceptId=concept1Id) as concept1, "
            + "(SELECT concept FROM concepts WHERE conceptId=concept2Id) as concept2, "
            + "frequency FROM assertions";
    List<Map<String, String>> data = select(query);
    Object[][] tableData = null;/*www .j  a  v a  2  s  .  com*/
    try {
        tableData = new Object[data.size()][5];
        for (int i = 0; i < data.size(); i++) {
            tableData[i][0] = new Integer(Integer.parseInt(data.get(i).get("assertionId")));
            tableData[i][1] = data.get(i).get("relation");
            tableData[i][2] = data.get(i).get("concept1");
            tableData[i][3] = data.get(i).get("concept2");
            tableData[i][4] = new Integer(Integer.parseInt(data.get(i).get("frequency")));
        }
    } catch (Exception e) {
        System.err.println(e.getClass().getName() + ": " + e.getMessage());
    }
    return tableData;
}

From source file:model.SQLiteModel.java

private static List<Map<String, String>> select(String query) {
    //query = StringEscapeUtils.escapeJavaScript(query);
    //System.out.println(query);
    ResultSet rs = null;//w w w .j  a  va  2 s. c  o  m
    Statement stmt = null;
    int first = 1;
    List<String> columnNames = new ArrayList<String>();
    List<Map<String, String>> data = new ArrayList<Map<String, String>>();
    try {
        stmt = c.createStatement();
        rs = stmt.executeQuery(query);
        while (rs.next()) {
            ResultSetMetaData rsmd = rs.getMetaData();
            int count = rsmd.getColumnCount();
            if (first == 1) {
                for (int i = 1; i <= count; i++) {
                    columnNames.add(rsmd.getColumnName(i));
                }
            }
            Map<String, String> curr = new HashMap<String, String>();
            for (int i = 1; i <= count; i++) {
                curr.put(columnNames.get(i - 1), rs.getString(i));
            }
            data.add(curr);
            first++;
        }
        stmt.close();
    } catch (Exception e) {
        System.err.println(e.getClass().getName() + ": " + e.getMessage());
        System.out.println("Unsuccessful select query: " + query);
        writeLineToLog("Unsuccessful select query: " + query);
    }
    return data;
}

From source file:com.pdftron.pdf.utils.Utils.java

public static String encryptIt(Context context, String value) {
    String cryptoPass = context.getString(context.getApplicationInfo().labelRes);
    try {//from   w  w  w  .j a  v a2s  .  co  m
        DESKeySpec keySpec = new DESKeySpec(cryptoPass.getBytes("UTF8"));
        SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
        SecretKey key = keyFactory.generateSecret(keySpec);

        byte[] clearText = value.getBytes("UTF8");
        // Cipher is not thread safe
        Cipher cipher = Cipher.getInstance("DES");
        cipher.init(Cipher.ENCRYPT_MODE, key);

        String encrypedValue = Base64.encodeToString(cipher.doFinal(clearText), Base64.DEFAULT);
        Log.d("MiscUtils", "Encrypted: " + value + " -> " + encrypedValue);
        return encrypedValue;

    } catch (Exception e) {
        Log.d(e.getClass().getName(), e.getMessage());
    }
    return value;
}

From source file:com.pdftron.pdf.utils.Utils.java

public static String decryptIt(Context context, String value) {
    String cryptoPass = context.getString(context.getApplicationInfo().labelRes);
    try {//from   w  w  w.ja  va2s .  c  om
        DESKeySpec keySpec = new DESKeySpec(cryptoPass.getBytes("UTF8"));
        SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
        SecretKey key = keyFactory.generateSecret(keySpec);

        byte[] encrypedPwdBytes = Base64.decode(value, Base64.DEFAULT);
        // cipher is not thread safe
        Cipher cipher = Cipher.getInstance("DES");
        cipher.init(Cipher.DECRYPT_MODE, key);
        byte[] decrypedValueBytes = (cipher.doFinal(encrypedPwdBytes));

        String decrypedValue = new String(decrypedValueBytes);
        Log.d("MiscUtils", "Decrypted: " + value + " -> " + decrypedValue);
        return decrypedValue;

    } catch (Exception e) {
        Log.e(e.getClass().getName(), e.getMessage());
    }
    return value;
}

From source file:com.revorg.goat.IndexManager.java

/**
 * Checks to see whether an index exists or not
 *
 * @param indexPath Directory that contains the Lucene Collection
 * @throws Exception//from   w ww  .j a va 2  s.  co  m
 * @return ActionResult
 */
public static String isIndexExistant(String indexPath) {
    try {
        IndexReader reader = IndexReader.open(indexPath);
        boolean indexExists = reader.indexExists(indexPath);
        reader.close(); //Close Index
        if (indexExists) {
            ActionResult = "Yes";
        } else {
            ActionResult = "No";
        }
        return ActionResult;
    } catch (Exception e) {
        IndexManager.deleteIndex(indexPath); //Delete index
        ActionResultError = " caught a " + e.getClass() + " with message: " + e.getMessage();
        System.out.println("Failure to check index: " + indexPath);
    }
    ActionResult = "Failure";
    return ActionResult + ActionResultError;
}