ok … foi no link ai , li o que tinha lá ( falando sobre um tal de RFID Anywhere , que pelo o que eu intendi , é um software ou bibliotecas , não sei direito … ) baixei o exemplo que tem lá … mas quando vou compilar não roda …
diz lá no site que não precisa ter nenhum hardware pra rodar o programa … mas mesmo assim não rodou …
as classes são :
XMLAssentManager.java
[code]
package com.jeffhanson.apps.rfid;
import java.util.LinkedList;
import java.util.ListIterator;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.DefaultHandler;
public class XMLAssetManager extends DefaultHandler
{
private RFID_ALE_Demo app ;
private Asset curAsset;
private LinkedList tagHierarchy;
boolean isAdding;
public XMLAssetManager(RFID_ALE_Demo app)
{
tagHierarchy = new LinkedList();
isAdding = false;
curAsset = new Asset();
this.app = app;
}
public void error(SAXParseException e)
throws SAXException
{
app.setStatusText(“Error parsing XML: (” + e.getLineNumber()
+ “,” + e.getColumnNumber() + “)”);
}
public void fatalError(SAXParseException e)
throws SAXException
{
app.setStatusText(“Error parsing XML: (” + e.getLineNumber()
+ “,” + e.getColumnNumber() + “)”);
}
public void startElement(String uri,
String name,
String qName,
Attributes atts)
{
tagHierarchy.add(qName);
}
public void endElement(String uri, String name, String qName)
{
tagHierarchy.removeLast();
}
public void characters(char ch[], int start, int length)
{
char data[] = new char[length];
System.arraycopy(ch, start, data, 0, length);
String strData = new String(data);
processTagData(strData);
}
public void processTagData(String strData)
{
ListIterator iterator = tagHierarchy.listIterator();
String curItem = null;
while (iterator.hasNext())
{
curItem = iterator.next();
if (curItem.equals("TagObserved"))
{
isAdding = true;
}
else if (curItem.equals("TagLost"))
{
isAdding = false;
}
else if (curItem.equals("ID"))
{
curAsset.setID(strData);
}
else if (curItem.equals("Company"))
{
curAsset.setCompany(strData);
}
else if (curItem.equals("SKU"))
{
curAsset.setSKU(strData);
}
else if (curItem.equals("Source"))
{
curAsset.setSource(strData);
}
// check to see if the asset is ready to be added
if (curAsset.getID().length() > 0 &&
curAsset.getCompany().length() > 0 &&
curAsset.getSKU().length() > 0 &&
curAsset.getSource().length() > 0)
{
if (isAdding)
{
app.addAssetToList(curAsset);
}
else
{
app.removeAssetFromList(curAsset);
}
curAsset = new Asset();
}
app.setStatusText(curItem);
app.setStatusText("->");
}
app.setStatusText(strData);
}
}[/code]
RFID_ALE_Demo.java
[code]
package com.jeffhanson.apps.rfid;
import java.awt.*;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import javax.swing.DefaultListModel;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.UIManager;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;
public class RFID_ALE_Demo extends javax.swing.JFrame
implements Runnable
{
private javax.swing.JPanel mainPanel;
private javax.swing.JPanel labelPanel;
private javax.swing.JPanel locationDataPanel;
private javax.swing.JPanel messagesPanel;
private javax.swing.JLabel loadingDocDoorLbl;
private javax.swing.JList loadingDocDoorList;
private javax.swing.JScrollPane loadingDocDoorScrollPane;
private javax.swing.JLabel storageCabinetLbl;
private javax.swing.JList storageCabinetList;
private javax.swing.JScrollPane storageCabinetScrollPane;
private javax.swing.JLabel lblStatus;
private int port;
private ServerSocket serverSocket;
private boolean isListening;
private Thread listenerThread;
private XMLAssetManager contentHandler;
/**
* @param args the command line arguments
*/
public static void main(String args[])
{
try
{
UIManager.setLookAndFeel(
UIManager.getSystemLookAndFeelClassName());
}
catch (Exception e)
{
System.err.println(“Error setting look and feel.”);
e.printStackTrace();
}
java.awt.EventQueue.invokeLater(new Runnable()
{
public void run()
{
RFID_ALE_Demo app = new RFID_ALE_Demo();
app.setSize(800, 600);
app.setVisible(true);
}
});
}
/**
* Creates new form RFID_ALE_Demo
*/
public RFID_ALE_Demo()
{
port = 10001;
isListening = true;
contentHandler = new XMLAssetManager(this);
initGUIComponents();
loadConfiguration();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Asset testAsset = new Asset("id", "company", "sku");
//Asset testAsset2 = new Asset("id2", "company2", "sku2");
listenerThread = new Thread(this);
listenerThread.start();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
/**
* This method is called from within the constructor to
* initialize the GUI components.
*/
private void initGUIComponents()
{
setTitle(“RFID ALE Demo”);
setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
mainPanel = new javax.swing.JPanel();
labelPanel = new javax.swing.JPanel();
locationDataPanel = new javax.swing.JPanel();
messagesPanel = new javax.swing.JPanel();
loadingDocDoorLbl = new javax.swing.JLabel();
loadingDocDoorScrollPane = new javax.swing.JScrollPane();
loadingDocDoorList = new javax.swing.JList();
storageCabinetLbl = new javax.swing.JLabel();
storageCabinetScrollPane = new javax.swing.JScrollPane();
storageCabinetList = new javax.swing.JList();
lblStatus = new javax.swing.JLabel();
labelPanel.setLayout(new FlowLayout());
labelPanel.setPreferredSize(new Dimension(780, 30));
labelPanel.setSize(new Dimension(780, 30));
loadingDocDoorLbl.setPreferredSize(new Dimension(385, 22));
loadingDocDoorLbl.setSize(new Dimension(385, 22));
storageCabinetLbl.setPreferredSize(new Dimension(385, 22));
storageCabinetLbl.setSize(new Dimension(385, 22));
labelPanel.add(loadingDocDoorLbl);
labelPanel.add(storageCabinetLbl);
locationDataPanel.setLayout(new FlowLayout());
locationDataPanel.setPreferredSize(new Dimension(780, 480));
locationDataPanel.setSize(new Dimension(780, 480));
locationDataPanel.setBorder(
javax.swing.BorderFactory.createTitledBorder("Location Data"));
loadingDocDoorList.setModel(new DefaultListModel());
loadingDocDoorScrollPane.setPreferredSize(new Dimension(375, 440));
loadingDocDoorScrollPane.setSize(new Dimension(375, 440));
loadingDocDoorScrollPane.setViewportView(loadingDocDoorList);
locationDataPanel.add(loadingDocDoorScrollPane);
storageCabinetList.setModel(new DefaultListModel());
storageCabinetScrollPane.setPreferredSize(new Dimension(375, 440));
storageCabinetScrollPane.setSize(new Dimension(375, 440));
storageCabinetScrollPane.setViewportView(storageCabinetList);
locationDataPanel.add(storageCabinetScrollPane);
mainPanel.setPreferredSize(new Dimension(800, 600));
mainPanel.setSize(new Dimension(800, 600));
mainPanel.setLayout(new FlowLayout());
mainPanel.add(labelPanel);
mainPanel.add(locationDataPanel);
messagesPanel.setBorder(
javax.swing.BorderFactory.createTitledBorder("Messages"));
FlowLayout layout = new FlowLayout();
layout.setHgap(4);
layout.setVgap(-8);
messagesPanel.setLayout(layout);
messagesPanel.setPreferredSize(new Dimension(780, 40));
messagesPanel.setSize(new Dimension(780, 40));
lblStatus.setPreferredSize(new Dimension(750, 22));
lblStatus.setSize(new Dimension(750, 22));
messagesPanel.add(lblStatus);
mainPanel.add(messagesPanel);
getContentPane().add(mainPanel);
pack();
}
private void loadConfiguration()
{
port = 10001;
Font labelFont = loadingDocDoorLbl.getFont();
loadingDocDoorLbl.setFont(new Font(labelFont.getName(),
Font.BOLD,
labelFont.getSize()));
storageCabinetLbl.setFont(new Font(labelFont.getName(),
Font.BOLD,
labelFont.getSize()));
loadingDocDoorLbl.setText("Loading Dock Door");
storageCabinetLbl.setText("Storage Cabinet");
}
public void setStatusText(String text)
{
lblStatus.setText(text);
lblStatus.paintImmediately(lblStatus.getBounds());
}
public void run()
{
int bytesRead;
byte[] bytes = new byte[256];
int totalBytesRead = 0;
try
{
serverSocket = new ServerSocket(port);
while (isListening)
{
totalBytesRead = 0;
StringBuffer xml = new StringBuffer();
setStatusText("Server listening on port: " + port);
Socket listenSocket = serverSocket.accept();
setStatusText("Server accepted new client: "
+ listenSocket.getInetAddress());
BufferedInputStream bufIn =
new BufferedInputStream(listenSocket.getInputStream());
while ((bytesRead = bufIn.read(bytes, 0, bytes.length)) != -1)
{
xml.append(new String(bytes));
totalBytesRead += bytesRead;
}
// because all 256 bytes get appended to the StringBuffer
// every read, at the end of the stream there is junk left
// over in the array.
processXML(xml.substring(0, totalBytesRead));
listenSocket.close();
}
}
catch (IOException ioe)
{
setStatusText("Disconnected from server");
}
}
protected void processXML(String xml)
{
while (xml.indexOf("<?xml") != xml.lastIndexOf("<?xml"))
{
processXMLDocument(xml.substring(0, xml.indexOf("<?xml", 5)));
xml = xml.substring(xml.indexOf("<?xml", 5) - 1);
}
processXMLDocument(xml);
}
protected void processXMLDocument(final String xml)
{
try
{
XMLReader xmlReader = XMLReaderFactory.createXMLReader();
xmlReader.setContentHandler(contentHandler);
xmlReader.setErrorHandler(contentHandler);
xmlReader.parse(
new InputSource(new ByteArrayInputStream(xml.getBytes())));
}
catch (IOException ioe)
{
setStatusText(“Error reading XML data”);
ioe.printStackTrace();
}
catch (SAXException saxe)
{
setStatusText(“Error parsing XML”);
saxe.printStackTrace();
}
}
public boolean addAssetToList(Asset asset)
{
boolean itemInList = false;
JList list = getJListFromSourceStr(asset.getSource());
if (list == null)
{
return false;
}
DefaultListModel listModel = (DefaultListModel) list.getModel();
for (int curIndex = 0; curIndex < listModel.getSize(); ++curIndex)
{
Asset curAsset = (Asset) listModel.getElementAt(curIndex);
if (curAsset.equals(asset))
{
itemInList = true;
}
}
if (!itemInList)
{
listModel.addElement(asset);
return true;
}
else
{
return false;
}
}
public int removeAssetFromList(Asset asset)
{
JList list = getJListFromSourceStr(asset.getSource());
if (list == null)
{
return 0;
}
int count = 0;
boolean itemInList = false;
DefaultListModel listModel = (DefaultListModel) list.getModel();
for (int curIndex = 0; curIndex < listModel.getSize(); ++curIndex)
{
Asset curAsset = (Asset) listModel.getElementAt(curIndex);
if (curAsset.equals(asset))
{
listModel.removeElementAt(curIndex);
++count;
}
}
return count;
}
public JList getJListFromSourceStr(String source)
{
JList list = null;
// simple fail-safe mechanism in case a user has named the antenna
if (source.equals("InvTracSim1\InvTracSim1") ||
source.equals("InvTracSim1\Default"))
{
list = loadingDocDoorList;
}
else if (source.equals("InvTracSim2\InvTracSim2") ||
source.equals("InvTracSim2\Default"))
{
list = storageCabinetList;
}
else
{
setStatusText("Error: invalid source specified - " + source);
}
return list;
}
}[/code]
Asset.java
[code]
package com.jeffhanson.apps.rfid;
/**
-
This class stores the ID, the company, the SKU of an asset, and the
-
location at which it was last scanned.
*/
class Asset
{
private String id;
private String company;
private String sku;
private String source;
public Asset()
{
id = “”;
company = “”;
sku = “”;
source = “”;
}
public Asset(String id, String company, String sku, String source)
{
this.id = id;
this.company = company;
this.sku = sku;
this.source = source;
}
public String getID()
{
return id;
}
public void setID(String id)
{
this.id = id;
}
public String getCompany()
{
return company;
}
public void setCompany(String company)
{
this.company = company;
}
public String getSKU()
{
return sku;
}
public void setSKU(String sku)
{
this.sku = sku;
}
public String getSource()
{
return source;
}
public void setSource(String source)
{
this.source = source;
}
public String toString()
{
return id + ", " + company + ", " + sku;
}
public boolean equals(Object obj)
{
if (!(obj instanceof Asset))
{
return false;
}
Asset asset = (Asset) obj;
if (asset.getID().equals(id))
{
return true;
}
else
{
return false;
}
}
}[/code]
pra ser cincero amigos … não entendi quase nada delas … :oops: e outra … tem pouco comentários nelas …
alguem pode me dar uma luz … por favor … ? acho que se eu entender como isso funciona vai ficar fácil …

té + !!