当前位置: 首页>>代码示例>>Java>>正文


Java AnnotationStrategy类代码示例

本文整理汇总了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;
  }
 
开发者ID:c2mon,项目名称:c2mon,代码行数:19,代码来源:TagConfigImpl.java

示例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;
  }
 
开发者ID:c2mon,项目名称:c2mon,代码行数:19,代码来源:AlarmValueImpl.java

示例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;
  }
 
开发者ID:c2mon,项目名称:c2mon,代码行数:19,代码来源:CommandTagImpl.java

示例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;
}
 
开发者ID:shevek,项目名称:simple-xml-serializers,代码行数:18,代码来源:TypeConverterTest.java

示例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);
}
 
开发者ID:ngallagher,项目名称:simplexml,代码行数:17,代码来源:ConverterMapTest.java

示例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);     
}
 
开发者ID:ngallagher,项目名称:simplexml,代码行数:25,代码来源:ConverterDecorationTest.java

示例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());
}
 
开发者ID:ngallagher,项目名称:simplexml,代码行数:20,代码来源:PathWithConverterTest.java

示例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());
}
 
开发者ID:ngallagher,项目名称:simplexml,代码行数:20,代码来源:PathWithConverterTest.java

示例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);
        }
    }
}
 
开发者ID:SETTE-Testing,项目名称:sette-tool,代码行数:25,代码来源:EvoSuiteParserMutation.java

示例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;
}
 
开发者ID:zouzhirong,项目名称:configx,代码行数:12,代码来源:XmlConfigConverter.java

示例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();
    }
  }
}
 
开发者ID:c2mon,项目名称:c2mon,代码行数:41,代码来源:XMLConverter.java

示例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;
}
 
开发者ID:c2mon,项目名称:c2mon,代码行数:15,代码来源:ConfigurationLoaderImpl.java

示例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);

}
 
开发者ID:asanchezyu,项目名称:RetrofitSoapSample,代码行数:29,代码来源:ApplicationModule.java

示例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);

}
 
开发者ID:jorabin,项目名称:KeePassJava2,代码行数:13,代码来源:SimpleDatabase.java

示例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;
}
 
开发者ID:miniME89,项目名称:PassBeam,代码行数:14,代码来源:FileManager.java


注:本文中的org.simpleframework.xml.convert.AnnotationStrategy类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。