Example usage for java.lang ClassNotFoundException fillInStackTrace

List of usage examples for java.lang ClassNotFoundException fillInStackTrace

Introduction

In this page you can find the example usage for java.lang ClassNotFoundException fillInStackTrace.

Prototype

public synchronized Throwable fillInStackTrace() 

Source Link

Document

Fills in the execution stack trace.

Usage

From source file:org.cosmo.common.template.Parser.java

public static Page parsePageString(String pageString, File src, boolean reParse) throws Exception {
    ArrayList<byte[]> segmentContainer = new ArrayList();
    ArrayList<CharSequence> bindingContainer = new ArrayList();
    StringBuilder segment = new StringBuilder(256);
    StringBuilder binding = null;

    char[] pageChars = pageString.toCharArray();

    // extract args string
    int end = pageString.indexOf(PageEndToken, PageBeginTokenSize);
    String argString = pageString.substring(PageBeginTokenSize + 1, end);
    StringTokens args = StringTokens.on(argString);
    Options options = new Options(args);

    // extract get pageName and bindingSrc className , by default pageName IS The bindingSrc class name, unless options bindingSrc:xxx is specified
    String pageName = options._pageName;
    Class clazz = null;//from  w ww .  j  a v a  2 s .c o  m
    if (pageName.startsWith("!")) {
        // virtual page
        pageName = pageName.substring(1, pageName.length()); // strip ! so that it can be referenced without "!"
        clazz = options._bindingSrc == null ? BindingSrc.class : Class.forName(options._bindingSrc);
    } else {
        try {
            clazz = options._bindingSrc == null ? Class.forName(pageName) : Class.forName(options._bindingSrc);
        } catch (ClassNotFoundException e) {
            ClassNotFoundException cnfe = new ClassNotFoundException(e.getMessage() + " from page" + src, e);
            cnfe.fillInStackTrace();
            throw cnfe;

        }
    }

    // parse segments and bindings
    for (int i = end + PageEndTokenSize; i < pageChars.length; i++) {

        // handles bindings
        if (pageChars[i] == BindingChar) {
            if (binding == null) {
                binding = new StringBuilder();
                continue;
            } else {
                segmentContainer.add(options._jsonEncode ? Util.jsonQuoteBytes(segment) : Util.bytes(segment));
                segment = new StringBuilder(256);
                //indents.add(currentIndent);

                segmentContainer
                        .add(options._jsonEncode ? Page.BindingMarkerBytesQuoted : Page.BindingMarkerBytes);
                bindingContainer.add(binding.toString());
                binding = null;
                continue;
            }
        }
        if (binding != null) {
            binding.append(pageChars[i]);
        }

        // handles trim and escapeQuote
        if (binding == null) {

            if (pageChars[i] == '\n' || pageChars[i] == '\r') {
                if (!options._trim) {
                    segment.append(pageChars[i]);
                }
            } else {
                if (pageChars[i] == '\t') {
                    if (!options._trim) {
                        segment.append(pageChars[i]);
                    }
                } else {
                    if (options._escapeQuote && pageChars[i] == '\"') {
                        segment.append("\\");
                    }
                    segment.append(pageChars[i]);
                }
            }
        }
    }

    // convert segments to raw bytes
    Page page = new Page(pageName, clazz, src, options, reParse);
    segmentContainer.add(options._jsonEncode ? Util.jsonQuoteBytes(segment) : Util.bytes(segment));
    page._segmentArray = (byte[][]) segmentContainer.toArray(new byte[][] {});

    // convert binding string to parsed bindings
    BindingContainer bindingsContainer = Parser.parseBindings(page, bindingContainer, 0,
            page._segmentArray.length, 0);
    page._bindingArray = (Binding[]) bindingsContainer.toArray(new Binding[] {});

    for (Binding aBinding : page._bindingArray) {
        if (aBinding instanceof Binding.ValueBinding) {
            page._bindingMap.put(aBinding.name(), aBinding);
        }
    }
    return page;
}

From source file:org.openmrs.module.jasperreport.ReportGenerator.java

/**
 * @throws ClassNotFoundException//from  w  w w .java 2  s  .  co  m
 * @throws SQLException
 */
private static Connection connect(String url) throws SQLException {
    // Step 1: Load the JDBC driver.
    try {
        Class.forName("com.mysql.jdbc.Driver");
    } catch (ClassNotFoundException e) {
        log.error("Could not find JDBC driver class.", e);
        throw (SQLException) e.fillInStackTrace();
    }

    // Step 2: Establish the connection to the database.
    String username = Context.getRuntimeProperties().getProperty("connection.username");
    String password = Context.getRuntimeProperties().getProperty("connection.password");
    log.debug("connecting to DATABASE: " + OpenmrsConstants.DATABASE_NAME + " USERNAME: " + username + " URL: "
            + url);
    return DriverManager.getConnection(url, username, password);
}