1 23 24 package com.sun.enterprise.config.serverbeans.validation; 25 26 import java.util.Vector ; 27 import java.util.logging.Level ; 28 29 import com.sun.enterprise.config.ConfigContext; 30 import com.sun.enterprise.config.ConfigException; 31 import com.sun.enterprise.config.serverbeans.validation.tests.StaticTest; 32 33 import com.sun.enterprise.config.serverbeans.Domain; 34 import com.sun.enterprise.config.serverbeans.Resources; 35 import com.sun.enterprise.config.serverbeans.AdminObjectResource; 36 import com.sun.enterprise.config.serverbeans.ConnectorConnectionPool; 37 import com.sun.enterprise.config.serverbeans.CustomResource; 38 import com.sun.enterprise.config.serverbeans.ConnectorResource; 39 import com.sun.enterprise.config.serverbeans.ExternalJndiResource; 40 import com.sun.enterprise.config.serverbeans.JdbcConnectionPool; 41 import com.sun.enterprise.config.serverbeans.JdbcResource; 42 import com.sun.enterprise.config.serverbeans.MailResource; 43 import com.sun.enterprise.config.serverbeans.PersistenceManagerFactoryResource; 44 import com.sun.enterprise.config.serverbeans.ResourceAdapterConfig; 45 46 58 59 60 61 public class AttrUniqueJNDI extends AttrType { 62 63 public AttrUniqueJNDI(String name, String type, boolean optional) { 64 super(name,type, optional); 65 } 66 67 public void validate(Object o, ValidationContext valCtx) { 68 super.validate(o, valCtx); String jndiName = null; 70 String choice = valCtx.choice; 71 boolean flag = false; 72 if(o == null || o.equals("")) 73 return; 74 jndiName = (String )o; 75 if(choice.equals("ADD") && isResourceBeingUsed(valCtx.context, jndiName)){ 76 valCtx.result.failed( 77 valCtx.smh.getLocalString( 78 getClass().getName() + ".jndiNameBeingUsed", 79 "Attribute({0}={1}) : name already used by some other resource", 80 new Object []{valCtx.attrName,jndiName})); 81 } 82 if (jndiName.indexOf("'") != -1){ 93 valCtx.result.failed( 94 valCtx.smh.getLocalString( 95 getClass().getName() + ".invalidJndiName", 96 "Apostrophe not allowed in jndi name: {0}", 97 new Object []{jndiName})); 98 } 99 100 } 101 102 public boolean isResourceBeingUsed(ConfigContext context, String jndi) { 103 104 int count=0; 105 try { 106 Resources resources = ((Domain)context.getRootConfigBean()).getResources(); 107 108 AdminObjectResource[] admin = resources.getAdminObjectResource(); 109 ConnectorResource[] connres = resources.getConnectorResource(); 110 CustomResource[] custom = resources.getCustomResource(); 111 ExternalJndiResource[] external = resources.getExternalJndiResource(); 112 JdbcResource[] jdbcres = resources.getJdbcResource(); 113 MailResource[] mailres = resources.getMailResource(); 114 PersistenceManagerFactoryResource[] pers = resources.getPersistenceManagerFactoryResource(); 115 116 for(int i=0;i<admin.length;i++) { 117 if(jndi.equals(admin[i].getJndiName())) 118 return true; 119 } 120 for(int i=0;i<connres.length;i++) { 121 if(jndi.equals(connres[i].getJndiName())) 122 return true; 123 } 124 125 for(int i=0;i<custom.length;i++) { 126 if(jndi.equals(custom[i].getJndiName())) 127 return true; 128 } 129 130 for(int i=0;i<external.length;i++) { 131 if(jndi.equals(external[i].getJndiName())) 132 return true; 133 } 134 135 for(int i=0;i<jdbcres.length;i++) { 136 if(jndi.equals(jdbcres[i].getJndiName())) 137 return true; 138 } 139 140 for(int i=0;i<mailres.length;i++) { 141 if(jndi.equals(mailres[i].getJndiName())) 142 return true; 143 } 144 145 for(int i=0;i<pers.length;i++) { 146 if(jndi.equals(pers[i].getJndiName())) 147 return true; 148 } 149 150 } catch(ConfigException e) { 151 _logger.log(Level.FINE, "domainxmlverifier_error", e); 152 } 153 return false; 154 } 155 156 } 157 | Popular Tags |