J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. Sun designates this |
| 8 | * particular file as subject to the "Classpath" exception as provided |
| 9 | * by Sun in the LICENSE file that accompanied this code. |
| 10 | * |
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | * version 2 for more details (a copy is included in the LICENSE file that |
| 15 | * accompanied this code). |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License version |
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 23 | * have any questions. |
| 24 | */ |
| 25 | /* |
| 26 | * $Id: ExcC14NParameterSpec.java,v 1.7 2005/05/13 18:45:42 mullan Exp $ |
| 27 | */ |
| 28 | package javax.xml.crypto.dsig.spec; |
| 29 | |
| 30 | import javax.xml.crypto.dsig.CanonicalizationMethod; |
| 31 | import java.util.ArrayList; |
| 32 | import java.util.Collections; |
| 33 | import java.util.List; |
| 34 | |
| 35 | /** |
| 36 | * Parameters for the W3C Recommendation: |
| 37 | * <a href="http://www.w3.org/TR/xml-exc-c14n/"> |
| 38 | * Exclusive XML Canonicalization (C14N) algorithm</a>. The |
| 39 | * parameters include an optional inclusive namespace prefix list. The XML |
| 40 | * Schema Definition of the Exclusive XML Canonicalization parameters is |
| 41 | * defined as: |
| 42 | * <pre><code> |
| 43 | * <schema xmlns="http://www.w3.org/2001/XMLSchema" |
| 44 | * xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" |
| 45 | * targetNamespace="http://www.w3.org/2001/10/xml-exc-c14n#" |
| 46 | * version="0.1" elementFormDefault="qualified"> |
| 47 | * |
| 48 | * <element name="InclusiveNamespaces" type="ec:InclusiveNamespaces"/> |
| 49 | * <complexType name="InclusiveNamespaces"> |
| 50 | * <attribute name="PrefixList" type="xsd:string"/> |
| 51 | * </complexType> |
| 52 | * </schema> |
| 53 | * </code></pre> |
| 54 | * |
| 55 | * @author Sean Mullan |
| 56 | * @author JSR 105 Expert Group |
| 57 | * @since 1.6 |
| 58 | * @see CanonicalizationMethod |
| 59 | */ |
| 60 | public final class ExcC14NParameterSpec implements C14NMethodParameterSpec { |
| 61 | |
| 62 | private List preList; |
| 63 | |
| 64 | /** |
| 65 | * Indicates the default namespace ("#default"). |
| 66 | */ |
| 67 | public static final String DEFAULT = "#default"; |
| 68 | |
| 69 | /** |
| 70 | * Creates a <code>ExcC14NParameterSpec</code> with an empty prefix |
| 71 | * list. |
| 72 | */ |
| 73 | public ExcC14NParameterSpec() { |
| 74 | preList = Collections.EMPTY_LIST; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Creates a <code>ExcC14NParameterSpec</code> with the specified list |
| 79 | * of prefixes. The list is copied to protect against subsequent |
| 80 | * modification. |
| 81 | * |
| 82 | * @param prefixList the inclusive namespace prefix list. Each entry in |
| 83 | * the list is a <code>String</code> that represents a namespace prefix. |
| 84 | * @throws NullPointerException if <code>prefixList</code> is |
| 85 | * <code>null</code> |
| 86 | * @throws ClassCastException if any of the entries in the list are not |
| 87 | * of type <code>String</code> |
| 88 | */ |
| 89 | public ExcC14NParameterSpec(List prefixList) { |
| 90 | if (prefixList == null) { |
| 91 | throw new NullPointerException("prefixList cannot be null"); |
| 92 | } |
| 93 | this.preList = new ArrayList(prefixList); |
| 94 | for (int i = 0, size = preList.size(); i < size; i++) { |
| 95 | if (!(preList.get(i) instanceof String)) { |
| 96 | throw new ClassCastException("not a String"); |
| 97 | } |
| 98 | } |
| 99 | preList = Collections.unmodifiableList(preList); |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Returns the inclusive namespace prefix list. Each entry in the list |
| 104 | * is a <code>String</code> that represents a namespace prefix. |
| 105 | * |
| 106 | * <p>This implementation returns an {@link |
| 107 | * java.util.Collections#unmodifiableList unmodifiable list}. |
| 108 | * |
| 109 | * @return the inclusive namespace prefix list (may be empty but never |
| 110 | * <code>null</code>) |
| 111 | */ |
| 112 | public List getPrefixList() { |
| 113 | return preList; |
| 114 | } |
| 115 | } |