Attribute Types

When you define a new type in Design Studio you select an attribute type for each attribute. Some of these attributes can contain text, like Short text, Long Text, Password, HTML, XML, and when used inside a robot there may be requirements to the text store in these attributes. If you store text in a XML attribute, the text must be a valid XML document. This validation occurs when the type is used inside a robot, but since the API doesn't know the anything about the type it doesn't validate attribute values in the same manner. As a result the API only has 8 attribute types versus the 19 available in Design Studio This table shows the mapping between the API and Design Studio attribute types.

API Attribute Type

Design Studio Attribute Type

Text

Short Text, Long Text, Password, HTML, XML, Properties, Language, Country, Currency, Refind Key

Integer

Integer

Boolean

Boolean

Number

Number

Character

Character

Date

Date

Session

Session

Binary

Binary, Image, PDF

API to Design Studio mapping


The API attribute types are then mapped to Java in the following way.

Attribute Type

Java Class

Text

java.lang.String

Integer

java.lang.Long

Boolean

java.lang.Boolean

Number

java.lang.Double

Character

java.lang.Character

Date

java.util.Date

Session

com.kapowtech.robosuite.api.construct.Session

Binary

com.kapowtech.robosuite.api.construct.Binary

Java types for attributes


The RQlObjectBuilder's setAttribute method is overloaded so you don't need to specify the attribute type explicitly when configuring an attribute through the API, as long as the right java class is used as argument. Here is an example that shows how to set the attributes for an object with all possible (Design Studio) attribute types.


Request request  = new Request("Library:/AllTypes.robot");
RQLObjectBuilder inputBuilder = request.createInputVariable("AllTypes");
inputBuilder.setAttribute("anInt", new Long(42L));
inputBuilder.setAttribute("aNumber", new Double(12.34));
inputBuilder.setAttribute("aBoolean", Boolean.TRUE);
inputBuilder.setAttribute("aCharacter", 'c');
inputBuilder.setAttribute("aShortText", "some text");
inputBuilder.setAttribute("aLongText", "a longer test");
inputBuilder.setAttribute("aPassword", "secret");
inputBuilder.setAttribute("aHTML", "<html>bla</html>");
inputBuilder.setAttribute("anXML", "<tag>text</tag>");
inputBuilder.setAttribute("aDate", new Date());
inputBuilder.setAttribute("aBinary", new Binary("some bytes".getBytes()));
inputBuilder.setAttribute("aPDF", (Binary) null);
inputBuilder.setAttribute("anImage", (Binary) null);
inputBuilder.setAttribute("aProperties", "name=value\nname2=value2");
inputBuilder.setAttribute("aSession", (Session) null);
inputBuilder.setAttribute("aCurrency", "USD");
inputBuilder.setAttribute("aCountry", "US");
inputBuilder.setAttribute("aLanguage", "en");
inputBuilder.setAttribute("aRefindKey", "Never use this a input");

Recommended usage of setAttribute


The above example explicitly uses new Long(42L), and new Double(12.34), although 42L and 12.34 would be sufficient due to auto boxing. Also notice that we have to cast null values, because the Java compiler can't otherwise determine which of the overloaded setAttribute methods we want to call. However since since unconfigured attributes will automatically be null, you never need to set null explicitly.

It is possible to specify the Attribute and AttributeType explicitly when creating input using the API. This is approach is not recommended, but may be needed in rare cases, and would look like this.


Request request  = new Request("Library:/AllTypes.robot");
RQLObjectBuilder inputBuilder = request.createInputVariable("AllTypes");
inputBuilder.setAttribute(new Attribute("anInt", "42", AttributeType.INTEGER));
inputBuilder.setAttribute(new Attribute("aNumber", "12.34", AttributeType.NUMBER));
inputBuilder.setAttribute(new Attribute("aBoolean", "true", AttributeType.BOOLEAN));
inputBuilder.setAttribute(new Attribute("aCharacter", "c", AttributeType.CHARACTER));
inputBuilder.setAttribute(new Attribute("aShortText", "some text", AttributeType.TEXT));
inputBuilder.setAttribute(new Attribute("aLongText", "a longer test", AttributeType.TEXT));
inputBuilder.setAttribute(new Attribute("aPassword", "secret", AttributeType.TEXT));
inputBuilder.setAttribute(new Attribute("aHTML", "<html>bla</html>", AttributeType.TEXT));
inputBuilder.setAttribute(new Attribute("anXML", "<tag>text</tag>", AttributeType.TEXT));
inputBuilder.setAttribute(new Attribute("aDate", "2012-01-15 23:59:59.123", AttributeType.DATE));
inputBuilder.setAttribute(new Attribute("aBinary", Base64Encoder.encode("some bytes".getBytes()), AttributeType.BINARY));
inputBuilder.setAttribute(new Attribute("aPDF", null, AttributeType.BINARY));
inputBuilder.setAttribute(new Attribute("anImage", null, AttributeType.BINARY));
inputBuilder.setAttribute(new Attribute("aProperties", "name=value\nname2=value2", AttributeType.TEXT));
inputBuilder.setAttribute(new Attribute("aSession", null, AttributeType.SESSION));
inputBuilder.setAttribute(new Attribute("aCurrency", "USD", AttributeType.TEXT));
inputBuilder.setAttribute(new Attribute("aCountry", "US", AttributeType.TEXT));
inputBuilder.setAttribute(new Attribute("aLanguage", "en", AttributeType.TEXT));
inputBuilder.setAttribute(new Attribute("aRefindKey", "Never use this a input", AttributeType.TEXT));

Not recommended usage of setAttribute


As we can see all attribute values must be provided in the form of strings. The string values are then converted to the appropriate Java objects based on the Attribute type provided. This is only useful if you build other generic APIs on top of the Kapow Katalyst Java API.