KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > deployers > plugins > structure > vfs > jar > JARStructure


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2006, 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.deployers.plugins.structure.vfs.jar;
23
24 import java.io.IOException JavaDoc;
25 import java.util.Set JavaDoc;
26
27 import org.jboss.deployers.plugins.structure.ContextInfoImpl;
28 import org.jboss.deployers.plugins.structure.vfs.AbstractStructureDeployer;
29 import org.jboss.deployers.spi.structure.vfs.StructureMetaData;
30 import org.jboss.deployers.spi.structure.vfs.StructuredDeployers;
31 import org.jboss.virtual.VirtualFile;
32 import org.jboss.virtual.plugins.context.jar.JarUtils;
33
34 /**
35  * JARStructure.
36  *
37  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
38  * @version $Revision: 1.1 $
39  */

40 public class JARStructure extends AbstractStructureDeployer
41 {
42    public JARStructure()
43    {
44       this(null);
45    }
46
47    /**
48     * Sets the default relative order 10000.
49     *
50     */

51    public JARStructure(Set JavaDoc<String JavaDoc> suffixes)
52    {
53       if( suffixes != null )
54          JarUtils.setJarSuffixes(suffixes);
55       setRelativeOrder(10000);
56    }
57
58    /**
59     * Gets the set of suffixes recognised as jars
60     *
61     * @return the set of suffixes
62     */

63    public Set JavaDoc<String JavaDoc> getSuffixes()
64    {
65       return JarUtils.getSuffixes();
66    }
67    /**
68     * Gets the set of suffixes recognised as jars
69     *
70     * @param suffixes - the set of suffixes
71     */

72    public void setSuffixes(Set JavaDoc<String JavaDoc> suffixes)
73    {
74       JarUtils.setJarSuffixes(suffixes);
75    }
76
77    public boolean determineStructure(VirtualFile root, StructureMetaData metaData, StructuredDeployers deployers)
78    {
79       String JavaDoc contextPath = null;
80       try
81       {
82          if (root.isLeaf() == false)
83          {
84             // For non top level directories that don't look like jars
85
// we require a META-INF otherwise each subdirectory would be a subdeployment
86
if (JarUtils.isArchive(root.getName()) == false)
87             {
88                if (isTopLevel(root, metaData) == false)
89                {
90                   try
91                   {
92                      root.findChild("META-INF");
93                      log.trace("... ok - non top level directory has a META-INF subdirectory");
94                   }
95                   catch (IOException JavaDoc e)
96                   {
97                      log.trace("... no - doesn't look like a jar and no META-INF subdirectory.");
98                      return false;
99                   }
100                }
101                else
102                {
103                   log.trace("... ok - doesn't look like a jar but it is a top level directory.");
104                }
105             }
106          }
107          else if(JarUtils.isArchive(root.getName()))
108          {
109             log.trace("... ok - its an archive or at least pretending to be.");
110          }
111          else
112          {
113             log.trace("... no - not a directory or an archive.");
114             return false;
115          }
116
117          // Create a context for this jar file
118
ContextInfoImpl context = new ContextInfoImpl(root.getPathName());
119          // The metadata path is META-INF
120
context.setMetaDataPath("META-INF");
121
122          // The classpath is the root
123
super.addClassPath(root, root, true, true, context);
124          metaData.addContext(context);
125          contextPath = context.getVfsPath();
126
127          // We tentatively try all the children as potential subdeployments
128
addAllChildren(root, metaData, deployers);
129          return true;
130       }
131       catch (Exception JavaDoc e)
132       {
133          log.warn("Error determining structure: " + root.getName(), e);
134          // Remove the invalid context
135
if( contextPath != null )
136             metaData.removeContext(contextPath);
137          return false;
138       }
139    }
140 }
141
Popular Tags