Source Code Cross Referenced for JsfJavaDataLoader.java in  » IDE-Netbeans » visualweb.api.designer » org » netbeans » modules » visualweb » project » jsfloader » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » visualweb.api.designer » org.netbeans.modules.visualweb.project.jsfloader 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:
042:        package org.netbeans.modules.visualweb.project.jsfloader;
043:
044:        import org.netbeans.modules.visualweb.project.jsf.api.JsfProjectUtils;
045:        import java.io.IOException;
046:        import java.lang.reflect.Method;
047:        import org.netbeans.api.java.loaders.JavaDataSupport;
048:        import org.openide.ErrorManager;
049:        import org.openide.filesystems.FileObject;
050:        import org.openide.loaders.DataObject;
051:        import org.openide.loaders.DataObjectExistsException;
052:        import org.openide.loaders.MultiDataObject;
053:        import org.openide.loaders.MultiFileLoader;
054:        import org.openide.util.NbBundle;
055:
056:        /**
057:         * Data lodaer of JSF Java DataObjects, what means it loads java file,
058:         * only in case there is corresponding jsp file, and maintains its loose
059:         * reference, which is kind-of one part of virtual JSF DataObject (which
060:         * we are simulating).
061:         *
062:         * @author  Peter Zavadsky
063:         */
064:        public class JsfJavaDataLoader extends MultiFileLoader {
065:
066:            static final long serialVersionUID = -5809935261731217882L;
067:
068:            public static final String JAVA_EXTENSION = "java"; // NOI18N
069:
070:            protected static Object dataObjectPool;
071:            protected static Method dataObjectPoolFindMethod;
072:
073:            static {
074:                // EAT: All this to make sure I dont make a change to NB to make DataObjectPool public
075:                try {
076:                    Class clazz = Class
077:                            .forName("org.openide.loaders.DataObjectPool");
078:                    Method getPoolMethod = clazz.getDeclaredMethod("getPOOL",
079:                            new Class[0]);
080:                    getPoolMethod.setAccessible(true);
081:                    dataObjectPool = getPoolMethod.invoke(null, new Object[0]);
082:                    dataObjectPoolFindMethod = clazz.getDeclaredMethod("find",
083:                            new Class[] { FileObject.class });
084:                    dataObjectPoolFindMethod.setAccessible(true);
085:                } catch (Exception e) {
086:                    ErrorManager.getDefault().notify(ErrorManager.ERROR, e);
087:                }
088:            }
089:
090:            public static DataObject DataObjectPoolFind(FileObject fileObject) {
091:                // EAT: All this to make sure I dont make a change to NB to make DataObjectPool public
092:                try {
093:                    Object result = dataObjectPoolFindMethod.invoke(
094:                            dataObjectPool, new Object[] { fileObject });
095:                    return (DataObject) result;
096:                } catch (Exception e) {
097:                    ErrorManager.getDefault().notify(ErrorManager.ERROR, e);
098:                    return null;
099:                }
100:            }
101:
102:            public JsfJavaDataLoader() {
103:                // use String name instead of class.getName() for performance reasons
104:                super (
105:                        "org.netbeans.modules.visualweb.project.jsfloader.JsfJavaDataObject"); // NOI18N
106:            }
107:
108:            protected String defaultDisplayName() {
109:                return NbBundle.getMessage(JsfJavaDataLoader.class,
110:                        "PROP_JsfJavaDataLoader_Name");
111:            }
112:
113:            protected String actionsContext() {
114:                return "Loaders/text/x-java/Actions/"; // NOI18N
115:            }
116:
117:            protected ThreadLocal findPrimaryFileThreadLocal = new ThreadLocal();
118:
119:            protected FileObject findPrimaryFile(FileObject fo) {
120:                if (fo.isFolder()) {
121:                    return null;
122:                }
123:
124:                FileObject primaryFile = findPrimaryJavaFile(fo);
125:                if (primaryFile == null) {
126:                    return null;
127:                }
128:
129:                Object attrib = primaryFile
130:                        .getAttribute(JsfJavaDataObject.JSF_ATTRIBUTE);
131:                if (attrib != null && attrib instanceof  Boolean) {
132:                    if (((Boolean) attrib).booleanValue() == true)
133:                        return primaryFile;
134:                    else
135:                        return null;
136:                }
137:
138:                // XXX JsfProjectUtils.isJsfProjectFile() is very slow and should be revisited
139:                // since this affects all loaded java files in NetBeans
140:                boolean isTemplate = Utils.isTemplateFileObject(primaryFile);
141:                if (!isTemplate
142:                        && !JsfProjectUtils.isJsfProjectFile(primaryFile)) {
143:                    return null;
144:                }
145:
146:                // It is most likely a Java file, however, we need to see if there is already a JsfJavaDataObject registered
147:                // for this file object.  There is a case where by in middle of refactoring, the JSP and the JAVA file are not
148:                // linked as they should be, but there is still a JsfJavaDataObject registered uner this file object
149:                // Duplicated in JsfJspDataObject
150:                // XXX This causes some performance issues and should probably be removed
151:                DataObject dataObject = DataObjectPoolFind(fo);
152:                if (dataObject instanceof  JsfJavaDataObject) {
153:                    return fo;
154:                }
155:                // We now know look for the jsp file
156:                FileObject jspFile = Utils.findJspForJava(primaryFile);
157:                if (jspFile == null) {
158:                    // If there is no backing file, then this is not a JSF data object.
159:                    return null;
160:                }
161:                // It has to be linked vice versa too.
162:                if (primaryFile != Utils.findJavaForJsp(jspFile)) {
163:                    return null;
164:                }
165:
166:                if (!isTemplate) {
167:                    setJsfFileAttribute(primaryFile);
168:                }
169:
170:                return primaryFile;
171:            }
172:
173:            protected MultiDataObject createMultiObject(
174:                    final FileObject primaryFile)
175:                    throws DataObjectExistsException, IOException {
176:                return new JsfJavaDataObject(primaryFile, this );
177:            }
178:
179:            @Override
180:            protected MultiDataObject.Entry createPrimaryEntry(
181:                    MultiDataObject obj, FileObject primaryFile) {
182:                return JavaDataSupport.createJavaFileEntry(obj, primaryFile);
183:            }
184:
185:            @Override
186:            protected MultiDataObject.Entry createSecondaryEntry(
187:                    MultiDataObject obj, FileObject secondaryFile) {
188:                throw new UnsupportedOperationException("Not supported yet.");
189:            }
190:
191:            private FileObject findPrimaryJavaFile(FileObject fo) {
192:                if (fo.getExt().equals(JAVA_EXTENSION)) {
193:                    return fo;
194:                }
195:                return null;
196:            }
197:
198:            private void setJsfFileAttribute(FileObject fo) {
199:                try {
200:                    fo.setAttribute(JsfJavaDataObject.JSF_ATTRIBUTE,
201:                            Boolean.TRUE);
202:                } catch (IOException ex) {
203:                    ErrorManager.getDefault().notify(
204:                            ErrorManager.INFORMATIONAL, ex);
205:                }
206:            }
207:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.