本文整理汇总了Java中org.simpleframework.xml.convert.AnnotationStrategy类的典型用法代码示例。如果您正苦于以下问题:Java AnnotationStrategy类的具体用法?Java AnnotationStrategy怎么用?Java AnnotationStrategy使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AnnotationStrategy类属于org.simpleframework.xml.convert包,在下文中一共展示了AnnotationStrategy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fromXml
import org.simpleframework.xml.convert.AnnotationStrategy; //导入依赖的package包/类
public static TagConfigImpl fromXml(final String xml) throws Exception {
TagConfigImpl conf = null;
StringReader sr = null;
Serializer serializer = new Persister(new AnnotationStrategy());
try {
sr = new StringReader(xml);
conf = serializer.read(TagConfigImpl.class, new StringReader(xml), false);
} finally {
if (sr != null) {
sr.close();
}
}
return conf;
}
示例2: fromXml
import org.simpleframework.xml.convert.AnnotationStrategy; //导入依赖的package包/类
public static AlarmValueImpl fromXml(final String xml) throws Exception {
AlarmValueImpl alarmVal = null;
StringReader sr = null;
Serializer serializer = new Persister(new AnnotationStrategy());
try {
sr = new StringReader(xml);
alarmVal = serializer.read(AlarmValueImpl.class, new StringReader(xml), false);
} finally {
if (sr != null) {
sr.close();
}
}
return alarmVal;
}
示例3: fromXml
import org.simpleframework.xml.convert.AnnotationStrategy; //导入依赖的package包/类
public static CommandTagImpl fromXml(final String xml) throws Exception {
CommandTagImpl commandTag = null;
StringReader sr = null;
Serializer serializer = new Persister(new AnnotationStrategy());
try {
sr = new StringReader(xml);
commandTag = serializer.read(CommandTagImpl.class, new StringReader(xml), false);
} finally {
if (sr != null) {
sr.close();
}
}
return commandTag;
}
示例4: testSerialization
import org.simpleframework.xml.convert.AnnotationStrategy; //导入依赖的package包/类
@Nonnull
public static <T> T testSerialization(@Nonnull Class<T> type, @Nonnull T in) throws Exception {
Persister persister = new Persister(new AnnotationStrategy(), newRegistryMatcher());
LOG.info("In: " + in);
ByteArrayOutputStream os = new ByteArrayOutputStream();
persister.write(in, os);
byte[] data = os.toByteArray();
LOG.info("Xml: " + new String(data, Charsets.UTF_8));
ByteArrayInputStream is = new ByteArrayInputStream(data);
T out = persister.read(type, is);
LOG.info("Out: " + out);
return out;
}
示例5: testMap
import org.simpleframework.xml.convert.AnnotationStrategy; //导入依赖的package包/类
public void testMap() throws Exception {
Strategy strategy = new AnnotationStrategy();
Serializer serializer = new Persister(strategy);
MapHolder holder = new MapHolder();
holder.put("a", "A");
holder.put("b", "B");
holder.put("c", "C");
holder.put("d", "D");
holder.put("e", "E");
holder.put("f", "F");
serializer.write(holder, System.out);
validate(holder, serializer);
}
示例6: testConverter
import org.simpleframework.xml.convert.AnnotationStrategy; //导入依赖的package包/类
public void testConverter() throws Exception {
Style style = new CamelCaseStyle();
Format format = new Format(style);
Strategy cycle = new CycleStrategy();
Strategy strategy = new AnnotationStrategy(cycle);
Persister persister = new Persister(strategy, format);
List<ConverterDecorationExample> list = new ArrayList<ConverterDecorationExample>();
List<NormalExample> normal = new ArrayList<NormalExample>();
ConverterDecoration example = new ConverterDecoration(list, normal);
ConverterDecorationExample duplicate = new ConverterDecorationExample("duplicate");
NormalExample normalDuplicate = new NormalExample("duplicate");
list.add(duplicate);
list.add(new ConverterDecorationExample("a"));
list.add(new ConverterDecorationExample("b"));
list.add(new ConverterDecorationExample("c"));
list.add(duplicate);
list.add(new ConverterDecorationExample("d"));
list.add(duplicate);
normal.add(normalDuplicate);
normal.add(new NormalExample("1"));
normal.add(new NormalExample("2"));
normal.add(normalDuplicate);
persister.write(example, System.err);
}
示例7: testConverterWithPathInHyphenStyle
import org.simpleframework.xml.convert.AnnotationStrategy; //导入依赖的package包/类
public void testConverterWithPathInHyphenStyle() throws Exception {
Style style = new HyphenStyle();
Format format = new Format(style);
Strategy strategy = new AnnotationStrategy();
Persister persister = new Persister(strategy, format);
ServerDetails primary = new ServerDetails("host1.blah.com", 4567, "PRIMARY");
ServerDetails secondary = new ServerDetails("host2.foo.com", 4567, "SECONDARY");
ServerDetailsReference reference = new ServerDetailsReference(primary, secondary);
StringWriter writer = new StringWriter();
persister.write(reference, writer);
System.out.println(writer);
ServerDetailsReference recovered = persister.read(ServerDetailsReference.class, writer.toString());
assertEquals(recovered.getPrimary().getHost(), reference.getPrimary().getHost());
assertEquals(recovered.getPrimary().getPort(), reference.getPrimary().getPort());
assertEquals(recovered.getPrimary().getName(), reference.getPrimary().getName());
assertEquals(recovered.getSecondary().getHost(), reference.getSecondary().getHost());
assertEquals(recovered.getSecondary().getPort(), reference.getSecondary().getPort());
assertEquals(recovered.getSecondary().getName(), reference.getSecondary().getName());
}
示例8: testConverterWithPathInCamelStyle
import org.simpleframework.xml.convert.AnnotationStrategy; //导入依赖的package包/类
public void testConverterWithPathInCamelStyle() throws Exception {
Style style = new CamelCaseStyle();
Format format = new Format(style);
Strategy strategy = new AnnotationStrategy();
Persister persister = new Persister(strategy, format);
ServerDetails primary = new ServerDetails("host1.blah.com", 4567, "PRIMARY");
ServerDetails secondary = new ServerDetails("host2.foo.com", 4567, "SECONDARY");
ServerDetailsReference reference = new ServerDetailsReference(primary, secondary);
StringWriter writer = new StringWriter();
persister.write(reference, writer);
System.out.println(writer);
ServerDetailsReference recovered = persister.read(ServerDetailsReference.class, writer.toString());
assertEquals(recovered.getPrimary().getHost(), reference.getPrimary().getHost());
assertEquals(recovered.getPrimary().getPort(), reference.getPrimary().getPort());
assertEquals(recovered.getPrimary().getName(), reference.getPrimary().getName());
assertEquals(recovered.getSecondary().getHost(), reference.getSecondary().getHost());
assertEquals(recovered.getSecondary().getPort(), reference.getSecondary().getPort());
assertEquals(recovered.getSecondary().getName(), reference.getSecondary().getName());
}
示例9: parse
import org.simpleframework.xml.convert.AnnotationStrategy; //导入依赖的package包/类
public void parse() throws Exception {
beforeParse();
for (SnippetContainer snippetContainer : getSnippetProject().getSnippetContainers()) {
for (Snippet snippet : snippetContainer.getSnippets().values()) {
File inputsXmlFile = RunnerProjectUtils.getSnippetInputsFile(
getRunnerProjectSettings(),
snippet);
Serializer serializer = new Persister(new AnnotationStrategy());
SnippetInputsXml inputsXml = serializer.read(SnippetInputsXml.class, inputsXmlFile);
inputsXml.validate();
if (inputsXml.getResultType() == ResultType.NA
|| inputsXml.getResultType() == ResultType.EX
|| inputsXml.getResultType() == ResultType.TM) {
log.info("Skipping {}: {}", snippet.getId(), inputsXml.getResultType());
return;
}
parseOne(snippet);
}
}
}
示例10: convert
import org.simpleframework.xml.convert.AnnotationStrategy; //导入依赖的package包/类
@Override
public Object convert(String propertyName, String propertyValue, TypeDescriptor targetType) {
Class<?> targetClass = targetType.getType();
Serializer serializer = new Persister(new AnnotationStrategy());
try {
return serializer.read(targetClass, propertyValue, false);
} catch (Exception e) {
LOGGER.error("Convert xml to " + targetClass + " error", e);
}
return null;
}
示例11: fromXml
import org.simpleframework.xml.convert.AnnotationStrategy; //导入依赖的package包/类
/**
* Static method for creating a Process object
* from a XML String by making use of the simpleframework XML library.
* @param xml The XML representation of a <code>processConnectionResponse</code> object
* @param processType The process type to call the proper object cast
* @return Object Object created from the given XML String
* @throws Exception In case of a parsing error or a wrong XML definition
*/
private final Object fromXml(final String xml, final ProcessMessageType processType) throws Exception {
StringReader sr = null;
Serializer serializer = new Persister(new AnnotationStrategy());
try {
sr = new StringReader(xml);
switch(processType) {
case CONNECT_REQUEST:
LOGGER.trace("fromXml() : converting from XML to ProcessConnectionRequest.");
return serializer.read(ProcessConnectionRequest.class, sr, false);
case CONNECT_RESPONSE:
LOGGER.trace("fromXml() : converting from XML to ProcessConnectionResponse.");
return serializer.read(ProcessConnectionResponse.class, sr, false);
case CONFIG_REQUEST:
LOGGER.trace("fromXml() : converting from XML to ProcessConfigurationRequest.");
return serializer.read(ProcessConfigurationRequest.class, sr, false);
case CONFIG_RESPONSE:
LOGGER.trace("fromXml() : converting from XML to ProcessConfigurationResponse.");
return serializer.read(ProcessConfigurationResponse.class, sr, false);
case DISCONNETION_REQUEST:
LOGGER.trace("fromXml() : converting from XML to ProcessDisconnectionRequest.");
return serializer.read(ProcessDisconnectionRequest.class, sr, false);
default:
LOGGER.error("fromXml() : Process type not found: " + processType);
throw new MessageFormatException("fromXml(): Process type not found: " + processType);
}
} finally {
if (sr != null) {
sr.close();
}
}
}
示例12: getSerializer
import org.simpleframework.xml.convert.AnnotationStrategy; //导入依赖的package包/类
/**
* Retrieve a {@link Serializer} instance suitable for deserialising a
* {@link ConfigurationReport}.
*
* @return a new {@link Serializer} instance
*/
private Serializer getSerializer() {
DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
RegistryMatcher matcher = new RegistryMatcher();
matcher.bind(Timestamp.class, new DateFormatConverter(format));
Strategy strategy = new AnnotationStrategy();
Serializer serializer = new Persister(strategy, matcher);
return serializer;
}
示例13: providesApi
import org.simpleframework.xml.convert.AnnotationStrategy; //导入依赖的package包/类
@Provides
@Singleton
public UsStatesApi providesApi(){
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
Strategy strategy = new AnnotationStrategy();
Serializer serializer = new Persister(strategy);
OkHttpClient okHttpClient = new OkHttpClient.Builder()
.addInterceptor(interceptor)
.connectTimeout(2, TimeUnit.MINUTES)
.writeTimeout(2, TimeUnit.MINUTES)
.readTimeout(2, TimeUnit.MINUTES)
.build();
Retrofit retrofit = new Retrofit.Builder()
.addConverterFactory(SimpleXmlConverterFactory.create(serializer))
.baseUrl("http://www.webservicex.net/")
.client(okHttpClient)
.build();
return retrofit.create( UsStatesApi.class);
}
示例14: getSerializer
import org.simpleframework.xml.convert.AnnotationStrategy; //导入依赖的package包/类
/**
* Utility to get a simple framework persister
* @return a persister
* @throws Exception when things get tough
*/
private static Serializer getSerializer() throws Exception {
Registry registry = new Registry();
registry.bind(String.class, EmptyStringConverter.class);
Strategy strategy = new AnnotationStrategy(new RegistryStrategy(registry));
return new Persister(strategy);
}
示例15: loadXmlFile
import org.simpleframework.xml.convert.AnnotationStrategy; //导入依赖的package包/类
public <T> T loadXmlFile(File file, Class<T> c) throws FileManagerException {
Strategy strategy = new AnnotationStrategy();
Serializer serializer = new Persister(strategy, new TransformMatcher());
T instance;
try {
instance = serializer.read(c, file);
} catch (Exception e) {
throw new FileManagerException(String.format("couldn't decode XML of file '%s'", file.getPath()), e);
}
return instance;
}