1 23 24 package com.sun.enterprise.config.serverbeans.validation; 25 26 import java.io.File ; 27 import java.util.logging.Level ; 28 29 41 42 43 44 public class AttrClassName extends AttrType { 45 46 public AttrClassName(String name, String type, boolean optional) { 47 super(name,type, optional); 48 } 49 50 public void validate(Object o, ValidationContext valCtx) { 51 _logger.log(Level.CONFIG, "Testing attr: "+valCtx.attrName); 52 53 super.validate(o, valCtx); if(o == null) 55 return; 56 if(o.equals("")) 57 valCtx.result.failed(valCtx.smh.getLocalString(getClass().getName() + ".nullClassName", 58 "Attribute({0}=\"\" : ClassName not Valid", new Object [] {valCtx.attrName})); 59 60 String className = (String )o; 62 int classStart = className.lastIndexOf("."); 63 if(classStart != -1) 64 className = className.substring(classStart+1); 65 if(!isValidClassName(className)){ 66 valCtx.result.failed(valCtx.smh.getLocalString(getClass().getName() + ".invalidClassName", 67 "Attribute({0}={1}) : ClassName not Valid", new Object [] {valCtx.attrName, (String )o})); 68 } 69 } 70 71 public static boolean isValidClassName(String className) { 72 boolean valid = true; 73 for(int i=0;i<className.length();i++) { 74 if(i == 0) { 75 if(!Character.isJavaIdentifierStart(className.charAt(i))) 76 valid = false; 77 } 78 if(!Character.isJavaIdentifierPart(className.charAt(i))) 79 valid = false; 80 } 81 return valid; 82 } 83 } 84 | Popular Tags |