KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > core > jsploader > JspServletDataLoader


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.web.core.jsploader;
21
22 import org.openide.ErrorManager;
23 import org.openide.filesystems.*;
24 import org.openide.loaders.*;
25 import org.openide.util.NbBundle;
26
27 import org.netbeans.api.java.loaders.JavaDataSupport;
28
29 /** The DataLoader for servlets (JavaDataObjects), which have been generated by JaSPer
30 * from JSP pages. Recognizes by string <code>_jsp_</code> in the name of the file.
31 * Does not recognize associated .class files, which are recognized as a separate ClassDataObject
32 *
33 * @author Petr Jiricka
34 */

35 public final class JspServletDataLoader extends MultiFileLoader {
36
37     /** serialVersionUID */
38     private static final long serialVersionUID = -6033464827752236719L;
39
40     /** The standard extension for Java source files. */
41     public static final String JavaDoc JAVA_EXTENSION = "java"; // NOI18N
42

43     public static final String JavaDoc JSP_MARK = "_jsp"; // NOI18N
44

45     /** Creates a new JspServletDataLoader
46     * Should <em>not</em> be used by subclasses.
47      */

48     public JspServletDataLoader() {
49         super("org.netbeans.modules.web.core.jsploader.JspServletDataObject"); // NOI18N
50
}
51     
52     /** Gets default display name. Overrides superclass mthod. */
53     protected @Override JavaDoc String JavaDoc defaultDisplayName() {
54         return NbBundle.getBundle(JspServletDataLoader.class).getString("PROP_JspServletLoader_Name");
55     }
56     
57     protected String JavaDoc actionsContext() {
58         return "Loaders/text/x-jsp-servlet/Actions/"; // NOI18N
59
}
60
61     /** For a given file finds a primary file.
62     * @param fo the file to find primary file for
63     * @return the primary file for the file or null if the file is not
64     * recognized by this loader
65     */

66     protected FileObject findPrimaryFile (FileObject fo) {
67         // detects *_jsp*.java
68
FileObject javaPrim;
69         // never recognize folders.
70
if (fo.isFolder())
71             javaPrim = null;
72         else if (fo.getExt().equals(JAVA_EXTENSION))
73             javaPrim = fo;
74         else
75             javaPrim = null;
76         
77         if (javaPrim == null)
78             return null;
79         
80         // if there is a source JSP set then this is generated from a JSP
81
if (javaPrim.getAttribute(JspServletDataObject.EA_ORIGIN_JSP_PAGE) != null) {
82             return javaPrim;
83         }
84
85         // PENDING: old way of recognition was by name, need to remove this later
86
//if (javaPrim.getName().lastIndexOf(JSP_MARK) != -1)
87
// return javaPrim;
88

89         return null;
90     }
91
92     /** Create the <code>JspServletDataObject</code>.
93     * @param primaryFile the primary file
94     * @return the data object for this file
95     * @exception DataObjectExistsException if the primary file already has a data object
96     */

97     protected MultiDataObject createMultiObject (FileObject primaryFile)
98     throws DataObjectExistsException, java.io.IOException JavaDoc {
99         return new JspServletDataObject(primaryFile, this);
100     }
101
102     /** Create the primary file entry.
103     * @param primaryFile primary file recognized by this loader
104     * @return primary entry for that file
105     */

106     protected MultiDataObject.Entry createPrimaryEntry (MultiDataObject obj, FileObject primaryFile) {
107         if (JAVA_EXTENSION.equals(primaryFile.getExt())) {
108             return JavaDataSupport.createJavaFileEntry(obj, primaryFile);
109         }
110         else {
111             return new FileEntry(obj, primaryFile);
112         }
113     }
114
115     /** Create a secondary file entry.
116     * By default, {@link FileEntry.Numb} is used for the class files
117     *
118     * @param secondaryFile secondary file to create entry for
119     * @return the entry
120     */

121     protected MultiDataObject.Entry createSecondaryEntry (MultiDataObject obj, FileObject secondaryFile) {
122         //The JavaDataObject itself has no secondary entries, but its subclasses have.
123
//So we have to keep it as MultiFileLoader
124
ErrorManager.getDefault().log ("Subclass of JavaDataLoader ("+this.getClass().getName()
125                 +") has secondary entries but does not override createSecondaryEntries (MultidataObject, FileObject) method."); // NOI18N
126
return new FileEntry.Numb(obj, secondaryFile);
127     }
128
129 }
130
Popular Tags