www.pudn.com > cryptix-asn1-0.1.11.zip > GeneralString.java


/* $Id: GeneralString.java,v 1.2 2001/05/24 16:52:49 raif Exp $ 
 * 
 * Copyright (C) 1997-2001 The Cryptix Foundation Limited. All rights reserved. 
 * 
 * Use, modification, copying and distribution of this software is subject to 
 * the terms and conditions of the Cryptix General Licence. You should have 
 * received a copy of the Cryptix General Licence along with this library; if 
 * not, you can download a copy from http://www.cryptix.org/ 
 */ 
package cryptix.asn1.lang; 
 
import cryptix.asn1.io.ASNReader; 
import cryptix.asn1.io.ASNWriter; 
import cryptix.asn1.io.BlankElementException; 
import cryptix.asn1.io.ElementNotFoundException; 
 
import org.apache.log4j.Category; 
 
import java.io.EOFException; 
import java.io.IOException; 
 
/** 
 * The basic implementation of an ASN.1 GeneralString type.

* * @version $Revision: 1.2 $ * @author Raif S. Naffah */ public class GeneralString extends ASNString implements IType { // Constants and vars // ....................................................................... static Category cat = Category.getInstance(GeneralString.class.getName()); // Constructor(s) // ....................................................................... public GeneralString() { super("", new Tag(Tag.GENERAL_STRING)); } public GeneralString(String name) { super(name, new Tag(Tag.GENERAL_STRING)); } public GeneralString(String name, Tag tag) { super(name, tag); } public GeneralString(String name, Object value) { this(name, new Tag(Tag.GENERAL_STRING), value); } /** * Constructs a new instance of a GeneralString type, given a designated * Tag and a designated initial value. * * @param name the name of this instance. * @param tag the designated Tag value. * @param value the designated initial value. Allowed types are: * java.lang.String, and any subclass of cryptix.asn1.lang.ASNString. * @exception ClassCastException if the designated value is not a String. */ public GeneralString(String name, Tag tag, Object value) { super(name, tag); value(value); if (this.value != null) defaultValue(this.value); } // Class methods // ....................................................................... /** * Returns a new instance of this type with a trivial name and the * designated value. * * @param value a designated initial value for the new instance. * @return a new instance with the designated value. * @exception ClassCastException if the designated value is not appropriate * (see constructor with 3 arguments for suitable types of value). */ public static GeneralString getInstance(String value) { return new GeneralString("", value); } /** * Returns a new instance of this type with a trivial name and the * designated value. * * @param value a designated initial value for the new instance. * @return a new instance with the designated value. * @exception ClassCastException if the designated value is not appropriate * (see constructor with 3 arguments for suitable types of value). */ public static GeneralString getInstance(ASNString value) { return new GeneralString("", value); } // Redefinition of methods in superclass Type // ....................................................................... /** * Decodes a GeneralString from an input stream. * * @param is the ASN.1 stream to read from. * @exception IOException if an exception occurs during the operation. */ public void decode(ASNReader is) throws IOException { this.decodeInternal(is, Tag.GENERAL_STRING); } /** * Encodes a GeneralString to an output stream. * * @param os the ASN.1 stream to write to. * @exception IOException if an exception occurs during the operation. */ public void encode(ASNWriter os) throws IOException { this.encodeInternal(os, Tag.GENERAL_STRING); } }