Example usage for java.lang UnsupportedOperationException getClass

List of usage examples for java.lang UnsupportedOperationException getClass

Introduction

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

Prototype

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

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:com.mijecu25.sqlplus.SQLPlus.java

public static void main(String[] args) throws IOException {
    // Create and load the properties from the application properties file
    Properties properties = new Properties();
    properties.load(SQLPlus.class.getClassLoader().getResourceAsStream(SQLPlus.APPLICATION_PROPERTIES_FILE));

    SQLPlus.logger.info("Initializing " + SQLPlus.PROGRAM_NAME + " version "
            + properties.getProperty(SQLPlus.APPLICATION_PROPERTIES_FILE_VERSION));

    // Check if the user is using a valid console (i.e. not from Eclipse)
    if (System.console() == null) {
        // The Console object for the JVM could not be found. Alert the user 
        SQLPlus.logger.fatal(Messages.FATAL + "A JVM Console object was not found. Try running "
                + SQLPlus.PROGRAM_NAME + "from the command line");
        System.out.println(//from  w  w w.j  av  a  2s.  com
                Messages.FATAL + SQLPlus.PROGRAM_NAME + " was not able to find your JVM's Console object. "
                        + "Try running " + SQLPlus.PROGRAM_NAME + " from the command line.");

        SQLPlus.exitSQLPlus();

        SQLPlus.logger.fatal(Messages.FATAL + Messages.QUIT_PROGRAM_ERROR(PROGRAM_NAME));
        return;
    }

    // UI intro
    System.out.println("Welcome to " + SQLPlus.PROGRAM_NAME
            + "! This program has a DSL to add alerts to various SQL DML events.");
    System.out.println("Be sure to use " + SQLPlus.PROGRAM_NAME + " from the command line.");
    System.out.println();

    // Get the version
    System.out.println("Version: " + properties.getProperty(SQLPlus.APPLICATION_PROPERTIES_FILE_VERSION));
    System.out.println();

    // Read the license file
    BufferedReader bufferedReader;
    bufferedReader = new BufferedReader(new FileReader(SQLPlus.LICENSE_FILE));

    // Read a line
    String line = bufferedReader.readLine();

    // While the line is not null
    while (line != null) {
        System.out.println(line);

        // Read a new lines
        line = bufferedReader.readLine();
    }

    // Close the buffer
    bufferedReader.close();
    System.out.println();

    // Create the jline console that allows us to remember commands, use arrow keys, and catch interruptions
    // from the user
    SQLPlus.console = new ConsoleReader();
    SQLPlus.console.setHandleUserInterrupt(true);

    try {
        // Get credentials from the user
        SQLPlus.logger.info("Create SQLPlusConnection");
        SQLPlus.createSQLPlusConnection();
    } catch (NullPointerException | SQLException | IllegalArgumentException e) {
        // NPE: This exception can occur if the user is running the program where the JVM Console
        // object cannot be found.
        // SQLE: TODO should I add here the error code?
        // This exception can occur when trying to establish a connection
        // IAE: This exception can occur when trying to establish a connection
        SQLPlus.logger
                .fatal(Messages.FATAL + Messages.FATAL_EXIT(SQLPlus.PROGRAM_NAME, e.getClass().getName()));
        System.out.println(Messages.FATAL + Messages.FATAL_EXCEPTION_ACTION(e.getClass().getSimpleName()) + " "
                + Messages.CHECK_LOG_FILES);
        SQLPlus.exitSQLPlus();

        SQLPlus.logger.fatal(Messages.FATAL + Messages.QUIT_PROGRAM_ERROR(SQLPlus.PROGRAM_NAME));
        return;
    } catch (UserInterruptException uie) {
        SQLPlus.logger.warn(Messages.WARNING + "The user typed an interrupt instruction.");
        SQLPlus.exitSQLPlus();

        return;
    }

    System.out.println("Connection established! Commands end with " + SQLPlus.END_OF_COMMAND);
    System.out.println("Type " + SQLPlus.EXIT + " or " + SQLPlus.QUIT + " to exit the application ");

    try {
        // Execute the input scanner
        while (true) {
            // Get a line from the user until the hit enter (carriage return, line feed/ new line).
            System.out.print(SQLPlus.PROMPT);
            try {
                line = SQLPlus.console.readLine().trim();
            } catch (NullPointerException npe) {
                // TODO test this behavior
                // If this exception is catch, it is very likely that the user entered the end of line command.
                // This means that the program should quit.
                SQLPlus.logger.warn(Messages.WARNING + "The input from the user is null. It is very likely that"
                        + "the user entered the end of line command and they want to quit.");
                SQLPlus.exitSQLPlus();

                return;
            }

            // If the user did not enter anything
            if (line.isEmpty()) {
                // Continue to the next iteration
                continue;
            }

            if (line.equals(".")) {
                line = "use courses;";
            }

            if (line.equals("-")) {
                line = "select created_at from classes;";
            }

            if (line.equals("--")) {
                line = "select name, year from classes;";
            }

            if (line.equals("*")) {
                line = "select * from classes;";
            }

            if (line.equals("x")) {
                line = "select name from classes, classes;";
            }

            if (line.equals("e")) {
                line = "select * feom classes;";
            }

            // Logic to quit
            if (line.equals(SQLPlus.QUIT) || line.equals(SQLPlus.EXIT)) {
                SQLPlus.logger.info("The user wants to quit " + SQLPlus.PROGRAM_NAME);
                SQLPlus.exitSQLPlus();
                break;
            }

            // Use a StringBuilder since jline works weird when it has read a line. The issue we were having was with the
            // end of command logic. jline does not keep the input from the user in the variable that was stored in. Each
            // time jline reads a new line, the variable is empty
            StringBuilder query = new StringBuilder();
            query.append(line);

            // While the user does not finish the command with the SQLPlus.END_OF_COMMAND
            while (query.charAt(query.length() - 1) != SQLPlus.END_OF_COMMAND) {
                // Print the wait for command prompt and get the next line for the user
                System.out.print(SQLPlus.WAIT_FOR_END_OF_COMMAND);
                query.append(" ");
                line = StringUtils.stripEnd(SQLPlus.console.readLine(), null);
                query.append(line);
            }

            SQLPlus.logger.info("Raw input from the user: " + query);

            try {
                Statement statement;

                try {
                    // Execute the antlr code to parse the user input
                    SQLPlus.logger.info("Will parse the user input to determine what to execute");
                    ANTLRStringStream input = new ANTLRStringStream(query.toString());
                    SQLPlusLex lexer = new SQLPlusLex(input);
                    CommonTokenStream tokens = new CommonTokenStream(lexer);
                    SQLPlusParser parser = new SQLPlusParser(tokens);

                    statement = parser.sqlplus();
                } catch (RecognitionException re) {
                    // TODO move this to somehwere else
                    //                        String message = Messages.WARNING + "You have an error in your SQL syntax. Check the manual"
                    //                                + " that corresponds to your " + SQLPlus.sqlPlusConnection.getCurrentDatabase()
                    //                                + " server or " + SQLPlus.PROGRAM_NAME + " for the correct syntax";
                    //                        SQLPlus.logger.warn(message);
                    //                        System.out.println(message);
                    statement = new StatementDefault();
                }

                statement.setStatement(query.toString());
                SQLPlus.sqlPlusConnection.execute(statement);
            } catch (UnsupportedOperationException uoe) {
                // This exception can occur when the user entered a command allowed by the parsers, but not currently
                // supported by SQLPlus. This can occur because the parser is written in such a way that supports
                // the addition of features.
                SQLPlus.logger.warn(Messages.WARNING + uoe);
                System.out.println(
                        Messages.WARNING + Messages.FATAL_EXCEPTION_ACTION(uoe.getClass().getSimpleName()) + " "
                                + Messages.CHECK_LOG_FILES);
                SQLPlus.logger.warn(Messages.WARNING + "The previous command is not currently supported.");
            }

        }
    } catch (IllegalArgumentException iae) {
        // This exception can occur when a command is executed but it had illegal arguments. Most likely
        // it is a programmer's error and should be addressed by the developer.
        SQLPlus.logger
                .fatal(Messages.FATAL + Messages.FATAL_EXIT(SQLPlus.PROGRAM_NAME, iae.getClass().getName()));
        SQLPlus.exitSQLPlus();

        SQLPlus.logger.fatal(Messages.FATAL + Messages.QUIT_PROGRAM_ERROR(SQLPlus.PROGRAM_NAME));
    } catch (UserInterruptException uie) {
        SQLPlus.logger.warn(Messages.WARNING + "The user typed an interrupt instruction.");
        SQLPlus.exitSQLPlus();
    }
}

From source file:com.evolveum.midpoint.provisioning.ucf.impl.connid.ConnectorInstanceConnIdImpl.java

private void retrieveResourceSchema(List<QName> generateObjectClasses, OperationResult parentResult)
        throws CommunicationException, ConfigurationException, GenericFrameworkException {
    // Connector operation cannot create result for itself, so we need to
    // create result for it
    OperationResult icfResult = parentResult.createSubresult(ConnectorFacade.class.getName() + ".schema");
    icfResult.addContext("connector", connIdConnectorFacade.getClass());

    org.identityconnectors.framework.common.objects.Schema icfSchema = null;
    try {/*from w  w w. j  a v a 2  s  .com*/

        // Fetch the schema from the connector (which actually gets that
        // from the resource).
        InternalMonitor.recordConnectorOperation("schema");
        // TODO have context present
        //recordIcfOperationStart(reporter, ProvisioningOperation.ICF_GET_SCHEMA, null);
        icfSchema = connIdConnectorFacade.schema();
        //recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_GET_SCHEMA, null);

        icfResult.recordSuccess();
    } catch (UnsupportedOperationException ex) {
        //recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_GET_SCHEMA, null, ex);
        // The connector does no support schema() operation.
        icfResult.recordStatus(OperationResultStatus.NOT_APPLICABLE, ex.getMessage());
        resetResourceSchema();
        return;
    } catch (Throwable ex) {
        //recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_GET_SCHEMA, null, ex);
        // conditions.
        // Therefore this kind of heavy artillery is necessary.
        // ICF interface does not specify exceptions or other error
        // TODO maybe we can try to catch at least some specific exceptions
        Throwable midpointEx = processConnIdException(ex, this, icfResult);

        // Do some kind of acrobatics to do proper throwing of checked
        // exception
        if (midpointEx instanceof CommunicationException) {
            icfResult.recordFatalError(midpointEx.getMessage(), midpointEx);
            throw (CommunicationException) midpointEx;
        } else if (midpointEx instanceof ConfigurationException) {
            icfResult.recordFatalError(midpointEx.getMessage(), midpointEx);
            throw (ConfigurationException) midpointEx;
        } else if (midpointEx instanceof GenericFrameworkException) {
            icfResult.recordFatalError(midpointEx.getMessage(), midpointEx);
            throw (GenericFrameworkException) midpointEx;
        } else if (midpointEx instanceof RuntimeException) {
            icfResult.recordFatalError(midpointEx.getMessage(), midpointEx);
            throw (RuntimeException) midpointEx;
        } else if (midpointEx instanceof Error) {
            icfResult.recordFatalError(midpointEx.getMessage(), midpointEx);
            throw (Error) midpointEx;
        } else {
            icfResult.recordFatalError(midpointEx.getMessage(), midpointEx);
            throw new SystemException(
                    "Got unexpected exception: " + ex.getClass().getName() + ": " + ex.getMessage(), ex);
        }
    }

    if (icfSchema == null) {
        icfResult.recordStatus(OperationResultStatus.NOT_APPLICABLE, "Null schema returned");
        resetResourceSchema();
        return;
    }

    parseResourceSchema(icfSchema, generateObjectClasses);
}

From source file:com.evolveum.midpoint.provisioning.ucf.impl.ConnectorInstanceIcfImpl.java

private void retrieveResourceSchema(List<QName> generateObjectClasses, OperationResult parentResult)
        throws CommunicationException, ConfigurationException, GenericFrameworkException {
    // Connector operation cannot create result for itself, so we need to
    // create result for it
    OperationResult icfResult = parentResult.createSubresult(ConnectorFacade.class.getName() + ".schema");
    icfResult.addContext("connector", icfConnectorFacade.getClass());

    org.identityconnectors.framework.common.objects.Schema icfSchema = null;
    try {/*from  w w  w.  ja v a2s .c  o  m*/

        // Fetch the schema from the connector (which actually gets that
        // from the resource).
        InternalMonitor.recordConnectorOperation("schema");
        // TODO have context present
        //recordIcfOperationStart(reporter, ProvisioningOperation.ICF_GET_SCHEMA, null);
        icfSchema = icfConnectorFacade.schema();
        //recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_GET_SCHEMA, null);

        icfResult.recordSuccess();
    } catch (UnsupportedOperationException ex) {
        //recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_GET_SCHEMA, null, ex);
        // The connector does no support schema() operation.
        icfResult.recordStatus(OperationResultStatus.NOT_APPLICABLE, ex.getMessage());
        resetResourceSchema();
        return;
    } catch (Throwable ex) {
        //recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_GET_SCHEMA, null, ex);
        // conditions.
        // Therefore this kind of heavy artillery is necessary.
        // ICF interface does not specify exceptions or other error
        // TODO maybe we can try to catch at least some specific exceptions
        Throwable midpointEx = processIcfException(ex, this, icfResult);

        // Do some kind of acrobatics to do proper throwing of checked
        // exception
        if (midpointEx instanceof CommunicationException) {
            icfResult.recordFatalError(midpointEx.getMessage(), midpointEx);
            throw (CommunicationException) midpointEx;
        } else if (midpointEx instanceof ConfigurationException) {
            icfResult.recordFatalError(midpointEx.getMessage(), midpointEx);
            throw (ConfigurationException) midpointEx;
        } else if (midpointEx instanceof GenericFrameworkException) {
            icfResult.recordFatalError(midpointEx.getMessage(), midpointEx);
            throw (GenericFrameworkException) midpointEx;
        } else if (midpointEx instanceof RuntimeException) {
            icfResult.recordFatalError(midpointEx.getMessage(), midpointEx);
            throw (RuntimeException) midpointEx;
        } else if (midpointEx instanceof Error) {
            icfResult.recordFatalError(midpointEx.getMessage(), midpointEx);
            throw (Error) midpointEx;
        } else {
            icfResult.recordFatalError(midpointEx.getMessage(), midpointEx);
            throw new SystemException(
                    "Got unexpected exception: " + ex.getClass().getName() + ": " + ex.getMessage(), ex);
        }
    }

    if (icfSchema == null) {
        icfResult.recordStatus(OperationResultStatus.NOT_APPLICABLE, "Null schema returned");
        resetResourceSchema();
        return;
    }

    parseResourceSchema(icfSchema, generateObjectClasses);
}