1 package org.apache.tools.ant.taskdefs.optional.jmx; 2 3 52 53 import org.apache.tools.ant.BuildException; 54 import org.apache.tools.ant.taskdefs.optional.jmx.connector.JMXConnector; 55 56 57 70 public class JndiLookup extends AbstractManagementTask { 71 72 private String property = null; 73 private String refid = null; 74 75 public JndiLookup() { 76 } 77 78 79 84 public void execute() throws BuildException { 85 try { 86 87 javax.naming.Context namingContext = getNamingContext( 88 getProviderUrl(), 89 getJndiName(), 90 getUser(), 91 getPassword()); 92 93 try { 94 Object result = namingContext.lookup(this.getJndiName()); 95 96 if (getProperty() != null) { 97 getProject().setProperty(getProperty(),"true"); 98 } 99 100 if (getRefid() != null) { 101 getProject().addReference(getRefid(),result); 102 } 103 } catch (javax.naming.NamingException ne) { 104 if (this.getFailOnError()) { 105 ne.printStackTrace(); 106 throw new BuildException("Error! " + ne, ne); 107 } 108 } 109 } catch (Exception x) { 110 if (this.getFailOnError()) { 111 x.printStackTrace(); 112 throw new BuildException("Error! " + x, x); 113 } else { 114 log("Warning! " + x,org.apache.tools.ant.Project.MSG_WARN); 115 } 116 } 117 } 118 119 120 133 protected javax.naming.Context getNamingContext(String providerUrl, String jndiName, String user, String password) throws javax.naming.NamingException { 134 try { 135 136 if (getContext().getServerType() == null) { 137 log("Warning! serverType not specified or unrecognized type. Defaulting to WebLogic."); 138 getContext().setServerType("weblogic"); 139 } 140 141 JMXConnector jmxServer = org.apache.tools.ant.taskdefs.optional.jmx.connector.JMXConnectorFactory.createConnector(getContext().getServerType()); 142 java.util.Hashtable properties = jmxServer.getInitialContextProperties(providerUrl,user,password); 143 144 return new javax.naming.InitialContext (properties); 145 146 } catch (Exception e) { 147 e.printStackTrace(); 148 throw new BuildException("JNDI Error. " + e.getMessage(), e); 149 } 150 } 151 152 156 public java.lang.String getProperty() { 157 return property; 158 } 159 160 164 public void setProperty(java.lang.String property) { 165 this.property = property; 166 } 167 168 172 public java.lang.String getRefid() { 173 return refid; 174 } 175 176 180 public void setRefid(java.lang.String refid) { 181 this.refid = refid; 182 } 183 184 } 185 186 | Popular Tags |