1 /** 2 * EasyBeans 3 * Copyright (C) 2006 Bull S.A.S. 4 * Contact: easybeans@objectweb.org 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public 8 * License as published by the Free Software Foundation; either 9 * 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 925 2006-07-25 12:37:03Z benoitf $ 23 * -------------------------------------------------------------------------- 24 */ 25 26 package org.objectweb.easybeans.deployment.xml; 27 28 import java.net.URL; 29 30 import org.objectweb.easybeans.api.EZBArchive; 31 import org.objectweb.easybeans.api.EZBArchiveException; 32 import org.objectweb.easybeans.deployment.xml.parsing.EJB3DeploymentDescLoader; 33 import org.objectweb.easybeans.deployment.xml.parsing.ParsingException; 34 import org.objectweb.easybeans.deployment.xml.struct.EJB3; 35 36 /** 37 * Utility class to get a deployment descriptor. 38 * @author Florent Benoit 39 */ 40 public final class EJB3DeploymentDesc { 41 42 /** 43 * Utility class, no public constructor. 44 */ 45 private EJB3DeploymentDesc() { 46 47 } 48 49 /** 50 * Gets EJB3 for a given archive. 51 * @param archive file/directory. 52 * @throws EJB3DeploymentDescException if no xml is present. 53 * @return EJB3 instance or null. 54 */ 55 public static EJB3 getEjb3(final EZBArchive archive) throws EJB3DeploymentDescException { 56 57 // Get XML entry 58 URL ejbjarXmlURL = null; 59 try { 60 ejbjarXmlURL = archive.getResource("META-INF/ejb-jar.xml"); 61 } catch (EZBArchiveException e) { 62 throw new EJB3DeploymentDescException("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.loadDeploymentDescriptor(ejbjarXmlURL); 71 } catch (ParsingException e) { 72 throw new EJB3DeploymentDescException("Cannot parse URL '" + ejbjarXmlURL + "'."); 73 } 74 } 75 return ejb3; 76 } 77 } 78