01: /**
02: * EasyBeans
03: * Copyright (C) 2006 Bull S.A.S.
04: * Contact: easybeans@ow2.org
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2.1 of the License, or any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public
17: * License along with this library; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19: * USA
20: *
21: * --------------------------------------------------------------------------
22: * $Id: EJB3DeploymentDesc.java 2059 2007-11-22 17:22:33Z benoitf $
23: * --------------------------------------------------------------------------
24: */package org.ow2.easybeans.deployment.xml;
25:
26: import java.net.URL;
27:
28: import org.ow2.easybeans.deployment.xml.parsing.EJB3DeploymentDescLoader;
29: import org.ow2.easybeans.deployment.xml.parsing.ParsingException;
30: import org.ow2.easybeans.deployment.xml.struct.EJB3;
31: import org.ow2.util.ee.deploy.api.archive.ArchiveException;
32: import org.ow2.util.ee.deploy.api.archive.IArchive;
33:
34: /**
35: * Utility class to get a deployment descriptor.
36: * @author Florent Benoit
37: */
38: public final class EJB3DeploymentDesc {
39:
40: /**
41: * Utility class, no public constructor.
42: */
43: private EJB3DeploymentDesc() {
44:
45: }
46:
47: /**
48: * Gets EJB3 for a given archive.
49: * @param archive file/directory.
50: * @throws EJB3DeploymentDescException if no xml is present.
51: * @return EJB3 instance or null.
52: */
53: public static EJB3 getEjb3(final IArchive archive)
54: throws EJB3DeploymentDescException {
55:
56: // Get XML entry
57: URL ejbjarXmlURL = null;
58: try {
59: ejbjarXmlURL = archive.getResource("META-INF/ejb-jar.xml");
60: } catch (ArchiveException e) {
61: throw new EJB3DeploymentDescException(
62: "Cannot get resource 'META-INF/ejb-jar.xml' on the archive '"
63: + archive.getName() + "'.");
64: }
65:
66: EJB3 ejb3 = null;
67: // Get EJB3 object (if url valid)
68: if (ejbjarXmlURL != null) {
69: try {
70: ejb3 = EJB3DeploymentDescLoader
71: .loadDeploymentDescriptor(ejbjarXmlURL);
72: } catch (ParsingException e) {
73: throw new EJB3DeploymentDescException(
74: "Cannot parse URL '" + ejbjarXmlURL + "'.", e);
75: }
76: }
77: return ejb3;
78: }
79: }
|