以下转载自[url]http://simple.sourceforge.net/download/stream/doc/examples/examples.php[/url]
This page provides a series of examples illustrating how a class can be annotated. It acts as a quick and dirty overview of how the framework can be used and also acts as a reference page. All examples can be downloaded for convenience. For further information take a look at the Tutorial.
1 Creating nested path elements
Here an example of how to use the Path annotation to create nested elements and attributes using a single annotated class. Below is an example showing two elements nested within a XPath expression.
@Root public class Example {
@Path("a/b[1]") @Element private String x;
@Path("a/b[2]") @Element private String y; }
The below snippet shows an example of the resulting XML that can be generated by this class.
This example can be downloaded from here.
2 Dynamically selecting an element name
Here an example of how to use the ElementUnion annotation to specify a list of options to use for serialization. The union annotation pairs an element name with a type, this allows the element name to dictate selection of the type deserialized and also allows a known type to be serialized with a specific element name.
The below snippet shows an example of the resulting XML, here because the object value was an integer the resulting XML element is called int.
12
This example can be downloaded from here.
3 Constructor injection
Constructor injection can be performed with any number of arguments using any of the XML annotations. In this example the Element annotation is used to identify two values to be injected in to a specific constructor.
@Root public class Point {
@Element private final int x;
@Element private final int y;
public Point(@Element(name="x") int x, @Element(name="y") int y) { this.x = x; this.y = y; } }
The below snippet shows an example of the resulting XML, both the x and y values will be injected in to the annotated constructor.
10 4
This example can be downloaded from here.
4 Constructor injection with nested path elements
In this example constructor injection is performed on two elements which also have Path annotations. As can be seen if there is no ambiguity there is no need to specify the path annotations on the constructor. This reduces the clutter that can occur with excessive annotations.
@Root public class Point {
@Path("a/b[1]") @Element private final int x;
@Path("a/b[1]") @Element private final int y;
public Point(@Element(name="x") int x, @Element(name="y") int y) { this.x = x; this.y = y; } }
The below snippet shows an example of the resulting XML, both the x and y values will be injected in to the annotated constructor.
This example can be downloaded from here.
5 Using namespaces
Below is an example of how to use namespaces with the Namespace annotation. Here two namespaces are declared without a prefix, this means they belong to the default namespace.
This example can be downloaded from here.
6 Declaring a namespace prefix
When using the Namespace annotation a prefix can be specified. This prefix is added to the qualified XML elements to ensure they are within a specific namespace, rather than the default namespace.
The resulting XML shows that both elements contain the namespace prefix declared in the annotation.
foo bar
This example can be downloaded from here.
7 Namespace prefix inheritance
Here a class level namespace is declared using the Namespace annotation. The element declared with the same namespace reference does not need to declare a prefix as it will be inherited from the class level annotation.
@Root @Namespace(prefix="ns1", reference="http://www.blah.com/ns/a") public class Example {
As can be seen in the resulting XML the namespace is declared only once, the child element inherits the original prefix reducing the verbosity of the XML.
This example can be downloaded from here.
8 Default serialization
This example shows how the Default annotation can be used. When this annotation is used fields will be serialized without the need for annotations.
@Default public class Example {
private List a; private String b; private String c; private Date d;
}
As can be seen in the resulting XML is generated for all fields within the class.
This example can be downloaded from here.
9 Default serialization of properties
This example shows how the Default annotation can be configured to use bean methods instead of fields for serialization. When used in this manner all methods that follow the Java Bean naming conventions will be considered for serialization.
@Default(DefaultType.PROPERTY) public class Example {
private String name;
public String getName() { return name; }
public void setName(String name) { this.name = name; }
}
As can be seen in the resulting XML is generated for the Java Bean method.
John Doe
This example can be downloaded from here.
10 Collecting various types in a single list
Here an example of how to use the ElementListUnion can be seen. This annotation allows a number of types to be declared to match a single list, all elements that match the declared names will be gathered in to the list.
The below snippet shows an example of the resulting XML, each type is given a name according to its type.
12 2012-22-05 1977-18-11 blah 1 34525 2001-01-05
This example can be downloaded from here.
11 Dynamically matching a constructor
Here an example of how to use the ElementUnion to dynamically select a constructor based on the value deserialized. Constructor matching will be done by examining the declared name and the instance type.
public Example(@Element(name="int") int value) { this.value = value; }
public Example(@Element(name="date") Date value) { this.value = value; }
public Example(@Element(name="text") String value) { this.value = value; } }
The below snippet shows an example of the resulting XML, here the constructor accepting a date will be invoked as that is what is deserialized from the file.
访问权限是java中一个比较中要的知识点,它规定者什么方法可以访问,什么不可以访问
一:包访问权限;
自定义包:
package com.wj.control;
//包
public class Demo {
//定义一个无参的方法
public void DemoPackage(){
System.out.println("调用
用户自定义聚合函数,用户提供的多个入参通过聚合计算(求和、求最大值、求最小值)得到一个聚合计算结果的函数。
问题:UDF也可以提供输入多个参数然后输出一个结果的运算,比如加法运算add(3,5),add这个UDF需要实现UDF的evaluate方法,那么UDF和UDAF的实质分别究竟是什么?
Double evaluate(Double a, Double b)
在利用tomcat-redis-session-manager做session同步时,遇到了在session保存一个自定义对象时,修改该对象中的某个属性,session未进行序列化,属性没有被存储到redis中。 在 tomcat-redis-session-manager的github上有如下说明: Session Change Tracking
As noted in the &qu
关于Table Driven Approach的一篇非常好的文章:
http://www.codeproject.com/Articles/42732/Table-driven-Approach
package com.ljn.base;
import java.util.Random;
public class TableDriven {
public