/*
* Copyright 2003 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
package javax.xml.bind;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
import java.util.Map;
import java.util.Properties;
import java.util.StringTokenizer;
import java.util.logging.ConsoleHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import static javax.xml.bind.JAXBContext.JAXB_CONTEXT_FACTORY;
//import java.lang.reflect.InvocationTargetException;
/**
* This class is package private and therefore is not exposed as part of the
* JAXB API.
*
* This code is designed to implement the JAXB 1.0 spec pluggability feature
*
* @author <ul><li>Ryan Shoemaker, Sun Microsystems, Inc.</li></ul>
* @version $Revision: 1.20 $
* @see JAXBContext
*/
class ContextFinder {
private static final Logger logger;
static {
logger = Logger.getLogger("javax.xml.bind");
try {
if (System.getProperty("jaxb.debug", null) != null) {
// disconnect the logger from a bigger framework (if any)
// and take the matters into our own hands
logger.setUseParentHandlers(false);
logger.setLevel(Level.ALL);
ConsoleHandler handler = new ConsoleHandler();
handler.setLevel(Level.ALL);
logger.addHandler(handler);
} else {
// don't change the setting of this logger
// to honor what other frameworks
// have done on configurations.
}
} catch(Throwable t) {
// just to be extra safe. in particular System.getProperty may throw
// SecurityException.
}
}
/**
* If the {@link InvocationTargetException} wraps an exception that shouldn't be wrapped,
* throw the wrapped exception.
*/
private static void handleInvocationTargetException(InvocationTargetException x) throws JAXBException {
Throwable t = x.getTargetException();
if( t != null ) {
if( t instanceof JAXBException )
// one of our exceptions, just re-throw
throw (JAXBException)t;
if( t instanceof RuntimeException )
// avoid wrapping exceptions unnecessarily
throw (RuntimeException)t;
if( t instanceof Error )
throw (Error)t;
}
}
/**
* Determine if two types (JAXBContext in this case) will generate a ClassCastException.
*
* For example, (targetType)originalType
*
* @param originalType
* The Class object of the type being cast
* @param targetType
* The Class object of the type that is being cast to
* @throws JAXBException
* If the cast would fail
*/
private static void handleClassCastException(Class originalType, Class targetType) throws JAXBException {
final URL targetTypeURL = which(targetType);
throw new JAXBException(Messages.format(Messages.ILLEGAL_CAST,
// we don't care where the impl class is, we want to know where JAXBContext lives in the impl
// class' ClassLoader
originalType.getClass().getClassLoader().getResource("javax/xml/bind/JAXBContext.class").toString(),
targetTypeURL.toString()));
}
=1= |