/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 * 
 *  http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package org.apache.rampart.policy;

import java.util.Iterator;

import org.apache.ws.secpolicy.model.Header;
import org.apache.ws.secpolicy.model.SupportingToken;

public class SupportingPolicyData extends RampartPolicyData {

    public void build(SupportingToken token) {

        if (token.getSignedParts() != null && !token.getSignedParts().isOptional()) {
            Iterator<Header> it = token.getSignedParts().getHeaders().iterator();
            this.setSignBody(token.getSignedParts().isBody());
            while (it.hasNext()) {
                Header header = it.next();
                this.addSignedPart(header.getNamespace(), header.getName());
            }
        }

        if (token.getEncryptedParts() != null && !token.getEncryptedParts().isOptional()) {
            Iterator<Header> it = token.getEncryptedParts().getHeaders().iterator();
            this.setEncryptBody(token.getEncryptedParts().isBody());
            while (it.hasNext()) {
                Header header = it.next();
                this.setEncryptedParts(header.getNamespace(), header.getName(),
                        "Header");
            }
        }

        if (token.getSignedElements() != null && !token.getSignedElements().isOptional()) {
            Iterator<String> it = token.getSignedElements().getXPathExpressions()
                    .iterator();
            while (it.hasNext()) {
                this.setSignedElements(it.next());
            }
            this.addDeclaredNamespaces(token.getSignedElements()
                    .getDeclaredNamespaces());
        }

        if (token.getEncryptedElements() != null && !token.getEncryptedElements().isOptional()) {
            Iterator<String> it = token.getEncryptedElements().getXPathExpressions()
                    .iterator();
            while (it.hasNext()) {
                this.setEncryptedElements(it.next());
            }
            if (token.getSignedElements() == null) {
                this.addDeclaredNamespaces(token.getEncryptedElements()
                        .getDeclaredNamespaces());
            }
        }
    }
}

@@ -843,36 +843,8 @@
 y;%0A%0A
-import java.util.Iterator;%0A%0A
 impo
@@ -1152,218 +1152,130 @@
     
-Iterator%3CHeader%3E it = token.getSignedParts().getHeaders().iterator();%0A            this.setSignBody(token.getSignedParts().isBody());%0A            while (it.hasNext()) %7B%0A                Header header = it.next();
+this.setSignBody(token.getSignedParts().isBody());%0A            for (Header header : token.getSignedParts().getHeaders()) %7B
 %0A   
@@ -1469,93 +1469,8 @@
 ) %7B%0A
-            Iterator%3CHeader%3E it = token.getEncryptedParts().getHeaders().iterator();%0A
     
@@ -1550,73 +1550,70 @@
     
-while (it.hasNext()) %7B%0A                Header header = it.next();
+for (Header header : token.getEncryptedParts().getHeaders()) %7B
 %0A   
@@ -1853,37 +1853,35 @@
         
-Iterator%3CString%3E it =
+for (String xpath :
  token.g
@@ -1924,73 +1924,8 @@
 ns()
-%0A                    .iterator();%0A            while (it.hasNext()
 ) %7B%0A
@@ -1959,33 +1959,29 @@
 nedElements(
-it.next()
+xpath
 );%0A         
@@ -2222,29 +2222,27 @@
     
-Iterator%3CString%3E it =
+for (String xpath :
  tok
@@ -2292,73 +2292,8 @@
 ns()
-%0A                    .iterator();%0A            while (it.hasNext()
 ) %7B%0A
@@ -2338,17 +2338,13 @@
 nts(
-it.next()
+xpath
 );%0A 

Use for loops instead of iterators.