KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > deployment > common > api > SourceFileMap


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.deployment.common.api;
21
22 import java.io.File JavaDoc;
23 import javax.enterprise.deploy.model.DDBean JavaDoc;
24 import javax.enterprise.deploy.model.DeployableObject JavaDoc;
25 import org.netbeans.api.project.FileOwnerQuery;
26 import org.netbeans.api.project.Project;
27 import org.netbeans.modules.j2ee.deployment.config.DDCommon;
28 import org.netbeans.modules.j2ee.deployment.config.DeployableObjectImpl;
29 import org.netbeans.modules.j2ee.deployment.config.StandardDDImpl;
30 import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider;
31 import org.openide.filesystems.FileObject;
32 import org.openide.util.Lookup;
33
34 /**
35  * Extra file mapping service for each j2ee module. This service cover irregular source to
36  * distribution file mapping. Users of the mapping could update the mapping. Provider of
37  * the mapping has to ensure the mapping persistence.
38  *
39  * Note: the initial design is for non-static configuration file such as schema file used in
40  * CMP mapping, but it could be used to expose any kind of source-to-distribution mapping.
41  *
42  * @author nn136682
43  */

44 public abstract class SourceFileMap {
45     
46     /**
47      * Returns the concrete file for the given distribution path.
48      * @param distributionPath distribution path for to find source file for.
49      */

50     public abstract FileObject[] findSourceFile(String JavaDoc distributionPath);
51
52     /**
53      * Returns the relative path in distribution of the given concrete source file.
54      * @param distributionPath distribution path for to find source file for.
55      */

56     public abstract File JavaDoc getDistributionPath(FileObject sourceFile);
57     
58     /**
59      * Return source roots this file mapping is operate on.
60      */

61     public abstract FileObject[] getSourceRoots();
62
63     /**
64      * Return context name, typically the J2EE module project name.
65      */

66     public abstract String JavaDoc getContextName();
67     
68     /**
69      * Returns directory paths to repository of enterprise resource definition files.
70      * If the directories pointed to by the returned path does not exists writing user
71      * of the method call could attempt to create it.
72      */

73     public abstract File JavaDoc getEnterpriseResourceDir();
74     
75     /**
76      * Returns directory paths to repository of enterprise resource definition files.
77      * If the directories pointed to by the returned path does not exists writing user
78      * of the method call could attempt to create it.
79      * For a stand-alone J2EE module, the returned list should contain only one path as
80      * returned by getEnterpriseResourceDir.
81      *
82      * For J2EE application module, the list contains resource directory paths of all child modules.
83      */

84     public abstract File JavaDoc[] getEnterpriseResourceDirs();
85     
86     /**
87      * Add new mapping or update existing mapping of the given distribution path.
88      * Provider of the mapping needs to extract and persist the relative path to
89      * ensure the mapping is in project sharable data. The mapping would be
90      * used in ensuring that during build time the source file is put at the
91      * right relative path in the distribution content.
92      *
93      * @param distributionPath file path in the distribution content
94      * @param sourceFile souce concrete file object.
95      * @return true if added successfully; false if source file is out of this mapping scope.
96      */

97     public abstract boolean add(String JavaDoc distributionPath, FileObject sourceFile);
98
99     /**
100      * Remove mapping for the given distribution path.
101      * @param distributionPath file path in the distribution content
102      */

103     public abstract FileObject remove(String JavaDoc distributionPath);
104
105     /**
106      * Returns a source file map for the module, or null if none can be identified.
107      *
108      * @param source A non-null source file (java, descriptor or dbschema) to establish mapping context.
109      */

110     public static final SourceFileMap findSourceMap(FileObject source) {
111         Project owner = FileOwnerQuery.getOwner(source);
112         if (owner != null) {
113             Lookup l = owner.getLookup();
114             J2eeModuleProvider projectModule = (J2eeModuleProvider) l.lookup(J2eeModuleProvider.class);
115             if (projectModule != null) {
116                 return projectModule.getSourceFileMap();
117             }
118         }
119         return null;
120     }
121
122     /**
123      * Returns a source file map for the module, or null if none can be identified.
124      *
125      * @param ddbean An instance of ddbean to establish mapping context.
126      */

127     public static final SourceFileMap findSourceMap(DDBean JavaDoc ddbean) {
128         if (ddbean instanceof DDCommon) {
129             DDCommon dd = (DDCommon) ddbean;
130             return dd.getModuleProvider().getSourceFileMap();
131         } else if (ddbean instanceof StandardDDImpl) {
132             StandardDDImpl dd = (StandardDDImpl) ddbean;
133             return dd.getModuleProvider().getSourceFileMap();
134         }
135         return null;
136     }
137
138     /**
139      * Returns a source file map for the module, or null if none can be identified.
140      *
141      * @param ddbean An instance of ddbean to establish mapping context.
142      */

143     public static final SourceFileMap findSourceMap(DeployableObject JavaDoc deployable) {
144         if (deployable instanceof DeployableObjectImpl) {
145             return ((DeployableObjectImpl)deployable).getProvider().getSourceFileMap();
146         }
147         return null;
148     }
149 }
150
Popular Tags