KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > deployment > Deployment


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: Deployment.java 925 2006-07-25 12:37:03Z benoitf $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.easybeans.deployment;
27
28 import org.objectweb.easybeans.api.EZBArchive;
29 import org.objectweb.easybeans.deployment.annotations.analyzer.AnnotationDeploymentAnalyzer;
30 import org.objectweb.easybeans.deployment.annotations.exceptions.AnalyzerException;
31 import org.objectweb.easybeans.deployment.annotations.exceptions.ResolverException;
32 import org.objectweb.easybeans.deployment.annotations.helper.ResolverHelper;
33 import org.objectweb.easybeans.deployment.annotations.metadata.ClassAnnotationMetadata;
34 import org.objectweb.easybeans.deployment.xml.EJB3DeploymentDesc;
35 import org.objectweb.easybeans.deployment.xml.EJB3DeploymentDescException;
36 import org.objectweb.easybeans.deployment.xml.helper.MetadataMerge;
37 import org.objectweb.easybeans.deployment.xml.struct.EJB3;
38 import org.objectweb.easybeans.log.JLog;
39 import org.objectweb.easybeans.log.JLogFactory;
40
41 /**
42  * This class will parse given ejb-jar file and completes metadata by using
43  * resolver.
44  * @author Florent Benoit
45  */

46 public class Deployment {
47
48     /**
49      * Logger.
50      */

51     private static JLog logger = JLogFactory.getLog(Deployment.class);
52
53     /**
54      * Archive which will be analyzed.
55      */

56     private EZBArchive archive = null;
57
58     /**
59      * Annotation deployment analyzer.
60      */

61     private AnnotationDeploymentAnalyzer annotationDeploymentAnalyzer = null;
62
63     /**
64      * Constructor.<br> Archive which will be used when analyzing.
65      * @param archive the archive to analyze.
66      */

67     public Deployment(final EZBArchive archive) {
68         this.archive = archive;
69         this.annotationDeploymentAnalyzer = new AnnotationDeploymentAnalyzer(archive);
70     }
71
72     /**
73      * Analyzes the jarFile.
74      * @throws AnalyzerException if analyze of jar file fails.
75      * @throws ResolverException if resolver fails.
76      * @throws EJB3DeploymentDescException if parsing fails.
77      */

78     @SuppressWarnings JavaDoc("boxing")
79     public void analyze() throws AnalyzerException, EJB3DeploymentDescException, ResolverException {
80
81         // for time debugging
82
long tAnalyzeStart = System.currentTimeMillis();
83         annotationDeploymentAnalyzer.analyze();
84         // time if debugging
85
if (logger.isDebugEnabled()) {
86             long tAnalyzeStartEnd = System.currentTimeMillis();
87             if (logger.isDebugEnabled()) {
88                 logger.debug("Analyze of file {0} took {1} ms.", archive.getName(), (tAnalyzeStartEnd - tAnalyzeStart));
89             }
90         }
91
92         // Get EJB3 DD.
93
EJB3 ejb3 = EJB3DeploymentDesc.getEjb3(archive);
94         annotationDeploymentAnalyzer.getEjbJarAnnotationMetadata().setEjb3(ejb3);
95
96         // Merge DD with annotations metadata
97
MetadataMerge.merge(annotationDeploymentAnalyzer.getEjbJarAnnotationMetadata());
98
99         // Complete metadata
100
long tResolverStart = System.currentTimeMillis();
101         ResolverHelper.resolve(annotationDeploymentAnalyzer.getEjbJarAnnotationMetadata());
102         // time if debugging
103
if (logger.isDebugEnabled()) {
104             long tResolverEnd = System.currentTimeMillis();
105             if (logger.isDebugEnabled()) {
106                 logger.debug("Resolver on metadata from {0} took {1} ms.'", archive.getName(), (tResolverEnd - tResolverStart));
107             }
108         }
109
110         if (logger.isDebugEnabled()) {
111             for (ClassAnnotationMetadata classAnnotationMetadata : annotationDeploymentAnalyzer
112                     .getEjbJarAnnotationMetadata().getClassAnnotationMetadataCollection()) {
113                 logger.debug("Result for class = " + classAnnotationMetadata);
114             }
115         }
116     }
117
118     /**
119      * @return annotation deployment analyzer
120      */

121     public AnnotationDeploymentAnalyzer getAnnotationDeploymentAnalyzer() {
122         return annotationDeploymentAnalyzer;
123     }
124 }
125
Popular Tags