0N/A/*
661N/A * reserved comment block
661N/A * DO NOT REMOVE OR ALTER!
0N/A */
0N/A/*
661N/A * Copyright 2005 The Apache Software Foundation.
661N/A *
661N/A * Licensed under the Apache License, Version 2.0 (the "License");
661N/A * you may not use this file except in compliance with the License.
661N/A * You may obtain a copy of the License at
661N/A *
661N/A * http://www.apache.org/licenses/LICENSE-2.0
661N/A *
661N/A * Unless required by applicable law or agreed to in writing, software
661N/A * distributed under the License is distributed on an "AS IS" BASIS,
661N/A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
661N/A * See the License for the specific language governing permissions and
661N/A * limitations under the License.
661N/A *
661N/A */
661N/A/*
2362N/A * Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved.
661N/A */
661N/A/*
661N/A * $Id: DOMKeyInfoFactory.java,v 1.2 2008/07/24 15:20:32 mullan Exp $
0N/A */
0N/Apackage org.jcp.xml.dsig.internal.dom;
0N/A
0N/Aimport java.math.BigInteger;
661N/Aimport java.security.KeyException;
661N/Aimport java.security.PublicKey;
0N/Aimport java.util.List;
0N/Aimport javax.xml.crypto.*;
0N/Aimport javax.xml.crypto.dsig.*;
0N/Aimport javax.xml.crypto.dom.*;
0N/Aimport javax.xml.crypto.dsig.keyinfo.*;
0N/Aimport org.w3c.dom.Document;
0N/Aimport org.w3c.dom.Element;
0N/Aimport org.w3c.dom.Node;
0N/A
0N/A/**
0N/A * DOM-based implementation of KeyInfoFactory.
0N/A *
0N/A * @author Sean Mullan
0N/A */
0N/Apublic final class DOMKeyInfoFactory extends KeyInfoFactory {
0N/A
0N/A public DOMKeyInfoFactory() { }
0N/A
0N/A public KeyInfo newKeyInfo(List content) {
0N/A return newKeyInfo(content, null);
0N/A }
0N/A
0N/A public KeyInfo newKeyInfo(List content, String id) {
0N/A return new DOMKeyInfo(content, id);
0N/A }
0N/A
0N/A public KeyName newKeyName(String name) {
0N/A return new DOMKeyName(name);
0N/A }
0N/A
0N/A public KeyValue newKeyValue(PublicKey key) throws KeyException {
0N/A return new DOMKeyValue(key);
0N/A }
0N/A
0N/A public PGPData newPGPData(byte[] keyId) {
0N/A return newPGPData(keyId, null, null);
0N/A }
0N/A
0N/A public PGPData newPGPData(byte[] keyId, byte[] keyPacket, List other) {
0N/A return new DOMPGPData(keyId, keyPacket, other);
0N/A }
0N/A
0N/A public PGPData newPGPData(byte[] keyPacket, List other) {
0N/A return new DOMPGPData(keyPacket, other);
0N/A }
0N/A
0N/A public RetrievalMethod newRetrievalMethod(String uri) {
0N/A return newRetrievalMethod(uri, null, null);
0N/A }
0N/A
0N/A public RetrievalMethod newRetrievalMethod(String uri, String type,
0N/A List transforms) {
0N/A if (uri == null) {
0N/A throw new NullPointerException("uri must not be null");
0N/A }
0N/A return new DOMRetrievalMethod(uri, type, transforms);
0N/A }
0N/A
0N/A public X509Data newX509Data(List content) {
0N/A return new DOMX509Data(content);
0N/A }
0N/A
0N/A public X509IssuerSerial newX509IssuerSerial(String issuerName,
0N/A BigInteger serialNumber) {
0N/A return new DOMX509IssuerSerial(issuerName, serialNumber);
0N/A }
0N/A
0N/A public boolean isFeatureSupported(String feature) {
0N/A if (feature == null) {
0N/A throw new NullPointerException();
0N/A } else {
0N/A return false;
0N/A }
0N/A }
0N/A
0N/A public URIDereferencer getURIDereferencer() {
0N/A return DOMURIDereferencer.INSTANCE;
0N/A }
0N/A
0N/A public KeyInfo unmarshalKeyInfo(XMLStructure xmlStructure)
0N/A throws MarshalException {
0N/A if (xmlStructure == null) {
0N/A throw new NullPointerException("xmlStructure cannot be null");
0N/A }
0N/A Node node =
0N/A ((javax.xml.crypto.dom.DOMStructure) xmlStructure).getNode();
0N/A node.normalize();
0N/A
0N/A Element element = null;
0N/A if (node.getNodeType() == Node.DOCUMENT_NODE) {
0N/A element = ((Document) node).getDocumentElement();
0N/A } else if (node.getNodeType() == Node.ELEMENT_NODE) {
0N/A element = (Element) node;
0N/A } else {
0N/A throw new MarshalException
0N/A ("xmlStructure does not contain a proper Node");
0N/A }
0N/A
0N/A // check tag
0N/A String tag = element.getLocalName();
0N/A if (tag == null) {
0N/A throw new MarshalException("Document implementation must " +
0N/A "support DOM Level 2 and be namespace aware");
0N/A }
0N/A if (tag.equals("KeyInfo")) {
661N/A return new DOMKeyInfo(element, null, getProvider());
0N/A } else {
0N/A throw new MarshalException("invalid KeyInfo tag: " + tag);
0N/A }
0N/A }
0N/A}