本文整理汇总了Java中org.codehaus.stax2.XMLStreamReader2.getAttributeAsDouble方法的典型用法代码示例。如果您正苦于以下问题:Java XMLStreamReader2.getAttributeAsDouble方法的具体用法?Java XMLStreamReader2.getAttributeAsDouble怎么用?Java XMLStreamReader2.getAttributeAsDouble使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.codehaus.stax2.XMLStreamReader2
的用法示例。
在下文中一共展示了XMLStreamReader2.getAttributeAsDouble方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseForwardingRule
import org.codehaus.stax2.XMLStreamReader2; //导入方法依赖的package包/类
protected void parseForwardingRule(NetPlan netPlan, long layerId, XMLStreamReader2 xmlStreamReader , DoubleMatrix2D f_de) throws XMLStreamException
{
long linkId = xmlStreamReader.getAttributeAsLong(xmlStreamReader.getAttributeIndex(null, "linkId"));
long demandId = xmlStreamReader.getAttributeAsLong(xmlStreamReader.getAttributeIndex(null, "demandId"));
double splittingRatio = xmlStreamReader.getAttributeAsDouble(xmlStreamReader.getAttributeIndex(null, "splittingRatio"));
f_de.set (mapOldId2Demand.get(Pair.of (layerId,demandId)).index , mapOldId2Link.get(Pair.of(layerId , linkId)).index , splittingRatio);
while(xmlStreamReader.hasNext())
{
xmlStreamReader.next();
switch(xmlStreamReader.getEventType())
{
case XMLEvent.START_ELEMENT:
String startElementName = xmlStreamReader.getName().toString();
switch(startElementName)
{
case "attribute":
break;
default:
throw new RuntimeException("Bad");
}
break;
case XMLEvent.END_ELEMENT:
String endElementName = xmlStreamReader.getName().toString();
if (endElementName.equals("forwardingRule")) return;
break;
}
}
throw new RuntimeException("'Forwarding rule' element not parsed correctly (end tag not found)");
}
示例2: parseForwardingRule
import org.codehaus.stax2.XMLStreamReader2; //导入方法依赖的package包/类
protected void parseForwardingRule(NetPlan netPlan, long layerId, XMLStreamReader2 xmlStreamReader , DoubleMatrix2D f_de) throws XMLStreamException
{
long linkId = xmlStreamReader.getAttributeAsLong(xmlStreamReader.getAttributeIndex(null, "linkId"));
long demandId = xmlStreamReader.getAttributeAsLong(xmlStreamReader.getAttributeIndex(null, "demandId"));
double splittingRatio = xmlStreamReader.getAttributeAsDouble(xmlStreamReader.getAttributeIndex(null, "splittingRatio"));
f_de.set (mapOldId2Demand.get(demandId).index , mapOldId2Link.get(linkId).index , splittingRatio);
while(xmlStreamReader.hasNext())
{
xmlStreamReader.next();
switch(xmlStreamReader.getEventType())
{
case XMLEvent.START_ELEMENT:
String startElementName = xmlStreamReader.getName().toString();
switch(startElementName)
{
case "attribute":
break;
default:
throw new RuntimeException("Bad");
}
break;
case XMLEvent.END_ELEMENT:
String endElementName = xmlStreamReader.getName().toString();
if (endElementName.equals("forwardingRule")) return;
break;
}
}
throw new RuntimeException("'Forwarding rule' element not parsed correctly (end tag not found)");
}
示例3: parseNode
import org.codehaus.stax2.XMLStreamReader2; //导入方法依赖的package包/类
protected void parseNode(NetPlan netPlan, XMLStreamReader2 xmlStreamReader) throws XMLStreamException
{
long nodeId = xmlStreamReader.getAttributeAsLong(xmlStreamReader.getAttributeIndex(null, "id"));
double xCoord = xmlStreamReader.getAttributeAsDouble(xmlStreamReader.getAttributeIndex(null, "xCoord"));
double yCoord = xmlStreamReader.getAttributeAsDouble(xmlStreamReader.getAttributeIndex(null, "yCoord"));
String nodeName = xmlStreamReader.getAttributeValue(xmlStreamReader.getAttributeIndex(null, "name"));
Node newNode = netPlan.addNode(xCoord, yCoord, nodeName, null);
mapOldId2Node.put (nodeId , newNode);
while(xmlStreamReader.hasNext())
{
xmlStreamReader.next();
switch(xmlStreamReader.getEventType())
{
case XMLEvent.START_ELEMENT:
String startElementName = xmlStreamReader.getName().toString();
switch(startElementName)
{
case "attribute":
String key = xmlStreamReader.getAttributeValue(xmlStreamReader.getAttributeIndex(null, "key"));
String name = xmlStreamReader.getAttributeValue(xmlStreamReader.getAttributeIndex(null, "value"));
newNode.setAttribute(key, name);
break;
default:
throw new RuntimeException("Bad");
}
break;
case XMLEvent.END_ELEMENT:
String endElementName = xmlStreamReader.getName().toString();
if (endElementName.equals("node")) return;
break;
}
}
throw new RuntimeException("'Node' element not parsed correctly (end tag not found)");
}
示例4: parseDemand
import org.codehaus.stax2.XMLStreamReader2; //导入方法依赖的package包/类
protected void parseDemand(NetPlan netPlan, XMLStreamReader2 xmlStreamReader) throws XMLStreamException
{
long ingressNodeId = -1;
long egressNodeId = -1;
double offeredTraffic = 0;
Map<String, String> attributeMap = new LinkedHashMap<String, String>();
int numAttributes = xmlStreamReader.getAttributeCount();
for(int i = 0; i < numAttributes; i++)
{
String localName = xmlStreamReader.getAttributeLocalName(i);
switch(localName)
{
case "ingressNodeId":
ingressNodeId = xmlStreamReader.getAttributeAsLong(i);
break;
case "egressNodeId":
egressNodeId = xmlStreamReader.getAttributeAsLong(i);
break;
case "offeredTrafficInErlangs":
offeredTraffic = xmlStreamReader.getAttributeAsDouble(i);
break;
default:
attributeMap.put(localName, xmlStreamReader.getAttributeValue(i));
break;
}
}
while(xmlStreamReader.hasNext())
{
xmlStreamReader.next();
switch(xmlStreamReader.getEventType())
{
case XMLEvent.START_ELEMENT:
throw new RuntimeException("No nested elements allowed for 'Demand' element");
case XMLEvent.END_ELEMENT:
String endElementName = xmlStreamReader.getName().toString();
if (endElementName.equals("demandEntry"))
{
netPlan.addDemand(netPlan.nodes.get((int) ingressNodeId), netPlan.nodes.get((int) egressNodeId), offeredTraffic, attributeMap);
return;
}
break;
}
}
throw new RuntimeException("'Demand' element not parsed correctly (end tag not found)");
}
示例5: parseLink
import org.codehaus.stax2.XMLStreamReader2; //导入方法依赖的package包/类
protected void parseLink(NetPlan netPlan, XMLStreamReader2 xmlStreamReader) throws XMLStreamException
{
Map<String, String> attributeMap = new LinkedHashMap<String, String>();
double linkCapacity = 0;
double linkLengthInKm = 0;
long originNodeId = -1;
long destinationNodeId = -1;
int numAttributes = xmlStreamReader.getAttributeCount();
for(int i = 0; i < numAttributes; i++)
{
String localName = xmlStreamReader.getAttributeLocalName(i);
switch(localName)
{
case "originNodeId":
originNodeId = xmlStreamReader.getAttributeAsLong(i);
break;
case "destinationNodeId":
destinationNodeId = xmlStreamReader.getAttributeAsLong(i);
break;
case "linkCapacityInErlangs":
linkCapacity = xmlStreamReader.getAttributeAsDouble(i);
break;
case "linkLengthInKm":
linkLengthInKm = xmlStreamReader.getAttributeAsDouble(i);
break;
default:
attributeMap.put(localName, xmlStreamReader.getAttributeValue(i));
break;
}
}
while(xmlStreamReader.hasNext())
{
xmlStreamReader.next();
switch(xmlStreamReader.getEventType())
{
case XMLEvent.START_ELEMENT:
throw new RuntimeException("No nested elements allowed for 'Link' element");
case XMLEvent.END_ELEMENT:
String endElementName = xmlStreamReader.getName().toString();
if (endElementName.equals("link"))
{
netPlan.addLink(netPlan.nodes.get((int) originNodeId), netPlan.nodes.get((int) destinationNodeId), linkCapacity, linkLengthInKm, 200000 , attributeMap);
return;
}
break;
}
}
throw new RuntimeException("'Link' element not parsed correctly (end tag not found)");
}
示例6: parseNode
import org.codehaus.stax2.XMLStreamReader2; //导入方法依赖的package包/类
protected void parseNode(NetPlan netPlan, XMLStreamReader2 xmlStreamReader) throws XMLStreamException
{
double xCoord = 0;
double yCoord = 0;
String nodeName = null;
Map<String, String> attributeMap = new LinkedHashMap<String, String>();
int numAttributes = xmlStreamReader.getAttributeCount();
for(int i = 0; i < numAttributes; i++)
{
String localName = xmlStreamReader.getAttributeLocalName(i);
switch(localName)
{
case "xCoord":
xCoord = xmlStreamReader.getAttributeAsDouble(i);
break;
case "yCoord":
yCoord = xmlStreamReader.getAttributeAsDouble(i);
break;
case "name":
nodeName = xmlStreamReader.getAttributeValue(i);
break;
default:
attributeMap.put(localName, xmlStreamReader.getAttributeValue(i));
}
}
while(xmlStreamReader.hasNext())
{
xmlStreamReader.next();
switch(xmlStreamReader.getEventType())
{
case XMLEvent.START_ELEMENT:
throw new RuntimeException("No nested elements allowed for 'Node' element");
case XMLEvent.END_ELEMENT:
String endElementName = xmlStreamReader.getName().toString();
if (endElementName.equals("node"))
{
netPlan.addNode(xCoord, yCoord, nodeName, attributeMap);
return;
}
break;
}
}
throw new RuntimeException("'Node' element not parsed correctly (end tag not found)");
}
示例7: parseProtectionSegment
import org.codehaus.stax2.XMLStreamReader2; //导入方法依赖的package包/类
protected void parseProtectionSegment(NetPlan netPlan, XMLStreamReader2 xmlStreamReader) throws XMLStreamException
{
double reservedBandwidthInErlangs = 0;
Map<String, String> attributeMap = new LinkedHashMap<String, String>();
int numAttributes = xmlStreamReader.getAttributeCount();
for(int i = 0; i < numAttributes; i++)
{
String localName = xmlStreamReader.getAttributeLocalName(i);
switch(localName)
{
case "reservedBandwidthInErlangs":
reservedBandwidthInErlangs = xmlStreamReader.getAttributeAsDouble(i);
break;
default:
attributeMap.put(localName, xmlStreamReader.getAttributeValue(i));
}
}
List<Long> seqLinks = new LinkedList<Long>();
while(xmlStreamReader.hasNext())
{
xmlStreamReader.next();
switch(xmlStreamReader.getEventType())
{
case XMLEvent.START_ELEMENT:
String startElementName = xmlStreamReader.getName().toString();
switch(startElementName)
{
case "linkEntry":
seqLinks.add(xmlStreamReader.getAttributeAsLong(xmlStreamReader.getAttributeIndex(null, "id")));
break;
default:
throw new RuntimeException("Bad");
}
break;
case XMLEvent.END_ELEMENT:
String endElementName = xmlStreamReader.getName().toString();
if (endElementName.equals("protectionSegment"))
{
List<Link> newSeqLinks = new LinkedList<Link> (); for (long linkId : seqLinks) newSeqLinks.add (netPlan.defaultLayer.links.get((int) linkId));
/* Protection segments are not added */
//netPlan.addProtectionSegment(newSeqLinks, reservedBandwidthInErlangs, attributeMap);
return;
}
break;
}
}
throw new RuntimeException("'Protection segment' element not parsed correctly (end tag not found)");
}
示例8: parseRoute
import org.codehaus.stax2.XMLStreamReader2; //导入方法依赖的package包/类
protected void parseRoute(NetPlan netPlan, XMLStreamReader2 xmlStreamReader) throws XMLStreamException
{
long demandId = -1;
double carriedTrafficInErlangs = 0;
Map<String, String> attributeMap = new LinkedHashMap<String, String>();
int numAttributes = xmlStreamReader.getAttributeCount();
for(int i = 0; i < numAttributes; i++)
{
String localName = xmlStreamReader.getAttributeLocalName(i);
switch(localName)
{
case "carriedTrafficInErlangs":
carriedTrafficInErlangs = xmlStreamReader.getAttributeAsDouble(i);
break;
case "demandId":
demandId = xmlStreamReader.getAttributeAsLong(i);
break;
default:
attributeMap.put(localName, xmlStreamReader.getAttributeValue(i));
}
}
List<Long> seqLinks = new LinkedList<Long>();
List<Long> backupSegmentList = new LinkedList<Long>();
while(xmlStreamReader.hasNext())
{
xmlStreamReader.next();
switch(xmlStreamReader.getEventType())
{
case XMLEvent.START_ELEMENT:
String startElementName = xmlStreamReader.getName().toString();
switch(startElementName)
{
case "linkEntry":
seqLinks.add(xmlStreamReader.getAttributeAsLong(xmlStreamReader.getAttributeIndex(null, "id")));
break;
case "protectionSegmentEntry":
backupSegmentList.add(xmlStreamReader.getAttributeAsLong(xmlStreamReader.getAttributeIndex(null, "id")));
break;
default:
throw new RuntimeException("Bad");
}
break;
case XMLEvent.END_ELEMENT:
String endElementName = xmlStreamReader.getName().toString();
if (endElementName.equals("route"))
{
List<Link> newSeqLinks = new LinkedList<Link> (); for (long linkId : seqLinks) newSeqLinks.add (netPlan.defaultLayer.links.get((int) linkId));
Route route = netPlan.addRoute(netPlan.defaultLayer.demands.get ((int) demandId), carriedTrafficInErlangs, carriedTrafficInErlangs , newSeqLinks, attributeMap);
backupSegmentMap.put((long) route.index, backupSegmentList);
return;
}
break;
}
}
throw new RuntimeException("'Route' element not parsed correctly (end tag not found)");
}
示例9: parseSRG
import org.codehaus.stax2.XMLStreamReader2; //导入方法依赖的package包/类
protected void parseSRG(NetPlan netPlan, XMLStreamReader2 xmlStreamReader) throws XMLStreamException
{
double mttf = 0;
double mttr = 0;
Map<String, String> attributeMap = new LinkedHashMap<String, String>();
int numAttributes = xmlStreamReader.getAttributeCount();
for(int i = 0; i < numAttributes; i++)
{
String localName = xmlStreamReader.getAttributeLocalName(i);
switch(localName)
{
case "mttf":
mttf = xmlStreamReader.getAttributeAsDouble(i);
break;
case "mttr":
mttr = xmlStreamReader.getAttributeAsDouble(i);
break;
default:
attributeMap.put(localName, xmlStreamReader.getAttributeValue(i));
}
}
Set<Long> nodeIds_thisSRG = new LinkedHashSet<Long>();
Set<Long> linkIds_thisSRG = new LinkedHashSet<Long>();
while(xmlStreamReader.hasNext())
{
xmlStreamReader.next();
switch(xmlStreamReader.getEventType())
{
case XMLEvent.START_ELEMENT:
String startElementName = xmlStreamReader.getName().toString();
switch(startElementName)
{
case "linkEntry":
linkIds_thisSRG.add(xmlStreamReader.getAttributeAsLong(xmlStreamReader.getAttributeIndex(null, "id")));
break;
case "nodeEntry":
nodeIds_thisSRG.add(xmlStreamReader.getAttributeAsLong(xmlStreamReader.getAttributeIndex(null, "id")));
break;
default:
throw new RuntimeException("Bad");
}
break;
case XMLEvent.END_ELEMENT:
String endElementName = xmlStreamReader.getName().toString();
if (endElementName.equals("srg"))
{
SharedRiskGroup srg = netPlan.addSRG(mttf, mttr, attributeMap);
for(long nodeId : nodeIds_thisSRG) srg.addNode (netPlan.nodes.get((int) nodeId));
for(long linkId : linkIds_thisSRG) srg.addLink (netPlan.defaultLayer.links.get((int) linkId));
return;
}
break;
}
}
throw new RuntimeException("'SRG' element not parsed correctly (end tag not found)");
}
示例10: parseProtectionSegment
import org.codehaus.stax2.XMLStreamReader2; //导入方法依赖的package包/类
protected void parseProtectionSegment(NetPlan netPlan, long layerId, XMLStreamReader2 xmlStreamReader) throws XMLStreamException
{
long segmentId = xmlStreamReader.getAttributeAsLong(xmlStreamReader.getAttributeIndex(null, "id"));
double reservedCapacity = xmlStreamReader.getAttributeAsDouble(xmlStreamReader.getAttributeIndex(null, "reservedCapacity"));
List<Long> seqLinks = LongUtils.toList(xmlStreamReader.getAttributeAsLongArray(xmlStreamReader.getAttributeIndex(null, "seqLinks")));
// netPlan.nextSegmentId.put(layerId, segmentId);
List<Link> newSeqLinks = new LinkedList<Link> (); for (long linkId : seqLinks) newSeqLinks.add (mapOldId2Link.get(linkId));
// ProtectionSegment newSegment = netPlan.addProtectionSegment(newSeqLinks, reservedCapacity, null);
// mapOldId2ProtectionSegment.put (segmentId , newSegment);
while(xmlStreamReader.hasNext())
{
xmlStreamReader.next();
switch(xmlStreamReader.getEventType())
{
case XMLEvent.START_ELEMENT:
String startElementName = xmlStreamReader.getName().toString();
switch(startElementName)
{
case "attribute":
String key = xmlStreamReader.getAttributeValue(xmlStreamReader.getAttributeIndex(null, "key"));
String name = xmlStreamReader.getAttributeValue(xmlStreamReader.getAttributeIndex(null, "value"));
// newSegment.setAttribute(key, name);
break;
default:
throw new RuntimeException("Bad");
}
break;
case XMLEvent.END_ELEMENT:
String endElementName = xmlStreamReader.getName().toString();
if (endElementName.equals("protectionSegment")) return;
break;
}
}
throw new RuntimeException("'Protection segment' element not parsed correctly (end tag not found)");
}
示例11: parseNode
import org.codehaus.stax2.XMLStreamReader2; //导入方法依赖的package包/类
protected void parseNode(NetPlan netPlan, XMLStreamReader2 xmlStreamReader) throws XMLStreamException
{
long nodeId = xmlStreamReader.getAttributeAsLong(xmlStreamReader.getAttributeIndex(null, "id"));
double xCoord = xmlStreamReader.getAttributeAsDouble(xmlStreamReader.getAttributeIndex(null, "xCoord"));
double yCoord = xmlStreamReader.getAttributeAsDouble(xmlStreamReader.getAttributeIndex(null, "yCoord"));
String nodeName = xmlStreamReader.getAttributeValue(xmlStreamReader.getAttributeIndex(null, "name"));
boolean isUp = true; try { isUp = xmlStreamReader.getAttributeAsBoolean(xmlStreamReader.getAttributeIndex(null, "isUp")); } catch (Exception e) {}
//netPlan.nextNodeId = new MutableLong(nodeId);
Node newNode = netPlan.addNode(xCoord, yCoord, nodeName, null);
newNode.setFailureState(isUp);
mapOldId2Node.put (nodeId , newNode);
while(xmlStreamReader.hasNext())
{
xmlStreamReader.next();
switch(xmlStreamReader.getEventType())
{
case XMLEvent.START_ELEMENT:
String startElementName = xmlStreamReader.getName().toString();
switch(startElementName)
{
case "attribute":
String key = xmlStreamReader.getAttributeValue(xmlStreamReader.getAttributeIndex(null, "key"));
String name = xmlStreamReader.getAttributeValue(xmlStreamReader.getAttributeIndex(null, "value"));
newNode.setAttribute(key, name);
break;
default:
throw new RuntimeException("Bad");
}
break;
case XMLEvent.END_ELEMENT:
String endElementName = xmlStreamReader.getName().toString();
if (endElementName.equals("node")) return;
break;
}
}
throw new RuntimeException("'Node' element not parsed correctly (end tag not found)");
}
示例12: parseDemand
import org.codehaus.stax2.XMLStreamReader2; //导入方法依赖的package包/类
protected void parseDemand(NetPlan netPlan, long layerId, XMLStreamReader2 xmlStreamReader) throws XMLStreamException
{
long demandId = xmlStreamReader.getAttributeAsLong(xmlStreamReader.getAttributeIndex(null, "id"));
long ingressNodeId = xmlStreamReader.getAttributeAsLong(xmlStreamReader.getAttributeIndex(null, "ingressNodeId"));
long egressNodeId = xmlStreamReader.getAttributeAsLong(xmlStreamReader.getAttributeIndex(null, "egressNodeId"));
double offeredTraffic = xmlStreamReader.getAttributeAsDouble(xmlStreamReader.getAttributeIndex(null, "offeredTraffic"));
// netPlan.nextDemandId.put(layerId, demandId);
Demand newDemand = netPlan.addDemand(mapOldId2Node.get(ingressNodeId), mapOldId2Node.get(egressNodeId), offeredTraffic, null , mapOldId2Layer.get(layerId));
mapOldId2Demand.put (demandId , newDemand);
while(xmlStreamReader.hasNext())
{
xmlStreamReader.next();
switch(xmlStreamReader.getEventType())
{
case XMLEvent.START_ELEMENT:
String startElementName = xmlStreamReader.getName().toString();
switch(startElementName)
{
case "attribute":
String key = xmlStreamReader.getAttributeValue(xmlStreamReader.getAttributeIndex(null, "key"));
String name = xmlStreamReader.getAttributeValue(xmlStreamReader.getAttributeIndex(null, "value"));
if (key.equals(KEY_STRING_BIDIRECTIONALCOUPLE)) name = "" + mapOldId2Demand.get(Long.parseLong(name)).getId();
newDemand.setAttribute(key, name);
break;
default:
throw new RuntimeException("Bad");
}
break;
case XMLEvent.END_ELEMENT:
String endElementName = xmlStreamReader.getName().toString();
if (endElementName.equals("demand")) return;
break;
}
}
throw new RuntimeException("'Demand' element not parsed correctly (end tag not found)");
}
示例13: parseLink
import org.codehaus.stax2.XMLStreamReader2; //导入方法依赖的package包/类
protected void parseLink(NetPlan netPlan, long layerId, XMLStreamReader2 xmlStreamReader) throws XMLStreamException
{
long linkId = xmlStreamReader.getAttributeAsLong(xmlStreamReader.getAttributeIndex(null, "id"));
long originNodeId = xmlStreamReader.getAttributeAsLong(xmlStreamReader.getAttributeIndex(null, "originNodeId"));
long destinationNodeId = xmlStreamReader.getAttributeAsLong(xmlStreamReader.getAttributeIndex(null, "destinationNodeId"));
double capacity = xmlStreamReader.getAttributeAsDouble(xmlStreamReader.getAttributeIndex(null, "capacity"));
double lengthInKm = xmlStreamReader.getAttributeAsDouble(xmlStreamReader.getAttributeIndex(null, "lengthInKm"));
double propagationSpeedInKmPerSecond = xmlStreamReader.getAttributeAsDouble(xmlStreamReader.getAttributeIndex(null, "propagationSpeedInKmPerSecond"));
boolean isUp = true; try { isUp = xmlStreamReader.getAttributeAsBoolean(xmlStreamReader.getAttributeIndex(null, "isUp")); } catch (Exception e) {}
Link newLink = netPlan.addLink(mapOldId2Node.get(originNodeId), mapOldId2Node.get(destinationNodeId), capacity, lengthInKm, propagationSpeedInKmPerSecond, null , mapOldId2Layer.get (layerId));
mapOldId2Link.put (linkId , newLink);
newLink.setFailureState(isUp);
while(xmlStreamReader.hasNext())
{
xmlStreamReader.next();
switch(xmlStreamReader.getEventType())
{
case XMLEvent.START_ELEMENT:
String startElementName = xmlStreamReader.getName().toString();
switch(startElementName)
{
case "attribute":
String key = xmlStreamReader.getAttributeValue(xmlStreamReader.getAttributeIndex(null, "key"));
String name = xmlStreamReader.getAttributeValue(xmlStreamReader.getAttributeIndex(null, "value"));
if (key.equals(KEY_STRING_BIDIRECTIONALCOUPLE)) name = "" + mapOldId2Link.get(Long.parseLong(name)).getId();
newLink.setAttribute(key, name);
break;
default:
throw new RuntimeException("Bad");
}
break;
case XMLEvent.END_ELEMENT:
String endElementName = xmlStreamReader.getName().toString();
if (endElementName.equals("link")) return;
break;
}
}
throw new RuntimeException("'Link' element not parsed correctly (end tag not found)");
}
示例14: parseSRG
import org.codehaus.stax2.XMLStreamReader2; //导入方法依赖的package包/类
protected void parseSRG(NetPlan netPlan, XMLStreamReader2 xmlStreamReader) throws XMLStreamException
{
long srgId = xmlStreamReader.getAttributeAsLong(xmlStreamReader.getAttributeIndex(null, "id"));
double meanTimeToFailInHours = xmlStreamReader.getAttributeAsDouble(xmlStreamReader.getAttributeIndex(null, "meanTimeToFailInHours"));
double meanTimeToRepairInHours = xmlStreamReader.getAttributeAsDouble(xmlStreamReader.getAttributeIndex(null, "meanTimeToRepairInHours"));
SharedRiskGroup newSRG = netPlan.addSRG(meanTimeToFailInHours, meanTimeToRepairInHours, null);
mapOldId2Srg.put (srgId , newSRG);
while(xmlStreamReader.hasNext())
{
xmlStreamReader.next();
switch(xmlStreamReader.getEventType())
{
case XMLEvent.START_ELEMENT:
String startElementName = xmlStreamReader.getName().toString();
switch(startElementName)
{
case "attribute":
String key = xmlStreamReader.getAttributeValue(xmlStreamReader.getAttributeIndex(null, "key"));
String name = xmlStreamReader.getAttributeValue(xmlStreamReader.getAttributeIndex(null, "value"));
newSRG.setAttribute(key, name);
break;
case "node":
long nodeId = xmlStreamReader.getAttributeAsLong(xmlStreamReader.getAttributeIndex(null, "id"));
newSRG.addNode(mapOldId2Node.get(nodeId));
break;
case "link":
// long layerId = xmlStreamReader.getAttributeAsLong(xmlStreamReader.getAttributeIndex(null, "layerId"));
long linkId = xmlStreamReader.getAttributeAsLong(xmlStreamReader.getAttributeIndex(null, "linkId"));
newSRG.addLink(mapOldId2Link.get(linkId));
break;
default:
throw new RuntimeException("Bad");
}
break;
case XMLEvent.END_ELEMENT:
String endElementName = xmlStreamReader.getName().toString();
if (endElementName.equals("srg")) return;
break;
}
}
throw new RuntimeException("'SRG' element not parsed correctly (end tag not found)");
}
示例15: parseMulticastDemand
import org.codehaus.stax2.XMLStreamReader2; //导入方法依赖的package包/类
protected void parseMulticastDemand(NetPlan netPlan, long layerId, XMLStreamReader2 xmlStreamReader) throws XMLStreamException
{
long demandId = xmlStreamReader.getAttributeAsLong(xmlStreamReader.getAttributeIndex(null, "id"));
long ingressNodeId = xmlStreamReader.getAttributeAsLong(xmlStreamReader.getAttributeIndex(null, "ingressNodeId"));
Set<Long> egressNodeIds = new HashSet <Long>(LongUtils.toList(xmlStreamReader.getAttributeAsLongArray(xmlStreamReader.getAttributeIndex(null, "egressNodeIds"))));
Set<Node> newEgressNodes = new HashSet<Node> (); for (long nodeId : egressNodeIds) newEgressNodes.add (mapOldId2Node.get(nodeId));
double offeredTraffic = xmlStreamReader.getAttributeAsDouble(xmlStreamReader.getAttributeIndex(null, "offeredTraffic"));
MulticastDemand newDemand = netPlan.addMulticastDemand(mapOldId2Node.get(ingressNodeId), newEgressNodes , offeredTraffic, null , mapOldId2Layer.get(layerId));
mapOldId2MulticastDemand.put (demandId , newDemand);
while(xmlStreamReader.hasNext())
{
xmlStreamReader.next();
switch(xmlStreamReader.getEventType())
{
case XMLEvent.START_ELEMENT:
String startElementName = xmlStreamReader.getName().toString();
switch(startElementName)
{
case "attribute":
String key = xmlStreamReader.getAttributeValue(xmlStreamReader.getAttributeIndex(null, "key"));
String name = xmlStreamReader.getAttributeValue(xmlStreamReader.getAttributeIndex(null, "value"));
newDemand.setAttribute(key, name);
break;
default:
throw new RuntimeException("Bad");
}
break;
case XMLEvent.END_ELEMENT:
String endElementName = xmlStreamReader.getName().toString();
if (endElementName.equals("multicastDemand")) return;
break;
}
}
throw new RuntimeException("'MulticastDemand' element not parsed correctly (end tag not found)");
}