Click or drag to resize

Mapping Class

Defines the mapping between
  • the representation type names used in a dynamic view type specification and the associated component classes;
  • A user type names used on server side and the associated component classes;
  • the attribute labels used in a dynamic view type specification and attribute modifiers of the component classes.
Inheritance Hierarchy
SystemObject
  RW.Server.ComponentMapping

Namespace:  RW.Server.Component
Assembly:  RW.Server.Component (in RW.Server.Component.dll) Version: 7.2.0.0 (7.2.0.0)
Syntax
public class Mapping

The Mapping type exposes the following members.

Constructors
  NameDescription
Public methodMapping
Initializes a new instance of the Mapping class
Top
Properties
  NameDescription
Public propertyStatic memberIsTraced
Checks if a TextWriter has been set on Trace property.
Public propertyStatic memberTrace
Gets or sets the text writer where mapping trace can be directed.
Top
Methods
  NameDescription
Public methodStatic memberAddAttributeMapper
Adds an attribute mapper to the list of attribute mappers.
Public methodStatic memberAddRepresentationTypeMapper(MappingTypeMapper)
Adds an representation type mapper.
Public methodStatic memberAddRepresentationTypeMapper(String, String)
Adds a representation type mapper for a given namespace and assembly.
Public methodStatic memberAddUserTypeMapper(MappingTypeMapper)
Adds an user type mapper.
Public methodStatic memberAddUserTypeMapper(String, String)
Adds an user type mapper for a given namespace and assembly.
Public methodStatic memberComponentClass
Returns the type of the associated representation class.
Public methodStatic memberCpp
Creates a "C++ like" mapping.
Public methodStatic memberForceIntrospect
Forces the systematic introspection of representation object types.
Public methodStatic memberPropertySetter
Returns an MappingAttributeMapper that converts an attribute name to its .NET property setter according to .NET conventions.
Public methodStatic memberSetCap
Returns an MappingAttributeMapper that converts an attribute name to its Camel-case equivalent.
Top
Remarks

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)) {
     ...
With such a registered MappingTypeMapper, all the classes in Representation namespace, defined by the assembly of the current program will be located automatically.

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");
  }
  ...
}
These declaration functions can be found in the RpObject class. The second manner can be used if you decide to use the same naming convention to determine the modifier associated with a given attribute. In this case, all you have to do is to define an MappingAttributeMapper to specify your naming convention and set this MappingAttributeMapper by using the AddAttributeMapper(MappingAttributeMapper) method:
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)) {
    ...
The naming convention defined by this MappingAttributeMapper is the following: given an attribute named xxx, the associated modifier is the SetXxx method. Since it is a very frequent naming convention, this MappingAttributeMapper is predefined, so the code sample above is therefore equivalent to:
static public void main(String argv[]) {

  Mapping.AttributeMapper(Mapping.SetCap());
  ...
  if (MvProcess.Initialize(argv)) {
     ...
Another common MappingAttributeMapper is defined by PropertySetter which maps the setter of the server attribute "xxxx" to the setter of the .NET property "Xxxx".

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.

See Also