本文整理汇总了Java中org.simpleframework.xml.stream.Style类的典型用法代码示例。如果您正苦于以下问题:Java Style类的具体用法?Java Style怎么用?Java Style使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Style类属于org.simpleframework.xml.stream包,在下文中一共展示了Style类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: assembleAttributes
import org.simpleframework.xml.stream.Style; //导入依赖的package包/类
/**
* This is used to assemble the model by perform registrations
* based on the <code>Order</code> annotation. The initial
* registrations performed by this establish the element and
* attribute order for serialization of the schema class.
*
* @param model the model to perform registrations on
* @param order this is the order specified by the class
*/
private void assembleAttributes(Model model, Order order) throws Exception {
for(String value : order.attributes()) {
Expression path = builder.build(value);
if(!path.isAttribute() && path.isPath()) {
throw new PathException("Ordered attribute '%s' references an element in %s", path, detail);
}
if(!path.isPath()) {
Style style = format.getStyle();
String name = style.getAttribute(value);
model.registerAttribute(name);
} else {
registerAttributes(model, path);
}
}
}
开发者ID:ngallagher,项目名称:simplexml,代码行数:27,代码来源:ModelAssembler.java
示例2: testCycle
import org.simpleframework.xml.stream.Style; //导入依赖的package包/类
public void testCycle() throws Exception {
Style style = new CamelCaseStyle();
Format format = new Format(style);
Registry registry = new Registry();
Address address = new Address("An Address");
Person person = new Person(address, "Niall", 30);
CycleStrategy referencer = new CycleStrategy();
RegistryStrategy strategy = new RegistryStrategy(registry, referencer);
Serializer serializer = new Persister(strategy, format);
Converter converter = new PersonConverter(serializer);
Club club = new Club(address);
club.addMember(person);
registry.bind(Person.class, converter);
serializer.write(club, System.out);
}
开发者ID:ngallagher,项目名称:simplexml,代码行数:18,代码来源:RegistryConverterCycleTest.java
示例3: testPersonConverter
import org.simpleframework.xml.stream.Style; //导入依赖的package包/类
public void testPersonConverter() throws Exception {
Style style = new CamelCaseStyle();
Format format = new Format(style);
Registry registry = new Registry();
Person person = new Person("Niall", 30);
RegistryStrategy strategy = new RegistryStrategy(registry);
Serializer serializer = new Persister(strategy, format);
Converter converter = new PersonConverter(serializer);
StringWriter writer = new StringWriter();
registry.bind(Person.class, converter);
PersonProfile profile = new PersonProfile(person);
serializer.write(profile, writer);
System.out.println(writer.toString());
PersonProfile read = serializer.read(PersonProfile.class, writer.toString());
assertEquals(read.person.name, "Niall");
assertEquals(read.person.age, 30);
}
开发者ID:ngallagher,项目名称:simplexml,代码行数:23,代码来源:RegistryConverterTest.java
示例4: testCombinationStrategyWithStyle
import org.simpleframework.xml.stream.Style; //导入依赖的package包/类
public void testCombinationStrategyWithStyle() throws Exception {
Registry registry = new Registry();
AnnotationStrategy annotationStrategy = new AnnotationStrategy();
RegistryStrategy registryStrategy = new RegistryStrategy(registry, annotationStrategy);
Style style = new HyphenStyle();
Format format = new Format(style);
Persister persister = new Persister(registryStrategy, format);
CombinationExample example = new CombinationExample(1, 2, 3);
StringWriter writer = new StringWriter();
registry.bind(Item.class, RegistryItemConverter.class);
persister.write(example, writer);
String text = writer.toString();
System.out.println(text);
assertElementExists(text, "/combination-example/item/value");
assertElementHasValue(text, "/combination-example/item/value", "1");
assertElementHasValue(text, "/combination-example/item/type", RegistryItemConverter.class.getName());
assertElementExists(text, "/combination-example/overridden-item");
assertElementHasAttribute(text, "/combination-example/overridden-item", "value", "2");
assertElementHasAttribute(text, "/combination-example/overridden-item", "type", AnnotationItemConverter.class.getName());
assertElementExists(text, "/combination-example/extended-item");
assertElementHasAttribute(text, "/combination-example/extended-item", "value", "3");
assertElementHasAttribute(text, "/combination-example/extended-item", "type", ExtendedItemConverter.class.getName());
}
开发者ID:ngallagher,项目名称:simplexml,代码行数:27,代码来源:CombinedStrategyTest.java
示例5: testOtherStyle
import org.simpleframework.xml.stream.Style; //导入依赖的package包/类
public void testOtherStyle() throws Exception {
Style style = new CamelCaseStyle();
Format format = new Format(style);
OtherCaseExample example = new OtherCaseExample("a", "b");
Persister persister = new Persister(format);
StringWriter writer = new StringWriter();
boolean exception = false;
try {
persister.write(example, writer);
}catch(Exception e) {
e.printStackTrace();
exception = true;
}
System.out.println(writer.toString());
assertFalse("No exception should be thrown with the elements are not the same name", exception);
}
开发者ID:ngallagher,项目名称:simplexml,代码行数:17,代码来源:PathCaseTest.java
示例6: testConverter
import org.simpleframework.xml.stream.Style; //导入依赖的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.stream.Style; //导入依赖的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.stream.Style; //导入依赖的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: testCamelCaseStyle
import org.simpleframework.xml.stream.Style; //导入依赖的package包/类
public void testCamelCaseStyle() throws Exception {
Style style = new CamelCaseStyle();
Format format = new Format(style);
Persister persister = new Persister(format);
UnionListExample example = persister.read(UnionListExample.class, CAMEL_CASE_SOURCE);
List<Entry> entry = example.list;
assertEquals(entry.size(), 4);
assertEquals(entry.get(0).getClass(), IntegerEntry.class);
assertEquals(entry.get(0).foo(), 111);
assertEquals(entry.get(1).getClass(), DoubleEntry.class);
assertEquals(entry.get(1).foo(), 222.0);
assertEquals(entry.get(2).getClass(), StringEntry.class);
assertEquals(entry.get(2).foo(), "A");
assertEquals(entry.get(3).getClass(), StringEntry.class);
assertEquals(entry.get(3).foo(), "B");
assertEquals(example.entry.getClass(), IntegerEntry.class);
assertEquals(example.entry.foo(), 777);
persister.write(example, System.out);
validate(persister, example);
}
开发者ID:ngallagher,项目名称:simplexml,代码行数:21,代码来源:UnionStyleTest.java
示例10: testHyphenStyle
import org.simpleframework.xml.stream.Style; //导入依赖的package包/类
public void testHyphenStyle() throws Exception {
Style style = new HyphenStyle();
Format format = new Format(style);
Persister persister = new Persister(format);
UnionListExample example = persister.read(UnionListExample.class, HYPHEN_SOURCE);
List<Entry> entry = example.list;
assertEquals(entry.size(), 4);
assertEquals(entry.get(0).getClass(), IntegerEntry.class);
assertEquals(entry.get(0).foo(), 111);
assertEquals(entry.get(1).getClass(), DoubleEntry.class);
assertEquals(entry.get(1).foo(), 222.0);
assertEquals(entry.get(2).getClass(), StringEntry.class);
assertEquals(entry.get(2).foo(), "A");
assertEquals(entry.get(3).getClass(), StringEntry.class);
assertEquals(entry.get(3).foo(), "B");
assertEquals(example.entry.getClass(), IntegerEntry.class);
assertEquals(example.entry.foo(), 777);
persister.write(example, System.out);
validate(persister, example);
}
开发者ID:ngallagher,项目名称:simplexml,代码行数:21,代码来源:UnionStyleTest.java
示例11: getEntry
import org.simpleframework.xml.stream.Style; //导入依赖的package包/类
/**
* This is used to either provide the entry value provided within
* the annotation or compute a entry value. If the entry string
* is not provided the the entry value is calculated as the type
* of primitive the object is as a simplified class name.
*
* @return this returns the name of the XML entry element used
*/
public String getEntry() throws Exception {
Style style = format.getStyle();
if(detail.isEmpty(entry)) {
entry = detail.getEntry();
}
return style.getElement(entry);
}
开发者ID:ngallagher,项目名称:simplexml,代码行数:17,代码来源:ElementListLabel.java
示例12: getName
import org.simpleframework.xml.stream.Style; //导入依赖的package包/类
/**
* This is used to acquire the name of the element or attribute
* that is used by the class schema. The name is determined by
* checking for an override within the annotation. If it contains
* a name then that is used, if however the annotation does not
* specify a name the the field or method name is used instead.
*
* @return returns the name that is used for the XML property
*/
public String getName() throws Exception{
if(name == null) {
Style style = format.getStyle();
String value = detail.getName();
name = style.getElement(value);
}
return name;
}
开发者ID:ngallagher,项目名称:simplexml,代码行数:19,代码来源:ElementListLabel.java
示例13: getName
import org.simpleframework.xml.stream.Style; //导入依赖的package包/类
/**
* This is used to acquire the name of the element or attribute
* that is used by the class schema. The name is determined by
* checking for an override within the annotation. If it contains
* a name then that is used, if however the annotation does not
* specify a name the the field or method name is used instead.
*
* @return returns the name that is used for the XML property
*/
public String getName() throws Exception{
if(name == null) {
Style style = format.getStyle();
String value = detail.getName();
name = style.getElement(value);
}
return name;
}
开发者ID:ngallagher,项目名称:simplexml,代码行数:19,代码来源:ElementLabel.java
示例14: getEntry
import org.simpleframework.xml.stream.Style; //导入依赖的package包/类
/**
* This is used to either provide the entry value provided within
* the annotation or compute a entry value. If the entry string
* is not provided the the entry value is calculated as the type
* of primitive the object is as a simplified class name.
*
* @return this returns the name of the XML entry element used
*/
public String getEntry() throws Exception {
Style style = format.getStyle();
if(detail.isEmpty(entry)) {
entry = detail.getEntry();
}
return style.getElement(entry);
}
开发者ID:ngallagher,项目名称:simplexml,代码行数:17,代码来源:ElementArrayLabel.java
示例15: getEntry
import org.simpleframework.xml.stream.Style; //导入依赖的package包/类
/**
* This is used to either provide the entry value provided within
* the annotation or compute a entry value. If the entry string
* is not provided the the entry value is calculated as the type
* of primitive the object is as a simplified class name.
*
* @return this returns the name of the XML entry element used
*/
public String getEntry() throws Exception {
Style style = format.getStyle();
if(detail.isEmpty(parent)) {
parent = detail.getEntry();
}
return style.getElement(parent);
}
开发者ID:ngallagher,项目名称:simplexml,代码行数:17,代码来源:ElementMapLabel.java
示例16: getName
import org.simpleframework.xml.stream.Style; //导入依赖的package包/类
/**
* This is used to acquire the name of the element or attribute
* that is used by the class schema. The name is determined by
* checking for an override within the annotation. If it contains
* a name then that is used, if however the annotation does not
* specify a name the the field or method name is used instead.
*
* @return returns the name that is used for the XML property
*/
public String getName() throws Exception{
if(name == null) {
Style style = format.getStyle();
String value = entry.getEntry();
if(!label.inline()) {
value = detail.getName();
}
name = style.getElement(value);
}
return name;
}
开发者ID:ngallagher,项目名称:simplexml,代码行数:22,代码来源:ElementMapLabel.java
示例17: testConverter
import org.simpleframework.xml.stream.Style; //导入依赖的package包/类
public void testConverter() throws Exception {
Style style = new CamelCaseStyle();
Format format = new Format(style);
Registry registry = new Registry();
Customer customer = new Customer("Niall", "Some Place");
Envelope envelope = new Envelope(customer);
RegistryStrategy strategy = new RegistryStrategy(registry);
Serializer serializer = new Persister(strategy, format);
Converter converter = new EnvelopeConverter(serializer);
registry.bind(Envelope.class, converter);
OrderItem order = new OrderItem(envelope);
serializer.write(order, System.out);
}
开发者ID:ngallagher,项目名称:simplexml,代码行数:16,代码来源:RegistryConverterTest.java
示例18: testArrayExample
import org.simpleframework.xml.stream.Style; //导入依赖的package包/类
public void testArrayExample() throws Exception {
Style style = new CamelCaseStyle();
Format format = new Format(style);
Persister persister = new Persister(format);
ArrayExample example = persister.read(ArrayExample.class, ARRAY);
assertEquals(example.getArray().length, 5);
assertEquals(example.getArray()[0], "entry one");
assertEquals(example.getArray()[1], "entry two");
assertEquals(example.getArray()[2], "entry three");
assertEquals(example.getArray()[3], "entry four");
assertEquals(example.getArray()[4], "entry five");
validate(persister, example);
}
开发者ID:ngallagher,项目名称:simplexml,代码行数:16,代码来源:ConstructorInjectionTest.java
示例19: testCase
import org.simpleframework.xml.stream.Style; //导入依赖的package包/类
public void testCase() throws Exception {
Style style = new HyphenStyle();
Format format = new Format(style);
Persister writer = new Persister(format);
Persister reader = new Persister();
CaseExample example = reader.read(CaseExample.class, SOURCE);
assertEquals(example.version, 1.0f);
assertEquals(example.name, "example");
assertEquals(example.URL, "http://domain.com/");
writer.write(example, System.err);
validate(example, reader);
validate(example, writer);
}
开发者ID:ngallagher,项目名称:simplexml,代码行数:16,代码来源:StyleTest.java
示例20: testStyleDup
import org.simpleframework.xml.stream.Style; //导入依赖的package包/类
public void testStyleDup() throws Exception {
Style style = new CamelCaseStyle();
Format format = new Format(style);
StyleExample example = new StyleExample("a", "b");
Persister persister = new Persister(format);
StringWriter writer = new StringWriter();
persister.write(example, writer);
System.out.println(writer);
StyleExample restored = persister.read(StyleExample.class, writer.toString());
assertEquals(example.a, restored.a);
assertEquals(example.b, restored.b);
}
开发者ID:ngallagher,项目名称:simplexml,代码行数:13,代码来源:PathDuplicateTest.java
注:本文中的org.simpleframework.xml.stream.Style类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论