KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > deployers > JBoss5DeploymentUnit


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, Red Hat Middleware LLC., 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.deployers;
23
24 import org.jboss.deployers.spi.deployer.DeploymentUnit;
25 import org.jboss.ejb3.interceptor.InterceptorInfoRepository;
26 import org.jboss.virtual.VirtualFile;
27 import org.jboss.virtual.VirtualFileFilter;
28 import org.jboss.virtual.VisitorAttributes;
29 import org.jboss.virtual.plugins.context.jar.JarUtils;
30 import org.jboss.virtual.plugins.vfs.helpers.FilterVirtualFileVisitor;
31 import org.jboss.virtual.plugins.vfs.helpers.SuffixesExcludeFilter;
32
33 import java.net.URL JavaDoc;
34 import java.net.MalformedURLException JavaDoc;
35 import java.net.URISyntaxException JavaDoc;
36 import java.util.Hashtable JavaDoc;
37 import java.util.List JavaDoc;
38 import java.util.Map JavaDoc;
39 import java.io.IOException JavaDoc;
40 import java.io.File JavaDoc;
41
42 /**
43  * Comment
44  *
45  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
46  * @version $Revision: 43304 $
47  */

48 public class JBoss5DeploymentUnit implements org.jboss.ejb3.DeploymentUnit
49 {
50    private DeploymentUnit deploymentInfo;
51    private InterceptorInfoRepository interceptorInfoRepository = new InterceptorInfoRepository();
52    private Map JavaDoc defaultPersistenceProperties;
53
54    public JBoss5DeploymentUnit(DeploymentUnit deploymentInfo)
55    {
56       this.deploymentInfo = deploymentInfo;
57    }
58
59
60    public URL JavaDoc getRelativeURL(String JavaDoc jar)
61    {
62       try
63       {
64          return new URL JavaDoc(jar);
65       }
66       catch (MalformedURLException JavaDoc e)
67       {
68          try
69          {
70             if (jar.startsWith(".."))
71             {
72                if (getUrl() == null)
73                   throw new RuntimeException JavaDoc("relative <jar-file> not allowed when standalone deployment unit is used");
74                String JavaDoc tmpjar = jar.substring(3);
75                VirtualFile vf = deploymentInfo.getDeploymentContext().getRoot().getParent().findChild(tmpjar);
76                return vf.toURL();
77             }
78             else
79             {
80                File fp = new File(jar);
81                return fp.toURL();
82             }
83          }
84          catch (Exception JavaDoc e1)
85          {
86             throw new RuntimeException JavaDoc("could not find relative path: " + jar, e1);
87          }
88       }
89    }
90
91    URL JavaDoc extractDescriptorUrl(String JavaDoc resource)
92    {
93       try
94       {
95          VirtualFile vf = deploymentInfo.getMetaDataFile(resource);
96          if (vf == null) return null;
97          return vf.toURL();
98       }
99       catch (Exception JavaDoc e)
100       {
101          throw new RuntimeException JavaDoc(e);
102       }
103    }
104
105    public URL JavaDoc getPersistenceXml()
106    {
107       return extractDescriptorUrl("persistence.xml");
108    }
109
110    public URL JavaDoc getEjbJarXml()
111    {
112       return extractDescriptorUrl("ejb-jar.xml");
113    }
114
115    public URL JavaDoc getJbossXml()
116    {
117       return extractDescriptorUrl("jboss.xml");
118    }
119
120    public List JavaDoc<Class JavaDoc> getClasses()
121    {
122       return null;
123    }
124
125    public ClassLoader JavaDoc getClassLoader()
126    {
127       return deploymentInfo.getClassLoader();
128    }
129
130    public ClassLoader JavaDoc getResourceLoader()
131    {
132       return deploymentInfo.getClassLoader();
133    }
134
135    public String JavaDoc getShortName()
136    {
137       return deploymentInfo.getDeploymentContext().getRoot().getName();
138    }
139
140    public URL JavaDoc getUrl()
141    {
142       try
143       {
144          return deploymentInfo.getDeploymentContext().getRoot().toURL();
145       }
146       catch (Exception JavaDoc e)
147       {
148          throw new RuntimeException JavaDoc(e);
149       }
150    }
151
152    public String JavaDoc getDefaultEntityManagerName()
153    {
154       String JavaDoc url = getUrl().toString();
155       String JavaDoc name = url.substring(url.lastIndexOf('/') + 1, url.lastIndexOf('.'));
156       return name;
157    }
158
159    public Map JavaDoc getDefaultPersistenceProperties()
160    {
161       return defaultPersistenceProperties;
162    }
163
164    public void setDefaultPersistenceProperties(Map JavaDoc defaultPersistenceProperties)
165    {
166       this.defaultPersistenceProperties = defaultPersistenceProperties;
167    }
168
169    public Hashtable JavaDoc getJndiProperties()
170    {
171       return null;
172    }
173
174    public InterceptorInfoRepository getInterceptorInfoRepository()
175    {
176       return interceptorInfoRepository;
177    }
178
179    public List JavaDoc<VirtualFile> getResources(VirtualFileFilter filter)
180    {
181       VisitorAttributes va = new VisitorAttributes();
182       va.setLeavesOnly(true);
183       SuffixesExcludeFilter noJars = new SuffixesExcludeFilter(JarUtils.getSuffixes());
184       va.setRecurseFilter(noJars);
185       FilterVirtualFileVisitor visitor = new FilterVirtualFileVisitor(filter, va);
186
187       List JavaDoc<VirtualFile> classpath = deploymentInfo.getDeploymentContext().getClassPath();
188       if (classpath != null)
189       {
190          for (VirtualFile vf : classpath)
191          {
192             try
193             {
194                vf.visit(visitor);
195             }
196             catch (IOException JavaDoc e)
197             {
198                throw new RuntimeException JavaDoc(e);
199             }
200          }
201       }
202       return visitor.getMatched();
203    }
204
205 }
206
Popular Tags