1 23 package com.sun.enterprise.tools.verifier.tests.ejb; 24 25 import java.util.Iterator ; 26 27 import com.sun.enterprise.deployment.EjbDescriptor; 28 import com.sun.enterprise.deployment.EnvironmentProperty; 29 import com.sun.enterprise.tools.verifier.Result; 30 import com.sun.enterprise.tools.verifier.Verifier; 31 import com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor; 32 33 39 public class EjbEnvEntryValue extends EjbTest implements EjbCheck { 40 41 42 52 public Result check(EjbDescriptor descriptor) { 53 54 Result result = getInitializedResult(); 55 ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor(); 56 57 if (!descriptor.getEnvironmentProperties().isEmpty()) { 58 for (Iterator itr = descriptor.getEnvironmentProperties().iterator(); 61 itr.hasNext();) { 62 EnvironmentProperty nextEnvironmentProperty = 63 (EnvironmentProperty) itr.next(); 64 if ((nextEnvironmentProperty.getValue() != null) 65 && (nextEnvironmentProperty.getValue().length() > 0)) { 66 if(!validEnvType(nextEnvironmentProperty)) { 67 addErrorDetails(result, compName); 68 result.failed(smh.getLocalString 69 (getClass().getName() + ".failed", 70 "Error: Environment entry name [ {0} ] does not have" + 71 " valid value [ {1} ] for constructor of the specified type" + 72 " [ {2} ] that takes a single String parameter within bean [ {3} ]", 73 new Object [] {nextEnvironmentProperty.getName(), 74 nextEnvironmentProperty.getValue(), nextEnvironmentProperty.getType(), 75 descriptor.getName()})); 76 } 77 } 78 } 79 } 80 if(result.getStatus() != Result.FAILED) { 81 addGoodDetails(result, compName); 82 result.passed(smh.getLocalString 83 (getClass().getName() + ".passed", 84 "Environment entry name has valid value")); 85 86 } 87 return result; 88 } 89 90 private boolean validEnvType(EnvironmentProperty nextEnvironmentProperty) { 91 92 try { 93 if (nextEnvironmentProperty.getType().equals("java.lang.String")) { 94 new String (nextEnvironmentProperty.getValue()); 95 96 } else if (nextEnvironmentProperty.getType().equals("java.lang.Integer")) { 97 new Integer (nextEnvironmentProperty.getValue()); 98 99 } else if (nextEnvironmentProperty.getType().equals("java.lang.Boolean")) { 100 new Boolean (nextEnvironmentProperty.getValue()); 103 104 } else if (nextEnvironmentProperty.getType().equals("java.lang.Double")) { 105 106 new Double (nextEnvironmentProperty.getValue()); 107 108 } else if (nextEnvironmentProperty.getType().equals("java.lang.Character") 109 && (nextEnvironmentProperty.getValue().length() == 1)) { 110 char c = (nextEnvironmentProperty.getValue()).charAt(0); 111 new Character (c); 112 } else if (nextEnvironmentProperty.getType().equals("java.lang.Byte")) { 113 new Byte (nextEnvironmentProperty.getValue()); 114 115 } else if (nextEnvironmentProperty.getType().equals("java.lang.Short")) { 116 new Short (nextEnvironmentProperty.getValue()); 117 118 } else if (nextEnvironmentProperty.getType().equals("java.lang.Long")) { 119 new Long (nextEnvironmentProperty.getValue()); 120 121 } else if (nextEnvironmentProperty.getType().equals("java.lang.Float")) { 122 new Float (nextEnvironmentProperty.getValue()); 123 124 } else { 125 return false; 126 } 127 } catch (Exception ex) { 128 Verifier.debug(ex); 129 return false; 130 } 131 return true; 132 } 133 134 } 135 | Popular Tags |