package com.amazonaws.transform; import csdk.gluads.Consts; import java.util.ArrayList; import java.util.Deque; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; import org.xmlpull.v1.XmlPullParser; /* loaded from: classes.dex */ public class StaxUnmarshallerContext { public int currentEventType; public final Map headers; public final XmlPullParser xpp; public final Deque stack = new LinkedList(); public String stackString = ""; public Map metadata = new HashMap(); public List metadataExpressions = new ArrayList(); public Map getMetadata() { return this.metadata; } public boolean isStartOfDocument() { return this.currentEventType == 0; } public StaxUnmarshallerContext(XmlPullParser xmlPullParser, Map map) { this.xpp = xmlPullParser; this.headers = map; } public String readText() { String nextText = this.xpp.nextText(); if (this.xpp.getEventType() != 3) { this.xpp.next(); } this.currentEventType = this.xpp.getEventType(); updateContext(); return nextText; } public int getCurrentDepth() { return this.stack.size(); } public boolean testExpression(String str, int i) { if (Consts.STRING_PERIOD.equals(str)) { return true; } int i2 = -1; while (true) { i2 = str.indexOf("/", i2 + 1); if (i2 <= -1) { break; } if (str.charAt(i2 + 1) != '@') { i++; } } if (getCurrentDepth() == i) { if (this.stackString.endsWith("/" + str)) { return true; } } return false; } public int nextEvent() { int next = this.xpp.next(); this.currentEventType = next; if (next == 4) { this.currentEventType = this.xpp.next(); } updateContext(); if (this.currentEventType == 2) { Iterator it = this.metadataExpressions.iterator(); while (true) { if (!it.hasNext()) { break; } MetadataExpression metadataExpression = (MetadataExpression) it.next(); if (testExpression(metadataExpression.expression, metadataExpression.targetDepth)) { this.metadata.put(metadataExpression.key, readText()); break; } } } return this.currentEventType; } public void registerMetadataExpression(String str, int i, String str2) { this.metadataExpressions.add(new MetadataExpression(str, i, str2)); } public static class MetadataExpression { public String expression; public String key; public int targetDepth; public MetadataExpression(String str, int i, String str2) { this.expression = str; this.targetDepth = i; this.key = str2; } } public final void updateContext() { int i = this.currentEventType; if (i != 2) { if (i == 3) { this.stack.pop(); this.stackString = this.stack.isEmpty() ? "" : (String) this.stack.peek(); return; } return; } String str = this.stackString + "/" + this.xpp.getName(); this.stackString = str; this.stack.push(str); } }