本文整理汇总了Java中java.beans.ExceptionListener类的典型用法代码示例。如果您正苦于以下问题:Java ExceptionListener类的具体用法?Java ExceptionListener怎么用?Java ExceptionListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ExceptionListener类属于java.beans包,在下文中一共展示了ExceptionListener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import java.beans.ExceptionListener; //导入依赖的package包/类
/** Evaluates the attributes and creates a Context instance.
* If the creation of the Context instance fails the ElementHandler
* is marked as failed which may affect the parent handler other.
*
* @param attributes Attributes of the XML tag.
*/
public final void start(Attributes attributes,
ExceptionListener exceptionListener)
{
try
{
// lets the subclass create the appropriate Context instance
context = startElement(attributes, exceptionListener);
}
catch (AssemblyException pe)
{
Throwable t = pe.getCause();
if (t instanceof Exception)
exceptionListener.exceptionThrown((Exception) t);
else
throw new InternalError("Unexpected Throwable type in AssemblerException. Please file a bug report.");
notifyContextFailed();
return;
}
}
示例2: testInitialize_NullClass
import java.beans.ExceptionListener; //导入依赖的package包/类
public void testInitialize_NullClass() {
MockPersistenceDelegate pd = new MockPersistenceDelegate();
Encoder enc = new Encoder();
Object o1 = new Object();
Object o2 = new Object();
// enc.setPersistenceDelegate(MockFooStop.class,
// new MockPersistenceDelegate());
try {
enc.setExceptionListener(new ExceptionListener() {
public void exceptionThrown(Exception e) {
CallVerificationStack.getInstance().push(e);
}
});
pd.initialize(null, o1, o2, enc);
fail("Should throw NullPointerException!");
} catch (NullPointerException ex) {
// expected
}
assertTrue(CallVerificationStack.getInstance().empty());
}
示例3: write
import java.beans.ExceptionListener; //导入依赖的package包/类
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);
}
示例4: getXMLEncoder
import java.beans.ExceptionListener; //导入依赖的package包/类
/**
* Sets up the XMLEnconder.
*/
public XMLEncoder getXMLEncoder(OutputStream out) {
XMLEncoder e = new XMLEncoder(out);
e.setExceptionListener(new ExceptionListener() {
public void exceptionThrown(Exception e1) {
logger.error("", e1);
}
});
e.setPersistenceDelegate(BeanUser.class,
new DefaultPersistenceDelegate(new String[] { "name" }));
e.setPersistenceDelegate(Key.class, new DefaultPersistenceDelegate(
new String[] { "owner", "key" }));
e.setPersistenceDelegate(HostMask.class,
new DefaultPersistenceDelegate(new String[] { "mask" }));
return e;
}
示例5: startElement
import java.beans.ExceptionListener; //导入依赖的package包/类
protected final Context startElement(Attributes attributes, ExceptionListener exceptionListener)
throws AssemblyException
{
// note: simple elements should not have any attributes. We inform
// the user of this syntactical but uncritical problem by sending
// an IllegalArgumentException for each unneccessary attribute
int size = attributes.getLength();
for (int i = 0; i < size; i++) {
String attributeName = attributes.getQName(i);
Exception e =
new IllegalArgumentException(
"Unneccessary attribute '"
+ attributeName
+ "' discarded.");
exceptionListener.exceptionThrown(e);
}
return context = new ObjectContext();
}
示例6: start
import java.beans.ExceptionListener; //导入依赖的package包/类
/** Evaluates the attributes and creates a Context instance.
* If the creation of the Context instance fails the ElementHandler
* is marked as failed which may affect the parent handler other.
*
* @param attributes Attributes of the XML tag.
*/
public final void start(Attributes attributes,
ExceptionListener exceptionListener)
{
try
{
// lets the subclass create the appropriate Context instance
context = startElement(attributes, exceptionListener);
}
catch (AssemblyException pe)
{
Throwable t = pe.getCause();
if (t instanceof Exception)
exceptionListener.exceptionThrown((Exception) t);
else
throw new InternalError("Unexpected Throwable type in AssemblerException. Please file a bug report.");
notifyContextFailed();
return;
}
}
示例7: startElement
import java.beans.ExceptionListener; //导入依赖的package包/类
protected final Context startElement(Attributes attributes, ExceptionListener exceptionListener)
throws AssemblyException
{
// note: simple elements should not have any attributes. We inform
// the user of this syntactical but uncritical problem by sending
// an IllegalArgumentException for each unneccessary attribute
int size = attributes.getLength();
for (int i = 0; i < size; i++) {
String attributeName = attributes.getQName(i);
Exception e =
new IllegalArgumentException(
"Unneccessary attribute '"
+ attributeName
+ "' discarded.");
exceptionListener.exceptionThrown(e);
}
return context = new ObjectContext();
}
示例8: toXML
import java.beans.ExceptionListener; //导入依赖的package包/类
/**
* Serialize all the EventData items into an XML representation.
*
* @param map the Map to transform
* @return an XML String containing all the EventDAta items.
*/
public static String toXML(Map<String, Object> map) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
XMLEncoder encoder = new XMLEncoder(baos);
encoder.setExceptionListener(new ExceptionListener() {
public void exceptionThrown(Exception exception) {
exception.printStackTrace();
}
});
encoder.writeObject(map);
encoder.close();
return baos.toString();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
示例9: getBlackList
import java.beans.ExceptionListener; //导入依赖的package包/类
/**
* プラグインブラックリストの読み込み
*
* @param listener ExceptionListener
* @return プラグインブラックリスト
*/
private Set<String> getBlackList(ExceptionListener listener) {
Set<String> blackList = Collections.emptySet();
InputStream in = Launcher.class.getClassLoader().getResourceAsStream("logbook/plugin-black-list"); //$NON-NLS-1$
if (in != null) {
try (BufferedReader r = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8))) {
blackList = r.lines()
.filter(l -> l.length() >= 64)
.map(l -> l.substring(0, 64))
.collect(Collectors.toSet());
} catch (IOException e) {
listener.exceptionThrown(e);
}
}
return blackList;
}
示例10: writeXMLObject
import java.beans.ExceptionListener; //导入依赖的package包/类
/**
* Writes the objet and CLOSES the stream. Uses the persistence delegate registered in this class.
*
* @param os The stream to write to. Will be closed.
* @param o The object to be serialized.
* @param listener The listener to recieve the exeptions if there are any. If <code>null</code> not used.
*/
void writeXMLObject(final OutputStream os, final Object o, final ExceptionListener listener) {
final ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(LayoutUtilCommon.class.getClassLoader());
final XMLEncoder encoder = new XMLEncoder(os);
if (listener != null) {
encoder.setExceptionListener(listener);
}
encoder.writeObject(o);
encoder.close(); // Must be closed to write.
Thread.currentThread().setContextClassLoader(oldClassLoader);
}
示例11: writeAsXML
import java.beans.ExceptionListener; //导入依赖的package包/类
/**
* Writes an object to XML.
*
* @param out The boject out to write to. Will not be closed.
* @param o The object to write.
*/
public synchronized void writeAsXML(final ObjectOutput out, final Object o) throws IOException {
if (writeOutputStream == null) {
writeOutputStream = new ByteArrayOutputStream(16384);
}
writeOutputStream.reset();
writeXMLObject(writeOutputStream, o, new ExceptionListener() {
@Override
public void exceptionThrown(final Exception e) {
LOGGER.error(e);
}
});
final byte[] buf = writeOutputStream.toByteArray();
out.writeInt(buf.length);
out.write(buf);
}
示例12: exceptionThrown
import java.beans.ExceptionListener; //导入依赖的package包/类
public void exceptionThrown(Exception ex)
{
Object[] ls = listeners.toArray();
if (ls.length == 0)
Logger.getLogger(ExceptionListenerSupport.class.getName()).log(Level.SEVERE, null, ex);
else
{
boolean informed = false;
for (Object o : ls)
if (o instanceof ExceptionListener)
{
((ExceptionListener) o).exceptionThrown(ex);
informed = true;
}
else
Logger.getLogger(ExceptionListenerSupport.class.getName()).warning(String.format("Not an instance of exception listener: %s", o.toString()));
if (!informed)
Logger.getLogger(ExceptionListenerSupport.class.getName()).log(Level.SEVERE, null, ex);
}
}
示例13: testInitialize_NoGetter
import java.beans.ExceptionListener; //导入依赖的package包/类
public void testInitialize_NoGetter() throws Exception {
MockEncoder enc = new MockEncoder();
MockPersistenceDelegate pd = new MockPersistenceDelegate();
MockNoGetterBean b = new MockNoGetterBean();
b.setName("myName");
enc.setExceptionListener(new ExceptionListener() {
public void exceptionThrown(Exception e) {
CallVerificationStack.getInstance().push(e);
}
});
enc.writeObject(b);
CallVerificationStack.getInstance().clear();
MockNoGetterBean b2 = (MockNoGetterBean) enc.get(b);
b2.setName("yourName");
b2.setLabel("hehe");
pd.initialize(MockNoGetterBean.class, b, b2, enc);
assertTrue(CallVerificationStack.getInstance().empty());
}
示例14: testInitialize_NullInstances
import java.beans.ExceptionListener; //导入依赖的package包/类
public void testInitialize_NullInstances() {
MockPersistenceDelegate pd = new MockPersistenceDelegate();
Encoder enc = new Encoder();
MockFoo b = new MockFoo();
b.setName("myName");
// enc.setPersistenceDelegate(MockFooStop.class,
// new MockPersistenceDelegate());
enc.setExceptionListener(new ExceptionListener() {
public void exceptionThrown(Exception e) {
CallVerificationStack.getInstance().push(e);
}
});
try {
pd.initialize(MockFoo.class, null, b, enc);
fail("Should throw NullPointerException!");
} catch (NullPointerException ex) {
// expected
}
assertTrue(CallVerificationStack.getInstance().empty());
pd.initialize(MockFoo.class, b, null, enc);
assertFalse(CallVerificationStack.getInstance().empty());
}
示例15: test_Constructor_Normal
import java.beans.ExceptionListener; //导入依赖的package包/类
public void test_Constructor_Normal() throws Exception {
XMLDecoder xmlDecoder;
xmlDecoder = new XMLDecoder(new ByteArrayInputStream(xml123bytes));
assertEquals(null, xmlDecoder.getOwner());
final Vector<Exception> exceptions = new Vector<Exception>();
ExceptionListener el = new ExceptionListener() {
public void exceptionThrown(Exception e) {
exceptions.addElement(e);
}
};
xmlDecoder = new XMLDecoder(new ByteArrayInputStream(xml123bytes),
this, el);
assertEquals(el, xmlDecoder.getExceptionListener());
assertEquals(this, xmlDecoder.getOwner());
}