1 16 package org.apache.axis.types; 17 18 import org.apache.axis.utils.Messages; 19 20 28 public class Token extends NormalizedString { 29 30 public Token() { 31 super(); 32 } 33 34 38 public Token(String stValue) throws IllegalArgumentException { 39 try { 40 setValue(stValue); 41 } 42 catch (IllegalArgumentException e) { 43 throw new IllegalArgumentException ( 45 Messages.getMessage("badToken00") + "data=[" + 46 stValue + "]"); 47 } 48 } 49 50 63 public static boolean isValid(String stValue) { 64 int scan; 65 if ( (stValue == null) || (stValue.length() == 0) ) 67 return true; 68 69 if (stValue.charAt(0) == 0x20) 71 return false; 72 73 if (stValue.charAt(stValue.length() - 1) == 0x20) 75 return false; 76 77 for (scan=0; scan < stValue.length(); scan++) { 78 char cDigit = stValue.charAt(scan); 79 switch (cDigit) { 80 case 0x09: 81 case 0x0A: 82 return false; 83 case 0x20: 84 if (scan+1 < stValue.length()) 86 if (stValue.charAt(scan + 1) == 0x20) { 87 return false; 88 } 89 default: 90 break; 91 } 92 } 93 return true; 94 } 95 96 102 public void setValue(String stValue) throws IllegalArgumentException { 103 if (Token.isValid(stValue) == false) 104 throw new IllegalArgumentException ( 105 Messages.getMessage("badToken00") + 106 " data=[" + stValue + "]"); 107 m_value = stValue; 108 } 109 110 } 111 | Popular Tags |