KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xml > internal > security > keys > content > x509 > XMLX509IssuerSerial


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.keys.content.x509;
18
19
20
21 import java.math.BigInteger JavaDoc;
22 import java.security.cert.X509Certificate JavaDoc;
23
24 import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
25 import com.sun.org.apache.xml.internal.security.utils.Constants;
26 import com.sun.org.apache.xml.internal.security.utils.RFC2253Parser;
27 import com.sun.org.apache.xml.internal.security.utils.SignatureElementProxy;
28 import com.sun.org.apache.xml.internal.security.utils.XMLUtils;
29 import org.w3c.dom.Document JavaDoc;
30 import org.w3c.dom.Element JavaDoc;
31
32
33 /**
34  *
35  * @author $Author: raul $
36  */

37 public class XMLX509IssuerSerial extends SignatureElementProxy
38         implements XMLX509DataContent {
39
40    /** {@link java.util.logging} logging facility */
41     static java.util.logging.Logger JavaDoc log =
42         java.util.logging.Logger.getLogger(
43                     XMLX509IssuerSerial.class.getName());
44
45    /**
46     * Constructor XMLX509IssuerSerial
47     *
48     * @param element
49     * @param BaseURI
50     * @throws XMLSecurityException
51     */

52    public XMLX509IssuerSerial(Element JavaDoc element, String JavaDoc BaseURI)
53            throws XMLSecurityException {
54       super(element, BaseURI);
55    }
56
57    /**
58     * Constructor XMLX509IssuerSerial
59     *
60     * @param doc
61     * @param X509IssuerName
62     * @param X509SerialNumber
63     */

64    public XMLX509IssuerSerial(Document JavaDoc doc, String JavaDoc X509IssuerName,
65                               BigInteger JavaDoc X509SerialNumber) {
66
67       super(doc);
68
69       XMLUtils.addReturnToElement(this._constructionElement);
70       this.addTextElement(X509IssuerName, Constants._TAG_X509ISSUERNAME);
71       XMLUtils.addReturnToElement(this._constructionElement);
72       this.addTextElement(X509SerialNumber.toString(), Constants._TAG_X509SERIALNUMBER);
73    }
74
75    /**
76     * Constructor XMLX509IssuerSerial
77     *
78     * @param doc
79     * @param X509IssuerName
80     * @param X509SerialNumber
81     */

82    public XMLX509IssuerSerial(Document JavaDoc doc, String JavaDoc X509IssuerName,
83                               String JavaDoc X509SerialNumber) {
84       this(doc, X509IssuerName, new BigInteger JavaDoc(X509SerialNumber));
85    }
86
87    /**
88     * Constructor XMLX509IssuerSerial
89     *
90     * @param doc
91     * @param X509IssuerName
92     * @param X509SerialNumber
93     */

94    public XMLX509IssuerSerial(Document JavaDoc doc, String JavaDoc X509IssuerName,
95                               int X509SerialNumber) {
96       this(doc, X509IssuerName,
97            new BigInteger JavaDoc(Integer.toString(X509SerialNumber)));
98    }
99
100    /**
101     * Constructor XMLX509IssuerSerial
102     *
103     * @param doc
104     * @param x509certificate
105     */

106    public XMLX509IssuerSerial(Document JavaDoc doc, X509Certificate JavaDoc x509certificate) {
107
108       this(doc,
109            RFC2253Parser.normalize(x509certificate.getIssuerDN().getName()),
110            x509certificate.getSerialNumber());
111    }
112
113    /**
114     * Method getSerialNumber
115     *
116     *
117     * @return the serial number
118     */

119    public BigInteger JavaDoc getSerialNumber() {
120
121       String JavaDoc text =
122          this.getTextFromChildElement(Constants._TAG_X509SERIALNUMBER,
123                                       Constants.SignatureSpecNS);
124       if (true)
125         if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "In dem X509SerialNumber wurde gefunden: " + text);
126
127       return new BigInteger JavaDoc(text);
128    }
129
130    /**
131     * Method getSerialNumberInteger
132     *
133     *
134     * @return the serial number as plain int
135     */

136    public int getSerialNumberInteger() {
137       return this.getSerialNumber().intValue();
138    }
139
140    /**
141     * Method getIssuerName
142     *
143     *
144     * @return the issuer name
145     */

146    public String JavaDoc getIssuerName() {
147
148       return RFC2253Parser
149          .normalize(this
150             .getTextFromChildElement(Constants._TAG_X509ISSUERNAME,
151                                      Constants.SignatureSpecNS));
152    }
153
154    /** @inheritDoc */
155    public boolean equals(Object JavaDoc obj) {
156
157       if (!obj.getClass().getName().equals(this.getClass().getName())) {
158          return false;
159       }
160
161       XMLX509IssuerSerial other = (XMLX509IssuerSerial) obj;
162
163
164       if (other.getSerialNumber().equals(this.getSerialNumber())
165                  && other.getIssuerName().equals(this.getIssuerName())) {
166            return true;
167       }
168
169        return false;
170    }
171
172    /** @inheritDoc */
173    public String JavaDoc getBaseLocalName() {
174       return Constants._TAG_X509ISSUERSERIAL;
175    }
176 }
177
Popular Tags