The items and fields related to a table are decided server side by the
MetadataProvider.
When you subscribe a table you're not sending to the server item and field names, but a group name and a schema name.
Usually group and schema names are composed by space-separated item and field names. This special case is handled by the LiteralBasedProvider that is a MetadataProvider implementation distributed with the server.
If you implement your own MetadataProvider class (maybe extending an existing one)
you can completely change this logic implementing two methods:
getItemsand
getSchema.
Look the following example. I will use "ALL" as group name and I will be returned with the 30 items of the StockListDemo.
First I change the adapters.xml file of the classic StockListDemo as follows (note that the only difference is the metadata_provider class name:
[syntax="XML"]<?xml version="1.0"?>
<adapters_conf id="STOCKLISTDEMO">
<metadata_provider>
<adapter_class>com.lightstreamer.meta.allmeta.AllMetaExample</adapter_class>
<param name="item_family_1">item.*</param>
<param name="modes_for_item_family_1">MERGE</param>
</metadata_provider>
<data_provider>
<adapter_class>com.lightstreamer.adapters.stocklist_demo.DemoDataAdapter</adapter_class>
</data_provider>
</adapters_conf>
[/syntax]
This is the AllMetaExampleimplementation:
[syntax="JAVA"]
package com.lightstreamer.meta.allmeta;
import com.lightstreamer.adapters.metadata.LiteralBasedProvider;
public class AllMetaExample extends LiteralBasedProvider {
private static String[] completeList = new String[30];
static {
for (int i = 0; i < 30; i++) {
completeList
= "item" + (i+1);
}
}
public AllMetaExample() {
super();
}
public String[] getItems(String user, String groupName) {
if (groupName.equals("ALL")) {
return completeList;
} else {
//other logic to handle different group names
return null;
}
}
}
[/syntax]
and finally a simple client:
[syntax="HTML"]<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Lightstreamer StockList Demo</title>
<script language="JavaScript" src="/LS/lscommons.js"></script>
<script language="JavaScript" src="/LS/lspushpage.js"></script>
<link rel="stylesheet" type="text/css" href="css/table.css" />
</head>
<body>
<table cellspacing="0" cellpadding="10" border="0" >
<script>
for (var i = 1; i <= 30; i++) {
var suff = (i % 2 == 1) ? "A" : "B";
document.write('<tr class="lscold'+suff+'">');
document.write('<td nowrap style="text-align: left"><div class="stockname'+suff+'" source="lightstreamer" table="1" item="'+i+'" field="stock_name">Loading...</div></td>');
document.write('<td><div source="lightstreamer" table="1" item="'+i+'" field="time">-</div></td>');
document.write('<td><div source="lightstreamer" table="1" item="'+i+'" field="last_price">-</div></td>');
document.write('</tr>');
}
</script>
</table>
<script>
/////////////////PushPage Configuration
var lsPage = new PushPage();
var debugAlerts = false;
var remoteAlerts = false;
var pushHost = null;
var pushPort = null;
var useDomain = null;
lsPage.context.setDomain(useDomain);
lsPage.context.setDebugAlertsOnClientError(debugAlerts);
lsPage.context.setRemoteAlertsOnClientError(remoteAlerts);
lsPage.onEngineCreation = function(lsEngine) {
lsEngine.context.setDebugAlertsOnClientError(debugAlerts);
lsEngine.context.setRemoteAlertsOnClientError(remoteAlerts);
lsEngine.connection.setLSHost(pushHost);
lsEngine.connection.setLSPort(pushPort);
lsEngine.connection.setAdapterName("STOCKLISTDEMO");
lsEngine.changeStatus("STREAMING");
}
lsPage.bind();
lsPage.createEngine("SLEngine","/LS/","NEW_SESSION");
///////////////////////Table configuration
var allTable = new OverwriteTable("ALL", null, "MERGE");
allTable.setSnapshotRequired(true);
lsPage.addTable(allTable, "1");
</script>
</body>
</html>
[/syntax]
Note that once you give to the Table constructor a String instead of an Array (as in this case) you can't no more acces items by name but you must handle item indexes.
Some useful links:
http://www.lightstreamer.com/docs/client_web_jsdoc/Table.html#Table()
http://www.lightstreamer.com/docs/client_web_jsdoc/UpdateItemInfo.html
http://www.lightstreamer.com/vb/showthread.php?t=49&highlight=LiteralBasedProvider
Please check the FileBasedProvider before starting implement your own MetadataProvider. Maybe it already fit your needs.
Hope that helps.