< prev index next >
src/java.xml.ws/share/classes/javax/xml/soap/MimeHeaders.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2004, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
--- 1,7 ----
/*
! * Copyright (c) 2004, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
*** 40,57 ****
* @see SOAPMessage#getAttachments
* @see AttachmentPart
* @since 1.6
*/
public class MimeHeaders {
! private Vector headers;
/**
* Constructs a default {@code MimeHeaders} object initialized with
* an empty {@code Vector} object.
*/
public MimeHeaders() {
! headers = new Vector();
}
/**
* Returns all of the values for the specified header as an array of
* {@code String} objects.
--- 40,57 ----
* @see SOAPMessage#getAttachments
* @see AttachmentPart
* @since 1.6
*/
public class MimeHeaders {
! private Vector<MimeHeader> headers;
/**
* Constructs a default {@code MimeHeaders} object initialized with
* an empty {@code Vector} object.
*/
public MimeHeaders() {
! headers = new Vector<>();
}
/**
* Returns all of the values for the specified header as an array of
* {@code String} objects.
*** 60,73 ****
* @return a {@code String} array with all of the values for the
* specified header
* @see #setHeader
*/
public String[] getHeader(String name) {
! Vector values = new Vector();
for(int i = 0; i < headers.size(); i++) {
! MimeHeader hdr = (MimeHeader) headers.elementAt(i);
if (hdr.getName().equalsIgnoreCase(name)
&& hdr.getValue() != null)
values.addElement(hdr.getValue());
}
--- 60,73 ----
* @return a {@code String} array with all of the values for the
* specified header
* @see #setHeader
*/
public String[] getHeader(String name) {
! Vector<String> values = new Vector<>();
for(int i = 0; i < headers.size(); i++) {
! MimeHeader hdr = headers.elementAt(i);
if (hdr.getName().equalsIgnoreCase(name)
&& hdr.getValue() != null)
values.addElement(hdr.getValue());
}
*** 101,111 ****
if ((name == null) || name.equals(""))
throw new IllegalArgumentException("Illegal MimeHeader name");
for(int i = 0; i < headers.size(); i++) {
! MimeHeader hdr = (MimeHeader) headers.elementAt(i);
if (hdr.getName().equalsIgnoreCase(name)) {
if (!found) {
headers.setElementAt(new MimeHeader(hdr.getName(),
value), i);
found = true;
--- 101,111 ----
if ((name == null) || name.equals(""))
throw new IllegalArgumentException("Illegal MimeHeader name");
for(int i = 0; i < headers.size(); i++) {
! MimeHeader hdr = headers.elementAt(i);
if (hdr.getName().equalsIgnoreCase(name)) {
if (!found) {
headers.setElementAt(new MimeHeader(hdr.getName(),
value), i);
found = true;
*** 139,149 ****
throw new IllegalArgumentException("Illegal MimeHeader name");
int pos = headers.size();
for(int i = pos - 1 ; i >= 0; i--) {
! MimeHeader hdr = (MimeHeader) headers.elementAt(i);
if (hdr.getName().equalsIgnoreCase(name)) {
headers.insertElementAt(new MimeHeader(name, value),
i+1);
return;
}
--- 139,149 ----
throw new IllegalArgumentException("Illegal MimeHeader name");
int pos = headers.size();
for(int i = pos - 1 ; i >= 0; i--) {
! MimeHeader hdr = headers.elementAt(i);
if (hdr.getName().equalsIgnoreCase(name)) {
headers.insertElementAt(new MimeHeader(name, value),
i+1);
return;
}
*** 158,168 ****
* @param name a {@code String} with the name of the header for
* which to search
*/
public void removeHeader(String name) {
for(int i = 0; i < headers.size(); i++) {
! MimeHeader hdr = (MimeHeader) headers.elementAt(i);
if (hdr.getName().equalsIgnoreCase(name))
headers.removeElementAt(i--);
}
}
--- 158,168 ----
* @param name a {@code String} with the name of the header for
* which to search
*/
public void removeHeader(String name) {
for(int i = 0; i < headers.size(); i++) {
! MimeHeader hdr = headers.elementAt(i);
if (hdr.getName().equalsIgnoreCase(name))
headers.removeElementAt(i--);
}
}
*** 178,207 ****
* Returns all the {@code MimeHeader}s in this {@code MimeHeaders} object.
*
* @return an {@code Iterator} object over this {@code MimeHeaders}
* object's list of {@code MimeHeader} objects
*/
! public Iterator getAllHeaders() {
return headers.iterator();
}
! class MatchingIterator implements Iterator {
! private boolean match;
! private Iterator iterator;
! private String[] names;
! private Object nextHeader;
! MatchingIterator(String[] names, boolean match) {
this.match = match;
this.names = names;
! this.iterator = headers.iterator();
}
! private Object nextMatch() {
next:
while (iterator.hasNext()) {
! MimeHeader hdr = (MimeHeader) iterator.next();
if (names == null)
return match ? null : hdr;
for(int i = 0; i < names.length; i++)
--- 178,207 ----
* Returns all the {@code MimeHeader}s in this {@code MimeHeaders} object.
*
* @return an {@code Iterator} object over this {@code MimeHeaders}
* object's list of {@code MimeHeader} objects
*/
! public Iterator<MimeHeader> getAllHeaders() {
return headers.iterator();
}
! static class MatchingIterator implements Iterator<MimeHeader> {
! private final boolean match;
! private final Iterator<MimeHeader> iterator;
! private final String[] names;
! private MimeHeader nextHeader;
! MatchingIterator(String[] names, boolean match, Iterator<MimeHeader> i) {
this.match = match;
this.names = names;
! this.iterator = i;
}
! private MimeHeader nextMatch() {
next:
while (iterator.hasNext()) {
! MimeHeader hdr = iterator.next();
if (names == null)
return match ? null : hdr;
for(int i = 0; i < names.length; i++)
*** 215,243 ****
}
return null;
}
public boolean hasNext() {
if (nextHeader == null)
nextHeader = nextMatch();
return nextHeader != null;
}
! public Object next() {
// hasNext should've prefetched the header for us,
// return it.
if (nextHeader != null) {
! Object ret = nextHeader;
nextHeader = null;
return ret;
}
if (hasNext())
return nextHeader;
return null;
}
public void remove() {
iterator.remove();
}
}
--- 215,246 ----
}
return null;
}
+ @Override
public boolean hasNext() {
if (nextHeader == null)
nextHeader = nextMatch();
return nextHeader != null;
}
! @Override
! public MimeHeader next() {
// hasNext should've prefetched the header for us,
// return it.
if (nextHeader != null) {
! MimeHeader ret = nextHeader;
nextHeader = null;
return ret;
}
if (hasNext())
return nextHeader;
return null;
}
+ @Override
public void remove() {
iterator.remove();
}
}
*** 249,260 ****
* @param names an array of {@code String} objects with the names
* for which to search
* @return an {@code Iterator} object over the {@code MimeHeader}
* objects whose name matches one of the names in the given list
*/
! public Iterator getMatchingHeaders(String[] names) {
! return new MatchingIterator(names, true);
}
/**
* Returns all of the {@code MimeHeader} objects whose name does not
* match a name in the given array of names.
--- 252,263 ----
* @param names an array of {@code String} objects with the names
* for which to search
* @return an {@code Iterator} object over the {@code MimeHeader}
* objects whose name matches one of the names in the given list
*/
! public Iterator<MimeHeader> getMatchingHeaders(String[] names) {
! return new MatchingIterator(names, true, headers.iterator());
}
/**
* Returns all of the {@code MimeHeader} objects whose name does not
* match a name in the given array of names.
*** 262,270 ****
* @param names an array of {@code String} objects with the names
* for which to search
* @return an {@code Iterator} object over the {@code MimeHeader}
* objects whose name does not match one of the names in the given list
*/
! public Iterator getNonMatchingHeaders(String[] names) {
! return new MatchingIterator(names, false);
}
}
--- 265,273 ----
* @param names an array of {@code String} objects with the names
* for which to search
* @return an {@code Iterator} object over the {@code MimeHeader}
* objects whose name does not match one of the names in the given list
*/
! public Iterator<MimeHeader> getNonMatchingHeaders(String[] names) {
! return new MatchingIterator(names, false, headers.iterator());
}
}
< prev index next >