KickJava   Java API By Example, From Geeks To Geeks.

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


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.ejb3.DeploymentScope;
25 import org.jboss.ejb3.Ejb3Deployment;
26 import org.jboss.deployers.spi.structure.DeploymentContext;
27 import org.jboss.deployers.spi.deployer.DeploymentUnit;
28
29 import java.util.ArrayList JavaDoc;
30 import java.util.Collection JavaDoc;
31 import java.util.concurrent.ConcurrentHashMap JavaDoc;
32
33 /**
34  * Abstraction for an EAR/WAR or anything that scopes EJB deployments
35  *
36  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
37  * @version $Revision: 55144 $
38  */

39 public class JBoss5DeploymentScope implements DeploymentScope
40 {
41    private ConcurrentHashMap JavaDoc<String JavaDoc, Ejb3Deployment> deployments;
42    private String JavaDoc shortName;
43    private String JavaDoc baseName;
44
45    public JBoss5DeploymentScope(DeploymentContext parent)
46    {
47       // Use the root vfs path name
48
this.shortName = parent.getRoot().getPathName();
49       if( shortName.length() == 0 )
50       {
51          shortName = parent.getName();
52          // this is a hack because VFS has gay URL name.
53
if (shortName.endsWith("!/"))
54          {
55             this.shortName = shortName.substring(0, shortName.length() - 2);
56          }
57       }
58       // Further reduce the path to the last component of the url name
59
int x = shortName.lastIndexOf('/');
60       this.shortName = shortName.substring(x + 1);
61
62       baseName = shortName;
63       int idx = shortName.lastIndexOf('.');
64       if( idx > 0 )
65          baseName = shortName.substring(0, idx);
66       deployments = (ConcurrentHashMap JavaDoc<String JavaDoc, Ejb3Deployment>)parent.getDeploymentUnit().getAttachment("EJB_DEPLOYMENTS");
67       if (deployments == null)
68       {
69          deployments = new ConcurrentHashMap JavaDoc<String JavaDoc, Ejb3Deployment>();
70          parent.getDeploymentUnit().addAttachment("EJB_DEPLOYMENTS", deployments);
71       }
72    }
73
74    public Collection JavaDoc<Ejb3Deployment> getEjbDeployments()
75    {
76       return deployments.values();
77    }
78
79    public void register(Ejb3Deployment deployment)
80    {
81       deployments.put(deployment.getDeploymentUnit().getShortName(), deployment);
82    }
83
84    public void unregister(Ejb3Deployment deployment)
85    {
86       deployments.remove(deployment.getDeploymentUnit().getShortName());
87    }
88
89    public Ejb3Deployment findRelativeDeployment(String JavaDoc relativeName)
90    {
91       if (relativeName.startsWith("../"))
92       {
93          relativeName = relativeName.substring(3);
94       }
95       return deployments.get(relativeName);
96    }
97
98    public String JavaDoc getShortName()
99    {
100       return shortName;
101    }
102
103    public String JavaDoc getBaseName()
104    {
105       return baseName;
106    }
107
108 }
109
Popular Tags