|
Oracle Fusion Middleware Java API Reference for Oracle ADF Mobile 11g Release 2 (11.1.2.3.0) E27204-01 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object
oracle.adfmf.framework.api.GenericTypeBeanSerializationHelper
public class GenericTypeBeanSerializationHelper
GenericTypeBeanSerializationHelper is a helper class to provide an easy way for application developers to convert between ADFMF internal GenericType
objects and their user defined POJOs. Currently the only place GenericType
objects are exposed are for SOAP Data Controls.
The following rules are used by GenericTypeBeanSerializationHelper
to perform the conversion to and from GenericType
objects:
POJO to GenericType:
GenericType to POJO:
Example: Suppose we have a web service that passes back and forth an Employee element with the following properties:
name
of type Stringaddress
a complex object with street, city, state, and zipcode attributesid
of type longsalary
of type floatphones
of type String and could repeatWhile this type is fairly simple, it is not very convenient to work with as a GenericType. Java developers tend to like have stronger typed objects to use in their code. For sake of argument, lets also say the developer would like to reuse the Employee object throughout their business logic that might also contain an additional property password
that should never be transmitted to the back-end web service. Given that, their Employee object could look something like this:
public class Employee {
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public Address getAddress() { return address; }
public void setAddress(Address address) { this.address = address; }
public long getId() { return id; }
public void setId(long id) { this.id = id; }
public float getSalary() { return salary; }
public void setSalary(float salary) { this.salary = salary; }
public String getPassword() { return password; }
public void setPassword(String password) { this.password = password; }
public String[] getPhone() { return phone; }
public void setPhone(String phone) { this.phone = phone; }
protected String name;
protected Address address;
protected long id;
protected float salary;
protected String[] phone;
protected transient String password;
}
public class Address {
public String getStreet() { return street; }
public void setStreet(String street) { this.street = street; }
public String getCity() { return city; }
public void setCity(String city) { this.city = city; }
public String getState() { return state; }
public void setState(String state) { this.state = state; }
public String getZipcode() { return zipcode; }
public void setZipcode(String state) { this.zipcode = zipcode; }
protected String street;
protected String city;
protected String state;
protected String zipcode;
}
Conversion Notes:
password
is defined as transient so by the conversion rules above, this property is ignored with respect to the conversion algorithm.name, address, id, and salary
will all be converted to and from the GenericType
since they have both getter and setter accessors.address
) that do not have well known coercing rules will simply be recursed by the conversion algorithm to either build the child GenericType
or to create and populate the POJO complex object depending on the direction of the conversion.phone
is an array of strings each representing a unique phone number. Since the cardinality of this element is greater than one, the conversion algorithm will find all matches of the phone
attribute in the GenericType
object and make them into an array and invoke setPhone on the bean. And for the toGenericType
conversion will simply take each array element and append it to the toGenericType
as an individual phone
attribute.Using the following classes:
final String EMPLOYEE_VIRTUAL_BEAN_name="EmployeeDC_Types_Employee";
Employee emp = getEmployee();
GenericType gt = null;
gt = GenericTypeBeanSerializationHelper.toGenericType(EMPLOYEE_VIRTUAL_BEAN_NAME, emp);
or
emp = GenericTypeBeanSerializationHelper.fromGenericType(Employee.class, gt, null);
Best Practices
GenericType
structure fairly closely.GenericType
structure, one of the following strategies are done:
transient
GenericType
objects are exposed are for SOAP Data Controls. These virtual types have an associated virtual bean name that will be passed into the toGenericType
method. The virtual bean name can be obtained by hovering over the virtual type in the Data Controls window of JDeveloper. This is typically in the format <DCName>.Types.<methodName>.<argName>
.GenericType
, Converter.coerceToType(Object,Class)
Method Summary | |
---|---|
static java.lang.Object |
fromGenericType(java.lang.Class beanClass, GenericType gt) Method used to deserialize the passed-in GenericType to Java Bean object. |
static java.lang.Object |
fromGenericType(java.lang.Class beanClass, GenericType gt, java.lang.String attributeName) This method is used to deserialize the passed-in GenericType into a POJO. |
static GenericType |
toGenericType(java.lang.String virtualBeanName, java.lang.Object bean) Method used to serialize the passed in Java object to a GenericType . |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static GenericType toGenericType(java.lang.String virtualBeanName, java.lang.Object bean)
GenericType
. Typical usage is the java developer wants to invoke a web service operation from their application business logic. In this case we need to create the input parameters to pass to the web service operation. To do this we:
<methodName>_parameters.<argName>
that you wish to populate.virtualBeanName
by hovering over the argument name you wish to create, and take note of the value that pops up. This is typically in the format <DCName>.Types.<methodName>.<argName>
.setter
methods populate the objectGenericType
using the toGenericType
method.virtualBeanName
- the name of the Data Control type to convert tobean
- Object to be serializedpublic static java.lang.Object fromGenericType(java.lang.Class beanClass, GenericType gt)
GenericType
to Java Bean object. This is the same as calling fromGenericType(Class beanClass, GenericType gt, String attributeName)
with null for attributeName.beanClass
- Class of the Java Bean to creategt
- GenericType to deserializepublic static java.lang.Object fromGenericType(java.lang.Class beanClass, GenericType gt, java.lang.String attributeName)
GenericType
into a POJO.
The beanClass argument (and any other class referenced as nested properties) must have a public default constructor defined, or class creation will fail.
Typical usage is to create a class that mimics the structure of the return type attempting to be deserialized.
For example, to determine the structure of the returned value for a SOAP DC, go to the Data Controls window and find the structure <methodName>.Return
. This is always the GenericType instance returned from web service calls.
Your bean class should declare properties for any fields in <methodName>.Return
that you wish to populate.
If the method call returns an array, you will need to use the attributeName parameter. If <methodName>.Return.return
is the array you wish to deserialize and is of type int[], then the call would be:
fromGenericType(int[].class, gt, "return");
beanClass
- Class of the Java Bean to creategt
- GenericType to deserializeattributeName
- the name of the attribute on the passed in GenericType that corresponds to the class to create
|
Oracle Fusion Middleware Java API Reference for Oracle ADF Mobile 11g Release 2 (11.1.2.3.0) E27204-01 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |