Show TOC

Procedure documentationSetting Smart Aliases Locate this document in the navigation structure

 

The data model you use to write rules are based on either Java classes or XML schemas. The aliases are generated for the members of the model from Java classes or XML schemas. These aliases may not be user friendly. You can manually assign meaningful names to aliases by manually renaming each alias. However this can be tedious.

By setting smart aliases you can automatically generate meaningful alias names using annotations in Java classes and XML schemas.

Prerequisites

Configuring Smart Aliases
  1. In SAP NetWeaver Developer Studio, choose   Window   Preferences  

  2. In the dialog box that appears, on the left hand side, expand the Rules Composer node, the Smart Aliases node.

    You should see the Java and XSD options under the Smart Aliases node.

To use Java annotations for aliases
  1. Choose the Java option.

  2. In the screen that appears, select the Use Java Annotations for Aliases checkbox.

  3. Enter the class name and alias name method in the relevant fields.

    Example Example

    Annotation Class Name = com.sap.annotation.MyAlias

    Annotation Alias Name Method = aliasName for the following example.

    Annotation Class:

    package com.sap.annotaion;

    @RetentionPolicy(RetentionPolicy.RUNTIME)

    public @interface MyAlias {

    String aliasName();

    Sample Class:

    package com.sap.sample;

    @MyAlias(aliasName="Employee Object")

    public class Employee {

    private String name;

    @MyAlias(aliasName="Employee's Global Id")

    public String GLOBAL_ID = "I047312";

    @MyAlias(aliasName="New Employee")

    public Employee(){

    }

    @MyAlias(aliasName="Employee's Name")

    public String getName() {

    return name;

    }

    }

    End of the example.
  4. Select the Use Pattern checkbox and enter valid patterns in the text box.

    Note Note

    Examples of few valid patterns:

    • {MemberName} of {ClassName}

    • A {ClassName} has a {PropertyName}

    • {ClassName}.{MemberName} (This is similar to default aliases)

    Keywords

    {PropertyName} is a place holder for properties. The property names are derived from the member names of the class.

    {ClassName} is a place holder for Java class name or Definition name.

    {MemberName} is a place holder for properties. The property names are derived from the member names of the class.

    End of the note.

Note Note

  • Set Smart Aliases button is disabled (and are not generated) for the following classes.

    • com.sap.brms.pubutils.FunctionsUtil

    • com.sap.brms.pubutils.TimeUnit

  • If you select both Use Java Annotations for Aliases and Use Pattern checkboxes, Java annotations will be first considered for generating aliases. In case there are some issues with annotations, patterns will be considered. If the issue persists, the default aliases will remain unchanged.

End of the note.
To use XSD annotations as aliases
  1. Select the Use XSD Annotations as Aliases checkbox

  2. In the Read XSD Annotation as section. do one of the following:

    • Choose Attribute and enter the attribute name in the relevant field.

      Example Example

      Attribute Name = aliasname for the following sample schema:

      http://www.w3.org/2001/XMLSchema

      xmlns:ns4="http://demo.sap.com/samples"

      xmlns="xmlsc.xsd" targetNamespace="xmlsc.xsd"

      elementFormDefault="qualified" attributeFormDefault="qualified">

      <xsd:element name="students" type="studentsType"/>

      <xsd:complexType name="studentsType"/>

      <xsd:sequence maxOccurs="unbounded">

      <xsd:element name="student" type="studentType" />

      </xsd:sequence>

      </xsd:complexType>

      <xsd:complexType name="studentType">

      <xsd:sequence>

      <xsd:element name="rollNo" type="xsd string">

      <xsd:annotation>

      <xsd:appinfo ns4:aliasname=Student Roll Number />

      </xsd:annotation>

      </xsd:element>

      </xsd:sequence>

      </xsd:complexType>

      </xsd:schema>

      End of the example.
    • Choose Element with “source” URI and enter a valid source URI in the relevant field.

      Example Example

      Source URI = com.sap.brms.alias for the following sample schema:

      http://www.w3.org/2001/XMLSchema

      xmlns:ns4="http://demo.sap.com/samples"

      xmlns="xmlsc.xsd" targetNamespace="xmlsc.xsd"

      elementFormDefault="qualified" attributeFormDefault="qualified">

      <xsd:element name="students" type="studentsType"/>

      <xsd:complexType name="studentsType">

      <xsd:sequence maxOccurs="unbounded">

      <xsd:element name="student" type="studentType"/>

      </xsd:sequence>

      </xsd:complexType>

      <xsd:complexType name="studentType">

      <xsd:sequence>

      <xsd:element name="rollNo" type="xsd string">

      <xsd:annotation>

      <xsd:appinfo source="com.sap.brms.alias">

      Student Roll Number

      </xsd:appinfo>

      </xsd:annotation>

      </xsd:element>

      </xsd:sequence>

      </xsd:complexType>

      </xsd:schema>

      End of the example.
    • Choose Element without “source” URI .

      Example Example

      Sample XSD Element with annotation defined as an attribute without source URI:

      <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns4="http://demo.sap.com/samples" xmlns="xmlsc.xsd" targetNamespace="xmlsc.xsd" elementFormDefault="qualified" attributeFormDefault="qualified">

      <xsd:element name="students" type="studentsType" />

      <xsd:complexType name="studentsType">

      <xsd:sequence maxOccurs="unbounded">

      <xsd:element name="student" type="studentType" />

      </xsd:sequence>

      </xsd:complexType>

      <xsd:complexType name="studentType">

      <xsd:sequence>

      <xsd:annotation>

      <xsd:appinfo>

      Student Roll Number

      </xsd:appinfo>

      </xsd:annotation>

      </xsd:element>

      </xsd:sequence>

      </xsd:complexType>

      </xsd:schema>

      End of the example.

Procedure

  1. Locate the Project Resources node (Where is the Project Resources node?) and double-click the node.

  2. In the Project Resources editor, choose the Aliases tab.

  3. In the aliases editor, choose the Java Class or XSD element for which you have set preferences.

  4. Choose the Set Smart Aliases button.

    In the dialog box that appears you should see the generated smart alias names.

    Note Note

    You can also manually edit the alias names in the dialog box.

    End of the note.
  5. Choose Finish.

    You should see the existing alias names get replaced with the smart alias names.

    Note Note

    • The alias names do not get replaced with smart alias names when:

      • The pattern name is wrong or invalid

      • The method in annotation is inaccurate

      • The class name or method name in the annotation is empty

    • Once the smart aliases are generated you cannot revert to default aliases name directly

    • You need to either manually edit each of the aliases or reload the class or XSD

    End of the note.