001 /** 002 * 003 * Licensed to the Apache Software Foundation (ASF) under one or more 004 * contributor license agreements. See the NOTICE file distributed with 005 * this work for additional information regarding copyright ownership. 006 * The ASF licenses this file to You under the Apache License, Version 2.0 007 * (the "License"); you may not use this file except in compliance with 008 * the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 019 package org.apache.geronimo.util.asn1.x509; 020 021 import org.apache.geronimo.util.asn1.ASN1Encodable; 022 import org.apache.geronimo.util.asn1.ASN1EncodableVector; 023 import org.apache.geronimo.util.asn1.ASN1Sequence; 024 import org.apache.geronimo.util.asn1.DERObject; 025 import org.apache.geronimo.util.asn1.DERObjectIdentifier; 026 import org.apache.geronimo.util.asn1.DERSequence; 027 028 /** 029 * The AccessDescription object. 030 * <pre> 031 * AccessDescription ::= SEQUENCE { 032 * accessMethod OBJECT IDENTIFIER, 033 * accessLocation GeneralName } 034 * </pre> 035 */ 036 public class AccessDescription 037 extends ASN1Encodable 038 { 039 DERObjectIdentifier accessMethod = null; 040 GeneralName accessLocation = null; 041 042 public static AccessDescription getInstance( 043 Object obj) 044 { 045 if (obj instanceof AccessDescription) 046 { 047 return (AccessDescription)obj; 048 } 049 else if (obj instanceof ASN1Sequence) 050 { 051 return new AccessDescription((ASN1Sequence)obj); 052 } 053 054 throw new IllegalArgumentException("unknown object in factory"); 055 } 056 057 public AccessDescription( 058 ASN1Sequence seq) 059 { 060 if (seq.size() != 2) 061 { 062 throw new IllegalArgumentException("wrong number of elements in inner sequence"); 063 } 064 065 accessMethod = (DERObjectIdentifier)seq.getObjectAt(0); 066 accessLocation = GeneralName.getInstance(seq.getObjectAt(1)); 067 } 068 069 /** 070 * create an AccessDescription with the oid and location provided. 071 */ 072 public AccessDescription( 073 DERObjectIdentifier oid, 074 GeneralName location) 075 { 076 accessMethod = oid; 077 accessLocation = location; 078 } 079 080 /** 081 * 082 * @return the access method. 083 */ 084 public DERObjectIdentifier getAccessMethod() 085 { 086 return accessMethod; 087 } 088 089 /** 090 * 091 * @return the access location 092 */ 093 public GeneralName getAccessLocation() 094 { 095 return accessLocation; 096 } 097 098 public DERObject toASN1Object() 099 { 100 ASN1EncodableVector accessDescription = new ASN1EncodableVector(); 101 102 accessDescription.add(accessMethod); 103 accessDescription.add(accessLocation); 104 105 return new DERSequence(accessDescription); 106 } 107 108 public String toString() 109 { 110 return ("AccessDescription: Oid(" + this.accessMethod.getId() + ")"); 111 } 112 }