1 23 24 31 32 package com.sun.enterprise.config.serverbeans.validation.tests; 33 import java.util.regex.Pattern ; 34 import javax.management.ObjectName ; 35 import javax.management.MalformedObjectNameException ; 36 37 import com.sun.enterprise.config.serverbeans.validation.Result; 38 import com.sun.enterprise.config.ConfigContext; 39 40 import javax.xml.parsers.*; 41 import org.xml.sax.*; 42 import java.io.ByteArrayInputStream ; 43 import java.io.IOException ; 44 import java.io.File ; 45 import java.util.StringTokenizer ; 46 import java.util.Vector ; 47 48 import java.util.logging.Logger ; 50 import java.util.logging.Level ; 51 import com.sun.logging.LogDomains; 52 import java.lang.StringBuffer ; 53 54 import com.sun.enterprise.config.serverbeans.Config; 55 import com.sun.enterprise.config.serverbeans.ServerBeansFactory; 56 import java.net.UnknownHostException ; 57 import java.net.InetAddress ; 58 59 60 61 62 63 66 67 public class StaticTest { 68 69 72 73 public static final String ADD = "ADD"; 75 public static final String DELETE = "DELETE"; 77 public static final String UPDATE = "UPDATE"; 79 public static final String SET = "SET"; 81 public static final String VALIDATE = "VALIDATE"; 83 84 public static boolean fileCheck = false; 86 public static boolean classPathCheck = false; 88 public static boolean javaHomeCheck = false; 90 91 public StaticTest() { 92 } 93 94 95 100 public static void checkIPAddress(final String addr) throws UnknownHostException { 101 if (valueContainsTokenExpression (addr) || validSymbolicAddress(addr)){ 102 return; 103 } else { 104 InetAddress.getByName(addr); 105 } 106 } 107 108 112 private static boolean validSymbolicAddress(final String address){ 113 return address.equalsIgnoreCase("ANY") || 114 address.equalsIgnoreCase("INADDR_ANY") || 115 address.equalsIgnoreCase("localhost"); 116 } 117 118 119 public static Config getConfig(ConfigContext context) { 121 Config mConfig=null; 122 try { 123 mConfig = ServerBeansFactory.getConfigBean(context); 124 } catch(Exception e) { 125 } 126 return mConfig; 127 } 128 129 public static boolean isOptionsValid(String options) { 130 boolean flag = true; 131 StringTokenizer token = new StringTokenizer (options," "); 132 while(token.hasMoreTokens()) { 133 if(!token.nextToken().startsWith("-")) { 134 flag = false; 135 break; 136 } 137 } 138 return flag; 139 } 140 141 public static boolean isClassPathValid(String path) { 142 boolean flag = true; 143 StringTokenizer token = new StringTokenizer (path, File.pathSeparator); 144 while(token.hasMoreTokens()) { 145 File f = new File (token.nextToken()); 146 if(classPathCheck) { 148 if(!f.exists()) { 149 flag = false; 150 break; 151 } 152 } 153 } 154 return flag; 155 } 156 157 163 public static boolean isJavaHomeValid(String path) { 164 boolean flag = true; 165 if(javaHomeCheck) { 166 String jdkPath = path + File.separator + "bin" + File.separatorChar; 167 if(System.getProperty("os.name").startsWith("Win")) { 168 jdkPath = jdkPath + "java.exe"; 169 } else { 170 jdkPath = jdkPath + "java"; 171 } 172 StringTokenizer token = new StringTokenizer (path, File.pathSeparator); 173 while(token.hasMoreTokens()) { 174 File f = new File (token.nextToken()); 175 if(!f.exists()) { 177 flag = false; 178 break; 179 } 180 } 181 } 182 return flag; 183 } 184 185 186 public static Vector tokens(String value) { 187 StringTokenizer token = new StringTokenizer (value,","); 188 Vector test = new Vector (); 189 while(token.hasMoreTokens()) 190 test.add(token.nextToken().trim()); 191 return test; 192 } 193 194 public static boolean isIdInList(String list, String poolId) 195 { 196 return null != poolId && tokens(list+"").contains(poolId); 197 } 198 199 200 201 static void setJavaHomeCheck(boolean check) { 202 javaHomeCheck = true; 203 } 204 205 public static boolean valueContainsTokenExpression(final Object value){ 206 return null != value && value instanceof String && token_pattern.matcher((String ) value).lookingAt(); 207 } 208 209 private static Pattern token_pattern = Pattern.compile("\\$\\{[^}]*}"); 210 211 214 public static final String DAS_CONFIG_NAME = "server-config"; 215 216 219 public static final String CONFIG_TEMPLATE_NAME = "default-config"; 220 221 222 } 223 | Popular Tags |