1 23 24 package com.sun.enterprise.config.serverbeans.validation.tests; 25 26 import java.util.*; 27 import java.util.logging.Level ; 28 import java.io.File ; 29 30 import com.sun.enterprise.config.serverbeans.validation.GenericValidator; 31 import com.sun.enterprise.config.serverbeans.validation.ValidationDescriptor; 32 import com.sun.enterprise.config.serverbeans.validation.Result; 33 import com.sun.enterprise.config.serverbeans.ServerTags; 34 import com.sun.enterprise.config.serverbeans.JavaConfig; 35 import com.sun.enterprise.config.serverbeans.validation.AttrClassName; 36 import com.sun.enterprise.config.serverbeans.validation.tests.StaticTest; 37 38 import com.sun.enterprise.config.ConfigBean; 39 import com.sun.enterprise.config.ConfigContextEvent; 40 import com.sun.enterprise.config.ConfigException; 41 42 48 49 public class JavaConfigTest extends GenericValidator { 50 51 public JavaConfigTest(ValidationDescriptor desc) { 52 super(desc); 53 } 54 55 public Result validate(ConfigContextEvent cce) { 56 Result result = super.validate(cce); 58 if(cce.getChoice().equals(StaticTest.VALIDATE)) { 59 StaticTest.setJavaHomeCheck(true); 60 JavaConfig javaConfig = (JavaConfig) cce.getObject(); 61 if(javaConfig.getJavaHome().indexOf("${")<0) 62 validateAttribute(ServerTags.JAVA_HOME, javaConfig.getJavaHome(), result); 63 validateAttribute(ServerTags.DEBUG_OPTIONS, javaConfig.getDebugOptions(), result); 64 validateAttribute(ServerTags.RMIC_OPTIONS, javaConfig.getRmicOptions(), result); 65 validateAttribute(ServerTags.JAVAC_OPTIONS, javaConfig.getJavacOptions(), result); 66 67 validateAttribute(ServerTags.CLASSPATH_PREFIX, javaConfig.getClasspathPrefix(), result); 68 validateAttribute(ServerTags.CLASSPATH_SUFFIX, javaConfig.getClasspathSuffix(), result); 69 validateAttribute(ServerTags.NATIVE_LIBRARY_PATH_PREFIX, javaConfig.getNativeLibraryPathPrefix(), result); 70 validateAttribute(ServerTags.NATIVE_LIBRARY_PATH_SUFFIX, javaConfig.getNativeLibraryPathSuffix(), result); 71 validateAttribute(ServerTags.BYTECODE_PREPROCESSORS, javaConfig.getBytecodePreprocessors(), result); 72 JvmOptionsTest.validateJvmOptions(javaConfig.getJvmOptions(), result); 73 } 74 75 if(cce.getChoice().equals(StaticTest.UPDATE)) { 76 validateAttribute(cce.getName(), (String ) cce.getObject(), result); 77 } 78 else if(cce.getChoice().equals(StaticTest.SET)) { 79 final String name = cce.getName(); 80 85 if (name.equals("JvmOptions")) { 86 JvmOptionsTest.validateJvmOptions((String [])cce.getObject(), result); 87 } 88 } 89 else { 90 } 92 return result; 93 } 94 95 public void validateAttribute(String name, String value, Result result) { 96 97 if(value == null || value.equals("")) 98 return; 99 if(name.equals(ServerTags.DEBUG_OPTIONS)) { 100 if(!StaticTest.isOptionsValid(value)) 101 result.failed(smh.getLocalString(getClass().getName() + ".invalidDebugOption", 102 "{0} : Invalid Java Debug options should start with -", new Object []{value})); 103 104 validateRunJDWP(value, result); 105 } 106 if(name.equals(ServerTags.RMIC_OPTIONS)) { 107 if(!StaticTest.isOptionsValid(value)) 108 result.failed(smh.getLocalString(getClass().getName() + ".invalidRmicOption", 109 "{0} : Invalid RMIC options should start with -", new Object []{value})); 110 } 111 if(name.equals(ServerTags.JAVAC_OPTIONS)) { 112 if(!StaticTest.isOptionsValid(value)) 113 result.failed(smh.getLocalString(getClass().getName() + ".invalidJavacOptions", 114 "{0} : Invalid javac options should start with -", new Object []{value})); 115 } 116 117 if(name.equals(ServerTags.CLASSPATH_PREFIX) || name.equals(ServerTags.CLASSPATH_SUFFIX) || 118 name.equals(ServerTags.NATIVE_LIBRARY_PATH_PREFIX) || 119 name.equals(ServerTags.NATIVE_LIBRARY_PATH_SUFFIX)) { 120 if(!StaticTest.isClassPathValid(value)) 121 result.failed(smh.getLocalString(getClass().getName() + ".invalidClasspath", 122 "{0} Classpath contains invalid path : Check the path", new Object []{name})); 123 } 124 if(name.equals(ServerTags.JAVA_HOME)) { 125 if(!StaticTest.isJavaHomeValid(value)) 126 result.failed(smh.getLocalString(getClass().getName() + ".invalidJavaHome", 127 "Warning : (java-home={0}), JDK does not exists in java home", new Object []{value})); 128 } 129 if(name.equals(ServerTags.BYTECODE_PREPROCESSORS)) 130 { 131 StringTokenizer tokens = new StringTokenizer(value,"."); 132 while(tokens.hasMoreTokens()) 133 { 134 String token = tokens.nextToken().trim(); 135 if(!AttrClassName.isValidClassName(token)) 136 { 137 result.failed(smh.getLocalString(getClass().getName() + ".invalidClassName", 138 "Attribute (bytecode-preprocessors={0}), {1} Invalid Class Name", new Object []{value,token})); 139 } 140 } 141 } 142 } 143 144 public void validateRunJDWP(String value, Result result) { 145 146 String runjdwp = value.substring(value.indexOf("jdwp:")+5); 148 int index=0; 149 try { 150 if(runjdwp != null) 151 index = runjdwp.indexOf("-X"); 152 } catch(Exception e) { 153 } 154 String debugStr=null; 155 if(index > 0) 156 debugStr = runjdwp.substring(0,index); 157 else 158 debugStr = runjdwp; 159 if(debugStr != null) { 160 String [] tokens = debugStr.split(","); 161 for(int i=0;i<tokens.length;i++) { 162 if(tokens[i].indexOf("=") < 0) { 163 result.failed(smh.getLocalString(getClass().getName() + ".invalidJDWPDebugOption", 164 "{0} : Invalid -Xrunjdwp option, please check syntax", new Object []{debugStr})); 165 break; 166 } 167 } 168 } 169 } 170 } 171 | Popular Tags |