Example usage for java.lang IllegalAccessException printStackTrace

List of usage examples for java.lang IllegalAccessException printStackTrace

Introduction

In this page you can find the example usage for java.lang IllegalAccessException printStackTrace.

Prototype

public void printStackTrace(PrintStream s) 

Source Link

Document

Prints this throwable and its backtrace to the specified print stream.

Usage

From source file:uk.ac.kcl.texthunter.utils.Utils.java

public static Connection loadAndConnectDerby(Connection con) {
    /*//from   ww  w  . java2 s. c o m
     *  The JDBC driver is loaded by loading its class.
     *  If you are using JDBC 4.0 (Java SE 6) or newer, JDBC drivers may
     *  be automatically loaded, making this code optional.
     *
     *  In an embedded environment, this will also start up the Derby
     *  engine (though not any databases), since it is not already
     *  running. In a client environment, the Derby engine is being run
     *  by the network server framework.
     *
     *  In an embedded environment, any static Derby system properties
     *  must be set before loading the driver to take effect.
     */

    String driver = "org.apache.derby.jdbc.EmbeddedDriver";
    String protocol = "jdbc:derby:";
    try {
        Class.forName(driver).newInstance();
        //    System.out.println("Loaded the appropriate driver");
    } catch (ClassNotFoundException cnfe) {
        System.err.println("\nUnable to load the JDBC driver " + driver);
        System.err.println("Please check your CLASSPATH.");
        cnfe.printStackTrace(System.err);
    } catch (InstantiationException ie) {
        System.err.println("\nUnable to instantiate the JDBC driver " + driver);
        ie.printStackTrace(System.err);
    } catch (IllegalAccessException iae) {
        System.err.println("\nNot allowed to access the JDBC driver " + driver);
        iae.printStackTrace(System.err);
    }

    /* By default, the schema APP will be used when no username is
     * provided.
     * Otherwise, the schema name is the same as the user name (in this
     * case "user1" or USER1.)
     *
     * Note that user authentication is off by default, meaning that any
     * user can connect to your database using any password. To enable
     * authentication, see the Derby Developer's Guide.
     */
    String dbName = "annotationDB"; // the name of the database
    try {
        /*
         * This connection specifies create=true in the connection URL to
         * cause the database to be created when connecting for the first
         * time. To remove the database, remove the directory derbyDB (the
         * same as the database name) and its contents.
         *
         * The directory derbyDB will be created under the directory that
         * the system property derby.system.home points to, or the current
         * directory (user.dir) if derby.system.home is not set.
         */
        con = DriverManager.getConnection(protocol + dbName + ";create=true");
    } catch (SQLException ex) {
        Logger.getLogger(Utils.class.getName()).log(Level.SEVERE, null, ex);
    }

    return con;

}

From source file:org.mapfish.print.ShellMapPrinter.java

private void help(String message) {
    System.err.println(message);/*from   w ww.  ja  v a  2 s . com*/
    System.err.println();
    System.err.println("Usage:");
    System.err.println("  " + getClass().getName() + " " + GetOptions.getShortList(this));
    System.err.println("Params:");
    try {
        System.err.println(GetOptions.getLongList(this));
    } catch (IllegalAccessException e) {
        e.printStackTrace(System.err);
    }
    System.exit(-1);
}

From source file:org.sc.probro.BrokerData.java

public String writeHTMLObject(boolean asRow) {
    StringBuilder html = new StringBuilder();
    if (asRow) {//from   w ww  .  ja  v  a  2 s. c  om
        html.append(String.format("<tr class=\"obj_%s\">", getClass().getSimpleName().toLowerCase()));
    } else {
        html.append(String.format("<table class=\"obj_%s\">", getClass().getSimpleName().toLowerCase()));
    }
    for (Field f : getClass().getFields()) {
        int mod = f.getModifiers();
        if (Modifier.isPublic(mod) && !Modifier.isStatic(mod)) {
            String name = f.getName();
            try {
                Object objValue = f.get(this);
                String value = String.valueOf(objValue);

                if (name.equals("id")) {
                    value = String.format("<a href=\"%s?format=html\">%s</a>", value, "link");
                } else if (objValue != null && objValue instanceof BrokerData) {
                    value = ((BrokerData) objValue).writeHTMLLink();
                }

                if (!asRow) {
                    html.append(String.format("<tr class=\"field_%s\">", name.toLowerCase()));
                    html.append(String.format("<td>%s</td>", name));
                }
                html.append(String.format("<td class=\"value_%s\">%s</td>", name.toLowerCase(), value));
                if (!asRow) {
                    html.append("</tr>");
                }

            } catch (IllegalAccessException e) {
                e.printStackTrace(System.err);
            }
        }
    }
    if (asRow) {
        html.append(String.format("</tr>"));
    } else {
        html.append("</table>");
    }
    return html.toString();
}

From source file:com.tlabs.eve.api.parser.AbstractXMLParser.java

@SuppressWarnings("unchecked")
public synchronized final T parse(byte[] data) throws IOException {
    this.digester.clear();
    try {//w  ww.  jav a  2  s . co m
        T t = responseClass.newInstance();
        doBeforeParse(t);
        this.digester.push(t);
        t = (T) this.digester.parse(new ByteArrayInputStream(data));
        t.setContent(data);
        doAfterParse(t);
        return t;
    } catch (IllegalAccessException e) {
        throw new IOException(e.getLocalizedMessage());
    } catch (InstantiationException e) {
        throw new IOException(e.getLocalizedMessage());
    } catch (SAXException e) {
        e.printStackTrace(System.err);
        throw new IOException(e.getLocalizedMessage());
    }

}

From source file:org.sc.probro.data.DBObject.java

/**
 * Basically, isSubsetOf(x) is *almost* equivalent to !findMatchingFields(x).isEmpty(), 
 * except that it's directional -- it takes 'nulls' as missing values, and so it won't signal 
 * false for a null field in this object that has a value in the other.  
 * /*w w  w .  j a  va2 s. com*/
 * @param <T>
 * @param other
 * @return
 */
public <T extends DBObject> boolean isSubsetOf(T other) {
    if (!isSubclass(other.getClass(), getClass())) {
        throw new IllegalArgumentException(String.format("%s is not a subclass of %s",
                other.getClass().getSimpleName(), getClass().getSimpleName()));
    }

    for (Field f : getClass().getFields()) {
        int mod = f.getModifiers();
        if (Modifier.isPublic(mod) && !Modifier.isStatic(mod)) {
            try {
                Object thisValue = f.get(this), thatValue = f.get(other);
                if (thisValue != null) {
                    if (thatValue == null || !thisValue.equals(thatValue)) {
                        return false;
                    }
                }
            } catch (IllegalAccessException e) {
                e.printStackTrace(System.err);
            }
        }
    }

    return true;
}

From source file:org.sc.probro.data.DBObject.java

/**
 * Returns the set of field names for which the values whose values differ between this object
 * and the object given as an argument.  The argument object must be a subclass of the class of 
 * 'this'.  Two values are said to 'differ' if one is 'null' when the other isn't, or if both
 * values are non-null but equals() (when called on one value, given the other value as an argument) 
 * returns false./*www. j a  va  2s . c  om*/
 * 
 * @param <T>
 * @param other  The other object to compare to. 
 * @throws IllegalArgumentException if the argument object is not a subclass of the class of 'this'.
 * @return
 */
public <T extends DBObject> Set<String> findMismatchingFields(T other) {
    if (!isSubclass(other.getClass(), getClass())) {
        throw new IllegalArgumentException(String.format("%s is not a subclass of %s",
                other.getClass().getSimpleName(), getClass().getSimpleName()));
    }

    Set<String> mismatches = new TreeSet<String>();

    for (Field f : getClass().getFields()) {
        int mod = f.getModifiers();
        if (Modifier.isPublic(mod) && !Modifier.isStatic(mod)) {
            try {
                Object thisValue = f.get(this), thatValue = f.get(other);
                if (thisValue != null || thatValue != null) {
                    if (thisValue == null || thatValue == null || !thisValue.equals(thatValue)) {
                        mismatches.add(f.getName());
                    }
                }
            } catch (IllegalAccessException e) {
                e.printStackTrace(System.err);
            }
        }
    }

    return mismatches;
}

From source file:org.sc.probro.data.DBObject.java

public String writeHTMLObject(boolean asRow) {
    StringBuilder html = new StringBuilder();
    if (asRow) {//from   w  ww  . j  a v  a  2 s  .  c o m
        html.append(String.format("<tr class=\"obj_%s\">", getClass().getSimpleName().toLowerCase()));
    } else {
        html.append(String.format("<table class=\"obj_%s\">", getClass().getSimpleName().toLowerCase()));
    }
    for (Field f : getClass().getFields()) {
        int mod = f.getModifiers();
        if (Modifier.isPublic(mod) && !Modifier.isStatic(mod)) {
            String name = f.getName();
            try {
                String value = String.valueOf(f.get(this));

                if (!asRow) {
                    html.append(String.format("<tr class=\"field_%s\">", name.toLowerCase()));
                    html.append(String.format("<td>%s</td>", name));
                }
                html.append(String.format("<td class=\"value_%s\">%s</td>", name.toLowerCase(), value));
                if (!asRow) {
                    html.append("</tr>");
                }

            } catch (IllegalAccessException e) {
                e.printStackTrace(System.err);
            }
        }
    }
    if (asRow) {
        html.append(String.format("</tr>"));
    } else {
        html.append("</table>");
    }
    return html.toString();
}

From source file:padl.creator.classfile.AbstractClassFileCreator.java

private void createElements(final ICodeLevelModel aCodeLevelModel, final List listOfSourceConstituents,
        final ConstituentsRepository constituentsRepository, final ClassFile[] listOfElements) {

    RelationshipAnalyzer.initialise(this.mapOfIDsEntities);
    Context.initialise(this.mapOfIDsEntities);

    int[] sortedElements = new int[listOfElements.length];
    final StringBuffer buffer = new StringBuffer();
    String constituentName;/*from  w  w w. j  av  a2  s  . c  om*/

    for (int x = 0; x < listOfElements.length; x++) {
        constituentName = constituentsRepository.getElements()[x].getName();

        try {
            buffer.append("recognize");
            buffer.append(constituentName.substring(constituentName.lastIndexOf('.') + 1));
            buffer.append("Priority");
            sortedElements[x] = ((Integer) this.getClass().getMethod(buffer.toString(), new java.lang.Class[0])
                    .invoke(this, new Object[0])).intValue();
            buffer.setLength(0);
        } catch (final Throwable t) {
            t.printStackTrace(ProxyConsole.getInstance().errorOutput());
        } finally {
            // Yann 2004/03/31: Reset!
            // In any case (okay or exception), I reset
            // the buffer from its content.
            buffer.setLength(0);
        }
    }
    sortedElements = Utils.sortByPriority(sortedElements);

    // Yann 2002/08/01: Concurrent modification.
    // While I iterate over the list of entities,
    // I may want to add new entities (instances of Ghost),
    // thus I cannot use the iterator mechanism provided
    // by Java, because it implements a fail-safe security.
    // Yann 2004/04/10: Sorting out!
    // The fix described in the above comment is no longer valid.
    // I now sort the entities and the elements to get them in a
    // consistent order across platforms and implementations
    // (mainly for testing purposes). Thus, ghosts created during
    // the creation of elements may "push down" the list the entity
    // being analyzed... and element will be added (or tried to)
    // more than once, resulting in not-good-looking exceptions.
    // I added code to refocus the i index.

    // Yann 2006/02/10: Wrong order... all this time!
    // I should not iterate over entities and call the
    // recognise() methods on it but iterate over each
    // recognise() methods and call each on all the entities
    // this should prevent the "duplicate actor ID" problem...

    final List listOfSubmittedElements = new ArrayList();
    for (int elementRecogniserNumber = 0; elementRecogniserNumber < listOfElements.length; elementRecogniserNumber++) {

        // Yann 2006/08/03: Member entities!
        // I should not iterate over the entities of the code-level model
        // because this model does not contain *directly* references to
        // member entities and thus these entities are not fed with their
        // methods and fields!!!
        //   final Iterator iteratorOnEntities =
        //      aCodeLevelModel.getIteratorOnConstituents(IEntity.class);
        // I now iterate over the list of provided classfiles, thus
        // including method in member classes.
        final Iterator iteratorOnEntities = listOfSourceConstituents.iterator();
        while (iteratorOnEntities.hasNext()) {
            // I look for the entity corresponding instance of class Class.
            // I cannot use:
            //      Class.forName(((Entity) enum.nextElement()).getName())
            // Since the given user's classes may not be in the classpath and
            // have been loaded from a different class loader.
            // Yann 2005/10/07: Packages!
            // A model may now contrain entities and packages.
            final ClassFile currentClass = (ClassFile) iteratorOnEntities.next();
            final char[] currentClassName = currentClass.getName().toCharArray();

            if (!Utils.isAnonymousOrLocalEntity(currentClassName)
                    && !Utils.isLocalOrLocalMemberEntity(currentClassName)) {

                final IFirstClassEntity firstClassEntity = Utils.getEntityOrCreateGhost(aCodeLevelModel,
                        currentClassName, this.mapOfIDsEntities);

                constituentName = constituentsRepository.getElements()[sortedElements[elementRecogniserNumber]]
                        .getName();

                if (!(firstClassEntity instanceof IGhost)) {
                    aCodeLevelModel.fireModelChange(IModelListener.ENTITY_ANALYZED,
                            new AnalysisEvent(currentClassName, constituentName.toCharArray()));

                    // I reset the list of submitted elements and entities.
                    listOfSubmittedElements.clear();

                    // I fill up the Element.
                    for (int i = 0; i < currentClass.getMethods().length(); i++) {

                        // Yann 2016/09/21: Synthetic attributes!
                        // Starting with JDK 1.6. generic introduced
                        // all kind of perks... including "new"
                        // synthetic methods!
                        // https://docs.oracle.com/javase/tutorial/java/generics/bridgeMethods.html
                        final MethodInfo methodInfo = currentClass.getMethods().get(i);
                        if (AttrUtils.getAttrByName(methodInfo.getAttrs(), "Synthetic") == null) {

                            listOfSubmittedElements.add(new ExtendedMethodInfo(currentClass, methodInfo));
                        }
                    }

                    for (int i = 0; i < currentClass.getFields().length(); i++) {

                        listOfSubmittedElements
                                .add(new ExtendedFieldInfo(currentClass, currentClass.getFields().get(i)));
                    }

                    try {
                        // Yann 2002/07/31: Priorities.
                        // I must keep the fields and the methods in
                        // the list of submitted constituents,
                        // because they might be used later to create
                        // a Aggregation linked with them.
                        // Yann 2003/12/22: ICodeLevelModelCreator.
                        // I now use the method provided by the instance
                        // of ICodeLevelModelCreator.
                        //   Misc
                        //      .getDeclaredMethod(
                        //         constituentRepository
                        //            .getElements()[sortedElements[x]],
                        //         "recognize")
                        //      .invoke(
                        //         null,
                        //         new Object[] {
                        //            listOfSubmittedElements,
                        //            this });
                        buffer.append("recognize");
                        buffer.append(constituentName.substring(constituentName.lastIndexOf('.') + 1));

                        this.getClass()
                                .getMethod(buffer.toString(),
                                        new java.lang.Class[] { List.class, ICodeLevelModel.class })
                                .invoke(this, new Object[] { listOfSubmittedElements, aCodeLevelModel });
                    } catch (final NoSuchMethodException t) {
                        ProxyConsole.getInstance().errorOutput()
                                .print(AbstractClassFileCreator.class.getName());
                        ProxyConsole.getInstance().errorOutput().print(" cannot invoke ");
                        ProxyConsole.getInstance().errorOutput()
                                .println(listOfElements[sortedElements[elementRecogniserNumber]].getName());
                        //   t.printStackTrace(ProxyConsole
                        //      .getInstance()
                        //      .errorOutput());
                        // Yann 2004/06/02: Flush.
                        // I make sure I flush the output stream to
                        // display as soon as possible exceptions.
                        // Yann 2004/07/15: Flush!
                        // This is now taken care of by the OutputManager class.
                        //   OutputManager
                        //      .getCurrentOutputManager()
                        //      .getErrorOutput()
                        //      .flush();
                    } catch (IllegalAccessException e) {
                        e.printStackTrace(ProxyConsole.getInstance().errorOutput());
                    } catch (IllegalArgumentException e) {
                        e.printStackTrace(ProxyConsole.getInstance().errorOutput());
                    } catch (InvocationTargetException e) {
                        e.printStackTrace(ProxyConsole.getInstance().errorOutput());
                    } catch (SecurityException e) {
                        e.printStackTrace(ProxyConsole.getInstance().errorOutput());
                    } finally {
                        // Yann 2004/03/31: Reset!
                        // In any case (okay or exception), I reset
                        // the buffer from its content.
                        buffer.setLength(0);
                    }
                } else {
                    aCodeLevelModel.fireModelChange(IModelListener.ENTITY_SKIPPED,
                            new AnalysisEvent(currentClassName, constituentName.toCharArray()));
                }
            }
        }

        // Yann 2004/04/10: Refocus.
        // Ghosts created during the analysis may have
        // "pushed down" the current entities down the
        // temporary list. I need to refocus the index
        // accordingly. I start from the index because
        // entities can be added only, not deleted.
        // I need to do this for each entity.
        //   for (int j = i; j < temporayListOfEntities.size(); j++) {
        //      if (((IEntity) temporayListOfEntities.get(j))
        //         .getName()
        //         .equals(currentClassName)) {
        //
        //         i = j;
        //         j = temporayListOfEntities.size();
        //      }
        //   }
    }
}