001: /**
002: * EasyBeans
003: * Copyright (C) 2006 Bull S.A.S.
004: * Contact: easybeans@ow2.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: Deployment.java 1970 2007-10-16 11:49:25Z benoitf $
023: * --------------------------------------------------------------------------
024: */package org.ow2.easybeans.deployment;
025:
026: import java.util.ArrayList;
027: import java.util.List;
028:
029: import org.ow2.easybeans.deployment.annotations.analyzer.AnnotationDeploymentAnalyzer;
030: import org.ow2.easybeans.deployment.annotations.exceptions.AnalyzerException;
031: import org.ow2.easybeans.deployment.annotations.exceptions.ResolverException;
032: import org.ow2.easybeans.deployment.annotations.helper.ExtraMetadataHelper;
033: import org.ow2.easybeans.deployment.annotations.helper.ResolverHelper;
034: import org.ow2.easybeans.deployment.annotations.metadata.ClassAnnotationMetadata;
035: import org.ow2.easybeans.deployment.annotations.metadata.EjbJarAnnotationMetadata;
036: import org.ow2.easybeans.deployment.annotations.metadata.LibrariesAnnotationMetadata;
037: import org.ow2.easybeans.deployment.xml.EJB3DeploymentDesc;
038: import org.ow2.easybeans.deployment.xml.EJB3DeploymentDescException;
039: import org.ow2.easybeans.deployment.xml.helper.MetadataMerge;
040: import org.ow2.easybeans.deployment.xml.struct.EJB3;
041: import org.ow2.util.ee.deploy.api.archive.IArchive;
042: import org.ow2.util.log.Log;
043: import org.ow2.util.log.LogFactory;
044:
045: /**
046: * This class will parse given ejb-jar file and completes metadata by using
047: * resolver.
048: * @author Florent Benoit
049: */
050: public class Deployment {
051:
052: /**
053: * Logger.
054: */
055: private static Log logger = LogFactory.getLog(Deployment.class);
056:
057: /**
058: * Archive which will be analyzed.
059: */
060: private IArchive archive = null;
061:
062: /**
063: * Extra archives.
064: */
065: private List<IArchive> extraArchives = null;
066:
067: /**
068: * Annotation deployment analyzer.
069: */
070: private AnnotationDeploymentAnalyzer annotationDeploymentAnalyzer = null;
071:
072: /**
073: * Constructor.<br> Archive which will be used when analyzing.
074: * @param archive the archive to analyze.
075: */
076: public Deployment(final IArchive archive) {
077: this .archive = archive;
078: this .annotationDeploymentAnalyzer = new AnnotationDeploymentAnalyzer(
079: archive);
080: }
081:
082: /**
083: * Build a new Annotation Deployment Analyzer.
084: */
085: public void reset() {
086: this .annotationDeploymentAnalyzer = new AnnotationDeploymentAnalyzer(
087: archive);
088: }
089:
090: /**
091: * Analyzes the jarFile.
092: * @throws AnalyzerException if analyze of jar file fails.
093: * @throws ResolverException if resolver fails.
094: * @throws EJB3DeploymentDescException if parsing fails.
095: */
096: @SuppressWarnings("boxing")
097: public void analyze() throws AnalyzerException,
098: EJB3DeploymentDescException, ResolverException {
099:
100: // for time debugging
101: long tAnalyzeStart = System.currentTimeMillis();
102: annotationDeploymentAnalyzer.analyze();
103: // time if debugging
104: if (logger.isDebugEnabled()) {
105: long tAnalyzeStartEnd = System.currentTimeMillis();
106: if (logger.isDebugEnabled()) {
107: logger.debug("Analyze of file {0} took {1} ms.",
108: archive.getName(),
109: (tAnalyzeStartEnd - tAnalyzeStart));
110: }
111: }
112:
113: LibrariesAnnotationMetadata librariesAnnotationMetadata = new LibrariesAnnotationMetadata();
114: // Extra archives ?
115: if (extraArchives != null) {
116: List<EjbJarAnnotationMetadata> ejbJarAnnotationMetadataList = new ArrayList<EjbJarAnnotationMetadata>();
117:
118: // Analyze the extra archives
119: for (IArchive extraArchive : extraArchives) {
120: AnnotationDeploymentAnalyzer analyzer = new AnnotationDeploymentAnalyzer(
121: extraArchive);
122: analyzer.analyze();
123: ejbJarAnnotationMetadataList.add(analyzer
124: .getEjbJarAnnotationMetadata());
125: }
126: librariesAnnotationMetadata
127: .setEjbJarAnnotationMetadataList(ejbJarAnnotationMetadataList);
128: }
129:
130: // Extra metadata ? complete them
131: ExtraMetadataHelper.complete(annotationDeploymentAnalyzer
132: .getEjbJarAnnotationMetadata(),
133: librariesAnnotationMetadata);
134:
135: // Get EJB3 DD.
136: EJB3 ejb3 = EJB3DeploymentDesc.getEjb3(archive);
137: annotationDeploymentAnalyzer.getEjbJarAnnotationMetadata()
138: .setEjb3(ejb3);
139:
140: // Merge DD with annotations metadata
141: MetadataMerge.merge(annotationDeploymentAnalyzer
142: .getEjbJarAnnotationMetadata());
143:
144: // Complete metadata
145: long tResolverStart = System.currentTimeMillis();
146: ResolverHelper.resolve(annotationDeploymentAnalyzer
147: .getEjbJarAnnotationMetadata());
148: // time if debugging
149: if (logger.isDebugEnabled()) {
150: long tResolverEnd = System.currentTimeMillis();
151: if (logger.isDebugEnabled()) {
152: logger.debug(
153: "Resolver on metadata from {0} took {1} ms.'",
154: archive.getName(),
155: (tResolverEnd - tResolverStart));
156: }
157: }
158:
159: if (logger.isDebugEnabled()) {
160: for (ClassAnnotationMetadata classAnnotationMetadata : annotationDeploymentAnalyzer
161: .getEjbJarAnnotationMetadata()
162: .getClassAnnotationMetadataCollection()) {
163: logger.debug("Result for class = "
164: + classAnnotationMetadata);
165: }
166: }
167: }
168:
169: /**
170: * Add extra archives for finding classes.
171: * @param extraArchives the given archives.
172: */
173: public void setExtraArchives(final List<IArchive> extraArchives) {
174: this .extraArchives = extraArchives;
175: }
176:
177: /**
178: * @return annotation deployment analyzer
179: */
180: public AnnotationDeploymentAnalyzer getAnnotationDeploymentAnalyzer() {
181: return annotationDeploymentAnalyzer;
182: }
183:
184: /**
185: * @return the archive of this deployment.
186: */
187: public IArchive getArchive() {
188: return archive;
189: }
190: }
|