java.beans.ExceptionListener Java Examples

The following examples show how to use java.beans.ExceptionListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestObjectEncode.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testNodeChange() throws BackingStoreException, IOException {

  String filename = File.createTempFile("foo", "bar").getAbsolutePath();
  OutputStream objOS = new BufferedOutputStream(new FileOutputStream(filename, false));

  XMLEncoder beanEncoder = new XMLEncoder(objOS);
  beanEncoder.setExceptionListener(new ExceptionListener() {
    public void exceptionThrown(Exception exception) {
      System.out.println("XMLStore.save()");
      exception.printStackTrace();
    }
  });

  beanEncoder.writeObject(new java.awt.Rectangle(100, 200));
  beanEncoder.writeObject(new TesterBean());
  beanEncoder.close();
}
 
Example #2
Source File: XMLBeanConvertor.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public @Override void write(java.io.Writer w, final Object inst) throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    XMLEncoder e = new XMLEncoder(out);
    e.setExceptionListener(new ExceptionListener() {
        public @Override void exceptionThrown(Exception x) {
            Logger.getLogger(XMLBeanConvertor.class.getName()).log(Level.INFO, "Problem writing " + inst, x);
        }
    });
    ClassLoader ccl = Thread.currentThread().getContextClassLoader();
    try {
        // XXX would inst.getClass().getClassLoader() be more appropriate?
        ClassLoader ccl2 = Lookup.getDefault().lookup(ClassLoader.class);
        if (ccl2 != null) {
            Thread.currentThread().setContextClassLoader(ccl2);
        }
        e.writeObject(inst);
    } finally {
        Thread.currentThread().setContextClassLoader(ccl);
    }
    e.close();
    String data = new String(out.toByteArray(), "UTF-8");
    data = data.replaceFirst("<java", "<!DOCTYPE xmlbeans PUBLIC \"-//NetBeans//DTD XML beans 1.0//EN\" \"http://www.netbeans.org/dtds/xml-beans-1_0.dtd\">\n<java");
    w.write(data);
}
 
Example #3
Source File: XMLStore.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Save the current state of the Preferences tree to the given OutputStream.
 */
public void save(OutputStream out) throws java.io.IOException {
  outputExceptionMessage = null;

  // the OutputMunger strips off the XMLEncoder header
  OutputMunger bos = new OutputMunger(out);
  PrintWriter pw = new PrintWriter(new OutputStreamWriter(bos, StandardCharsets.UTF_8));

  XMLEncoder beanEncoder = new XMLEncoder(bos);
  beanEncoder.setExceptionListener(new ExceptionListener() {
    public void exceptionThrown(Exception exception) {
      System.out.println("XMLStore.save() got Exception: abort saving the preferences!");
      exception.printStackTrace();
      outputExceptionMessage = exception.getMessage();
    }
  });

  pw.printf("<?xml version='1.0' encoding='UTF-8'?>%n");
  pw.printf("<preferences EXTERNAL_XML_VERSION='1.0'>%n");
  if (!rootPrefs.isUserNode())
    pw.printf("  <root type='system'>%n");
  else
    pw.printf("  <root type='user'>%n");

  Indent indent = new Indent(2);
  indent.incr();
  writeXmlNode(bos, pw, rootPrefs, beanEncoder, indent);
  if (outputExceptionMessage != null)
    throw new IOException(outputExceptionMessage);

  pw.printf("  </root>%n");
  pw.printf("</preferences>%n");
  pw.flush();
}
 
Example #4
Source File: XSSviaXMLDeserialization.java    From spiracle with Apache License 2.0 5 votes vote down vote up
private static void serializeToXML (User settings, String path) throws IOException
{
    FileOutputStream fos = new FileOutputStream(path);
    XMLEncoder encoder = new XMLEncoder(fos);
    encoder.setExceptionListener(new ExceptionListener() {
            public void exceptionThrown(Exception e) {
                System.out.println("Exception! :"+e.toString());
            }
    });
    encoder.writeObject(settings);
    encoder.close();
    fos.close();
}
 
Example #5
Source File: StreamHandler.java    From siddhi with Apache License 2.0 5 votes vote down vote up
public StreamHandler(List<StreamJunction.Receiver> receivers, int batchSize,
                     String streamName, String siddhiAppName, StreamJunction faultStreamJunction,
                     StreamJunction.OnErrorAction onErrorAction, ExceptionListener exceptionListener) {
    this.receivers = receivers;
    this.batchSize = batchSize;
    this.streamName = streamName;
    this.siddhiAppName = siddhiAppName;
    this.faultStreamJunction = faultStreamJunction;
    this.onErrorAction = onErrorAction;
    this.exceptionListener = exceptionListener;
}
 
Example #6
Source File: JarBasedPlugin.java    From logbook-kai with MIT License 5 votes vote down vote up
public static JarBasedPlugin toJarBasedPlugin(Path p, ExceptionListener listener) {
    try {
        return new JarBasedPlugin(p);
    } catch (IOException e) {
        listener.exceptionThrown(e);
        return null;
    }
}
 
Example #7
Source File: Test4676532.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    StringBuilder sb = new StringBuilder(256);
    sb.append("file:");
    sb.append(System.getProperty("test.src", "."));
    sb.append(File.separatorChar);
    sb.append("test.jar");

    URL[] url = {new URL(sb.toString())};
    URLClassLoader cl = new URLClassLoader(url);

    Class type = cl.loadClass("test.Test");
    if (type == null) {
        throw new Error("could not find class test.Test");
    }


    InputStream stream = new ByteArrayInputStream(DATA.getBytes());

    ExceptionListener el = new ExceptionListener() {
        public void exceptionThrown(Exception exception) {
            throw new Error("unexpected exception", exception);
        }
    };

    XMLDecoder decoder = new XMLDecoder(stream, null, el, cl);
    Object object = decoder.readObject();
    decoder.close();

    if (!type.equals(object.getClass())) {
        throw new Error("unexpected " + object.getClass());
    }
}
 
Example #8
Source File: Test4676532.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    StringBuilder sb = new StringBuilder(256);
    sb.append("file:");
    sb.append(System.getProperty("test.src", "."));
    sb.append(File.separatorChar);
    sb.append("test.jar");

    URL[] url = {new URL(sb.toString())};
    URLClassLoader cl = new URLClassLoader(url);

    Class type = cl.loadClass("test.Test");
    if (type == null) {
        throw new Error("could not find class test.Test");
    }


    InputStream stream = new ByteArrayInputStream(DATA.getBytes());

    ExceptionListener el = new ExceptionListener() {
        public void exceptionThrown(Exception exception) {
            throw new Error("unexpected exception", exception);
        }
    };

    XMLDecoder decoder = new XMLDecoder(stream, null, el, cl);
    Object object = decoder.readObject();
    decoder.close();

    if (!type.equals(object.getClass())) {
        throw new Error("unexpected " + object.getClass());
    }
}
 
Example #9
Source File: Test4676532.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    StringBuilder sb = new StringBuilder(256);
    sb.append("file:");
    sb.append(System.getProperty("test.src", "."));
    sb.append(File.separatorChar);
    sb.append("test.jar");

    URL[] url = {new URL(sb.toString())};
    URLClassLoader cl = new URLClassLoader(url);

    Class type = cl.loadClass("test.Test");
    if (type == null) {
        throw new Error("could not find class test.Test");
    }


    InputStream stream = new ByteArrayInputStream(DATA.getBytes());

    ExceptionListener el = new ExceptionListener() {
        public void exceptionThrown(Exception exception) {
            throw new Error("unexpected exception", exception);
        }
    };

    XMLDecoder decoder = new XMLDecoder(stream, null, el, cl);
    Object object = decoder.readObject();
    decoder.close();

    if (!type.equals(object.getClass())) {
        throw new Error("unexpected " + object.getClass());
    }
}
 
Example #10
Source File: Test4676532.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    StringBuilder sb = new StringBuilder(256);
    sb.append("file:");
    sb.append(System.getProperty("test.src", "."));
    sb.append(File.separatorChar);
    sb.append("test.jar");

    URL[] url = {new URL(sb.toString())};
    URLClassLoader cl = new URLClassLoader(url);

    Class type = cl.loadClass("test.Test");
    if (type == null) {
        throw new Error("could not find class test.Test");
    }


    InputStream stream = new ByteArrayInputStream(DATA.getBytes());

    ExceptionListener el = new ExceptionListener() {
        public void exceptionThrown(Exception exception) {
            throw new Error("unexpected exception", exception);
        }
    };

    XMLDecoder decoder = new XMLDecoder(stream, null, el, cl);
    Object object = decoder.readObject();
    decoder.close();

    if (!type.equals(object.getClass())) {
        throw new Error("unexpected " + object.getClass());
    }
}
 
Example #11
Source File: Test4676532.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    StringBuilder sb = new StringBuilder(256);
    sb.append("file:");
    sb.append(System.getProperty("test.src", "."));
    sb.append(File.separatorChar);
    sb.append("test.jar");

    URL[] url = {new URL(sb.toString())};
    URLClassLoader cl = new URLClassLoader(url);

    Class type = cl.loadClass("test.Test");
    if (type == null) {
        throw new Error("could not find class test.Test");
    }


    InputStream stream = new ByteArrayInputStream(DATA.getBytes());

    ExceptionListener el = new ExceptionListener() {
        public void exceptionThrown(Exception exception) {
            throw new Error("unexpected exception", exception);
        }
    };

    XMLDecoder decoder = new XMLDecoder(stream, null, el, cl);
    Object object = decoder.readObject();
    decoder.close();

    if (!type.equals(object.getClass())) {
        throw new Error("unexpected " + object.getClass());
    }
}
 
Example #12
Source File: Test4676532.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    StringBuilder sb = new StringBuilder(256);
    sb.append("file:");
    sb.append(System.getProperty("test.src", "."));
    sb.append(File.separatorChar);
    sb.append("test.jar");

    URL[] url = {new URL(sb.toString())};
    URLClassLoader cl = new URLClassLoader(url);

    Class type = cl.loadClass("test.Test");
    if (type == null) {
        throw new Error("could not find class test.Test");
    }


    InputStream stream = new ByteArrayInputStream(DATA.getBytes());

    ExceptionListener el = new ExceptionListener() {
        public void exceptionThrown(Exception exception) {
            throw new Error("unexpected exception", exception);
        }
    };

    XMLDecoder decoder = new XMLDecoder(stream, null, el, cl);
    Object object = decoder.readObject();
    decoder.close();

    if (!type.equals(object.getClass())) {
        throw new Error("unexpected " + object.getClass());
    }
}
 
Example #13
Source File: Test4676532.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    StringBuilder sb = new StringBuilder(256);
    sb.append("file:");
    sb.append(System.getProperty("test.src", "."));
    sb.append(File.separatorChar);
    sb.append("test.jar");

    URL[] url = {new URL(sb.toString())};
    URLClassLoader cl = new URLClassLoader(url);

    Class type = cl.loadClass("test.Test");
    if (type == null) {
        throw new Error("could not find class test.Test");
    }


    InputStream stream = new ByteArrayInputStream(DATA.getBytes());

    ExceptionListener el = new ExceptionListener() {
        public void exceptionThrown(Exception exception) {
            throw new Error("unexpected exception", exception);
        }
    };

    XMLDecoder decoder = new XMLDecoder(stream, null, el, cl);
    Object object = decoder.readObject();
    decoder.close();

    if (!type.equals(object.getClass())) {
        throw new Error("unexpected " + object.getClass());
    }
}
 
Example #14
Source File: Test4676532.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    StringBuilder sb = new StringBuilder(256);
    sb.append("file:");
    sb.append(System.getProperty("test.src", "."));
    sb.append(File.separatorChar);
    sb.append("test.jar");

    URL[] url = {new URL(sb.toString())};
    URLClassLoader cl = new URLClassLoader(url);

    Class type = cl.loadClass("test.Test");
    if (type == null) {
        throw new Error("could not find class test.Test");
    }


    InputStream stream = new ByteArrayInputStream(DATA.getBytes());

    ExceptionListener el = new ExceptionListener() {
        public void exceptionThrown(Exception exception) {
            throw new Error("unexpected exception", exception);
        }
    };

    XMLDecoder decoder = new XMLDecoder(stream, null, el, cl);
    Object object = decoder.readObject();
    decoder.close();

    if (!type.equals(object.getClass())) {
        throw new Error("unexpected " + object.getClass());
    }
}
 
Example #15
Source File: Test4676532.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    StringBuilder sb = new StringBuilder(256);
    sb.append("file:");
    sb.append(System.getProperty("test.src", "."));
    sb.append(File.separatorChar);
    sb.append("test.jar");

    URL[] url = {new URL(sb.toString())};
    URLClassLoader cl = new URLClassLoader(url);

    Class type = cl.loadClass("test.Test");
    if (type == null) {
        throw new Error("could not find class test.Test");
    }


    InputStream stream = new ByteArrayInputStream(DATA.getBytes());

    ExceptionListener el = new ExceptionListener() {
        public void exceptionThrown(Exception exception) {
            throw new Error("unexpected exception", exception);
        }
    };

    XMLDecoder decoder = new XMLDecoder(stream, null, el, cl);
    Object object = decoder.readObject();
    decoder.close();

    if (!type.equals(object.getClass())) {
        throw new Error("unexpected " + object.getClass());
    }
}
 
Example #16
Source File: Test4676532.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    StringBuilder sb = new StringBuilder(256);
    sb.append("file:");
    sb.append(System.getProperty("test.src", "."));
    sb.append(File.separatorChar);
    sb.append("test.jar");

    URL[] url = {new URL(sb.toString())};
    URLClassLoader cl = new URLClassLoader(url);

    Class type = cl.loadClass("test.Test");
    if (type == null) {
        throw new Error("could not find class test.Test");
    }


    InputStream stream = new ByteArrayInputStream(DATA.getBytes());

    ExceptionListener el = new ExceptionListener() {
        public void exceptionThrown(Exception exception) {
            throw new Error("unexpected exception", exception);
        }
    };

    XMLDecoder decoder = new XMLDecoder(stream, null, el, cl);
    Object object = decoder.readObject();
    decoder.close();

    if (!type.equals(object.getClass())) {
        throw new Error("unexpected " + object.getClass());
    }
}
 
Example #17
Source File: XMLStore.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private XMLDecoder openBeanDecoder(InputStream objIS) {
  // filter stream for XMLDecoder
  XMLDecoder beanDecoder = new XMLDecoder(objIS, null, new ExceptionListener() {
    public void exceptionThrown(Exception e) {
      if (showDecoderExceptions)
        System.out.println("***XMLStore.read() got Exception= " + e.getClass().getName() + " " + e.getMessage());
      e.printStackTrace();
    }
  });

  return beanDecoder;
}
 
Example #18
Source File: Test4676532.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    StringBuilder sb = new StringBuilder(256);
    sb.append("file:");
    sb.append(System.getProperty("test.src", "."));
    sb.append(File.separatorChar);
    sb.append("test.jar");

    URL[] url = {new URL(sb.toString())};
    URLClassLoader cl = new URLClassLoader(url);

    Class type = cl.loadClass("test.Test");
    if (type == null) {
        throw new Error("could not find class test.Test");
    }


    InputStream stream = new ByteArrayInputStream(DATA.getBytes());

    ExceptionListener el = new ExceptionListener() {
        public void exceptionThrown(Exception exception) {
            throw new Error("unexpected exception", exception);
        }
    };

    XMLDecoder decoder = new XMLDecoder(stream, null, el, cl);
    Object object = decoder.readObject();
    decoder.close();

    if (!type.equals(object.getClass())) {
        throw new Error("unexpected " + object.getClass());
    }
}
 
Example #19
Source File: Test4676532.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    StringBuilder sb = new StringBuilder(256);
    sb.append("file:");
    sb.append(System.getProperty("test.src", "."));
    sb.append(File.separatorChar);
    sb.append("test.jar");

    URL[] url = {new URL(sb.toString())};
    URLClassLoader cl = new URLClassLoader(url);

    Class type = cl.loadClass("test.Test");
    if (type == null) {
        throw new Error("could not find class test.Test");
    }


    InputStream stream = new ByteArrayInputStream(DATA.getBytes());

    ExceptionListener el = new ExceptionListener() {
        public void exceptionThrown(Exception exception) {
            throw new Error("unexpected exception", exception);
        }
    };

    XMLDecoder decoder = new XMLDecoder(stream, null, el, cl);
    Object object = decoder.readObject();
    decoder.close();

    if (!type.equals(object.getClass())) {
        throw new Error("unexpected " + object.getClass());
    }
}
 
Example #20
Source File: XMLStore.java    From tds with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private XMLDecoder openBeanDecoder(InputStream objIS) {
  // filter stream for XMLDecoder
  XMLDecoder beanDecoder = new XMLDecoder(objIS, null, new ExceptionListener() {
    public void exceptionThrown(Exception e) {
      if (showDecoderExceptions)
        System.out.println("***XMLStore.read() got Exception= " + e.getClass().getName() + " " + e.getMessage());
      e.printStackTrace();
    }
  });

  // System.out.println("openBeanDecoder at "+objIS);
  return beanDecoder;
}
 
Example #21
Source File: Test4676532.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    StringBuilder sb = new StringBuilder(256);
    sb.append("file:");
    sb.append(System.getProperty("test.src", "."));
    sb.append(File.separatorChar);
    sb.append("test.jar");

    URL[] url = {new URL(sb.toString())};
    URLClassLoader cl = new URLClassLoader(url);

    Class type = cl.loadClass("test.Test");
    if (type == null) {
        throw new Error("could not find class test.Test");
    }


    InputStream stream = new ByteArrayInputStream(DATA.getBytes());

    ExceptionListener el = new ExceptionListener() {
        public void exceptionThrown(Exception exception) {
            throw new Error("unexpected exception", exception);
        }
    };

    XMLDecoder decoder = new XMLDecoder(stream, null, el, cl);
    Object object = decoder.readObject();
    decoder.close();

    if (!type.equals(object.getClass())) {
        throw new Error("unexpected " + object.getClass());
    }
}
 
Example #22
Source File: XMLStore.java    From tds with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Save the current state of the Preferences tree to the given OutputStream.
 */
public void save(OutputStream out) throws java.io.IOException {
  outputExceptionMessage = null;

  // the OutputMunger strips off the XMLEncoder header
  OutputMunger bos = new OutputMunger(out);
  PrintWriter pw = new PrintWriter(new OutputStreamWriter(bos, StandardCharsets.UTF_8));

  XMLEncoder beanEncoder = new XMLEncoder(bos);
  beanEncoder.setExceptionListener(new ExceptionListener() {
    public void exceptionThrown(Exception exception) {
      System.out.println("XMLStore.save() got Exception: abort saving the preferences!");
      exception.printStackTrace();
      outputExceptionMessage = exception.getMessage();
    }
  });

  pw.printf("<?xml version='1.0' encoding='UTF-8'?>%n");
  pw.printf("<preferences EXTERNAL_XML_VERSION='1.0'>%n");
  if (!rootPrefs.isUserNode())
    pw.printf("  <root type='system'>%n");
  else
    pw.printf("  <root type='user'>%n");

  Indent indent = new Indent(2);
  indent.incr();
  writeXmlNode(bos, pw, rootPrefs, beanEncoder, indent);
  if (outputExceptionMessage != null)
    throw new IOException(outputExceptionMessage);

  pw.printf("  </root>%n");
  pw.printf("</preferences>%n");
  pw.flush();
}
 
Example #23
Source File: SiddhiAppContext.java    From siddhi with Apache License 2.0 4 votes vote down vote up
public void setRuntimeExceptionListener(ExceptionListener runtimeExceptionListener) {
    this.runtimeExceptionListener = runtimeExceptionListener;
}
 
Example #24
Source File: SiddhiAppContext.java    From siddhi with Apache License 2.0 4 votes vote down vote up
public ExceptionListener getRuntimeExceptionListener() {
    return runtimeExceptionListener;
}
 
Example #25
Source File: SiddhiAppRuntimeImpl.java    From siddhi with Apache License 2.0 4 votes vote down vote up
public void handleRuntimeExceptionWith(ExceptionListener exceptionListener) {
    siddhiAppContext.setRuntimeExceptionListener(exceptionListener);
}
 
Example #26
Source File: DocumentHandler.java    From openjdk-8 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Sets the exception listener for parsing.
 * The exception listener is notified
 * when handler catches recoverable exceptions.
 *
 * @param listener  the exception listener for parsing
 */
public void setExceptionListener(ExceptionListener listener) {
    this.listener = listener;
}
 
Example #27
Source File: DocumentHandler.java    From openjdk-8 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the exception listener for parsing.
 * The exception listener is notified
 * when handler catches recoverable exceptions.
 * If the exception listener has not been explicitly set
 * then default exception listener is returned.
 *
 * @return the exception listener for parsing
 */
public ExceptionListener getExceptionListener() {
    return this.listener;
}
 
Example #28
Source File: DocumentHandler.java    From TencentKona-8 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the exception listener for parsing.
 * The exception listener is notified
 * when handler catches recoverable exceptions.
 * If the exception listener has not been explicitly set
 * then default exception listener is returned.
 *
 * @return the exception listener for parsing
 */
public ExceptionListener getExceptionListener() {
    return this.listener;
}
 
Example #29
Source File: DocumentHandler.java    From jdk8u_jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the exception listener for parsing.
 * The exception listener is notified
 * when handler catches recoverable exceptions.
 * If the exception listener has not been explicitly set
 * then default exception listener is returned.
 *
 * @return the exception listener for parsing
 */
public ExceptionListener getExceptionListener() {
    return this.listener;
}
 
Example #30
Source File: DocumentHandler.java    From jdk8u_jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Sets the exception listener for parsing.
 * The exception listener is notified
 * when handler catches recoverable exceptions.
 *
 * @param listener  the exception listener for parsing
 */
public void setExceptionListener(ExceptionListener listener) {
    this.listener = listener;
}