001 /*
002 * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025 /*
026 * $Id: ExcC14NParameterSpec.java,v 1.7 2005/05/13 18:45:42 mullan Exp $
027 */
028 package javax.xml.crypto.dsig.spec;
029
030 import javax.xml.crypto.dsig.CanonicalizationMethod;
031 import java.util.ArrayList;
032 import java.util.Collections;
033 import java.util.List;
034
035 /**
036 * Parameters for the W3C Recommendation:
037 * <a href="http://www.w3.org/TR/xml-exc-c14n/">
038 * Exclusive XML Canonicalization (C14N) algorithm</a>. The
039 * parameters include an optional inclusive namespace prefix list. The XML
040 * Schema Definition of the Exclusive XML Canonicalization parameters is
041 * defined as:
042 * <pre><code>
043 * <schema xmlns="http://www.w3.org/2001/XMLSchema"
044 * xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#"
045 * targetNamespace="http://www.w3.org/2001/10/xml-exc-c14n#"
046 * version="0.1" elementFormDefault="qualified">
047 *
048 * <element name="InclusiveNamespaces" type="ec:InclusiveNamespaces"/>
049 * <complexType name="InclusiveNamespaces">
050 * <attribute name="PrefixList" type="xsd:string"/>
051 * </complexType>
052 * </schema>
053 * </code></pre>
054 *
055 * @author Sean Mullan
056 * @author JSR 105 Expert Group
057 * @since 1.6
058 * @see CanonicalizationMethod
059 */
060 public final class ExcC14NParameterSpec implements
061 C14NMethodParameterSpec {
062
063 private List preList;
064
065 /**
066 * Indicates the default namespace ("#default").
067 */
068 public static final String DEFAULT = "#default";
069
070 /**
071 * Creates a <code>ExcC14NParameterSpec</code> with an empty prefix
072 * list.
073 */
074 public ExcC14NParameterSpec() {
075 preList = Collections.EMPTY_LIST;
076 }
077
078 /**
079 * Creates a <code>ExcC14NParameterSpec</code> with the specified list
080 * of prefixes. The list is copied to protect against subsequent
081 * modification.
082 *
083 * @param prefixList the inclusive namespace prefix list. Each entry in
084 * the list is a <code>String</code> that represents a namespace prefix.
085 * @throws NullPointerException if <code>prefixList</code> is
086 * <code>null</code>
087 * @throws ClassCastException if any of the entries in the list are not
088 * of type <code>String</code>
089 */
090 public ExcC14NParameterSpec(List prefixList) {
091 if (prefixList == null) {
092 throw new NullPointerException("prefixList cannot be null");
093 }
094 this .preList = new ArrayList(prefixList);
095 for (int i = 0, size = preList.size(); i < size; i++) {
096 if (!(preList.get(i) instanceof String)) {
097 throw new ClassCastException("not a String");
098 }
099 }
100 preList = Collections.unmodifiableList(preList);
101 }
102
103 /**
104 * Returns the inclusive namespace prefix list. Each entry in the list
105 * is a <code>String</code> that represents a namespace prefix.
106 *
107 * <p>This implementation returns an {@link
108 * java.util.Collections#unmodifiableList unmodifiable list}.
109 *
110 * @return the inclusive namespace prefix list (may be empty but never
111 * <code>null</code>)
112 */
113 public List getPrefixList() {
114 return preList;
115 }
116 }
|