1 23 24 package com.sun.enterprise.config.serverbeans.validation.tests; 25 26 import java.util.logging.Level ; 27 28 import com.sun.enterprise.config.ConfigContextEvent; 29 import com.sun.enterprise.config.ConfigException; 30 import com.sun.enterprise.config.serverbeans.JmsHost; 31 import com.sun.enterprise.config.serverbeans.JmsService; 32 import com.sun.enterprise.config.serverbeans.ServerTags; 33 import com.sun.enterprise.config.serverbeans.validation.GenericValidator; 34 import com.sun.enterprise.config.serverbeans.validation.Result; 35 import com.sun.enterprise.config.serverbeans.validation.ValidationDescriptor; 36 37 43 44 public class JmsHostTest extends GenericValidator { 45 46 private static final char [] illegalChars = {'*', ',', ':'}; 47 48 public JmsHostTest (ValidationDescriptor desc) { 49 super(desc); 50 } 51 52 public Result validate(ConfigContextEvent cce) { 53 54 Result result = super.validate(cce); 55 try { 56 if (cce.getChoice().equals(StaticTest.DELETE)){ 57 if (isReferencedByParent(cce)){ 58 result.failed( 59 smh.getLocalString( 60 getClass().getName() + ".cannotDeleteReferencedJmsHost", 61 "Jms host (name={0}) can not be removed. It is referenced by its parent jms-service", 62 new Object []{getJmsHost(cce).getName()})); 63 } 64 } else { 65 if (cce.getName().equals(ServerTags.ADMIN_USER_NAME)) { 66 validateAdminUserName((String ) cce.getObject(), result); 67 } else if (cce.getName().equals(ServerTags.ADMIN_PASSWORD)) { 68 validateAdminUserPassword((String ) cce.getObject(), result); 69 } 70 } 71 } catch(Exception e) { 72 _logger.log(Level.FINE, "domainxmlverifier.exception", e); 73 } 74 return result; 75 } 76 77 private final boolean isReferencedByParent(final ConfigContextEvent cce) throws ConfigException { 78 final JmsHost host = getJmsHost(cce); 79 final JmsService parent = (JmsService) host.parent(); 80 return parent.getDefaultJmsHost() != null && parent.getDefaultJmsHost().equals(host.getName()); 81 } 82 83 private void validateAdminUserName(String name, Result result) { 84 85 if ((name == null) || (name.equals("")) || (name.length() < 1)) { 86 result.failed(smh.getLocalString(getClass().getName() + 87 ".blankOrNullString", 88 "Attribute {0} : cannot be null or blank", 89 new Object [] {ServerTags.ADMIN_USER_NAME})); 90 return; 91 } 92 93 if (hasIllegalChar(name.toCharArray(), illegalChars)) { 94 result.failed(smh.getLocalString(getClass().getName() + 95 ".stringHasIllegalChars", 96 "Attribute {0} cannot have any of illegal characters {1}", 97 new Object [] {ServerTags.ADMIN_USER_NAME, new String (illegalChars)})); 98 } 99 } 100 101 private void validateAdminUserPassword(String name, Result result) { 102 103 if ((name == null) || (name.equals("")) || (name.length() < 1)) { 104 result.failed(smh.getLocalString(getClass().getName() + 105 ".blankOrNullString", 106 "Attribute {0} : cannot be null or blank", 107 new Object [] {ServerTags.ADMIN_PASSWORD})); 108 return; 109 } 110 111 if (hasIllegalChar(name.toCharArray(), illegalChars)) { 112 result.failed(smh.getLocalString(getClass().getName() + 113 ".stringHasIllegalChars", 114 "Attribute {0} cannot have any of illegal characters {1}", 115 new Object [] {ServerTags.ADMIN_PASSWORD, new String (illegalChars)})); 116 } 117 } 118 119 private boolean hasIllegalChar (char[] inputCharArr, char[] illegalCharArr) { 120 121 int inputCharArrLen = inputCharArr.length; 122 int illegalCharArrLen = illegalCharArr.length; 123 124 for (int i=0; i<illegalCharArrLen; i++) { 125 for (int j=0; j<inputCharArrLen; j++) { 126 if (inputCharArr[j] == illegalCharArr[i]) { 127 return true; 128 } 129 } 130 } 131 132 return false; 133 } 134 135 private final JmsHost getJmsHost(final ConfigContextEvent cce) throws ConfigException{ 136 return (JmsHost) cce.getValidationTarget(); 137 } 138 139 } 140 | Popular Tags |