本文整理汇总了Java中com.thoughtworks.xstream.mapper.CannotResolveClassException类的典型用法代码示例。如果您正苦于以下问题:Java CannotResolveClassException类的具体用法?Java CannotResolveClassException怎么用?Java CannotResolveClassException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CannotResolveClassException类属于com.thoughtworks.xstream.mapper包,在下文中一共展示了CannotResolveClassException类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBarfsIfItDoesNotExist
import com.thoughtworks.xstream.mapper.CannotResolveClassException; //导入依赖的package包/类
public void testBarfsIfItDoesNotExist() {
String xml = "" +
"<X-array>\n" +
" <X>\n" +
" <anInt>0</anInt>\n" +
" </X>\n" +
"</X-array>";
// now change the alias
xstream.alias("Xxxxxxxx", X.class);
try {
xstream.fromXML(xml);
fail("ShouldCannotResolveClassException expected");
} catch (CannotResolveClassException expectedException) {
// expected
}
}
示例2: convertXStreamException
import com.thoughtworks.xstream.mapper.CannotResolveClassException; //导入依赖的package包/类
/**
* Convert the given XStream exception to an appropriate exception from the
* {@code org.springframework.oxm} hierarchy.
* <p>A boolean flag is used to indicate whether this exception occurs during marshalling or
* unmarshalling, since XStream itself does not make this distinction in its exception hierarchy.
* @param ex XStream exception that occurred
* @param marshalling indicates whether the exception occurs during marshalling ({@code true}),
* or unmarshalling ({@code false})
* @return the corresponding {@code XmlMappingException}
*/
protected XmlMappingException convertXStreamException(Exception ex, boolean marshalling) {
if (ex instanceof StreamException || ex instanceof CannotResolveClassException ||
ex instanceof ConversionException) {
if (marshalling) {
return new MarshallingFailureException("XStream marshalling exception", ex);
}
else {
return new UnmarshallingFailureException("XStream unmarshalling exception", ex);
}
}
else {
// fallback
return new UncategorizedMappingException("Unknown XStream exception", ex);
}
}
示例3: generateXStream
import com.thoughtworks.xstream.mapper.CannotResolveClassException; //导入依赖的package包/类
/**
* {@link XStream} generator
* <p>
*
* @param hierarchicalStreamDriver
* {@link HierarchicalStreamDriver}
* @return {@link XStream}
*/
private XStream generateXStream(HierarchicalStreamDriver hierarchicalStreamDriver) {
XStream xStream = new XStream(hierarchicalStreamDriver) {
@Override
protected MapperWrapper wrapMapper(MapperWrapper next) {
return new MapperWrapper(next) {
@Override
// avoid {@link XStream} crash when field misses
public boolean shouldSerializeMember(Class definedIn, String fieldName) {
try {
return definedIn != Object.class || realClass(fieldName) != null;
}
catch (CannotResolveClassException cnrce) {
return false;
}
}
};
}
};
xStream.autodetectAnnotations(true);
return xStream;
}
示例4: convertXStreamException
import com.thoughtworks.xstream.mapper.CannotResolveClassException; //导入依赖的package包/类
/**
* Convert the given XStream exception to an appropriate exception from the
* {@code org.springframework.oxm} hierarchy.
* <p>A boolean flag is used to indicate whether this exception occurs during marshalling or
* unmarshalling, since XStream itself does not make this distinction in its exception hierarchy.
* @param ex XStream exception that occured
* @param marshalling indicates whether the exception occurs during marshalling ({@code true}),
* or unmarshalling ({@code false})
* @return the corresponding {@code XmlMappingException}
*/
protected XmlMappingException convertXStreamException(Exception ex, boolean marshalling) {
if (ex instanceof StreamException || ex instanceof CannotResolveClassException ||
ex instanceof ConversionException) {
if (marshalling) {
return new MarshallingFailureException("XStream marshalling exception", ex);
}
else {
return new UnmarshallingFailureException("XStream unmarshalling exception", ex);
}
}
else {
// fallback
return new UncategorizedMappingException("Unknown XStream exception", ex);
}
}
示例5: convertSyntaxException
import com.thoughtworks.xstream.mapper.CannotResolveClassException; //导入依赖的package包/类
/**
* We don't want to expose the conversion exceptions, so let's translate them into our own exception...
*/
private NaaccrIOException convertSyntaxException(ConversionException ex) {
String msg = ex.get("message");
// reading a file that has bad tags is very common, so let's try to get a better error message in that case:
if (CannotResolveClassException.class.getName().equals(ex.get("cause-exception")))
msg = "invalid tag: " + ex.get("cause-message");
else if (StreamException.class.getName().equals(ex.get("cause-exception")))
msg = "invalid XML syntax";
if (msg == null)
msg = ex.getMessage();
NaaccrIOException e = new NaaccrIOException(msg, ex);
if (ex.get("line number") != null)
e.setLineNumber(Integer.valueOf(ex.get("line number")));
e.setPath(ex.get("path"));
return e;
}
示例6: realClass
import com.thoughtworks.xstream.mapper.CannotResolveClassException; //导入依赖的package包/类
public Class realClass(String elementName) {
try {
if (elementName.startsWith(XSTREAM_PACKAGE_ROOT)) {
return DefaultMapper.class.getClassLoader().loadClass(elementName);
} else if (elementName.charAt(0) != '[') {
return classLoader.loadClass(elementName);
} else if (elementName.endsWith(";")) {
return Class.forName(elementName.toString(), false, classLoader.getClassLoader());
} else {
return Class.forName(elementName.toString());
}
} catch (ClassNotFoundException e) {
throw new CannotResolveClassException(elementName);
}
}
示例7: fromString
import com.thoughtworks.xstream.mapper.CannotResolveClassException; //导入依赖的package包/类
@Override
public Object fromString(final String str) {
try {
return mapper.realClass(str);
} catch (final CannotResolveClassException e) {
throw new ConversionException("Cannot load java class " + str, e.getCause());
}
}
示例8: testInjectingReplacements
import com.thoughtworks.xstream.mapper.CannotResolveClassException; //导入依赖的package包/类
public void testInjectingReplacements() {
XStream xstream = new XStream() {
protected MapperWrapper wrapMapper(MapperWrapper next) {
return new MapperWrapper(next) {
public Class realClass(String elementName) {
try {
return super.realClass(elementName);
} catch (CannotResolveClassException e) {
if (elementName.endsWith("oo")) {
return Integer.class;
}
if (elementName.equals("UnknownList")) {
return LinkedList.class;
}
throw e;
}
}
};
}
};
setupSecurity(xstream);
xstream.alias("wl", WithList.class);
WithList wl = (WithList)xstream.fromXML(""
+ "<wl>\n"
+ " <things class='UnknownList'>\n"
+ " <foo>1</foo>\n"
+ " <cocoo>2</cocoo>\n"
+ " </things>\n"
+ "</wl>");
assertEquals(new ArrayList(Arrays.asList(new Integer[]{new Integer(1), new Integer(2)})), wl.things);
assertTrue(wl.things instanceof LinkedList);
}
示例9: testDebugMessageIsNotNested
import com.thoughtworks.xstream.mapper.CannotResolveClassException; //导入依赖的package包/类
public void testDebugMessageIsNotNested() {
Exception ex = new CannotResolveClassException("JUnit");
ConversionException innerEx = new ConversionException("Inner", ex);
ConversionException outerEx = new ConversionException("Outer", innerEx);
StringTokenizer tokenizer = new StringTokenizer(outerEx.getMessage(), "\n\r");
int ends = 0;
while(tokenizer.hasMoreTokens()) {
if (tokenizer.nextToken().startsWith("---- Debugging information ----")) {
++ends;
}
}
assertEquals(1, ends);
}
示例10: fromString
import com.thoughtworks.xstream.mapper.CannotResolveClassException; //导入依赖的package包/类
public Object fromString(String paramString)
{
try
{
Class localClass = this.mapper.realClass(paramString);
return localClass;
}
catch (CannotResolveClassException localCannotResolveClassException)
{
throw new ConversionException("Cannot load java class " + paramString, localCannotResolveClassException.getCause());
}
}
示例11: readDocument
import com.thoughtworks.xstream.mapper.CannotResolveClassException; //导入依赖的package包/类
@Override
public void readDocument(InputStream is) {
XStream streamer = getTagStreamer();
try {
tagSet = (StyledTagSet) streamer.fromXML(is);
} catch (CannotResolveClassException e) {
throw new RuntimeException("failed to read XML, element "
+ e.getMessage());
}
}