Mapping Class |
Namespace: RW.Server.Component
The Mapping type exposes the following members.
Name | Description | |
---|---|---|
IsTraced |
Checks if a TextWriter has been set on
Trace property.
| |
Trace |
Gets or sets the text writer where mapping trace can be directed.
|
Name | Description | |
---|---|---|
AddAttributeMapper |
Adds an attribute mapper to the list of attribute mappers.
| |
AddRepresentationTypeMapper(MappingTypeMapper) |
Adds an representation type mapper.
| |
AddRepresentationTypeMapper(String, String) |
Adds a representation type mapper for a given namespace and
assembly.
| |
AddUserTypeMapper(MappingTypeMapper) |
Adds an user type mapper.
| |
AddUserTypeMapper(String, String) |
Adds an user type mapper for a given namespace and
assembly.
| |
ComponentClass |
Returns the type of the associated representation class.
| |
Cpp |
Creates a "C++ like" mapping.
| |
ForceIntrospect |
Forces the systematic introspection of representation
object types.
| |
PropertySetter |
Returns an MappingAttributeMapper that converts an
attribute name to its .NET property setter according to .NET
conventions.
| |
SetCap |
Returns an MappingAttributeMapper that converts an
attribute name to its Camel-case equivalent.
|
Representation classes
Let us suppose you have defined a representation object TreeRp in the view specification file. In .NET, the corresponding class will be probably defined in a namespace, in a given assembly. You must be able to indicate which namespace and which assembly: this is the purpose of the MappingTypeMapper delegate. First, you must define an object mapper that specifies your naming conventions.
In the following example, if the name of a representation object is TreeRp in the view specification file, the corresponding class in .NET will be Representation.TreeRp (from the Representation namespace). When loading a class, you must also indicate the assembly the class belongs to. In order to do so, you must add the full assembly name after the class name itself.
Let say the TreeRp class is defined in the program itself, and not in a separate assembly.
Once the type mapper is defined, you must register it by using the AddRepresentationTypeMapper(MappingTypeMapper) method, as follows:
static public void main(string argv[]) { Mapping.AddRepresentationTypeMapper((string orig) => { return "Representation." + orig + ", " + System.Reflection.Assembly.GetExecutingAssembly().FullName; } ); ... if (MvProcess.Initialize(argv)) { ...
Default mapped namespace is the RW.Server.Component namespace (defined in the RW.Server.Component assembly).
You can add several MappingTypeMapper. In this case, Rogue Wave Server tries to locate a bridge class by successively using each declared MappingTypeMapper, in the reverse declaration order, until the class is found. When two representation object classes have the same name in different namespaces, it is your responsibility to remove the ambiguity by prefixing the type name with the name of the namespace in the dynamic view type specification.
The most common mapping have been prefined, so that the above code can be reduced to:
static public void main(String argv[]) { Mapping.AddRepresentationTypeMapper("Representation"); if (MvProcess.Initialize(argv)) { ...
User types
There is a separate mapper list for user types, but it works exactly like the representation type mapper.
Attribute
Suppose a representation object TreeRp has a string attribute named label and you want to associate the SetLabel setter function. It can be done in two ways: The first manner is to use a mechanism based on the C++ approach, which consists in declaring the attribute with its associated modifier. Below is a short example:
public class TreeRp : RpObject { ... public void SetLabel(string s) { _tree.setLabel(s); } static TreeRp() { ILS_RP_ATTR_STRING("TreeRp", "label", "SetLabel"); } ... }
static public void Main(string argv[]) { Mapping.AddAttributeMapper(new AttributeMapper() { public String Get(Type c, String orig) { return "Set" + char.ToUpper(orig[0]) + orig.Substring(1)); } }); ... if (MvProcess.Initialize(argv)) { ...
static public void main(String argv[]) { Mapping.AttributeMapper(Mapping.SetCap()); ... if (MvProcess.Initialize(argv)) { ...
There can be only one MappingAttributeMapper set at a given time: the same MappingAttributeMapper will be used throughout the component life time to determine the names of the modifiers associated with a given attribute.