| Flex 2 Developer's Guide > Data Access and Interconnectivity > Distributing Data in Flex Applications > Mapping client-side objects to Java objects | |||
To represent a server-side Java object in a client application, you use the [RemoteClass(alias=" ")] metadata tag to create an ActionScript object that maps directly to the Java object. You specify the fully qualified class name of the Java class as the value of alias. This is the same technique that you use to map to Java objects when using RemoteObject components.
You can use the [RemoteClass] metadata tag without an alias if you do not map to a Java object on the server, but you do send back your object type from the server. Your ActionScript object is serialized to a Map object when it is sent to the server, but the object returned from the server to the clients is your original ActionScript type.
To create a managed association between client-side and server-side objects, you also use the [Managed] metadata tag or explicitly implement the mx.data.IManaged interface.
The CRM application that is included in the Flex Data Services sample applications provides a good example of a managed association. The following example shows the source code for the client-side ActionScript Company class. which has a managed association with the server-side Java Company class:
package samples.crm
{
import mx.collections.ArrayCollection;
[Managed]
[RemoteClass(alias="samples.crm.Company")]
public class Company
{
public var companyId:int;
public var name:String = "";
public var address:String = "";
public var city:String = "";
public var state:String = "";
public var zip:String = "";
public var industry:String = "";
public function Company()
{
}
}
}
The following example shows the source code for the corresponding server-side Java Company class:
package samples.crm;
import java.util.Set;
public class Company
{
private int companyId;
private String name;
private String address;
private String city;
private String zip;
private String state;
private String industry;
public String getAddress()
{
return address;
}
public void setAddress(String address)
{
this.address = address;
}
public String getCity()
{
return city;
}
public void setCity(String city)
{
this.city = city;
}
public int getCompanyId()
{
return companyId;
}
public void setCompanyId(int companyId)
{
this.companyId = companyId;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String getState()
{
return state;
}
public void setState(String state)
{
this.state = state;
}
public String getZip()
{
return zip;
}
public void setZip(String zip)
{
this.zip = zip;
}
public String getIndustry()
{
return this.industry;
}
public void setIndustry(String industry)
{
this.industry = industry;
}
public String toString()
{
return "Company(companyId=" + companyId + ", name=" + name + ", address=" + address +
", state" + state + ", zip=" + zip + " industry=" + industry + ")";
}
}
Flex 2.01