本文整理汇总了Java中org.codehaus.stax2.XMLStreamReader2.getAttributeCount方法的典型用法代码示例。如果您正苦于以下问题:Java XMLStreamReader2.getAttributeCount方法的具体用法?Java XMLStreamReader2.getAttributeCount怎么用?Java XMLStreamReader2.getAttributeCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.codehaus.stax2.XMLStreamReader2
的用法示例。
在下文中一共展示了XMLStreamReader2.getAttributeCount方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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)");
}
示例2: 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)");
}
示例3: parseNetwork
import org.codehaus.stax2.XMLStreamReader2; //导入方法依赖的package包/类
protected void parseNetwork(NetPlan netPlan, XMLStreamReader2 xmlStreamReader) throws XMLStreamException
{
int numAttributes = xmlStreamReader.getAttributeCount();
for(int i = 0; i < numAttributes; i++)
{
String localName = xmlStreamReader.getAttributeLocalName(i);
switch(localName)
{
case "description":
netPlan.setNetworkDescription(xmlStreamReader.getAttributeValue(i));
break;
case "name":
netPlan.setNetworkName(xmlStreamReader.getAttributeValue(i));
break;
default:
netPlan.setAttribute(localName, xmlStreamReader.getAttributeValue(i));
break;
}
}
while(xmlStreamReader.hasNext())
{
xmlStreamReader.next();
switch(xmlStreamReader.getEventType())
{
case XMLEvent.START_ELEMENT:
String startElementName = xmlStreamReader.getName().toString();
switch(startElementName)
{
case "physicalTopology":
parsePhysicalTopology(netPlan, xmlStreamReader);
break;
case "demandSet":
parseDemandSet(netPlan, xmlStreamReader);
break;
case "routingInfo":
parseRoutingInfo(netPlan, xmlStreamReader);
break;
case "protectionInfo":
parseProtectionInfo(netPlan, xmlStreamReader);
break;
case "srgInfo":
parseSRGInfo(netPlan, xmlStreamReader);
default:
throw new RuntimeException("Bad");
}
break;
case XMLEvent.END_ELEMENT:
String endElementName = xmlStreamReader.getName().toString();
if (endElementName.equals("network")) return;
break;
}
}
throw new RuntimeException("'Network' element not parsed correctly (end tag not found)");
}
示例4: 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)");
}
示例5: 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)");
}
示例6: 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)");
}
示例7: 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)");
}
示例8: onStartElement
import org.codehaus.stax2.XMLStreamReader2; //导入方法依赖的package包/类
@Override
public void onStartElement(XMLStreamReader2 reader) {
final String localName = reader.getName().getLocalPart();
stackTags.append(localName);
final StaxTag currentTag = new StaxTag(localName, stackTags.toString());
// System.out.println(currentTag);
if (title.equals(currentTag)) {
inTitle = true;
} else if (submittedDate.equals(currentTag)) {
for (int i = 0; i < reader.getAttributeCount(); i++) {
if ("type".equals(reader.getAttributeLocalName(i)) &&
"whenSubmitted".equals(reader.getAttributeValue(i))) {
inSubmissionDate = true;
break;
}
}
} else if (language.equals(currentTag)) {
inLanguage = true;
} else if (classCode.equals(currentTag)) {
for (int i = 0; i < reader.getAttributeCount(); i++) {
if ("scheme".equals(reader.getAttributeLocalName(i)) &&
"halTypology".equals(reader.getAttributeValue(i))) {
inClassCodeType = true;
break;
} else if ("scheme".equals(reader.getAttributeLocalName(i)) &&
"halDomain".equals(reader.getAttributeValue(i))) {
inClassCodeDomain = true;
break;
}
}
} else if (monograph.equals(currentTag)) {
inMonogr = true;
monogr = new Monograph();
publication.setMonograph(monogr);
} else if (monographIdno.equals(currentTag)) {
serialIdentifier = new Serial_Identifier();
inMonogrIdno = true;
monogrIdnoType = getAttributeValue(reader, "m");
} else if (monographTitle.equals(currentTag)) {
inMonogrTitle = true;
monogrTitleType = getAttributeValue(reader, "level");
} else if (monographMeeting.equals(currentTag)) {
inMonogrMeeting = true;
conferenceEvent = new Conference_Event();
conferenceEvent.setConference(new Conference());
} else if (monographMeetingTitle.equals(currentTag)) {
inMonogrMeetingTitle = true;
} else if (monographMeetingDate.equals(currentTag)) {
inMonogrMeetingDate = true;
monographMeetingDateType = getAttributeValue(reader, "type");
} else if (monographMeetingSettlement.equals(currentTag)) {
inMonogrMeetingSettlement = true;
} else if (monographMeetingCountry.equals(currentTag)) {
String countryISO = getAttributeValue(reader, "key");
Country country = new Country();
if (isNotEmpty(countryISO)) {
country.setIso(countryISO);
}
address.setCountry(country);
} else if (monographMeetingRegion.equals(currentTag)) {
inMonogrMeetingRegion = true;
} else if (monographImprint.equals(currentTag)) {
inMonogrImprint = true;
} else if (monographImprintPublisher.equals(currentTag)) {
inMonogrImprintPublisher = true;
} else if (monographImprintDate.equals(currentTag)) {
monographImprintDateType = getAttributeValue(reader, "type");
monographImprintDateWhen = getAttributeValue(reader, "when");
inMonogrImprintDate = true;
} else if (monographImprintBiblScope.equals(currentTag)) {
monographImprintBiblScopeUnit = getAttributeValue(reader, "unit");
inMonogrImprintBiblScope = true;
}
indentLevel++;
}