@Override public SessionCredentials getResult() { try { return builder.build(); } finally { builder = SessionCredentials.builder(); } }
/** @see <a href= "http://docs.aws.amazon.com/STS/latest/APIReference/API_Credentials.html" /> */ public class SessionCredentialsHandler extends ParseSax.HandlerForGeneratedRequestWithResult<SessionCredentials> { private final DateService dateService; @Inject protected SessionCredentialsHandler(DateService dateService) { this.dateService = dateService; } private StringBuilder currentText = new StringBuilder(); private SessionCredentials.Builder builder = SessionCredentials.builder(); @Override public SessionCredentials getResult() { try { return builder.build(); } finally { builder = SessionCredentials.builder(); } } @Override public void endElement(String uri, String name, String qName) { if (qName.equals("AccessKeyId")) { builder.accessKeyId(currentOrNull(currentText)); } else if (qName.equals("SecretAccessKey")) { builder.secretAccessKey(currentOrNull(currentText)); } else if (qName.equals("SessionToken")) { builder.sessionToken(currentOrNull(currentText)); } else if (qName.equals("Expiration")) { try { builder.expiration(dateService.iso8601SecondsDateParse(currentOrNull(currentText))); } catch (IllegalArgumentException e) { builder.expiration(dateService.iso8601DateParse(currentOrNull(currentText))); } } currentText.setLength(0); } @Override public void characters(char[] ch, int start, int length) { currentText.append(ch, start, length); } }