KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > JmxDeploymentUnit


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.ejb3;
23
24 import java.net.URL JavaDoc;
25 import java.net.MalformedURLException JavaDoc;
26 import java.util.Hashtable JavaDoc;
27 import java.util.List JavaDoc;
28 import java.util.Map JavaDoc;
29 import java.io.IOException JavaDoc;
30 import java.io.File JavaDoc;
31
32 import org.jboss.deployment.DeploymentInfo;
33 import org.jboss.ejb3.interceptor.InterceptorInfoRepository;
34 import org.jboss.mx.util.MBeanProxyExt;
35 import org.jboss.virtual.VirtualFile;
36 import org.jboss.virtual.VFS;
37 import org.jboss.virtual.VirtualFileFilter;
38 import org.jboss.virtual.VisitorAttributes;
39 import org.jboss.virtual.plugins.context.jar.JarUtils;
40 import org.jboss.virtual.plugins.vfs.helpers.FilterVirtualFileVisitor;
41 import org.jboss.virtual.plugins.vfs.helpers.SuffixesExcludeFilter;
42
43 /**
44  * Comment
45  *
46  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
47  * @version $Revision: 57946 $
48  */

49 public class JmxDeploymentUnit implements DeploymentUnit
50 {
51    private DeploymentInfo deploymentInfo;
52    InterceptorInfoRepository interceptorInfoRepository = new InterceptorInfoRepository();
53    private VirtualFile virtualFile;
54
55    public JmxDeploymentUnit(DeploymentInfo deploymentInfo)
56    {
57       this.deploymentInfo = deploymentInfo;
58       try
59       {
60          VFS vfs = VFS.getVFS(deploymentInfo.url);
61          virtualFile = vfs.getRoot();
62       }
63       catch (IOException JavaDoc e)
64       {
65          throw new RuntimeException JavaDoc();
66       }
67    }
68
69
70    public URL JavaDoc getRelativeURL(String JavaDoc jar)
71    {
72       URL JavaDoc url = null;
73       try
74       {
75          url = new URL JavaDoc(jar);
76       }
77       catch (MalformedURLException JavaDoc e)
78       {
79          try
80          {
81             if (jar.startsWith(".."))
82             {
83                if (getUrl() == null)
84                   throw new RuntimeException JavaDoc("relative <jar-file> not allowed when standalone deployment unit is used");
85                String JavaDoc base = getUrl().toString();
86                jar = jar.replaceAll("\\.\\./", "+");
87                int idx = jar.lastIndexOf('+');
88                jar = jar.substring(idx + 1);
89                for (int i = 0; i < idx + 1; i++)
90                {
91                   int slash = base.lastIndexOf('/');
92                   base = base.substring(0, slash + 1);
93                }
94                url = new URL JavaDoc(base + jar.substring(idx));
95             }
96             else
97             {
98                File JavaDoc fp = new File JavaDoc(jar);
99                url = fp.toURL();
100             }
101          }
102          catch (MalformedURLException JavaDoc e1)
103          {
104             throw new RuntimeException JavaDoc("Unable to find relative url: " + jar, e1);
105          }
106       }
107       return url;
108    }
109
110    URL JavaDoc extractDescriptorUrl(String JavaDoc resource)
111    {
112       String JavaDoc urlStr = deploymentInfo.url.getFile();
113       // However the jar must also contain at least one ejb-jar.xml
114
try
115       {
116          URL JavaDoc dd = deploymentInfo.localCl.findResource(resource);
117          if (dd == null)
118          {
119             return null;
120          }
121
122          // If the DD url is not a subset of the urlStr then this is coming
123
// from a jar referenced by the deployment jar manifest and the
124
// this deployment jar it should not be treated as an ejb-jar
125
if (deploymentInfo.localUrl != null)
126          {
127             urlStr = deploymentInfo.localUrl.toString();
128          }
129
130          String JavaDoc ddStr = dd.toString();
131          if (ddStr.indexOf(urlStr) >= 0)
132          {
133             return dd;
134          }
135       }
136       catch (Exception JavaDoc ignore)
137       {
138       }
139       return null;
140    }
141
142    public URL JavaDoc getPersistenceXml()
143    {
144       return extractDescriptorUrl("META-INF/persistence.xml");
145    }
146
147    public URL JavaDoc getEjbJarXml()
148    {
149       return extractDescriptorUrl("META-INF/ejb-jar.xml");
150    }
151
152    public URL JavaDoc getJbossXml()
153    {
154       return extractDescriptorUrl("META-INF/jboss.xml");
155    }
156
157    public List JavaDoc<Class JavaDoc> getClasses()
158    {
159       return null;
160    }
161
162    public ClassLoader JavaDoc getClassLoader()
163    {
164       return deploymentInfo.ucl;
165    }
166
167    public ClassLoader JavaDoc getResourceLoader()
168    {
169       return deploymentInfo.localCl;
170    }
171
172    public String JavaDoc getShortName()
173    {
174       return deploymentInfo.shortName;
175    }
176
177    public URL JavaDoc getUrl()
178    {
179       return deploymentInfo.url;
180    }
181
182    public String JavaDoc getDefaultEntityManagerName()
183    {
184       String JavaDoc url = getUrl().toString();
185       String JavaDoc name = url.substring(url.lastIndexOf('/') + 1, url.lastIndexOf('.'));
186       return name;
187    }
188
189    public Map JavaDoc getDefaultPersistenceProperties()
190    {
191       try
192       {
193          EJB3DeployerMBean deployer = (EJB3DeployerMBean) MBeanProxyExt.create(EJB3DeployerMBean.class, EJB3DeployerMBean.OBJECT_NAME,
194                  deploymentInfo.getServer());
195
196          return deployer.getDefaultProperties();
197       }
198       catch (Exception JavaDoc e)
199       {
200          throw new RuntimeException JavaDoc(e);
201       }
202    }
203
204
205    public Hashtable JavaDoc getJndiProperties()
206    {
207       return null;
208    }
209
210    public InterceptorInfoRepository getInterceptorInfoRepository()
211    {
212       return interceptorInfoRepository;
213    }
214
215
216    public List JavaDoc<VirtualFile> getResources(VirtualFileFilter filter)
217    {
218       VisitorAttributes va = new VisitorAttributes();
219       va.setLeavesOnly(true);
220       SuffixesExcludeFilter noJars = new SuffixesExcludeFilter(JarUtils.getSuffixes());
221       va.setRecurseFilter(noJars);
222       FilterVirtualFileVisitor visitor = new FilterVirtualFileVisitor(filter, va);
223       try
224       {
225          virtualFile.visit(visitor);
226       }
227       catch (IOException JavaDoc e)
228       {
229          throw new RuntimeException JavaDoc(e);
230       }
231       return visitor.getMatched();
232
233    }
234 }
235
Popular Tags