1 22 package org.jboss.management.j2ee; 23 24 import java.io.InputStream ; 25 import java.io.InputStreamReader ; 26 import java.io.Reader ; 27 import java.io.StringWriter ; 28 import java.net.URL ; 29 import java.net.URLClassLoader ; 30 import java.security.InvalidParameterException ; 31 32 import javax.management.MalformedObjectNameException ; 33 import javax.management.ObjectName ; 34 35 import org.jboss.logging.Logger; 36 37 45 public abstract class J2EEDeployedObject extends J2EEManagedObject 46 implements J2EEDeployedObjectMBean 47 { 48 50 public static final int APPLICATION = 0; 51 public static final int WEB = 1; 52 public static final int EJB = 2; 53 public static final int RAR = 3; 54 public static final int SAR = 4; 55 public static final int JBOSS = 5; 56 public static final int JAWS = 6; 57 public static final int CMP = 7; 58 public static final int JBOSS_WEB = 8; 59 60 61 private static final Logger log = Logger.getLogger(J2EEDeployedObject.class); 62 63 private static final String [] sDescriptors = new String []{ 64 "META-INF/application.xml", 65 "WEB-INF/web.xml", 66 "META-INF/ejb-jar.xml", 67 "META-INF/ra.xml", 68 "META-INF/jboss-service.xml", 69 "META-INF/jboss.xml", 70 "META-INF/jaws.xml", 71 "META-INF/jbosscmp-jdbc.xml", 72 "WEB-INF/jboss-web.xml", 73 }; 74 75 77 private String mDeploymentDescriptor; 78 79 81 public static String getDeploymentDescriptor(URL pJarUrl, int pType) 82 { 83 return getDeploymentDescriptor(pJarUrl, sDescriptors[pType]); 84 } 85 86 92 public static String getDeploymentDescriptor(URL baseJarUrl, String descriptor) 93 { 94 if (baseJarUrl == null) 95 { 96 return null; 98 } 99 String lDD = null; 100 Reader lInput = null; 101 StringWriter lOutput = null; 102 try 103 { 104 if (descriptor == null) 105 { 106 lInput = new InputStreamReader (baseJarUrl.openStream()); 108 } 109 else 110 { 111 log.debug("File: " + baseJarUrl + ", descriptor: " + descriptor); 113 ClassLoader localCl = new URLClassLoader (new URL []{baseJarUrl}); 114 InputStream lStream = localCl.getResourceAsStream(descriptor); 115 if (lStream == null) 116 { 117 return null; 119 } 120 lInput = new InputStreamReader (lStream); 121 } 122 lOutput = new StringWriter (); 123 char[] lBuffer = new char[1024]; 124 int lLength = 0; 125 while ((lLength = lInput.read(lBuffer)) > 0) 126 { 127 lOutput.write(lBuffer, 0, lLength); 128 } 129 lDD = lOutput.toString(); 130 } 131 catch (Exception e) 132 { 133 log.error("failed to get deployment descriptor", e); 134 } 135 finally 136 { 137 if (lInput != null) 138 { 139 try 140 { 141 lInput.close(); 142 } 143 catch (Exception e) 144 { 145 } 146 } 147 if (lOutput != null) 148 { 149 try 150 { 151 lOutput.close(); 152 } 153 catch (Exception e) 154 { 155 } 156 } 157 } 158 return lDD; 159 } 160 161 163 170 public J2EEDeployedObject(String pType, 171 String pName, 172 ObjectName pParent, 173 String pDeploymentDescriptor) 174 throws 175 MalformedObjectNameException , 176 InvalidParentException 177 { 178 super(pType, pName, pParent); 179 mDeploymentDescriptor = pDeploymentDescriptor; 180 } 181 182 184 186 189 public String getdeploymentDescriptor() 190 { 191 return mDeploymentDescriptor; 192 } 193 194 197 public String getserver() 198 { 199 return "unknown server name"; 201 } 202 203 205 public String toString() 206 { 207 return "J2EEDeployedObject { " + super.toString() + " } [ " + 208 "deployment descriptor: " + mDeploymentDescriptor + 209 " ]"; 210 } 211 212 214 216 218 220 } 221 | Popular Tags |