📄 myaleclient.java
字号:
/* * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * * $Id: MyAleClient.java,v 1.4 2005/03/12 21:36:29 cc34264 Exp $ */package com.sun.epcglobal.aleclient;import java.io.BufferedReader;import java.io.FileInputStream;import java.io.InputStreamReader;import java.util.List;import java.util.ArrayList;import java.util.Iterator;import com.sun.autoid.ale.client.ALEClient;import com.sun.autoid.ale.spec.ECSpec;import com.sun.autoid.ale.spec.ECReports;import com.sun.autoid.ale.XMLUtil;/** * * In order to hide some of the complexity of the JAX-RPC code, * an ALE client API is implemented. This program gives an example of * how to use the ALEClient to invokes the ALE Web Services. * * @author Chia Chang */public class MyAleClient { /** Creates a new instance of MyAleClient */ public MyAleClient() { } private void printList(List list) { if (list != null) { int itemCnt = 0; Iterator iter = list.iterator(); while (iter.hasNext()) { System.out.println("Item " + itemCnt++ + ":" + iter.next()); } } } private static void delay(long millis) { try { Thread.sleep(millis); } catch (Exception e) { } } /** * @param args the command line arguments */ public static void main(String[] args) { final String ENDPOINTADDRESS = "http://localhost/ALEService/ale"; final String ECSPEC_FILENAME = "./xml/ECSpec.xml"; List theList; ECSpec ecSpec; String endPointAddress = ENDPOINTADDRESS; String ecspecFile = ECSPEC_FILENAME; XMLUtil xmlUtil; switch (args.length) { case 0: break; case 1: endPointAddress = args[0]; break; case 2: endPointAddress = args[0]; ecspecFile = args[1]; break; default: endPointAddress = args[0]; ecspecFile = args[1]; } System.out.println("Endpoint address = " + endPointAddress); System.out.println("ECSpec file location = " + ecspecFile); try { ALEClient ac = new ALEClient(endPointAddress); xmlUtil = new XMLUtil(); // Read the ECSpec XML file FileInputStream fis = new FileInputStream(ecspecFile); BufferedReader br = new BufferedReader(new InputStreamReader(fis)); StringBuffer sb = new StringBuffer(); String line = null; while ((line = br.readLine()) != null) { sb.append(line); } String specStr = sb.toString(); System.out.println("This is the spec : " + specStr); //======================================================= // Define an ECSpec //======================================================= System.out.println("\n============ define ============"); try { ecSpec = xmlUtil.getSPEC(specStr); ac.define("TestSpec", ecSpec); System.out.println("Defining an ECSpec - TestSpec --> Succeeded"); } catch (Exception e) { System.out.println("Defining an ECSpec - TestSpec --> Failed"); System.out.println("Message for the exception: " + e.getMessage()); } delay(2000); //======================================================= // Get the Spec Names //======================================================= System.out.println("\n============ getECSpecNames ============"); try { theList = ac.getECSpecNames(); ac.printList(theList); System.out.println("Getting the Spec Names --> Succeeded"); } catch (Exception e) { System.out.println("Getting the Spec Names --> Failed"); System.out.println("Message for the exception: " + e.getMessage()); } delay(2000); //======================================================= // Get a Spec //======================================================= System.out.println("\n============ getECSpec ============"); try { ecSpec = ac.getECSpec("TestSpec"); System.out.println("The spec name returned: " + ecSpec.getSpecName()); System.out.println("Getting a Spec Name: TestSpec --> Succeeded"); } catch (Exception e) { System.out.println("Getting a Spec Name: TestSpec --> Failed"); System.out.println("Message for the exception: " + e.getMessage()); } delay(2000); //======================================================= // Subscribe //======================================================= System.out.println("\n============ subscribe ============"); try { ac.subscribe("TestSpec", "file:///tmp/aleOutput"); System.out.println("Subscribing the ECSpec: TestSpec --> Succeeded"); } catch (Exception e) { System.out.println("Subscribing the ECSpec: TestSpec --> Failed"); System.out.println("Message for the exception: " + e.getMessage()); } delay(2000); //======================================================= // Get the Subscriber //======================================================= System.out.println("\n============ getSubscribers ============"); try { theList = ac.getSubscribers("TestSpec"); ac.printList(theList); System.out.println("Getting the subscribed ECSpec: TestSpec --> Succeeded"); } catch (Exception e) { System.out.println("Getting the subscribed ECSpec: TestSpec --> Failed"); System.out.println("Message for the exception: " + e.getMessage()); } delay(2000); //======================================================= // Unsubscribe //======================================================= System.out.println("\n============ unsubscribe ============"); try { ac.unsubscribe("TestSpec", "file:///tmp/aleOutput"); System.out.println("Unsubscribing the ECSpec: TestSpec --> Succeeded"); } catch (Exception e) { System.out.println("Unsubscribing the ECSpec: TestSpec --> Failed"); System.out.println("Message for the exception: " + e.getMessage()); } delay(2000); //======================================================= // Poll //======================================================= System.out.println("\n============ poll ============"); try { System.out.println("Set the output, filter, and logger for ALE in RfidConfig.xml."); System.out.println("Make sure tagviewer and pmlreader are running."); System.out.println("Otherwise, the poll operation will be waiting for a long time."); ECReports reports = ac.poll("TestSpec"); System.out.println("Polling the ECSpec: TestSpec --> Succeeded"); } catch (Exception e) { System.out.println("Polling the ECSpec: TestSpec --> Failed"); System.out.println("Message for the exception: " + e.getMessage()); e.printStackTrace(); } delay(2000); //======================================================= // Immediate //======================================================= System.out.println("\n============ immediate ============"); try { ecSpec = xmlUtil.getSPEC(specStr); ECReports reports = ac.immediate(ecSpec); System.out.println("Immediately executing the ECSpec: ImmediateSpec --> Succeeded"); } catch (Exception e) { System.out.println("Immediately executing the ECSpec: ImmediateSpec --> Failed"); System.out.println("Message for the exception: " + e.getMessage()); e.printStackTrace(); } delay(2000); //======================================================= // Get the Standard Version //======================================================= System.out.println("\n============ getStandardVersion ============"); try { String str = ac.getStandardVersion(); System.out.println("Getting the Standard Version (" + str + ")--> Succeeded"); } catch (Exception e) { System.out.println("Getting the Standard Version --> Failed"); System.out.println("Message for the exception: " + e.getMessage()); e.printStackTrace(); } delay(2000); //======================================================= // Get the Vendor Version //======================================================= System.out.println("\n============ getVendorVersion ============"); try { String str = ac.getVendorVersion(); System.out.println("Getting the Vendor Version (" + str + ") --> Succeeded"); } catch (Exception e) { System.out.println("Getting the Vendor Version --> Failed"); System.out.println("Message for the exception: " + e.getMessage()); e.printStackTrace(); } delay(2000); //======================================================= // Undefine an ECSpec //======================================================= System.out.println("\n============ undefine ============"); try { ac.undefine("TestSpec"); System.out.println("Undefining ECSpec - TestSpec --> Succeeded"); } catch (Exception e) { System.out.println("Undefining ECSpec - TestSpec --> Failed"); System.out.println("Message for the exception: " + e.getMessage()); } delay(2000); } catch (Exception ex) { ex.printStackTrace(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -