FileDocCategorySizeDatePackage
ConnectionFieldParser.javaAPI DocphoneME MR2 API (J2ME)4347Wed May 02 18:00:42 BST 2007gov.nist.javax.sdp.parser

ConnectionFieldParser

public class ConnectionFieldParser extends SDPParser
Parser for Connection Field.
version
JAIN-SIP-1.1 This code is in the public domain.

Fields Summary
Constructors Summary
public ConnectionFieldParser(String connectionField)
Creates new ConnectionFieldParser.

param
connectionField connection string to be parsed

        this.lexer = new Lexer("charLexer", connectionField);
    
protected ConnectionFieldParser()
Default constructor.

        super();
    
Methods Summary
public ConnectionAddressconnectionAddress(java.lang.String address)
Perform the connection address field parsing

param
address the connection address string to parse
return
the parsed connection address field

        ConnectionAddress connectionAddress = new ConnectionAddress();

        int begin = address.indexOf("/");

        if (begin != -1) {
            connectionAddress.setAddress(new Host(address.substring(0, begin)));

            int middle = address.indexOf("/", begin+1);
            if (middle != -1) {
                String ttl = address.substring(begin+1, middle);
                connectionAddress.setTtl(Integer.parseInt(ttl.trim()));

                String addressNumber = address.substring(middle+1);
                connectionAddress
                .setPort(Integer.parseInt(addressNumber.trim()));
            } else {
                String ttl = address.substring(begin+1);
                connectionAddress.setTtl(Integer.parseInt(ttl.trim()));
            }
        } else
            connectionAddress.setAddress(new Host(address));

        return connectionAddress;
    
public ConnectionFieldconnectionField()
Perform the connection address field parsing

return
the parsed connection address field
exception
ParseException if a parsing error occurs

        try {
            lexer.match('c");
            lexer.SPorHT();
            lexer.match('=");
            lexer.SPorHT();

            ConnectionField connectionField = new ConnectionField();

            lexer.match(LexerCore.ID);
            lexer.SPorHT();
            Token token = lexer.getNextToken();
            connectionField.setNettype(token.getTokenValue());

            lexer.match(LexerCore.ID);
            lexer.SPorHT();
            token = lexer.getNextToken();
            connectionField.setAddressType(token.getTokenValue());
            lexer.SPorHT();
            String rest = lexer.getRest();
            ConnectionAddress connectionAddress =
            connectionAddress(rest.trim());

            connectionField.setAddress(connectionAddress);

            return connectionField;
        } catch (SdpException e) {
            throw new ParseException(e.getMessage(), lexer.getPtr());
        }
    
public SDPFieldparse()
Perform the connection address field parsing

return
the parsed connection address field
exception
ParseException if a parsing error occurs

        return this.connectionField();