Sequence

From Apache OpenOffice Wiki
Jump to: navigation, search



A sequence is a homogeneous collection of values of one UNO type with a variable number of elements. Sequences map to arrays in most current language bindings. Although such collections are sometimes implemented as objects with element access methods in UNO (e.g., via the com.sun.star.container.XEnumeration interface), there is also the sequence type, to be used where remote performance matters. Sequences are always written with pointed brackets in the API reference:

  // a sequence of strings is notated as follows in the API reference
  sequence< string > aStringSequence;

In Java, you treat sequences as arrays. (But do not use null for empty sequences, use arrays created via new and with a length of zero instead.) Furthermore, keep in mind that you only create an array of references when creating an array of Java objects, the actual objects are not allocated. Therefore, you must use new to create the array itself, then you must again use new for every single object and assign the new objects to the array. An empty sequence of PropertyValue structs is frequently needed for loadComponentFromURL:

  // create an empty array of PropertyValue structs for loadComponentFromURL
  PropertyValue[] emptyProps = new PropertyValue[0];



A sequence of PropertyValue structs is needed to use loading parameters with loadComponentFromURL(). The possible parameter values for loadComponentFromURL() and the com.sun.star.frame.XStorable interface can be found in the service com.sun.star.document.MediaDescriptor.


  // create an array with one PropertyValue struct for loadComponentFromURL, it contains references only
  PropertyValue[] loadProps = new PropertyValue[1];
 
  // instantiate PropertyValue struct and set its member fields
  PropertyValue asTemplate = new PropertyValue();
  asTemplate.Name = "AsTemplate";
  asTemplate.Value = Boolean.TRUE;
 
  // assign PropertyValue struct to first element in our array of references to PropertyValue structs
  loadProps[0] = asTemplate;
 
  // load calc file as template
  XComponent xSpreadsheetComponent = xComponentLoader.loadComponentFromURL(
    "file:///X:/share/samples/english/spreadsheets/OfficeSharingAssoc.sxc",
    "_blank", 0, loadProps);

In Apache OpenOffice Basic, a simple Dim creates an empty array.

  'OpenOffice Basic
  Dim loadProps()  'empty array

A sequence of structs is created using new together with Dim.

  'OpenOffice Basic
  Dim loadProps(0) as new com.sun.star.beans.PropertyValue 'one PropertyValue

In C++, there is a class template for sequences. An empty sequence can be created by omitting the number of elements required.

  //C++
  Sequence< ::com::sun::star::beans::PropertyValue > loadProps; // empty sequence

If you pass a number of elements, you get an array of the requested length.

  //C++
  Sequence< ::com::sun::star::beans::PropertyValue > loadProps( 1 );
  // the structs are default constructed
  loadProps[0].Name = OUString::createFromAscii( "AsTemplate" );
  loadProps[0].Handle <<= true;
 
  Reference< XComponent > rComponent = rComponentLoader->loadComponentFromURL(
  OUString::createFromAscii("private:factory/swriter"), 
  OUString::createFromAscii("_blank"), 
  0, 
  loadProps);
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages