KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ejbjar > CustomProvider


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.ejbjar;
21
22 import java.util.Collections JavaDoc;
23 import java.util.HashMap JavaDoc;
24 import org.netbeans.api.java.classpath.ClassPath;
25 import org.netbeans.modules.j2ee.api.ejbjar.*;
26 import org.netbeans.modules.j2ee.metadata.MetadataUnit;
27 import org.netbeans.modules.j2ee.spi.ejbjar.*;
28 import org.netbeans.spi.java.classpath.PathResourceImplementation;
29 import org.netbeans.spi.java.classpath.support.ClassPathSupport;
30 import org.openide.filesystems.FileObject;
31
32 /** A dummy provider that things that any *.foo file belongs to its web module.
33  *
34  * @author Pavel Buzek
35  */

36 public class CustomProvider implements EjbJarProvider {
37
38     private HashMap JavaDoc cache = new HashMap JavaDoc ();
39
40     public CustomProvider () {
41     }
42
43     public EjbJar findEjbJar (FileObject file) {
44         if (file.getExt ().equals ("foo")) {
45             EjbJar em = (EjbJar) cache.get (file.getParent ());
46             if (em == null) {
47                 em = EjbJarFactory.createEjbJar (new EM (file.getParent (), EjbProjectConstants.J2EE_14_LEVEL));
48                 cache.put (file.getParent (), em);
49             }
50             return em;
51         }
52         return null;
53     }
54     
55     private class EM implements EjbJarImplementation {
56         FileObject root;
57         String JavaDoc ver;
58         private MetadataUnit metadataUnit;
59         
60         public EM (FileObject root, String JavaDoc ver) {
61             this.root = root;
62             this.ver = ver;
63         }
64         
65         public String JavaDoc getJ2eePlatformVersion () {
66             return ver;
67         }
68         
69         public FileObject getDeploymentDescriptor () {
70             return root.getFileObject ("conf/ejb-jar.xml");
71         }
72         
73         public FileObject getMetaInf () {
74             return null;
75         }
76
77         public FileObject[] getJavaSources() {
78             return null;
79         }
80
81         public MetadataUnit getMetadataUnit() {
82             synchronized (this) {
83                 if (metadataUnit == null) {
84                     metadataUnit = new MetadataUnitImpl();
85                 }
86                 return metadataUnit;
87             }
88         }
89
90         private class MetadataUnitImpl implements MetadataUnit {
91             public ClassPath getClassPath() {
92                 return ClassPathSupport.createClassPath(Collections.<PathResourceImplementation>emptyList());
93             }
94             public FileObject getDeploymentDescriptor() {
95                 return EM.this.getDeploymentDescriptor();
96             }
97         }
98     }
99 }
100
Popular Tags