如果找到了对您有用的资料,烦请点击右手边的Google广告支持我继续共享知识,谢谢! http://dengpeng.spaces.live.com/

2008年7月29日星期二

2008年7月20日星期日

The Procedure of Sending and Receiving Pack On Sun SPOT

The timestamp is the system time when the packet was read in from the radio chip on receives and when the packet was sent on transmits. If you consider all the steps involved in transmitting & receiving a packet things will (hopefully) become clear:

on sending spot:

1. user app packs data to send into a radiogram packet.
2. user app initiates send of packet
3. radio stack checks for route to destination, etc.
4. finally ready to send so write data to radio chip
5. data written, wait for transmission to start
6. record time packet was actually sent
7. user app can now query when transmission occurred

on receiving spot:

1. user app blocks waiting to receive a radiogram
2. radio stack receive thread blocks waiting for interrupt
3. radio receives incoming packet and stores it in fifo buffer
4. Squawk VM responds to radio interrupt and restarts receive thread
5. receive thread reads in radiogram packet from radio's fifo buffer
6. record the current time to mark when packet was received
7. radio stack processes packet and passes it to user app
8. user app does whatever it needs to with packet

As you can see from the many steps a fair amount of time can pass between when a packet is physically received & when the user program finally gets handed the packet (& ditto when sending). The timestamp on the packet is a way to minimize some of this latency.

For most applications the latency doesn't matter, but it's essential for anyone who wants to do a time synchronization protocol in order to have the clocks on several spots all be within a few milliseconds of each other.

--rgoldman

--https://www.sunspotworld.com/forums/viewtopic.php?t=1484

2008年7月19日星期六

Beijing2008, 20 days to GO

Welcom to Beijing music video

As a oversea Chinese, I am so proud! Good luck Beijing!

北京欢迎你!

迎接另一个晨曦,带来全新空气。陈天佳
Let' s embrace another morning and enjoy its ever new air.
Ying jie ling yi ge chen xi, dai lai quan xin kong qi.
气息改变情味不变,茶香飘满情谊。刘欢
With the fragrance of tea, it smells different. But it feels great, full of friendship.
Qi xi gai bian qing wei bu bian, cha xiang tiao man qing yi.
我家大门常打开,开放怀抱等你。那英
Our door is always open. We are waiting for you open-armed.
Wo jia da men chang da kai, kai fang huai bao deng ni.
拥抱过就有了默契,你就会爱上这里。孙燕姿-Stefanie Sun
After a big hug, you'll feel close with us. And surely you will love this place.
Yong bao guo jiu you le mo qi, ni jiu hui ai shang zhe li.
不管远近都是客人,请不用客气。孙悦
Our guests, no matter where you come from, please feel at home.
Bu guan yuan jin dou shi ke ren, qing bu yong ke qi.
相约好了在一起,我们欢迎你。王力宏-Wang Lee Hom
We promised to get together here. So welcome!
Xiang yue hao le zai yi qi, wo men huan ying ni.
我家种着万年青,开放每段传奇。韩红
We cultivate Chinese Evergreen in the garden. All the time, it is producing a new legend.
Wo jia zhong zhe wan nian qing, kai fang mei duan chuan qi.
为传统的土壤播种,为你留下回忆。周华健-Emil Chou
In the soil rich in traditions, we plant. Hope everything we plant here leaves you a great experience.
Wei chuan tong de tu rang bo zhong, wei ni liu xia hui yi.
陌生熟悉都是客人,请不用拘礼。梁咏琪
Our guests, no matter we've met before or not, please feel at ease.
Mo sheng shu xi dou shi ke ren, qing bu yong ju li.
第几次来没关系,有太多话题。羽泉
Even if you have been here for many times, you won't feel bored 'cause we have vast new things for you.
Di ji ci lai mei guan xi, you tai duo hua ti.
北京欢迎你,为你开天辟地。成龙-Jackie Chan
Welcome to Beijing; we've done a lot for your visit.
Bei jing huan ying ni, wei ni kai tian bi di.
流动中的魅力,充满着朝气。任贤齐-Richie Ren
Its charm in ever changing is full of life.
Liu dong zhong de mei li, chong man zhe chao qi.
北京欢迎你,在太阳下分享呼吸。蔡依林-Jolin Tsai
Welcome to Beijing; let's breathe together in the sunshine.
Bei jing huan ying ni, zai tai yang xia fen xiang hu xi.
在黄土地刷新成绩!孙楠
Let's establish new records here in China.
Zai huang tu di shua xin cheng ji.
我家大门常打开,开怀容纳天地。周笔畅
Our door is always open. We are open armed, ready to embrace the world.
Wo jia da men chang da kai, kai huai rong na tian di.
岁月绽放青春笑容,迎接这个日期。韦唯
5000-year-old China is flashing a youthful smile, waiting for the day.
Sui yue zhan fang qing chun xiao rong, huan jie zhe ge re qi.
天大地大都是朋友,请不用客气。黄晓明-Huang Xiao Ming
Our guests, no matter where you come from, please feel at home.
Tian da di da dou shi peng you, qing bu yong ke qi.
画意诗意带笑意,只为等待你。韩庚-Hangeng from Super Junior
We paint pictures and write poems to express the joy for your coming.
Hua yi shi yi dai xiao yi, zhi wei deng dai ni.
北京欢迎你,像音乐感动你。汪峰
Welcome to Beijing; like moving music, our hospitality will warm your heart.
Bei jing huan ying ni, xiang ying yue gan dong ni.
让我们都加油去超越自己。莫文蔚-Karen Mok
Let's try to challenge ourselves.
Rang wo men dou jia you qu chao yue zi ji.
北京欢迎你,有梦想谁都了不起。谭晶
Welcome to Beijing; people who have dreams are all bravo.
Bei jing huan ying ni, you meng xiang shei dou liao bu qi.
有勇气就会有奇迹。陈奕迅
If only you keep the courage, miracles will happen.
You yong qi jiu hui you qi ji.
北京欢迎你,为你开天辟地。阎维文
Welcome to Beijing; we've done a lot for your visit.
Bei jing huan ying ni, wei ni kai tian bi di.
流动中的魅力,充满着朝气。戴玉强
Its charm in ever changing is full of life.
Liu dong zhong de mei li, chong man zhe chao qi.
北京欢迎你,在太阳下分享呼吸。王霞, 李双松
Welcome to Beijing; let's breathe together in the sunshine.
Bei jing huan ying ni, zai tai yang xia fen xiang hu xi.
在黄土地刷新成绩!廖昌永
Let's establish new records here in China.
Zai huang tu di shua xin cheng ji.
北京欢迎你,像音乐感动你。林依轮
Welcome to Beijing; like moving music, our hospitality will warm your heart.
Bei jing huan ying ni, xiang ying yue gan dong ni.
让我们都加油去超越自己。张娜拉
Let's try to challenge ourselves.
Rang wo men dou jia you qu chao yue zi ji.
北京欢迎你,有梦想谁都了不起。林俊杰-JJ Lin
Welcome to Beijing; people who have dreams are all bravo.
Bei jing huan ying ni, you meng xiang shei dou liao bu qi.
有勇气就会有奇迹。阿杜-Ah Du
If only you keep the courage, miracles will happen.
You yong qi jiu hui you qi ji.
我家大门常打开,开放怀抱等你。容祖儿-Joey Yung
Our door is always open. We are waiting for you open-armed.
Wo jia da men chang da kai, kai fang huai bao deng ni.
拥抱过就有了默契,你就会爱上这里。李宇春-Chris Li
After a big hug, you'll feel close with us. And surely you will love this place.
Yong bao guo jiu you le mo qi, ni jiu hui ai shang zhe li.
不管远近都是客人,请不用客气。黄大炜-Huang Da Wei
Our guests, no matter where you come from, please feel at home.
Bu guan yuan jin dou shi ke ren, qing bu yong ke qi.
相约好了在一起,我们欢迎你。陈坤-Chen Kun
We promised to get together here. So welcome!
Xiang yue hao le zai yi qi, wo men huan ying ni.
北京欢迎你,为你开天辟地。谢霆锋-Nicholas Tse
Welcome to Beijing; we've done a lot for your visit.
Bei jing huan ying ni, wei ni kai tian bi di.
流动中的魅力,充满着朝气。韩磊
Its charm in ever changing is full of life.
Liu dong zhong de mei li, chong man zhe chao qi.
北京欢迎你,在太阳下分享呼吸。徐若瑄-Vivian Hsu
Welcome to Beijing; let's breathe together in the sunshine.
Bei jing huan ying ni, zai tai yang xia fen xiang hu xi.
在黄土地刷新成绩!费翔
Let's establish new records here in China.
Zai huang tu di shua xin cheng ji.
我家大门常打开,开怀容纳天地。汤灿
Our door is always open. We are open armed, ready to embrace the world.
Wo jia da men chang da kai, kai huai yi rong na tian di.
岁月绽放青春笑容,迎接这个日期。林志玲-Lin Ci Ling, 张梓琳
5000-year-old China is flashing a youthful smile, waiting for the day.
Sui yue zhan fang qing chun xiao rong, huan jie zhe ge re qi.
天大地大都是朋友,请不用客气。张靓颖
Our guests, no matter where you come from, please feel at home.
Tian da di da dou shi peng you, qing bu yong ke qi.
画意诗意带笑意,只为等待你。许茹芸, 伍思凯
We paint pictures and write poems to express the joy for your coming.
Hua yi shi yi dai xiao yi, zhi wei deng dai ni.
北京欢迎你,像音乐感动你。杨坤, 范玮琪-Fan Wei Qi
Welcome to Beijing; like moving music, our hospitality will warm your heart.
Bei jing huan ying ni, xiang ying yue gan dong ni.
让我们都加油去超越自己。游鸿明, 周晓欧
Let's try to challenge ourselves.
Rang wo men dou jia you qu chao yue zi ji.
北京欢迎你,有梦想谁都了不起。沙宝亮, 满文军
Welcome to Beijing; people who have dreams are all bravo.
Bei jing huan ying ni, you meng xiang shei dou liao bu qi.
有勇气就会有奇迹。金海心, 何润东
If only you keep the courage, miracles will happen.
You yong qi jiu hui you qi ji.
北京欢迎你,为你开天辟地。飞儿-FIR, 庞龙
Welcome to Beijing; we've done a lot for your visit.
Bei jing huan ying ni, wei ni kai tian bi di.
流动中的魅力,充满着朝气。吴克群-Kenji Wu, 齐峰
Its charm in ever changing is full of life.
Liu dong zhong de mei li, chong man zhe chao qi.
北京欢迎你,在太阳下分享呼吸。5566, 胡彦斌-Anson Hu
Welcome to Beijing; let's breathe together in the sunshine.
Bei jing huan ying ni, zai tai yang xia fen xiang hu xi.
在黄土地刷新成绩!郑希怡, 刀郎
Let's establish new records here in China.
Zai huang tu di shua xin cheng ji.
北京欢迎你,像音乐感动你。纪敏加, 屠洪刚, 吴彤
Welcome to Beijing; like moving music, our hospitality will warm your heart.
Bei jing huan ying ni, xiang ying yue gan dong ni.
让我们都加油去超越自己。郭容, 刘耕宏, 腾格尔
Let's try to challenge ourselves.
Rang wo men dou jia you qu chao yue zi ji.
北京欢迎你,有梦想谁都了不起。金莎, 苏醒, 韦嘉
Welcome to Beijing; people who have dreams are all bravo.
Bei jing huan ying ni, you meng xiang shei dou liao bu qi.
有勇气就会有奇迹。付丽珊, 黄征, 房祖明
If only you keep the courage, miracles will happen.
You yong qi jiu hui you qi ji.
北京欢迎你,有梦想谁都了不起。
Welcome to Beijing; people who have dreams are all bravo.
Bei jing huan ying ni, you meng xiang shei dou liao bu qi.
有勇气就会有奇迹。
If only you keep the courage, miracles will happen.
You yong qi jiu hui you qi ji.
北京欢迎你,有梦想谁都了不起。
Welcome to Beijing; people who have dreams are all bravo.
Bei jing huan ying ni, you meng xiang shei dou liao bu qi.
有勇气就会有奇迹!
If only you keep the courage, miracles will happen.
You yong qi jiu hui you qi ji.

2008年7月18日星期五

Simple JAXP Application

The Java API for XML Processing, or JAXP (pronounced jaks-p), is one of the Java XML programming APIs. It provides the capability of validating and parsing XML documents. The three basic parsing interfaces are:

    * the Document Object Model parsing interface or DOM interface
    * the Simple API for XML parsing interface or SAX interface
    * the Streaming API for XML or StAX interface (added in JDK 6; separate jar available for JDK 5)

--http://en.wikipedia.org/wiki/Java_API_for_XML_Processing

This tutorial is based on http://www.vogella.de/articles/JavaXML/article.html

We have two XML files to read in this example. They are:

config.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
<mode>1</mode>
<unit>900</unit>
<current>1</current>
<interactive>1</interactive>
</config>





person.xml



<?xml version="1.0" encoding="UTF-8"?>
<people>
<person>
<firstname>Lars</firstname>
<lastname>Vogel</lastname>
<city>Heidelberg</city>
</person>

<person>
<firstname>Jim</firstname>
<lastname>Knopf</lastname>
<city>Heidelberg</city>
</person>

<person>
<firstname>Lars</firstname>
<lastname>Strangelastname</lastname>
<city>London</city>
</person>

<person>
<firstname>Landerman</firstname>
<lastname>Petrelli</lastname>
<city>Somewhere</city>
</person>

<person>
<firstname>Lars</firstname>
<lastname>Tim</lastname>
<city>SomewhereElse</city>
</person>

</people>


Now, Here below is a simple Java application to read and write and query XML:



/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package hellojaxp;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStream;

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLEventFactory;
import javax.xml.stream.XMLEventWriter;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.Characters;
import javax.xml.stream.events.EndElement;
import javax.xml.stream.events.StartDocument;
import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.XMLEvent;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathFactory;

import org.w3c.dom.Document;
import org.w3c.dom.NodeList;

public class Main {

public static void main(String args[]) {
Main object = new Main();
object.readXML("config.xml");
object.writeXML("config2.xml");
object.query("person.xml", null);
}

public void readXML(String path) {

try {
// First create a new XMLInputFactory
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
// Setup a new eventReader
InputStream in = new FileInputStream(path);
XMLEventReader eventReader = inputFactory.createXMLEventReader(in);
// Read the XML document
while (eventReader.hasNext()) {
XMLEvent event = eventReader.nextEvent();

if (event.isStartElement()) {
if (event.asStartElement().getName().getLocalPart().equals("mode")) {
event = eventReader.nextEvent();
System.out.println(event.asCharacters().getData());
continue;
}
if (event.asStartElement().getName().getLocalPart().equals("unit")) {
event = eventReader.nextEvent();
System.out.println(event.asCharacters().getData());
continue;
}
if (event.asStartElement().getName().getLocalPart().equals("current")) {
event = eventReader.nextEvent();
System.out.println(event.asCharacters().getData());
continue;
}
if (event.asStartElement().getName().getLocalPart().equals("interactive")) {
event = eventReader.nextEvent();
System.out.println(event.asCharacters().getData());
continue;
}
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (XMLStreamException e) {
e.printStackTrace();
}
}

private void createNode(XMLEventWriter eventWriter, String name, String value) {
try {
XMLEventFactory eventFactory = XMLEventFactory.newInstance();
XMLEvent end = eventFactory.createDTD("\n");
XMLEvent tab = eventFactory.createDTD("\t");
// Create Start node
StartElement sElement = eventFactory.createStartElement("", "", name);
eventWriter.add(tab);
eventWriter.add(sElement);
// Create Content
Characters characters = eventFactory.createCharacters(value);
eventWriter.add(characters);
// Create End node
EndElement eElement = eventFactory.createEndElement("", "", name);
eventWriter.add(eElement);
eventWriter.add(end);
} catch (XMLStreamException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}

private void writeXML(String path) {
try {
// Create a XMLOutputFactory
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
// Create XMLEventWriter
XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(new FileOutputStream(path));
// Create a EventFactory
XMLEventFactory eventFactory = XMLEventFactory.newInstance();
XMLEvent end = eventFactory.createDTD("\n");
// Create and write Start Tag
StartDocument startDocument = eventFactory.createStartDocument();
eventWriter.add(startDocument);

// Create config open tag
StartElement configStartElement = eventFactory.createStartElement("", "", "config");
eventWriter.add(configStartElement);
eventWriter.add(end);
// Write the different nodes
createNode(eventWriter, "mode", "1");
createNode(eventWriter, "unit", "901");
createNode(eventWriter, "current", "0");
createNode(eventWriter, "interactive", "0");

eventWriter.add(eventFactory.createEndElement("", "", "config"));
eventWriter.add(end);
eventWriter.add(eventFactory.createEndDocument());
eventWriter.close();
} catch (Exception ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}

private void query(String path, String keyword) {
try {
// Standard of reading a XML file
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder;
Document doc = null;
XPathExpression expr = null;
builder = factory.newDocumentBuilder();
doc = builder.parse(path);

// Create a XPathFactory
XPathFactory xFactory = XPathFactory.newInstance();

// Create a XPath object
XPath xpath = xFactory.newXPath();

// Compile the XPath expression
expr = xpath.compile("//person[firstname='Lars']/lastname/text()");
// Run the query and get a nodeset
Object result = expr.evaluate(doc, XPathConstants.NODESET);

// Cast the result to a DOM NodeList
NodeList nodes = (NodeList) result;
for (int i = 0; i < nodes.getLength(); i++) {
System.out.println(nodes.item(i).getNodeValue());
}

// New XPath expression to get the number of people with name lars
expr = xpath.compile("count(//person[firstname='Lars'])");
// Run the query and get the number of nodes
Double number = (Double) expr.evaluate(doc, XPathConstants.NUMBER);
System.out.println("Number of objects " + number);

// Do we have more then 2 people with name lars?
expr = xpath.compile("count(//person[firstname='Lars']) >2");
// Run the query and get the number of nodes
Boolean check = (Boolean) expr.evaluate(doc, XPathConstants.BOOLEAN);
System.out.println(check);
} catch (Exception ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}
}


You can download this Netbeans project from


http://www.mediafire.com/?mk445c5msi2

2008年7月17日星期四

Simple JAXB Application

Java Architecture for XML Binding (JAXB) allows Java developers to map Java classes to XML representations. JAXB provides two main features: the ability to marshal Java objects into XML and the inverse, i.e. to unmarshal XML back into Java objects. In other words, JAXB allows storing and retrieving data in memory in any XML format, without the need to implement a specific set of XML loading and saving routines for the program's class structure.

JAXB is particularly useful when the specification is complex and changing. In such a case, regularly changing the XML Schema definitions to keep them synchronised with the Java definitions can be time consuming and error prone.

The tool "xjc" can be used to convert XML Schema and other schema file types (as of Java 1.6, RELAX NG and XML DTDs are supported experimentally) to class representations. Classes are marked up using annotations from javax.xml.bind.annotation.* namespace, for example, @XmlRootElement and @XmlElement. XML list sequences are represented by attributes of type java.util.List. Marshallers and Unmarshallers are created through an instance of JAXBContext.

In addition, JAXB includes a "schemagen" tool which can essentially perform the inverse of "xjc", creating an XML Schema from a set of annotated classes.

--http://en.wikipedia.org/wiki/JAXB

country.xsd

<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="country" type="Country"/>
<xs:complexType name="Country">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="population" type="xs:decimal"/>
</xs:sequence>
</xs:complexType>
</xs:schema>





country.xml


<country
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="country.xsd">
<name>France</name>
<population>60144000</population>
</country>





1. Download JAXB from https://jaxb.dev.java.net/


2. Convert XML schema to Java class source file. The command is xjc.bat -package.name sourceXMLSchema.xsd. For example, execute xjc.bat –countries country.xsd, we should get these files:



  • Country.java


  • ObjectFactory.java



3. Create a project in Netbeans, and copy the generated source files to the folder of project source. And do not forget to add the JAXB 2.1 library in project properties.


4. Here below is the source code of main java which shows both read and write XML functions:


/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package simplejaxb;

import countries.Country;
import countries.ObjectFactory;
import java.io.File;
import java.io.FileOutputStream;
import java.math.BigDecimal;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;

/**
*
* @author pdeng
*/

public class Main {

/**
* @param args the command line arguments
*/

public static void main(String[] args) {
// Read and convert a XML file from disk to a Java object in memory
readAndConvert("country.xml");

// Write a Java object in memory to a XML file on disk
writeXML("country2.xml");
}

private static void readAndConvert(String path) {
try {
// Read XML to Java object
JAXBContext jc = JAXBContext.newInstance("countries");
Unmarshaller um = jc.createUnmarshaller();
JAXBElement<Country> countryElement = (JAXBElement<Country>) um.unmarshal(new File(path));
Country c = countryElement.getValue();

//Print out values from Java object
System.out.println(c.getName());
System.out.println(c.getPopulation());
} catch (JAXBException ex) {
ex.printStackTrace();
}
}

private static void writeXML(String path) {
try {
// Create java object and assign values to this object
JAXBContext jaxbContext = JAXBContext.newInstance("countries");
ObjectFactory objFactory = new ObjectFactory();
Country c = objFactory.createCountry();
c.setName("China");
c.setPopulation(BigDecimal.valueOf(130000000));
JAXBElement<Country> countryElement = objFactory.createCountry(c);

// Create instance of marshaller and write object to XML file
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, new Boolean(true));
marshaller.marshal(countryElement, new FileOutputStream(path));
} catch (Exception ex) {
ex.printStackTrace();
}

}
}


5. if you still confuse about how the app works, you can douload the project archieve from http://www.mediafire.com/?zpt74jm5gs2








This is another example which is a bit complex than the one above. We have XML Schema file and a XML file.



books.xsd



<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" jaxb:version="1.0">


<xs:element name="Collection">
<xs:complexType>
<xs:sequence>
<xs:element name ="books">
<xs:complexType>
<xs:sequence>
<xs:element name="book" type="bookType" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:complexType name="bookType">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="ISBN" type="xs:long"/>
<xs:element name="price" type="xs:string"/>
<xs:element name="authors" >
<xs:complexType>
<xs:sequence>
<xs:element name="authorName" type="xs:string" minOccurs="1"
maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="description" type="xs:string" minOccurs="0"/>
<xs:element name="promotion">
<xs:complexType>
<xs:choice>
<xs:element name="Discount" type="xs:string" />
<xs:element name="None" type="xs:string"/>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:element name="publicationDate" type="xs:date"/>
<xs:element name="bookCategory">
<xs:simpleType>
<xs:restriction base="xs:NCName">
<xs:enumeration value="magazine" />
<xs:enumeration value="novel" />
<xs:enumeration value="fiction" />
<xs:enumeration value="other" />
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
<xs:attribute name="itemId" type="xs:string" />
</xs:complexType>



<xs:simpleType name="bookCategoryType" >
<xs:restriction base="xs:string">
<xs:enumeration value="magazine" />
<xs:enumeration value="novel" />
<xs:enumeration value="fiction" />
<xs:enumeration value="other" />
</xs:restriction>
</xs:simpleType>


</xs:schema>





books.xml



<?xml version="1.0"?>
<Collection>
<books>
<book itemId="999">
<name>
Learning JAXB
</name>
<ISBN>
123445
</ISBN>
<price>
34 $
</price>
<authors>
<authorName> Jane Doe
</authorName>
</authors>
<description>
This books contains step by step instructions for beginners so that they can start using Java API for XML Binding.
</description>
<promotion>
<Discount> 10% on this book if purchased by March 2003
</Discount>
</promotion>
<publicationDate>
2003-01-01
</publicationDate>
<bookCategory>other
</bookCategory>
</book>

<book itemId="129">
<name>
Java Webservices today and Beyond
</name>
<ISBN>
522965
</ISBN>
<price>
29 $
</price>
<authors>
<authorName> John Brown
</authorName>
<authorName> Peter T.
</authorName>
</authors>
<description>
This books contains information for users so that they can start using Java Web Services Developer Pack.
</description>
<promotion>
<Discount> Buy one get Learning webservices Part 1 free
</Discount>
</promotion>
<publicationDate>
2002-11-01
</publicationDate>
<bookCategory>magazine
</bookCategory>
</book>
</books>
</Collection>




Follow the same first three steps of previous example. Here below is the source of main.java to read and output a XML file:



/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package hellojaxb;

import books.BookType;
import books.Collection;
import books.Collection.Books;
import books.ObjectFactory;
import java.io.File;
import java.io.FileOutputStream;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;

/**
*
* @author pdeng
*/

public class Main {

/**
* @param args the command line arguments
*/

public static void main(String[] args) {
// Read and convert a XML file from disk to a Java object in memory
readAndConvert("books.xml");

// Write a Java object in memory to a XML file on disk
writeXML("jaxbOutput2.xml");
}

private static void readAndConvert(String path) {
try {
// Read XML to Java object
JAXBContext jc = JAXBContext.newInstance("books");
Unmarshaller um = jc.createUnmarshaller();
Collection col = (Collection) um.unmarshal(new File(path));
Books bt = col.getBooks();
List bl = bt.getBook();

//Print out values from Java object
BookType book = (BookType) bl.get(0);
System.out.println(book.getName());
} catch (JAXBException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}

private static void writeXML(String path) {
try {
// Create java object and assign values to this object
JAXBContext jaxbContext = JAXBContext.newInstance("books");
ObjectFactory objFactory = new ObjectFactory();
Collection collection = (Collection) objFactory.createCollection();
Books booksType = objFactory.createCollectionBooks();
List bookList = booksType.getBook();

// Create one instance of book
BookType book = objFactory.createBookType();
book.setItemId("307");
book.setName("JAXB today and beyond");
book.setDescription("This is an intermediate book on JAXB");
book.setISBN(987665L);
book.setPrice("45$");
//book.setPublicationDate();
book.setBookCategory("other");
BookType.Promotion promotionType = objFactory.createBookTypePromotion();
promotionType.setDiscount("5% off regular price");
book.setPromotion(promotionType);
BookType.Authors authorsType = objFactory.createBookTypeAuthors();
List authorList = authorsType.getAuthorName();
authorList.add("Richard K");
book.setAuthors(authorsType);

bookList.add(book);
collection.setBooks(booksType);

// Create instance of marshaller and write object to XML file
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, new Boolean(true));
marshaller.marshal(collection, new FileOutputStream(path));
} catch (Exception ex) {
ex.printStackTrace();
}
}
}


5. if you still confuse about how the app works, you can douload the project archieve from http://www.mediafire.com/?vm5gy2xrcjd

2008年7月16日星期三

Identify the COM port number and device address of Sun SPOT

Basically, I am using the spotfinder.exe which is a tool provided with Sun SPOT SDK to detect the COM port in use and device adddress of the connected Sun SPOT.
NOTE: Only one SPOT can be detected in this, I would like to change it later.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package simpleexec;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
*
* @author pdeng
*/

public class Main {

/**
* @param args the command line arguments
*/

public static void main(String[] args) {
// TODO code application logic here
int portNumber = spotCOMPort();
System.out.println(portNumber);
String deviceMACAddress = getDeviceMACAddress();
System.out.println(deviceMACAddress);
}

private static String getDeviceMACAddress() {
try {
String rawString = "";
String line;
Process p = Runtime.getRuntime().exec("C:\\Program Files\\Sun\\SunSPOT\\sdk\\bin\\spotfinder.exe -vv");
BufferedReader input =
new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
rawString = rawString + line;
}
input.close();
String rawAddress = String.valueOf(rawString.subSequence(rawString.indexOf("00144F01") + 8, rawString.indexOf("00144F01") + 16));
String MACAddress = "0014.4F01." + rawAddress.substring(0, 4) + "." + rawAddress.substring(4, 8);
return MACAddress;
} catch (Exception err) {
err.printStackTrace();
return "-1";
}
}

private static int spotCOMPort() {
try {
String rawString = "";
String line;
Process p = Runtime.getRuntime().exec("C:\\Program Files\\Sun\\SunSPOT\\sdk\\bin\\spotfinder.exe -vv");
BufferedReader input =
new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
rawString = rawString + line;
//System.out.println(line);
}
input.close();
String comPort = String.valueOf(rawString.subSequence(rawString.indexOf("(COM") + 4, rawString.indexOf(")parsed")));
return Integer.parseInt(comPort);
} catch (Exception err) {
err.printStackTrace();
return -1;
}
}
}

Run SPOT Host application without ant 2

This blog is a supplementary of previous entry: http://pauldeng.blogspot.com/2008/03/run-spot-host-application-without-ant.html

1. Execute ant host-run –v, you should get the print out similar to text below:
Apache Ant version 1.7.1 compiled on June 27 2008
Buildfile: build.xml
Detected Java version: 1.5 in: C:\Program Files\Java\jdk1.5.0_16\jre
Detected OS: Windows XP
parsing buildfile C:\Program Files\Sun\SunSPOT\Demos\TelemetryDemo\Telemetry-onDesktop\build.xml with URI = file:/C:/Program%20Files/Sun/SunSPOT/Demos/TelemetryDemo/Telemetry-onDesktop/build.xml
Project base dir set to: C:\Program Files\Sun\SunSPOT\Demos\TelemetryDemo\Telemetry-onDesktop
[antlib:org.apache.tools.ant] Could not load definitions from resource org/apache/tools/ant/antlib.xml. It could not be found.
[property] Loading C:\Documents and Settings\tkob\.sunspot.properties
Importing file C:\Program Files\Sun\SunSPOT\sdk\build.xml from C:\Program Files\Sun\SunSPOT\Demos\TelemetryDemo\Telemetry-onDesktop\build.xml
parsing buildfile C:\Program Files\Sun\SunSPOT\sdk\build.xml with URI = file:/C:/Program%20Files/Sun/SunSPOT/sdk/build.xml
[property] Loading C:\Documents and Settings\tkob\.sunspot.properties
Override ignored for property "spotselector.basestation.lastport"
Override ignored for property "sunspot.lib"
Override ignored for property "spot.library.name"
Override ignored for property "sunspot.home"
parsing buildfile jar:file:/C:/Program%20Files/Sun/SunSPOT/sdk/ant/ant-contrib.jar!/net/sf/antcontrib/antlib.xml with URI = jar:file:/C:/Program%20Files/Sun/SunSPOT/sdk/ant/ant-contrib.jar!/net/sf/antcontrib/antlib.xml
Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\clean.xml from C:\Program Files\Sun\SunSPOT\sdk\build.xml
parsing buildfile C:\Program Files\Sun\SunSPOT\sdk\ant\clean.xml with URI = file:/C:/Program%20Files/Sun/SunSPOT/sdk/ant/clean.xml
Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\compile.xml from C:\Program Files\Sun\SunSPOT\sdk\build.xml
parsing buildfile C:\Program Files\Sun\SunSPOT\sdk\ant\compile.xml with URI = file:/C:/Program%20Files/Sun/SunSPOT/sdk/ant/compile.xml
Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\find-spots.xml from C:\Program Files\Sun\SunSPOT\sdk\build.xml
parsing buildfile C:\Program Files\Sun\SunSPOT\sdk\ant\find-spots.xml with URI = file:/C:/Program%20Files/Sun/SunSPOT/sdk/ant/find-spots.xml
Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\sysadmin.xml from C:\Program Files\Sun\SunSPOT\sdk\build.xml
parsing buildfile C:\Program Files\Sun\SunSPOT\sdk\ant\sysadmin.xml with URI = file:/C:/Program%20Files/Sun/SunSPOT/sdk/ant/sysadmin.xml
Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\run-spotclient.xml from C:\Program Files\Sun\SunSPOT\sdk\build.xml
parsing buildfile C:\Program Files\Sun\SunSPOT\sdk\ant\run-spotclient.xml with URI = file:/C:/Program%20Files/Sun/SunSPOT/sdk/ant/run-spotclient.xml
Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\find-spots.xml from C:\Program Files\Sun\SunSPOT\sdk\ant\run-spotclient.xml
Skipped already imported file:
C:\Program Files\Sun\SunSPOT\sdk\ant\find-spots.xml

Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\echo.xml from C:\Program Files\Sun\SunSPOT\sdk\build.xml
parsing buildfile C:\Program Files\Sun\SunSPOT\sdk\ant\echo.xml with URI = file:/C:/Program%20Files/Sun/SunSPOT/sdk/ant/echo.xml
Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\find-spots.xml from C:\Program Files\Sun\SunSPOT\sdk\ant\echo.xml
Skipped already imported file:
C:\Program Files\Sun\SunSPOT\sdk\ant\find-spots.xml

Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\debug-proxy.xml from C:\Program Files\Sun\SunSPOT\sdk\build.xml
parsing buildfile C:\Program Files\Sun\SunSPOT\sdk\ant\debug-proxy.xml with URI = file:/C:/Program%20Files/Sun/SunSPOT/sdk/ant/debug-proxy.xml
Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\deploy.xml from C:\Program Files\Sun\SunSPOT\sdk\build.xml
parsing buildfile C:\Program Files\Sun\SunSPOT\sdk\ant\deploy.xml with URI = file:/C:/Program%20Files/Sun/SunSPOT/sdk/ant/deploy.xml
Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\jar-app.xml from C:\Program Files\Sun\SunSPOT\sdk\ant\deploy.xml
parsing buildfile C:\Program Files\Sun\SunSPOT\sdk\ant\jar-app.xml with URI = file:/C:/Program%20Files/Sun/SunSPOT/sdk/ant/jar-app.xml
Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\help.xml from C:\Program Files\Sun\SunSPOT\sdk\build.xml
parsing buildfile C:\Program Files\Sun\SunSPOT\sdk\ant\help.xml with URI = file:/C:/Program%20Files/Sun/SunSPOT/sdk/ant/help.xml
Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\host-compile.xml from C:\Program Files\Sun\SunSPOT\sdk\build.xml
parsing buildfile C:\Program Files\Sun\SunSPOT\sdk\ant\host-compile.xml with URI = file:/C:/Program%20Files/Sun/SunSPOT/sdk/ant/host-compile.xml
Already defined in main or a previous import, ignore -post-host-compile
Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\host-run.xml from C:\Program Files\Sun\SunSPOT\sdk\build.xml
parsing buildfile C:\Program Files\Sun\SunSPOT\sdk\ant\host-run.xml with URI = file:/C:/Program%20Files/Sun/SunSPOT/sdk/ant/host-run.xml
Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\init.xml from C:\Program Files\Sun\SunSPOT\sdk\build.xml
parsing buildfile C:\Program Files\Sun\SunSPOT\sdk\ant\init.xml with URI = file:/C:/Program%20Files/Sun/SunSPOT/sdk/ant/init.xml
Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\library.xml from C:\Program Files\Sun\SunSPOT\sdk\build.xml
parsing buildfile C:\Program Files\Sun\SunSPOT\sdk\ant\library.xml with URI = file:/C:/Program%20Files/Sun/SunSPOT/sdk/ant/library.xml
Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\preverify.xml from C:\Program Files\Sun\SunSPOT\sdk\build.xml
parsing buildfile C:\Program Files\Sun\SunSPOT\sdk\ant\preverify.xml with URI = file:/C:/Program%20Files/Sun/SunSPOT/sdk/ant/preverify.xml
Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\run.xml from C:\Program Files\Sun\SunSPOT\sdk\build.xml
parsing buildfile C:\Program Files\Sun\SunSPOT\sdk\ant\run.xml with URI = file:/C:/Program%20Files/Sun/SunSPOT/sdk/ant/run.xml
Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\suite.xml from C:\Program Files\Sun\SunSPOT\sdk\build.xml
parsing buildfile C:\Program Files\Sun\SunSPOT\sdk\ant\suite.xml with URI = file:/C:/Program%20Files/Sun/SunSPOT/sdk/ant/suite.xml
Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\jar-app.xml from C:\Program Files\Sun\SunSPOT\sdk\build.xml
Skipped already imported file:
C:\Program Files\Sun\SunSPOT\sdk\ant\jar-app.xml

Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\sdk-info.xml from C:\Program Files\Sun\SunSPOT\sdk\build.xml
parsing buildfile C:\Program Files\Sun\SunSPOT\sdk\ant\sdk-info.xml with URI = file:/C:/Program%20Files/Sun/SunSPOT/sdk/ant/sdk-info.xml
Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\upgrade.xml from C:\Program Files\Sun\SunSPOT\sdk\build.xml
parsing buildfile C:\Program Files\Sun\SunSPOT\sdk\ant\upgrade.xml with URI = file:/C:/Program%20Files/Sun/SunSPOT/sdk/ant/upgrade.xml
Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\socket-proxy.xml from C:\Program Files\Sun\SunSPOT\sdk\build.xml
parsing buildfile C:\Program Files\Sun\SunSPOT\sdk\ant\socket-proxy.xml with URI = file:/C:/Program%20Files/Sun/SunSPOT/sdk/ant/socket-proxy.xml
Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\networktools-run.xml from C:\Program Files\Sun\SunSPOT\sdk\build.xml
parsing buildfile C:\Program Files\Sun\SunSPOT\sdk\ant\networktools-run.xml with URI = file:/C:/Program%20Files/Sun/SunSPOT/sdk/ant/networktools-run.xml
Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\spotworld.xml from C:\Program Files\Sun\SunSPOT\sdk\build.xml
parsing buildfile C:\Program Files\Sun\SunSPOT\sdk\ant\spotworld.xml with URI = file:/C:/Program%20Files/Sun/SunSPOT/sdk/ant/spotworld.xml
Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\spotworldextension.xml from C:\Program Files\Sun\SunSPOT\sdk\build.xml
parsing buildfile C:\Program Files\Sun\SunSPOT\sdk\ant\spotworldextension.xml with URI = file:/C:/Program%20Files/Sun/SunSPOT/sdk/ant/spotworldextension.xml
Build sequence for target(s) `host-run' is [-pre-init, -do-init, -post-init, init, -set-selector-for-host-run, -override-warning-find-spots, -prepare-conditions-for-find-spots, -find-shared-basestation, -run-spotfinder, -decide-whether-to-run-spotselector, -run-spotselector, -collect-spotselector-result, -clean-up-spotselector-output-file, -spotselector-fail, -decide-whether-to-start-basestation-manager, -start-new-basestation-manager, -do-find-spots, -pre-host-compile, -do-host-compile, -post-host-compile, host-compile, -pre-host-run, -do-host-run, -post-host-run, host-run]
Complete build sequence is [-pre-init, -do-init, -post-init, init, -set-selector-for-host-run, -override-warning-find-spots, -prepare-conditions-for-find-spots, -find-shared-basestation, -run-spotfinder, -decide-whether-to-run-spotselector, -run-spotselector, -collect-spotselector-result, -clean-up-spotselector-output-file, -spotselector-fail, -decide-whether-to-start-basestation-manager, -start-new-basestation-manager, -do-find-spots, -pre-host-compile, -do-host-compile, -post-host-compile, host-compile, -pre-host-run, -do-host-run, -post-host-run, host-run, -pre-library, -set-properties, -combine-manifests, create-manifest, -do-library-new, -unjar-utility-jar, -pre-compile, -do-compile, -post-compile, compile, preverify.-unjar-utility-jars, library.-combine-manifests, Telemetry-onDesktop.-failIfRemote, library.-append-manifest-contents, deploy.-do-deploy, -find-manifest, -set-jar-name, -check-for-jar, -remote-echo, find-spots.-decide-whether-to-start-basestation-manager, Telemetry-onDesktop.compile, -failIfSerial, getallappsstatus, -do-suite-new, -do-suite-old, suite.-do-suite, hello, run.-pre-run, help.-help, Telemetry-onDesktop.deletepublickey, -do-run, getsleepinfo, Telemetry-onDesktop.selectnothing, -do-debug, debug, Telemetry-onDesktop.debug-run, Telemetry-onDesktop.-set-selector-for-nonbasestation, -check-run-spotclient-parameters, Telemetry-onDesktop.system-properties, run-spotclient.-check-run-spotclient-parameters, jar-app.-pre-jar-app, Telemetry-onDesktop.disableota, -failIfRemote, -do-upgrade, Telemetry-onDesktop.upgrade, compile.-do-compile, -echo-progress-for-local-runs, -post-library, getappstatus, upgrade.-conditionally-deploy-selftest, init.-do-init, jar, SpotWorldExtensions.getallappsstatus, library.-do-library-old, socket-proxy.-set-selector-for-socket-proxy-run, SpotWorldExtensions.startapp, -echo-progress-for-remote-runs, -do-jar-app, deploy.-pre-deploy, startbasestation, suite.-post-suite, compile.-do-compile-single, -set-basestation-sharing, SpotWorldExtensions.stopapp, Telemetry-onDesktop.blink, getsuitemanifest, upgrade.-conditionally-upgrade-pctrlfirmware, find-spots.-run-spotselector, -pre-clean, -do-clean, -post-clean, clean, -pre-preverify, -make-preverify-directory, -unjar-utility-jars, -do-preverify, -post-preverify, preverify, -pre-jar-app, -post-jar-app, jar-app, -pre-suite, -do-suite, -post-suite, Telemetry-onDesktop.suite, preverify.-unjar-utility-jar, -set-selector-for-socket-proxy-run, -pre-socket-proxy-run, -do-socket-proxy-run, -post-socket-proxy-run, Telemetry-onDesktop.socket-proxy, debug-run, -do-debug-proxy-run, -run-spotclient-for-one-remote-id, debug-proxy.-do-debug-proxy-run, spotworldextension-help, socket-proxy, find-spots.-start-new-basestation-manager, resumeapp, delete-system-property, info, Telemetry-onDesktop.slots, Telemetry-onDesktop.settime, javadoc, run-spotclient.-echo-progress-for-local-runs, -pre-debug-proxy-run, -post-debug-proxy-run, Telemetry-onDesktop.debug-proxy, Telemetry-onDesktop.make-host-jar, selectnothing, sysadmin.-pre-sysadmin, disableota, run.-post-run, sysadmin.-post-sysadmin, SpotWorldExtensions.getsuitemanifest, -set-selector-for-nonbasestation, Telemetry-onDesktop.host-run, host-compile.-do-host-compile, -do-networktools-init, suite.-do-suite-old, -run-spotclient-once-with-remote-id, flashconfig, deploy.-post-deploy, echo.-local-echo, -do-library-old, -do-library, library, Telemetry-onDesktop.flashconfig, blink, Telemetry-onDesktop.selectbasestation, host-run.-set-selector-for-host-run, Telemetry-onDesktop.resetfat, selectbasestation, -pre-run, -post-run, run, base, suite, -local-echo, -check-port, echo.-do-echo, -post-sysadmin, Telemetry-onDesktop.library, -do-sdk-info, -pre-sysadmin, -test-ant-version, -unable-to-sysadmin, -really-do-sysadmin, -do-sysadmin, sysadmin, selectdummyapp, jar-app.-do-jar-app, run-spotclient.-run-spotclient-for-one-remote-id, system-properties, -do-deploy, slots, -do-networktools-run, tracert, -do-socket-proxy-gui-run, Telemetry-onDesktop.socket-proxy-gui, SpotWorldExtensions.pauseapp, preverify.-do-preverify, flashbootloader, Telemetry-onDesktop.flashbootloader, run-spotclient.-run-spotclient-once-locally, -post-compile-single, compile.-pre-compile, host-run.-pre-host-run, flashbootstrap, find-spots.-override-warning-find-spots, Telemetry-onDesktop.tracert, -set-flag-for-fork, sdk-info.-do-sdk-info, -pre-compile-single, deletepublickey, Telemetry-onDesktop.selectmeshrouter, SpotWorldExtensions.getpowerstats, -help, run-spotclient.-run-spotclient-once-with-remote-id, host-run.-do-host-run, startapp, Telemetry-onDesktop.debug, find-spots.-run-spotfinder, fork, run.-do-run, debug-proxy.-post-debug-proxy-run, find-spots, host-run.-post-host-run, Telemetry-onDesktop.start-shared-basestation, Telemetry-onDesktop.selectapplication, networktools-run.-do-networktools-run, init.init, suite.-pre-suite, clean.-pre-clean, Telemetry-onDesktop.resetlibrary, Telemetry-onDesktop.preverify, -do-compile-single, socket-proxy.-do-socket-proxy-run, upgrade.-conditionally-upgrade-demosensorboardfirmware, echo.-remote-echo, help, SpotWorldExtensions.spotworldextension-help, preverify.-make-preverify-directory, -conditionally-deploy-selftest, library.-post-library, SpotWorldExtensions.resumeapp, debug-proxy, -set-basestation-not-required, -do-run-spotworld, Telemetry-onDesktop.spotworld, find-spots.-decide-whether-to-run-spotselector, -run-spotclient-multiple-times-with-remote-id, -run-spotclient-once-locally, -run-spotclient-multiple-times-locally, -run-spotclient, socket-proxy.-pre-socket-proxy-run, setserialnumber, networktools-run.-do-networktools-init, Telemetry-onDesktop.setserialnumber, Telemetry-onDesktop.selectdummyapp, echo.-check-port, -check-for-manifest, -pre-deploy, -post-deploy, jar-deploy, Telemetry-onDesktop.deploy, socket-proxy-gui, Telemetry-onDesktop.setpublickey, Telemetry-onDesktop.-set-jar-name, -user-help, clean.-do-clean, Telemetry-onDesktop.-set-basestation-sharing, Telemetry-onDesktop.find-spots, SpotWorld.-do-run-spotworld, Telemetry-onDesktop.sysadmin, debug-proxy.-do-debug, run-spotclient.-run-spotclient-multiple-times-locally, pauseapp, find-spots.-collect-spotselector-result, find-spots.-spotselector-fail, setpublickey, Telemetry-onDesktop.host-compile, find-spots.-prepare-conditions-for-find-spots, Telemetry-onDesktop.flashbootstrap, jar-app.-post-jar-app, compile.-post-compile, selectmeshrouter, Telemetry-onDesktop.clean, init.-post-init, jar-app.-find-manifest, sysadmin.-do-sysadmin, Telemetry-onDesktop.enableota, library.-do-library-new, run-spotclient.-echo-progress-for-remote-runs, sysadmin.-really-do-sysadmin, compile.-post-compile-single, stopapp, selectapplication, flashapp, run.-set-flag-for-fork, library.-do-library, Telemetry-onDesktop.fork, flashvm, -do-echo, echo, make-host-jar, start-shared-basestation, library.create-manifest, preverify.-pre-preverify, socket-proxy.-do-socket-proxy-gui-run, library.-set-properties, help.-user-help, Telemetry-onDesktop.flashvm, sysadmin.-test-ant-version, -conditionally-upgrade-pctrlfirmware, getavailablesuites, getmemorystats, upgrade.-do-upgrade, clean.-post-clean, Telemetry-onDesktop.flashlibrary, compile-single, enableota, Telemetry-onDesktop.help, flashlibrary, suite.-do-suite-new, host-compile.-post-host-compile, deploy.-check-for-jar, upgrade, Telemetry-onDesktop.sdk-info, find-spots.-find-shared-basestation, resetlibrary, -append-manifest-contents, Telemetry-onDesktop.jar-deploy, sdk-info, SpotWorldExtensions.getsleepinfo, run-spotclient.-run-spotclient, SpotWorldExtensions.getmemorystats, compile.-pre-compile-single, sysadmin.-unable-to-sysadmin, deploy.-check-for-manifest, run-spotclient.-run-spotclient-once, preverify.-post-preverify, SpotWorldExtensions.getappstatus, Telemetry-onDesktop.set-system-property, find-spots.-do-find-spots, Telemetry-onDesktop.run, Telemetry-onDesktop.delete-system-property, init.-pre-init, socket-proxy.-post-socket-proxy-run, settime, host-compile.-pre-host-compile, Telemetry-onDesktop.info, Telemetry-onDesktop.-set-basestation-not-required, getpowerstats, Telemetry-onDesktop.startbasestation, set-system-property, find-spots.-clean-up-spotselector-output-file, run-spotclient.-run-spotclient-multiple-times-with-remote-id, library.-pre-library, Telemetry-onDesktop.hello, spotworld, Telemetry-onDesktop.flashapp, Telemetry-onDesktop.echo, -run-spotclient-once, Telemetry-onDesktop.jar-app, Telemetry-onDesktop.-failIfSerial, -conditionally-upgrade-demosensorboardfirmware, deploy, resetfat, debug-proxy-run, Telemetry-onDesktop.debug-proxy-run, debug-proxy.-pre-debug-proxy-run, SpotWorldExtensions.getavailablesuites, , Telemetry-onDesktop.compile-single]

-pre-init:

-do-init:
[property] Loading C:\Program Files\Sun\SunSPOT\Demos\TelemetryDemo\Telemetry-onDesktop\build.properties
[property] Loading C:\Program Files\Sun\SunSPOT\sdk\default.properties
Override ignored for property "sunspot.lib"
Override ignored for property "user.import.paths"
Override ignored for property "main.class"
Override ignored for property "host.java.version"
Override ignored for property "spot.library.name"
Override ignored for property "user.properties.file"
[property] Loading Environment env.
[available] Found: C:\Program Files\Java\jdk1.5.0_16\jre\bin\client\jvm.dll
Override ignored for property "do.set.jvmdll"
Override ignored for property "JVMDLL.KEY"
Override ignored for property "JVMDLL.VALUE"
Property "remoteid" has not been set
Property "remoteID" has not been set

-post-init:

init:

-set-selector-for-host-run:

-override-warning-find-spots:
Skipped because property 'port' not set.

-prepare-conditions-for-find-spots:

-find-shared-basestation:
Skipped because property 'spotselector.findsharedbasestation' not set.

-run-spotfinder:
[exec] Current OS is Windows XP
[exec] Error redirected to property: spotfinder.portlist
[exec] Executing 'C:\Program Files\Sun\SunSPOT\sdk\bin\spotfinder'
[exec] The ' characters around the executable and arguments are
[exec] not part of the command.
Property "basestation.not.required" has not been set

-decide-whether-to-run-spotselector:

-run-spotselector:
Override ignored for property "spottype"
Override ignored for property "querytype"
Property "spotport" has not been set
Override ignored for property "spotselector.preferred.port"
[mkdir] Skipping C:\Program Files\Sun\SunSPOT\sdk\temp because it already exists.
Property "spotclient.verbose" has not been set
[java] Executing 'C:\Program Files\Java\jdk1.5.0_16\jre\bin\java.exe' with arguments:
[java] '-Djava.library.path=C:/Program Files/Sun/SunSPOT/sdk/lib'
[java] '-Dspotselector.inhibit.full.basestation.check=false'
[java] '-Dverbose=${spotclient.verbose}'
[java] '-classpath'
[java] 'C:\Program Files\Sun\SunSPOT\sdk\lib\spotselector.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\multihoplib_rt.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\transducerlib_rt.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\spotworldext_rt.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\spotlib_host.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\spotlib_common.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\squawk_classes.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\RXTXcomm.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\spotclient.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\desktop_signing.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\spotworldext_spotclient.jar;C:\Program Files\Sun\SunSPOT\Demos\TelemetryDemo\Telemetry-onDesktop'
[java] 'com.sun.spot.spotselector.CommandLineSpotSelector'
[java] 'COM7 (00144F0100004BFD)'
[java] '2'
[java] 'COM7'
[java] 'C:\Program Files\Sun\SunSPOT\sdk\temp\spotselector-999496015'
[java]
[java] The ' characters around the executable and arguments are
[java] not part of the command.
[java] Please wait while connected Sun SPOTs are examined...
Property "basestation.not.required" has not been set

-collect-spotselector-result:
[loadfile] loading C:\Program Files\Sun\SunSPOT\sdk\temp\spotselector-999496015 into property port
[loadfile] loaded 4 characters
[echo]
[echo] Using Sun SPOT basestation on port COM7

-clean-up-spotselector-output-file:
[delete] Deleting: C:\Program Files\Sun\SunSPOT\sdk\temp\spotselector-999496015

-spotselector-fail:
Skipped because property 'spotselector.spotselector.failed' not set.

-decide-whether-to-start-basestation-manager:

-start-new-basestation-manager:
Skipped because property 'spotselector.should.start.shared.basestation' not set.

-do-find-spots:
Override ignored for property "port"

-pre-host-compile:

-do-host-compile:
[mkdir] Skipping C:\Program Files\Sun\SunSPOT\Demos\TelemetryDemo\Telemetry-onDesktop\build because it already exists.
[javac] org\sunspotworld\demo\AccelerometerListener.java omitted as C:\Program Files\Sun\SunSPOT\Demos\TelemetryDemo\Telemetry-onDesktop\build\org\sunspotworld\demo\AccelerometerListener.class is up to date.
[javac] org\sunspotworld\demo\GraphView.java omitted as C:\Program Files\Sun\SunSPOT\Demos\TelemetryDemo\Telemetry-onDesktop\build\org\sunspotworld\demo\GraphView.class is up to date.
[javac] org\sunspotworld\demo\PacketTypes.java omitted as C:\Program Files\Sun\SunSPOT\Demos\TelemetryDemo\Telemetry-onDesktop\build\org\sunspotworld\demo\PacketTypes.class is up to date.
[javac] C:\Program Files\Sun\SunSPOT\Demos\TelemetryDemo\Telemetry-onDesktop\src\org\sunspotworld\demo\TelemetryFrame.form skipped - don't know how to handle it
[javac] org\sunspotworld\demo\TelemetryFrame.java omitted as C:\Program Files\Sun\SunSPOT\Demos\TelemetryDemo\Telemetry-onDesktop\build\org\sunspotworld\demo\TelemetryFrame.class is up to date.
[javac] C:\Program Files\Sun\SunSPOT\Demos\TelemetryDemo\Telemetry-onDesktop\src\org\sunspotworld\demo\package.html skipped - don't know how to handle it
[javac] C:\Program Files\Sun\SunSPOT\Demos\TelemetryDemo\Telemetry-onDesktop\src\org\sunspotworld\demo\racecar.gif skipped - don't know how to handle it

-post-host-compile:
[copy] org\sunspotworld\demo\racecar.gif omitted as C:\Program Files\Sun\SunSPOT\Demos\TelemetryDemo\Telemetry-onDesktop\build\org\sunspotworld\demo\racecar.gif is up to date.
[copy] No sources found.

host-compile:

-pre-host-run:

-do-host-run:
[java] Executing 'C:\Program Files\Java\jdk1.5.0_16\jre\bin\java.exe' with arguments:
[java] '-Djava.library.path=C:/Program Files/Sun/SunSPOT/sdk/lib;'
[java] '-DSERIAL_PORT=COM7'
[java] '-Dremote.channel=26'
[java] '-Dremote.pan.id=3'
[java] '-Dspot.mesh.route.logging=false'
[java] '-Dspot.log.connections=true'
[java] '-Dspot.basestation.sharing=false'
[java] '-Dspotclient.addin.classes=com.sun.spot.client.command.spotworld.SpotWorldSpotClientExtension,'
[java] '-classpath'
[java] 'C:\Program Files\Sun\SunSPOT\Demos\TelemetryDemo\Telemetry-onDesktop\build;C:\Program Files\Sun\SunSPOT\sdk\lib\multihoplib_rt.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\transducerlib_rt.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\spotworldext_rt.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\spotlib_host.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\spotlib_common.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\squawk_classes.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\RXTXcomm.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\spotclient.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\desktop_signing.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\spotworldext_spotclient.jar;C:\Program Files\Sun\SunSPOT\Demos\TelemetryDemo\Telemetry-onDesktop'
[java] 'org.sunspotworld.demo.TelemetryFrame'
[java]
[java] The ' characters around the executable and arguments are
[java] not part of the command.
[java] [radiogram] Adding: Server on port 42
[java] [radiogram]Removing: Server on port 42
[java] Accelerometer Reader Thread Started ...
[java] [radiogram] Adding: Broadcast on port 43
[java] [radiogram]Removing: Broadcast on port 43
[java] [radiogram] Adding: Server on port 42
[java] Received request from: 0014.4F01.0000.4D86
[java] [radiogram]Removing: Server on port 42
[java] [radiogram] Adding: Output to 0014.4F01.0000.4D86 on port 43
[java] [radiogram] Adding: Input from 0014.4F01.0000.4D86 on port 43
[java] Accelerometer scale is set to 2G
[java] Accelerometer zero offsets:
[java] 2G: 465.0, 465.0, 465.0
[java] 6G: 465.0, 465.0, 465.0
[java] Accelerometer gains:
[java] 2G: 186.0, 186.0, 186.0
[java] 6G: 62.0, 62.0, 62.0
[java] Accelerometer rest offsets:
[java] 2G: 465.0, 465.0, 651.0
[java] 6G: 465.0, 465.0, 527.0
[java] Accelerometer scale is set to 2G
[java] Accelerometer zero offsets:
[java] 2G: 465.0, 465.0, 465.0
[java] 6G: 465.0, 465.0, 465.0
[java] Accelerometer gains:
[java] 2G: 186.0, 186.0, 186.0
[java] 6G: 62.0, 62.0, 62.0
[java] Accelerometer rest offsets:
[java] 2G: 465.0, 465.0, 651.0
[java] 6G: 465.0, 465.0, 527.0
[java] Accelerometer rest offsets:
[java] 2G: 475.0, 471.0, 638.0
[java] 6G: 468.0, 469.0, 526.0

-post-host-run:

host-run:

BUILD SUCCESSFUL
Total time: 34 seconds

2. Beware of the red text area, it contains key information we need to execute Sun SPOT host side application without ANT. What we need to do is re-construct the parameters to a command. Finally, We get:

java -Djava.library.path="C:/Program Files/Sun/SunSPOT/sdk/lib"; -DSERIAL_PORT=COM7 -Dremote.channel=26 -Dremote.pan.id=3 -Dspot.mesh.route.logging=false -Dspot.log.connections=true -Dspot.basestation.sharing=false -Dspotclient.addin.classes=com.sun.spot.client.command.spotworld.SpotWorldSpotClientExtension, -classpath "C:\Program Files\Sun\SunSPOT\Demos\TelemetryDemo\Telemetry-onDesktop\build;C:\Program Files\Sun\SunSPOT\sdk\lib\multihoplib_rt.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\transducerlib_rt.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\spotworldext_rt.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\spotlib_host.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\spotlib_common.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\squawk_classes.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\RXTXcomm.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\spotclient.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\desktop_signing.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\spotworldext_spotclient.jar;C:\Program Files\Sun\SunSPOT\Demos\TelemetryDemo\Telemetry-onDesktop" org.sunspotworld.demo.TelemetryFrame

3. Or, maybe you want to invoke the application from another Java application. Please use the command below:

"java -Djava.library.path=\"C:/Program Files/Sun/SunSPOT/sdk/lib\"; -DSERIAL_PORT=COM7 -Dremote.channel=26 -Dremote.pan.id=3 -Dspot.mesh.route.logging=false -Dspot.log.connections=true -Dspot.basestation.sharing=false -Dspotclient.addin.classes=com.sun.spot.client.command.spotworld.SpotWorldSpotClientExtension, -classpath \"C:/Program Files/Sun/SunSPOT/Demos/TelemetryDemo/Telemetry-onDesktop/build;C:/Program Files/Sun/SunSPOT/sdk/lib/multihoplib_rt.jar;C:/Program Files/Sun/SunSPOT/sdk/lib/transducerlib_rt.jar;C:/Program Files/Sun/SunSPOT/sdk/lib/spotworldext_rt.jar;C:/Program Files/Sun/SunSPOT/sdk/lib/spotlib_host.jar;C:/Program Files/Sun/SunSPOT/sdk/lib/spotlib_common.jar;C:/Program Files/Sun/SunSPOT/sdk/lib/squawk_classes.jar;C:/Program Files/Sun/SunSPOT/sdk/lib/RXTXcomm.jar;C:/Program Files/Sun/SunSPOT/sdk/lib/spotclient.jar;C:/Program Files/Sun/SunSPOT/sdk/lib/desktop_signing.jar;C:/Program Files/Sun/SunSPOT/sdk/lib/spotworldext_spotclient.jar;C:/Program Files/Sun/SunSPOT/Demos/TelemetryDemo/Telemetry-onDesktop/\" org.sunspotworld.demo.TelemetryFrame"

4. This is the source code of Java invoker which invokes the Sun SPOT host side application without ant:

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package simpleinvoker;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
*
* @author pdeng
*/

public class Main {

/**
* @param args the command line arguments
*/

public static void main(String[] args) {
try {
// TODO code application logic here
String line;
Process p = Runtime.getRuntime().exec("java -Djava.library.path=\"C:/Program Files/Sun/SunSPOT/sdk/lib\"; -DSERIAL_PORT=COM7 -Dremote.channel=26 -Dremote.pan.id=3 -Dspot.mesh.route.logging=false -Dspot.log.connections=true -Dspot.basestation.sharing=false -Dspotclient.addin.classes=com.sun.spot.client.command.spotworld.SpotWorldSpotClientExtension, -classpath \"C:/Program Files/Sun/SunSPOT/Demos/TelemetryDemo/Telemetry-onDesktop/build;C:/Program Files/Sun/SunSPOT/sdk/lib/multihoplib_rt.jar;C:/Program Files/Sun/SunSPOT/sdk/lib/transducerlib_rt.jar;C:/Program Files/Sun/SunSPOT/sdk/lib/spotworldext_rt.jar;C:/Program Files/Sun/SunSPOT/sdk/lib/spotlib_host.jar;C:/Program Files/Sun/SunSPOT/sdk/lib/spotlib_common.jar;C:/Program Files/Sun/SunSPOT/sdk/lib/squawk_classes.jar;C:/Program Files/Sun/SunSPOT/sdk/lib/RXTXcomm.jar;C:/Program Files/Sun/SunSPOT/sdk/lib/spotclient.jar;C:/Program Files/Sun/SunSPOT/sdk/lib/desktop_signing.jar;C:/Program Files/Sun/SunSPOT/sdk/lib/spotworldext_spotclient.jar;C:/Program Files/Sun/SunSPOT/Demos/TelemetryDemo/Telemetry-onDesktop/\" org.sunspotworld.demo.TelemetryFrame");
BufferedReader input =
new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
System.out.println(line);
}
input.close();
} catch (IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}
}