KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xml > internal > security > signature > SignatureProperties


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17 package com.sun.org.apache.xml.internal.security.signature;
18
19
20
21 import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
22 import com.sun.org.apache.xml.internal.security.utils.Constants;
23 import com.sun.org.apache.xml.internal.security.utils.IdResolver;
24 import com.sun.org.apache.xml.internal.security.utils.SignatureElementProxy;
25 import com.sun.org.apache.xml.internal.security.utils.XMLUtils;
26 import org.w3c.dom.Document JavaDoc;
27 import org.w3c.dom.Element JavaDoc;
28
29
30 /**
31  * Handles <code>&lt;ds:SignatureProperties&gt;</code> elements
32  * This Element holds {@link SignatureProperty} that contian additional information items
33  * concerning the generation of the signature.
34  * for example, data-time stamp, serial number of cryptographic hardware.
35  *
36  * @author Christian Geuer-Pollmann
37  *
38  */

39 public class SignatureProperties extends SignatureElementProxy {
40
41    /** {@link java.util.logging} logging facility */
42     static java.util.logging.Logger JavaDoc log =
43         java.util.logging.Logger.getLogger(SignatureProperties.class.getName());
44
45    /**
46     * Constructor SignatureProperties
47     *
48     * @param doc
49     */

50    public SignatureProperties(Document JavaDoc doc) {
51
52       super(doc);
53
54       XMLUtils.addReturnToElement(this._constructionElement);
55    }
56
57    /**
58     * Constructs {@link SignatureProperties} from {@link Element}
59     * @param element <code>SignatureProperties</code> elementt
60     * @param BaseURI the URI of the resource where the XML instance was stored
61     * @throws XMLSecurityException
62     */

63    public SignatureProperties(Element JavaDoc element, String JavaDoc BaseURI)
64            throws XMLSecurityException {
65       super(element, BaseURI);
66    }
67
68    /**
69     * Return the nonnegative number of added SignatureProperty elements.
70     *
71     * @return the number of SignatureProperty elements
72     */

73    public int getLength() {
74       
75          Element JavaDoc[] propertyElems =
76             XMLUtils.selectDsNodes(this._constructionElement,
77                                      Constants._TAG_SIGNATUREPROPERTY
78                                     );
79
80          return propertyElems.length;
81    }
82
83    /**
84     * Return the <it>i</it><sup>th</sup> SignatureProperty. Valid <code>i</code>
85     * values are 0 to <code>{link@ getSize}-1</code>.
86     *
87     * @param i Index of the requested {@link SignatureProperty}
88     * @return the <it>i</it><sup>th</sup> SignatureProperty
89     * @throws XMLSignatureException
90     */

91    public SignatureProperty item(int i) throws XMLSignatureException {
92       try {
93          Element JavaDoc propertyElem =
94             XMLUtils.selectDsNode(this._constructionElement,
95                                  Constants._TAG_SIGNATUREPROPERTY,
96                                  i );
97
98          if (propertyElem == null) {
99             return null;
100          }
101          return new SignatureProperty(propertyElem, this._baseURI);
102       } catch (XMLSecurityException ex) {
103          throw new XMLSignatureException("empty", ex);
104       }
105    }
106
107    /**
108     * Sets the <code>Id</code> attribute
109     *
110     * @param Id the <code>Id</code> attribute
111     */

112    public void setId(String JavaDoc Id) {
113
114       if ((this._state == MODE_SIGN) && (Id != null)) {
115          this._constructionElement.setAttributeNS(null, Constants._ATT_ID, Id);
116          IdResolver.registerElementById(this._constructionElement, Id);
117       }
118    }
119
120    /**
121     * Returns the <code>Id</code> attribute
122     *
123     * @return the <code>Id</code> attribute
124     */

125    public String JavaDoc getId() {
126       return this._constructionElement.getAttributeNS(null, Constants._ATT_ID);
127    }
128
129    /**
130     * Method addSignatureProperty
131     *
132     * @param sp
133     */

134    public void addSignatureProperty(SignatureProperty sp) {
135       this._constructionElement.appendChild(sp.getElement());
136       XMLUtils.addReturnToElement(this._constructionElement);
137    }
138
139    /** @inheritDoc */
140    public String JavaDoc getBaseLocalName() {
141       return Constants._TAG_SIGNATUREPROPERTIES;
142    }
143 }
144
Popular Tags