perfsonar-dev - perfsonar: r5253 - trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology
Subject: perfsonar development work
List archive
perfsonar: r5253 - trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology
Chronological Thread
- From:
- To:
- Subject: perfsonar: r5253 - trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology
- Date: Fri, 7 Aug 2009 08:03:10 -0400
Author: krzjed
Date: 2009-08-07 08:03:09 -0400 (Fri, 07 Aug 2009)
New Revision: 5253
Added:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/Handler.java
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/HandlersManager.java
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/NetworkTopologyElement.java
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/NetworkTopologyElementHandler.java
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/Subnet.java
Modified:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/EndPointPairTopologyElementHandler.java
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/NetworkInterfaceTopologyElementHandler.java
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/NodeTopologyElementHandler.java
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/ServicePSTopologyElementHandler.java
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/ServiceTopologyElementHandler.java
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/TopologyElementHandlerFactory.java
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/TopologyElementSAXHandler.java
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/UnknownTopologyElementHandler.java
Log:
Added possibility of adding custom topology element xml parsers
Modified:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/EndPointPairTopologyElementHandler.java
===================================================================
---
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/EndPointPairTopologyElementHandler.java
2009-08-07 11:47:04 UTC (rev 5252)
+++
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/EndPointPairTopologyElementHandler.java
2009-08-07 12:03:09 UTC (rev 5253)
@@ -14,13 +14,15 @@
* @author krzjed (PSNC)
*
*/
+@Handler(uri
= Namespaces.NMWGT, name = "endPointPair")
public class EndPointPairTopologyElementHandler extends
SpecificTopologyElementHandler {
private String id;
private Set<GenericTopologyElement> elements = new
HashSet<GenericTopologyElement>();
- EndPointPairTopologyElementHandler(String id) {
+ public EndPointPairTopologyElementHandler(Attributes attributes) {
+ String id = attributes.getValue("id");
this.id = id;
}
Added:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/Handler.java
Added:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/HandlersManager.java
Modified:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/NetworkInterfaceTopologyElementHandler.java
===================================================================
---
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/NetworkInterfaceTopologyElementHandler.java
2009-08-07 11:47:04 UTC (rev 5252)
+++
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/NetworkInterfaceTopologyElementHandler.java
2009-08-07 12:03:09 UTC (rev 5253)
@@ -13,6 +13,7 @@
* @author krzjed (PSNC)
*
*/
+@Handler(uri
= Namespaces.NMWGT, name = "interface")
public class NetworkInterfaceTopologyElementHandler extends
SpecificTopologyElementHandler {
@@ -26,7 +27,8 @@
private boolean inAuthRealm;
private String addressType;
- NetworkInterfaceTopologyElementHandler(String id) {
+ public NetworkInterfaceTopologyElementHandler(Attributes attributes) {
+ String id = attributes.getValue("id");
networkInterface.setId(id);
}
Added:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/NetworkTopologyElement.java
Added:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/NetworkTopologyElementHandler.java
Modified:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/NodeTopologyElementHandler.java
===================================================================
---
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/NodeTopologyElementHandler.java
2009-08-07 11:47:04 UTC (rev 5252)
+++
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/NodeTopologyElementHandler.java
2009-08-07 12:03:09 UTC (rev 5253)
@@ -15,6 +15,7 @@
* @author krzjed (PSNC)
*
*/
+@Handler(uri
= Namespaces.NMTB, name = "node")
public class NodeTopologyElementHandler extends
SpecificTopologyElementHandler {
private NodeTopologyElement node = new NodeTopologyElement();
private Set<Port> ports = new HashSet<Port>();
@@ -25,7 +26,8 @@
private String nameType;
private boolean inAddress;
- NodeTopologyElementHandler(String id) {
+ public NodeTopologyElementHandler(Attributes attributes) {
+ String id = attributes.getValue("id");
node.setId(id);
}
Modified:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/ServicePSTopologyElementHandler.java
===================================================================
---
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/ServicePSTopologyElementHandler.java
2009-08-07 11:47:04 UTC (rev 5252)
+++
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/ServicePSTopologyElementHandler.java
2009-08-07 12:03:09 UTC (rev 5253)
@@ -15,6 +15,7 @@
* @author krzjed (PSNC)
*
*/
+@Handler(uri
= Namespaces.PSSERVICE, name = "service")
public class ServicePSTopologyElementHandler extends
SpecificTopologyElementHandler {
private static String ADDRESS_TYPE = "accessPoint";
@@ -25,7 +26,8 @@
private boolean inServiceName;
private boolean inServiceType;
- ServicePSTopologyElementHandler(String id) {
+ public ServicePSTopologyElementHandler(Attributes attributes) {
+ String id = attributes.getValue("id");
service.setId(id);
}
Modified:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/ServiceTopologyElementHandler.java
===================================================================
---
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/ServiceTopologyElementHandler.java
2009-08-07 11:47:04 UTC (rev 5252)
+++
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/ServiceTopologyElementHandler.java
2009-08-07 12:03:09 UTC (rev 5253)
@@ -15,6 +15,7 @@
* @author krzjed (PSNC)
*
*/
+@Handler(uri
= Namespaces.__NMTB, name = "service")
public class ServiceTopologyElementHandler extends
SpecificTopologyElementHandler {
@@ -26,7 +27,8 @@
private boolean inName;
private boolean inType;
- ServiceTopologyElementHandler(String id) {
+ public ServiceTopologyElementHandler(Attributes attributes) {
+ String id = attributes.getValue("id");
service.setId(id);
}
Added:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/Subnet.java
Modified:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/TopologyElementHandlerFactory.java
===================================================================
---
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/TopologyElementHandlerFactory.java
2009-08-07 11:47:04 UTC (rev 5252)
+++
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/TopologyElementHandlerFactory.java
2009-08-07 12:03:09 UTC (rev 5253)
@@ -1,8 +1,10 @@
package org.perfsonar.ri.lsclient.data.topology;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.util.Map;
-import org.perfsonar.ri.lsclient.lsinfo.Namespaces;
+import org.apache.log4j.Logger;
import org.xml.sax.Attributes;
/**
@@ -12,6 +14,19 @@
*
*/
public class TopologyElementHandlerFactory {
+ protected final static Logger logger = Logger
+ .getLogger(TopologyElementHandlerFactory.class);
+ static {
+ HandlersManager
+ .addHandlerClass(EndPointPairTopologyElementHandler.class);
+ HandlersManager
+
.addHandlerClass(NetworkInterfaceTopologyElementHandler.class);
+ HandlersManager.addHandlerClass(NodeTopologyElementHandler.class);
+ HandlersManager.addHandlerClass(ServiceTopologyElementHandler.class);
+
HandlersManager.addHandlerClass(ServicePSTopologyElementHandler.class);
+ HandlersManager.addHandlerClass(NetworkTopologyElementHandler.class);
+ }
+
/**
* Creates concrete
{@link
SpecificTopologyElementHandler} for given tag
*
@@ -30,19 +45,63 @@
static SpecificTopologyElementHandler getTopologyElementHandler(String
uri,
String name, String qName, Attributes attributes,
Map<String, String> namespaces) {
- String id = attributes.getValue("id");
- if (uri.equals(Namespaces.NMWGT) && name.equals("interface")) {
- return new NetworkInterfaceTopologyElementHandler(id);
- } else if (uri.equals(Namespaces.NMTB) && name.equals("node")) {
- return new NodeTopologyElementHandler(id);
- } else if (uri.equals(Namespaces.__NMTB) && name.equals("service")) {
- return new ServiceTopologyElementHandler(id);
- } else if (uri.equals(Namespaces.PSSERVICE) &&
name.equals("service")) {
- return new ServicePSTopologyElementHandler(id);
- } else if (uri.equals(Namespaces.NMWGT) &&
name.equals("endPointPair")) {
- return new EndPointPairTopologyElementHandler(id);
+ HandlersManager manager = HandlersManager.getInstance();
+ Class<? extends SpecificTopologyElementHandler> handlerClass =
manager
+ .getHandlerClass(uri, name);
+ if (handlerClass == null) {
+ return new UnknownTopologyElementHandler(uri, name, qName,
+ attributes, namespaces);
}
- return new UnknownTopologyElementHandler(uri, name, qName,
attributes,
- namespaces, id);
+ Constructor<? extends SpecificTopologyElementHandler> constructor;
+ constructor = retrieveConstructor(uri, name, qName, attributes,
+ namespaces, handlerClass);
+ if (constructor == null) {
+ return new UnknownTopologyElementHandler(uri, name, qName,
+ attributes, namespaces);
+ }
+ return createInstance(uri, name, qName, attributes, namespaces,
+ constructor);
}
+
+ private static SpecificTopologyElementHandler createInstance(String uri,
+ String name, String qName, Attributes attributes,
+ Map<String, String> namespaces,
+ Constructor<? extends SpecificTopologyElementHandler>
constructor) {
+ try {
+ return constructor.newInstance(attributes);
+ } catch (IllegalArgumentException e) {
+ logger.error(e);
+ return new UnknownTopologyElementHandler(uri, name, qName,
+ attributes, namespaces);
+ } catch (InstantiationException e) {
+ logger.error(e);
+ return new UnknownTopologyElementHandler(uri, name, qName,
+ attributes, namespaces);
+ } catch (IllegalAccessException e) {
+ logger.error(e);
+ return new UnknownTopologyElementHandler(uri, name, qName,
+ attributes, namespaces);
+ } catch (InvocationTargetException e) {
+ logger.error(e);
+ return new UnknownTopologyElementHandler(uri, name, qName,
+ attributes, namespaces);
+ }
+ }
+
+ private static Constructor<? extends SpecificTopologyElementHandler>
retrieveConstructor(
+ String uri, String name, String qName, Attributes attributes,
+ Map<String, String> namespaces,
+ Class<? extends SpecificTopologyElementHandler> handlerClass) {
+ Constructor<? extends SpecificTopologyElementHandler> constructor;
+ try {
+ constructor = handlerClass.getConstructor(Attributes.class);
+ } catch (SecurityException e) {
+ logger.error(e);
+ return null;
+ } catch (NoSuchMethodException e) {
+ logger.error(e);
+ return null;
+ }
+ return constructor;
+ }
}
Modified:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/TopologyElementSAXHandler.java
===================================================================
---
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/TopologyElementSAXHandler.java
2009-08-07 11:47:04 UTC (rev 5252)
+++
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/TopologyElementSAXHandler.java
2009-08-07 12:03:09 UTC (rev 5253)
@@ -1,21 +1,22 @@
package org.perfsonar.ri.lsclient.data.topology;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Set;
import org.perfsonar.lsclient.data.EventType;
import org.perfsonar.lsclient.data.TopologyElement;
import org.perfsonar.ri.lsclient.data.implementation.EventTypeImpl;
-import org.perfsonar.ri.lsclient.lsinfo.Namespaces;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
/**
- * Handler for pasing
{@link
TopologyElement}s using SAX
+ * Handler for parsing
{@link
TopologyElement}s using SAX
*
* @author krzjed (PSNC)
*
@@ -36,7 +37,8 @@
*/
private Map<String, String> parameters = new HashMap<String, String>();
private Map<String, String> namespaces = new HashMap<String, String>();
- private SpecificTopologyElementHandler specificHandler;
+ private SpecificTopologyElementHandler actualHandler;
+ private List<SpecificTopologyElementHandler> handlers = new
ArrayList<SpecificTopologyElementHandler>();
private String subjectNamespace;
@@ -53,7 +55,7 @@
String parameterValue = new String(ch, start, length);
parameters.put(parameterName, parameterValue);
} else if (inSubject && (!enteredSubject)) {
- specificHandler.characters(ch, start, length);
+ actualHandler.characters(ch, start, length);
}
}
@@ -73,19 +75,21 @@
public void endPrefixMapping(String prefix) throws SAXException {
namespaces.remove(prefix);
if (inSubject && (!enteredSubject)) {
- specificHandler.endPrefixMapping(prefix);
+ actualHandler.endPrefixMapping(prefix);
}
}
private void eventTypeEndElement(String uri, String localName) {
- if (uri.equals(Namespaces.NMWG) && localName.equals("eventType")) {
+ if (localName.equals("eventType")) {
inEventType = false;
}
}
Set<TopologyElement> getTopologyElements() {
- Set<GenericTopologyElement> elements = specificHandler
- .getTopologyElements();
+ Set<GenericTopologyElement> elements = new
HashSet<GenericTopologyElement>();
+ for (SpecificTopologyElementHandler h : handlers) {
+ elements.addAll(h.getTopologyElements());
+ }
Map<String, String> parameters = Collections
.unmodifiableMap(this.parameters);
Set<EventType> eventTypes = Collections
@@ -103,19 +107,22 @@
}
private void parametersEndElement(String uri, String localName) {
- if (uri.equals(Namespaces.NMWG) && localName.equals("parameter")) {
+ if (localName.equals("parameter")) {
inParameter = false;
- } else if (uri.equals(Namespaces.NMWG)
- && localName.equals("parameters")) {
+ } else if (localName.equals("parameters")) {
inParameters = false;
}
}
private void parametersStartElement(String uri, String localName,
Attributes attributes) {
- if (uri.equals(Namespaces.NMWG) && localName.equals("parameter")) {
+ if (localName.equals("parameter")) {
inParameter = true;
parameterName = attributes.getValue("name");
+ String parameterValue = attributes.getValue("value");
+ if (parameterValue != null) {
+ parameters.put(parameterName, parameterValue);
+ }
}
}
@@ -130,10 +137,9 @@
subjectNamespace = uri;
inSubject = true;
enteredSubject = true;
- } else if (uri.equals(Namespaces.NMWG) &&
localName.equals("eventType")) {
+ } else if (localName.equals("eventType")) {
inEventType = true;
- } else if (uri.equals(Namespaces.NMWG)
- && localName.equals("parameters")) {
+ } else if (localName.equals("parameters")) {
inParameters = true;
}
@@ -144,7 +150,7 @@
throws SAXException {
namespaces.put(prefix, uri);
if (inSubject && (!enteredSubject)) {
- specificHandler.startPrefixMapping(prefix, uri);
+ actualHandler.startPrefixMapping(prefix, uri);
}
}
@@ -153,9 +159,11 @@
if (localName.equals("subject")) {
inSubject = false;
enteredSubject = false;
+ handlers.add(actualHandler);
+ actualHandler = null;
} else {
if (!qName.equals(topologyElementQName)) {
- specificHandler.endElement(uri, localName, qName);
+ actualHandler.endElement(uri, localName, qName);
}
}
}
@@ -165,12 +173,12 @@
if (enteredSubject) {
topologyElementQName = qName;
Map<String, String> map = new HashMap<String,
String>(namespaces);
- specificHandler = TopologyElementHandlerFactory
+ actualHandler = TopologyElementHandlerFactory
.getTopologyElementHandler(uri, localName, qName,
attributes, map);
enteredSubject = false;
} else {
- specificHandler.startElement(uri, localName, qName, attributes);
+ actualHandler.startElement(uri, localName, qName, attributes);
}
}
}
Modified:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/UnknownTopologyElementHandler.java
===================================================================
---
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/UnknownTopologyElementHandler.java
2009-08-07 11:47:04 UTC (rev 5252)
+++
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/UnknownTopologyElementHandler.java
2009-08-07 12:03:09 UTC (rev 5253)
@@ -26,7 +26,7 @@
private Map<String, String> localNamespaces = new HashMap<String,
String>();
public UnknownTopologyElementHandler(String uri, String name, String
qName,
- Attributes attributes, Map<String, String> namespaces, String
id) {
+ Attributes attributes, Map<String, String> namespaces) {
this.qName = qName;
xmlBuilder.append("<");
xmlBuilder.append(qName);
@@ -45,18 +45,23 @@
xmlBuilder.append("\"");
}
xmlBuilder.append(">");
+ String id = attributes.getValue("id");
element.setId(id);
}
@Override
public Set<GenericTopologyElement> getTopologyElements() {
if (!finished) {
- xmlBuilder.append("</");
- xmlBuilder.append(qName);
- xmlBuilder.append(">");
- finished = true;
- xmlDescription = xmlBuilder.toString();
- element.setXmlDescription(xmlDescription);
+ synchronized (this) {
+ if (!finished) {
+ xmlBuilder.append("</");
+ xmlBuilder.append(qName);
+ xmlBuilder.append(">");
+ finished = true;
+ xmlDescription = xmlBuilder.toString();
+ element.setXmlDescription(xmlDescription);
+ }
+ }
}
Set<GenericTopologyElement> set = new
HashSet<GenericTopologyElement>();
set.add(element);
- perfsonar: r5253 - trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology, svnlog, 08/07/2009
Archive powered by MHonArc 2.6.16.