Code example for StringTokenizer

Methods: hasMoreTokens, nextToken

0
            s_logger.error("Error parsing the response : " + e.toString());
        } 
    } 
 
    private void setProfileConfiguration(String value) {
        StringTokenizer tokens = new StringTokenizer(value.trim());
        if (tokens.hasMoreTokens()) {
            String currentToken = tokens.nextToken();
            if ("switchport".equalsIgnoreCase(currentToken)) {
                parseProfileMode(tokens);
            } else if ("service-policy".equalsIgnoreCase(currentToken)) {
                String ioType = tokens.nextToken();
                if ("input".equalsIgnoreCase(ioType)) {
                    _portProfile.inputPolicyMap = tokens.nextToken();
                } else if ("output".equalsIgnoreCase(ioType)) {
                    _portProfile.outputPolicyMap = tokens.nextToken();
                } 
            } 
        } 
    } 
 
    private void parseProfileMode(StringTokenizer tokens) {
        if (tokens.hasMoreTokens()) {
            String firstToken = tokens.nextToken();
            if ("mode".equalsIgnoreCase(firstToken)) {
                setPortMode(tokens.nextToken());
            } else if ("access".equalsIgnoreCase(firstToken)) {
                if (tokens.hasMoreTokens()) {
                    String secondToken = tokens.nextToken();
                    assert("vlan".equalsIgnoreCase(secondToken));
                    if (tokens.hasMoreTokens()) {
                        _portProfile.vlan = tokens.nextToken();
                    } 
                } 
            } 
        } 
    }