perfsonar-dev - perfsonar: r3607 - branches/perfsonarui/src/org/perfsonar/perfsonarui/test/ls
Subject: perfsonar development work
List archive
- From:
- To:
- Subject: perfsonar: r3607 - branches/perfsonarui/src/org/perfsonar/perfsonarui/test/ls
- Date: Fri, 4 Apr 2008 05:36:09 -0400
Author: michael.bischoff
Date: 2008-04-04 05:36:09 -0400 (Fri, 04 Apr 2008)
New Revision: 3607
Modified:
branches/perfsonarui/src/org/perfsonar/perfsonarui/test/ls/LSQuery.java
branches/perfsonarui/src/org/perfsonar/perfsonarui/test/ls/LSQueryTest.java
branches/perfsonarui/src/org/perfsonar/perfsonarui/test/ls/LSSupport.java
branches/perfsonarui/src/org/perfsonar/perfsonarui/test/ls/MetadataQuery.java
branches/perfsonarui/src/org/perfsonar/perfsonarui/test/ls/Service.java
branches/perfsonarui/src/org/perfsonar/perfsonarui/test/ls/ServiceQuery.java
Log:
improved abtractions
implemented metadata lookup
Modified:
branches/perfsonarui/src/org/perfsonar/perfsonarui/test/ls/LSQuery.java
===================================================================
--- branches/perfsonarui/src/org/perfsonar/perfsonarui/test/ls/LSQuery.java
2008-04-03 14:40:49 UTC (rev 3606)
+++ branches/perfsonarui/src/org/perfsonar/perfsonarui/test/ls/LSQuery.java
2008-04-04 09:36:09 UTC (rev 3607)
@@ -3,12 +3,16 @@
import java.io.ByteArrayInputStream;
import java.io.UnsupportedEncodingException;
import java.rmi.RemoteException;
+import java.util.Vector;
+import javax.xml.bind.UnmarshalException;
import javax.xml.namespace.QName;
import javax.xml.rpc.Call;
import javax.xml.rpc.ServiceException;
import org.apache.axis.message.SOAPBodyElement;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
public abstract class LSQuery {
@@ -55,4 +59,49 @@
return call.invoke(new Object[] {requestMessage});
}
+ public String getXpathResult(Vector<Node> vector) throws
UnmarshalException {
+ for (Node element : vector) {
+ if (element.getNodeType() == Node.ELEMENT_NODE) {
+ if
(element.getNodeName().endsWith("message")) {
+ Node dataNode = getNodeFrom(element,
"data");
+ if(dataNode!=null) {
+ Node datumNode =
getNodeFrom(dataNode, "datum");
+ if(datumNode!=null) {
+ return
getTextFrom(datumNode);
+ }
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ protected Node getNodeFrom(Node data, String nodeName) throws
UnmarshalException {
+ NodeList nodes = data.getChildNodes();
+ for (int i = 0; i < nodes.getLength(); i++) {
+ Node element = nodes.item(i);
+ if (element.getNodeType() == Node.ELEMENT_NODE) {
+ if (element.getNodeName().equals(nodeName) ||
element.getNodeName().endsWith(":" + nodeName) ) {
+ return element;
+ }
+ }
+ }
+ return null;
+ }
+
+ protected String getTextFrom(Node node) throws UnmarshalException {
+ StringBuffer buf = new StringBuffer();
+ NodeList nodes = node.getChildNodes();
+ for (int i = 0; i < nodes.getLength(); i++) {
+ Node n = nodes.item(i);
+
+ if (n.getNodeType() == Node.TEXT_NODE) {
+ buf.append(n.getNodeValue());
+ } else {
+ throw new UnmarshalException("Didn't expect
anything other then a text-node.");
+ // expected a text-only node!
+ }
+ }
+ return buf.toString();
+ }
}
Modified:
branches/perfsonarui/src/org/perfsonar/perfsonarui/test/ls/LSQueryTest.java
===================================================================
---
branches/perfsonarui/src/org/perfsonar/perfsonarui/test/ls/LSQueryTest.java
2008-04-03 14:40:49 UTC (rev 3606)
+++
branches/perfsonarui/src/org/perfsonar/perfsonarui/test/ls/LSQueryTest.java
2008-04-04 09:36:09 UTC (rev 3607)
@@ -10,9 +10,6 @@
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JList;
-import javax.swing.JPanel;
-import javax.swing.JTable;
-import javax.swing.ListModel;
import javax.xml.bind.UnmarshalException;
import javax.xml.rpc.ServiceException;
@@ -24,9 +21,18 @@
Service target = new Service();
target.setAddress("http://sonar1.amsterdam.surfnet.nl:8080/XML-LS-1.1.2/services/LookupService");
ServiceQuery query = new ServiceQuery(target);
- query.execute();
+ System.out.println(query.execute());
}
+ public void testMetadataQuery() throws RemoteException,
ServiceException, UnmarshalException {
+ Service ls = new Service();
+
ls.setAddress("http://sonar1.amsterdam.surfnet.nl:8080/XML-LS-1.1.2/services/LookupService");
+ Service target = new Service();
+
target.setAddress("http://sonar1.amsterdam.surfnet.nl:8080/flowsa-ma-0.9.1/services/FlowsaMeasurementArchiveService");
+ MetadataQuery query = new MetadataQuery(ls, target);
+ System.out.println(query.execute());
+ }
+
public void testAsync() {
LSSupport support = new LSSupport();
Service ls = new Service();
Modified:
branches/perfsonarui/src/org/perfsonar/perfsonarui/test/ls/LSSupport.java
===================================================================
--- branches/perfsonarui/src/org/perfsonar/perfsonarui/test/ls/LSSupport.java
2008-04-03 14:40:49 UTC (rev 3606)
+++ branches/perfsonarui/src/org/perfsonar/perfsonarui/test/ls/LSSupport.java
2008-04-04 09:36:09 UTC (rev 3607)
@@ -44,23 +44,27 @@
* against parallel calls; multiply concurrent calls might cause
* double work to be done.
*
+ * Perhaps add SwingUtilities.isEventDispatchThread() check.
+ *
+ * @param fromLs the ls to retrieve the metadata from
* @param forService target service to update the metadata of.
* @param listener the listener that is notified upon result
* (for async call)
* @return a future for tracking, canceling.
*/
- public Future<Object> lookupMetadataFor(final Service forService,
final ResultListener<Object> listener) {
+ public Future<String> lookupMetadataFor(final Service fromLs, final
Service forService, final ResultListener<Object> listener) {
+
// check if we haven't already obtained it.
- Object metadata = forService.getMetadata();
+ String metadata = forService.getMetadata();
if(metadata!=null) {
listener.result(metadata);
}
- return executor.submit(new Callable<Object>() {
+ return executor.submit(new Callable<String>() {
@Override
- public Object call() throws Exception {
- MetadataQuery query = new
MetadataQuery(forService);
- Object result = query.execute();
+ public String call() throws Exception {
+ MetadataQuery query = new
MetadataQuery(fromLs, forService);
+ String result = query.execute();
listener.result(result);
return result;
}
Modified:
branches/perfsonarui/src/org/perfsonar/perfsonarui/test/ls/MetadataQuery.java
===================================================================
---
branches/perfsonarui/src/org/perfsonar/perfsonarui/test/ls/MetadataQuery.java
2008-04-03 14:40:49 UTC (rev 3606)
+++
branches/perfsonarui/src/org/perfsonar/perfsonarui/test/ls/MetadataQuery.java
2008-04-04 09:36:09 UTC (rev 3607)
@@ -1,13 +1,30 @@
package org.perfsonar.perfsonarui.test.ls;
+import java.rmi.RemoteException;
+import java.util.Vector;
+
+import javax.xml.bind.UnmarshalException;
+import javax.xml.rpc.ServiceException;
+
+import org.w3c.dom.Node;
+
public class MetadataQuery extends LSQuery {
- public MetadataQuery(Service service) {
- super(service,
"/nmwg:store/nmwg:data[@metadataIdRef="
+ service.getAddress() + "]/nmwg:metadata/");
+ /**
+ * @param ls the ls to retrieve information from.
+ * @param service the service to obtain metadata about
+ */
+ public MetadataQuery(Service ls, Service service) {
+ super(ls,
"//nmwg:store/nmwg:data[@metadataIdRef='"
+ service.getAddress() + "']/nmwg:metadata");
}
- public Object execute() {
- // TODO Auto-generated method stub
+ @SuppressWarnings("unchecked")
+ public String execute() throws UnmarshalException, RemoteException,
ServiceException {
+ Object result = invokeCall();
+ if (result instanceof Vector) {
+ Vector<Node> vector = (Vector) result;
+ return getXpathResult(vector);
+ }
return null;
}
Modified:
branches/perfsonarui/src/org/perfsonar/perfsonarui/test/ls/Service.java
===================================================================
--- branches/perfsonarui/src/org/perfsonar/perfsonarui/test/ls/Service.java
2008-04-03 14:40:49 UTC (rev 3606)
+++ branches/perfsonarui/src/org/perfsonar/perfsonarui/test/ls/Service.java
2008-04-04 09:36:09 UTC (rev 3607)
@@ -18,7 +18,7 @@
return address;
}
- public Object getMetadata() {
+ public String getMetadata() {
//lazy load?
return null;
}
@@ -26,7 +26,6 @@
public void setAddress(String address) {
this.address = address;
}
-
public void setType(String type) {
this.type = type;
@@ -34,9 +33,8 @@
public void setName(String name) {
this.name = name;
- }
+ }
-
@Override
public String toString() {
return name + " - " + address;
Modified:
branches/perfsonarui/src/org/perfsonar/perfsonarui/test/ls/ServiceQuery.java
===================================================================
---
branches/perfsonarui/src/org/perfsonar/perfsonarui/test/ls/ServiceQuery.java
2008-04-03 14:40:49 UTC (rev 3606)
+++
branches/perfsonarui/src/org/perfsonar/perfsonarui/test/ls/ServiceQuery.java
2008-04-04 09:36:09 UTC (rev 3607)
@@ -18,37 +18,22 @@
public class ServiceQuery extends LSQuery {
public ServiceQuery(Service target) {
- super(target,
-
"/nmwg:store/nmwg:metadata/perfsonar:subject/psservice:service");
+ super(target,
"//nmwg:store/nmwg:metadata/perfsonar:subject/psservice:service");
}
+ @SuppressWarnings("unchecked")
public Collection<Service> execute() throws RemoteException,
ServiceException, UnmarshalException {
Object result = invokeCall();
if (result instanceof Vector) {
Vector<Node> vector = (Vector) result;
- return unMarshall(vector);
+ String xpathResult = getXpathResult(vector);
+ return extractServices(xpathResult);
}
return null;
}
- private Collection<Service> unMarshall(Vector<Node> vector) throws
UnmarshalException {
- for (Node element : vector) {
- if (element.getNodeType() == Node.ELEMENT_NODE) {
- if
(element.getNodeName().endsWith("message")) {
- Node dataNode = getNodeFrom(element,
"data");
- if(dataNode!=null) {
- Node datumNode =
getNodeFrom(dataNode, "datum");
- if(datumNode!=null) {
- return
extractServices(getTextFrom(datumNode));
- }
- }
- }
- }
- }
- return null;
- }
-
private Collection<Service> extractServices(String text) throws
UnmarshalException {
+ //TODO if text.equals("") -> no results.
Document xpathResult;
try {
xpathResult = XMLUtils.getDocumentBuilder().parse(new
InputSource(new StringReader(text)));
@@ -97,32 +82,4 @@
return null;
}
- private Node getNodeFrom(Node data, String nodeName) throws
UnmarshalException {
- NodeList nodes = data.getChildNodes();
- for (int i = 0; i < nodes.getLength(); i++) {
- Node element = nodes.item(i);
- if (element.getNodeType() == Node.ELEMENT_NODE) {
- if (element.getNodeName().equals(nodeName) ||
element.getNodeName().endsWith(":" + nodeName) ) {
- return element;
- }
- }
- }
- return null;
- }
-
- private String getTextFrom(Node node) throws UnmarshalException {
- StringBuffer buf = new StringBuffer();
- NodeList nodes = node.getChildNodes();
- for (int i = 0; i < nodes.getLength(); i++) {
- Node n = nodes.item(i);
-
- if (n.getNodeType() == Node.TEXT_NODE) {
- buf.append(n.getNodeValue());
- } else {
- throw new UnmarshalException("Didn't expect
anything other then a text-node.");
- // expected a text-only node!
- }
- }
- return buf.toString();
- }
}
- perfsonar: r3607 - branches/perfsonarui/src/org/perfsonar/perfsonarui/test/ls, svnlog, 04/04/2008
Archive powered by MHonArc 2.6.16.