/**
* EasyBeans
* Copyright (C) 2006 Bull S.A.S.
* Contact: easybeans@ow2.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
* --------------------------------------------------------------------------
* $Id: Deployment.java 1970 2007-10-16 11:49:25Z benoitf $
* --------------------------------------------------------------------------
*/
package org.ow2.easybeans.deployment;
import java.util.ArrayList;
import java.util.List;
import org.ow2.easybeans.deployment.annotations.analyzer.AnnotationDeploymentAnalyzer;
import org.ow2.easybeans.deployment.annotations.exceptions.AnalyzerException;
import org.ow2.easybeans.deployment.annotations.exceptions.ResolverException;
import org.ow2.easybeans.deployment.annotations.helper.ExtraMetadataHelper;
import org.ow2.easybeans.deployment.annotations.helper.ResolverHelper;
import org.ow2.easybeans.deployment.annotations.metadata.ClassAnnotationMetadata;
import org.ow2.easybeans.deployment.annotations.metadata.EjbJarAnnotationMetadata;
import org.ow2.easybeans.deployment.annotations.metadata.LibrariesAnnotationMetadata;
import org.ow2.easybeans.deployment.xml.EJB3DeploymentDesc;
import org.ow2.easybeans.deployment.xml.EJB3DeploymentDescException;
import org.ow2.easybeans.deployment.xml.helper.MetadataMerge;
import org.ow2.easybeans.deployment.xml.struct.EJB3;
import org.ow2.util.ee.deploy.api.archive.IArchive;
import org.ow2.util.log.Log;
import org.ow2.util.log.LogFactory;
/**
* This class will parse given ejb-jar file and completes metadata by using
* resolver.
* @author Florent Benoit
*/
public class Deployment {
/**
* Logger.
*/
private static Log logger = LogFactory.getLog(Deployment.class);
/**
* Archive which will be analyzed.
*/
private IArchive archive = null;
/**
* Extra archives.
*/
private List<IArchive> extraArchives = null;
/**
* Annotation deployment analyzer.
*/
private AnnotationDeploymentAnalyzer annotationDeploymentAnalyzer = null;
/**
* Constructor.<br> Archive which will be used when analyzing.
* @param archive the archive to analyze.
*/
public Deployment(final IArchive archive) {
this.archive = archive;
this.annotationDeploymentAnalyzer = new AnnotationDeploymentAnalyzer(archive);
}
/**
* Build a new Annotation Deployment Analyzer.
*/
public void reset() {
this.annotationDeploymentAnalyzer = new AnnotationDeploymentAnalyzer(archive);
}
/**
* Analyzes the jarFile.
* @throws AnalyzerException if analyze of jar file fails.
* @throws ResolverException if resolver fails.
* @throws EJB3DeploymentDescException if parsing fails.
*/
@SuppressWarnings("boxing")
public void analyze() throws AnalyzerException, EJB3DeploymentDescException, ResolverException {
// for time debugging
long tAnalyzeStart = System.currentTimeMillis();
annotationDeploymentAnalyzer.analyze();
// time if debugging
if (logger.isDebugEnabled()) {
long tAnalyzeStartEnd = System.currentTimeMillis();
if (logger.isDebugEnabled()) {
logger.debug("Analyze of file {0} took {1} ms.", archive.getName(), (tAnalyzeStartEnd - tAnalyzeStart));
}
}
LibrariesAnnotationMetadata librariesAnnotationMetadata = new LibrariesAnnotationMetadata();
// Extra archives ?
if (extraArchives != null) {
List<EjbJarAnnotationMetadata> ejbJarAnnotationMetadataList = new ArrayList<EjbJarAnnotationMetadata>();
// Analyze the extra archives
for (IArchive extraArchive : extraArchives) {
AnnotationDeploymentAnalyzer analyzer = new AnnotationDeploymentAnalyzer(extraArchive);
analyzer.analyze();
ejbJarAnnotationMetadataList.add(analyzer.getEjbJarAnnotationMetadata());
}
librariesAnnotationMetadata.setEjbJarAnnotationMetadataList(ejbJarAnnotationMetadataList);
}
// Extra metadata ? complete them
ExtraMetadataHelper.complete(annotationDeploymentAnalyzer.getEjbJarAnnotationMetadata(), librariesAnnotationMetadata);
// Get EJB3 DD.
EJB3 ejb3 = EJB3DeploymentDesc.getEjb3(archive);
annotationDeploymentAnalyzer.getEjbJarAnnotationMetadata().setEjb3(ejb3);
// Merge DD with annotations metadata
MetadataMerge.merge(annotationDeploymentAnalyzer.getEjbJarAnnotationMetadata());
// Complete metadata
long tResolverStart = System.currentTimeMillis();
ResolverHelper.resolve(annotationDeploymentAnalyzer.getEjbJarAnnotationMetadata());
// time if debugging
if (logger.isDebugEnabled()) {
long tResolverEnd = System.currentTimeMillis();
if (logger.isDebugEnabled()) {
logger.debug("Resolver on metadata from {0} took {1} ms.'", archive.getName(), (tResolverEnd - tResolverStart));
}
}
if (logger.isDebugEnabled()) {
for (ClassAnnotationMetadata classAnnotationMetadata : annotationDeploymentAnalyzer
.getEjbJarAnnotationMetadata().getClassAnnotationMetadataCollection()) {
logger.debug("Result for class = " + classAnnotationMetadata);
}
}
}
/**
* Add extra archives for finding classes.
* @param extraArchives the given archives.
*/
public void setExtraArchives(final List<IArchive> extraArchives) {
this.extraArchives = extraArchives;
}
/**
* @return annotation deployment analyzer
*/
public AnnotationDeploymentAnalyzer getAnnotationDeploymentAnalyzer() {
return annotationDeploymentAnalyzer;
}
/**
* @return the archive of this deployment.
*/
public IArchive getArchive() {
return archive;
}
}
|