1 /*
2 * Copyright 2006 University Corporation for Advanced Internet Development, Inc.
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 org.opensaml.xml.signature.impl;
18
19 import java.util.Collections;
20 import java.util.List;
21
22 import org.opensaml.xml.XMLObject;
23 import org.opensaml.xml.signature.X509CRL;
24 import org.opensaml.xml.util.DatatypeHelper;
25 import org.opensaml.xml.util.IndexingObjectStore;
26 import org.opensaml.xml.validation.AbstractValidatingXMLObject;
27
28 /** Concrete implementation of {@link X509CRL}. */
29 public class X509CRLImpl extends AbstractValidatingXMLObject implements X509CRL {
30
31 /** Class-level index of Base64 encoded CRL values. */
32 private static final IndexingObjectStore<String> B64_CRL_STORE = new IndexingObjectStore<String>();
33
34 /** Index to a stored Base64 encoded CRL. */
35 private String b64CRLIndex;
36
37 /**
38 * Constructor.
39 *
40 * @param namespaceURI the namespace the element is in
41 * @param elementLocalName the local name of the XML element this Object represents
42 * @param namespacePrefix the prefix for the given namespace
43 */
44 protected X509CRLImpl(String namespaceURI, String elementLocalName, String namespacePrefix) {
45 super(namespaceURI, elementLocalName, namespacePrefix);
46 }
47
48 /** {@inheritDoc} */
49 public String getValue() {
50 return B64_CRL_STORE.get(b64CRLIndex);
51 }
52
53 /** {@inheritDoc} */
54 public void setValue(String newValue) {
55 // Dump our cached DOM if the new value really is new
56 String currentCert = B64_CRL_STORE.get(b64CRLIndex);
57 String b64Cert = prepareForAssignment(currentCert, newValue);
58
59 // This is a new value, remove the old one, add the new one
60 if (!DatatypeHelper.safeEquals(currentCert, b64Cert)) {
61 B64_CRL_STORE.remove(b64CRLIndex);
62 b64CRLIndex = B64_CRL_STORE.put(b64Cert);
63 }
64 }
65
66 /** {@inheritDoc} */
67 public List<XMLObject> getOrderedChildren() {
68 return Collections.EMPTY_LIST;
69 }
70
71 /** {@inheritDoc} */
72 protected void finalize() throws Throwable {
73 super.finalize();
74 B64_CRL_STORE.remove(b64CRLIndex);
75 }
76 }