Source Code Cross Referenced for BeanInfoSource.java in  » IDE-Netbeans » beans » org » netbeans » modules » beans » beaninfo » 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 » beans » org.netbeans.modules.beans.beaninfo 
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-2006 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.beans.beaninfo;
043:
044:        import org.netbeans.api.editor.guards.GuardedSectionManager;
045:        import org.netbeans.api.editor.guards.InteriorSection;
046:        import org.netbeans.api.editor.guards.SimpleSection;
047:        import org.netbeans.modules.beans.GenerateBeanException;
048:        import org.openide.filesystems.FileObject;
049:        import org.openide.filesystems.Repository;
050:        import org.openide.loaders.DataObject;
051:        import org.openide.loaders.DataFolder;
052:        import org.openide.loaders.DataObjectNotFoundException;
053:
054:        /**
055:         * Finds or creates BeanInfo source elemnet for the class.
056:         * It can regenerate the source if there are the guarded blocks.
057:         * @author  Petr Hrebejk
058:         */
059:
060:        public final class BeanInfoSource extends Object {
061:
062:            private static final String BEANINFO_NAME_EXT = "BeanInfo"; // NOI18N
063:
064:            private static final String DESCRIPTOR_SECTION = "BeanDescriptor"; // NOI18N
065:            private static final String PROPERTIES_SECTION = "Properties"; // NOI18N
066:            private static final String EVENTSETS_SECTION = "Events"; // NOI18N
067:            private static final String ICONS_SECTION = "Icons"; // NOI18N
068:            private static final String IDX_SECTION = "Idx"; // NOI18N
069:            private static final String METHODS_SECTION = "Methods"; // NOI18N
070:            private static final String SUPERCLASS_SECTION = "Superclass"; // NOI18N
071:
072:            private DataObject javaDataObject;
073:            private DataObject biDataObject = null;
074:            private BIEditorSupport javaEditor = null;
075:
076:            /** Creates new BeanInfoSource */
077:            public BeanInfoSource(FileObject javafile)
078:                    throws GenerateBeanException {
079:
080:                findBeanInfo(javafile);
081:            }
082:
083:            /** Returns wether the bean info exists or not */
084:            boolean exists() {
085:                return biDataObject != null;
086:            }
087:
088:            /** Checks wether the bean info object has Guarded sections i.e.
089:             * was created from netbeans template.
090:             */
091:            boolean isNbBeanInfo() {
092:
093:                GuardedSectionManager guards = null;
094:                if (!exists()
095:                        || javaEditor == null
096:                        || null == (guards = javaEditor
097:                                .getGuardedSectionManager())) {
098:                    return false;
099:                }
100:
101:                //JavaEditor.InteriorSection dis = javaEditor.findInteriorSection( DESCRIPTOR_SECTION );
102:                InteriorSection pis = guards
103:                        .findInteriorSection(PROPERTIES_SECTION);
104:                InteriorSection eis = guards
105:                        .findInteriorSection(EVENTSETS_SECTION);
106:                //        JavaEditor.InteriorSection mis = javaEditor.findInteriorSection( METHODS_SECTION );
107:                //JavaEditor.SimpleSection iss = javaEditor.findSimpleSection( ICONS_SECTION );
108:                SimpleSection dss = guards.findSimpleSection(IDX_SECTION);
109:
110:                //return ( pis != null && eis != null && iss != null && dss != null);
111:                return (pis != null && eis != null && dss != null);
112:            }
113:
114:            boolean hasIconInfo() {
115:                GuardedSectionManager guards = javaEditor
116:                        .getGuardedSectionManager();
117:                if (guards == null) {
118:                    return false;
119:                }
120:                SimpleSection iss = guards.findSimpleSection(ICONS_SECTION);
121:                return (iss != null);
122:            }
123:
124:            /** Checks wether the bean descriptor object has Guarded sections i.e.
125:             * was created from new netbeans template.
126:             */
127:            boolean isNbBeanInfoDescriptor() {
128:
129:                GuardedSectionManager guards = null;
130:                if (!exists()
131:                        || javaEditor == null
132:                        || null == (guards = javaEditor
133:                                .getGuardedSectionManager())) {
134:                    return false;
135:                }
136:                InteriorSection dis = guards
137:                        .findInteriorSection(DESCRIPTOR_SECTION);
138:                return (dis != null);
139:            }
140:
141:            /** Checks wether the bean info object has Guarded sections for superclass i.e.
142:             * was created from new netbeans template.
143:             */
144:            boolean isNbSuperclass() {
145:
146:                GuardedSectionManager guards = null;
147:                if (!exists()
148:                        || javaEditor == null
149:                        || null == (guards = javaEditor
150:                                .getGuardedSectionManager())) {
151:                    return false;
152:                }
153:                InteriorSection dis = guards
154:                        .findInteriorSection(SUPERCLASS_SECTION);
155:                return (dis != null);
156:            }
157:
158:            /** Finds the bean info for classElement asspciated with this
159:                object */
160:            void findBeanInfo(FileObject javafile) throws GenerateBeanException {
161:
162:                javaEditor = null;
163:                try {
164:                    this .javaDataObject = DataObject.find(javafile);
165:                    FileObject parent = javafile.getParent();
166:                    FileObject bifile = parent.getFileObject(javafile.getName()
167:                            + BEANINFO_NAME_EXT, "java"); // NOI18N
168:                    if (bifile != null) {
169:                        biDataObject = DataObject.find(bifile);
170:                        javaEditor = biDataObject.getLookup().lookup(
171:                                BIEditorSupport.class);
172:                    }
173:                } catch (DataObjectNotFoundException ex) {
174:                    throw new GenerateBeanException();
175:                    // Do nothing if no data object is found
176:                }
177:            }
178:
179:            /** Deletes the BeanInfo */
180:            void delete() throws java.io.IOException {
181:                biDataObject.delete();
182:            }
183:
184:            /** Creates beanInfo data object */
185:            void createFromTemplate(boolean iconBlock) {
186:                FileObject foTemplates = Repository.getDefault()
187:                        .getDefaultFileSystem().findResource("Templates"); //NOI18N ;
188:                if (foTemplates == null) {
189:                    return;
190:                }
191:
192:                FileObject foClassTemplates = foTemplates
193:                        .getFileObject("Beans"); // NOI18N
194:                if (foClassTemplates == null) {
195:                    return;
196:                }
197:
198:                FileObject foBiTemplate = null;
199:
200:                if (iconBlock) {
201:                    foBiTemplate = foClassTemplates.getFileObject("BeanInfo",
202:                            "java"); // NOI18N
203:                } else {
204:                    foBiTemplate = foClassTemplates.getFileObject(
205:                            "NoIconBeanInfo", "java"); // NOI18N
206:                }
207:
208:                if (foBiTemplate == null) {
209:                    return;
210:                }
211:
212:                try {
213:                    DataObject doBiTemplate = DataObject.find(foBiTemplate);
214:                    DataFolder folder = this .javaDataObject.getFolder();
215:                    biDataObject = doBiTemplate.createFromTemplate(folder,
216:                            this .javaDataObject.getName() + BEANINFO_NAME_EXT);
217:                    javaEditor = biDataObject.getLookup().lookup(
218:                            BIEditorSupport.class);
219:                } catch (org.openide.loaders.DataObjectNotFoundException e) {
220:                    //System.out.println ( e );
221:                    // Do nothing if no data object is found
222:                } catch (java.io.IOException e) {
223:                    //System.out.println ( e );
224:                    // Do nothing if no data object is found
225:                }
226:            }
227:
228:            /** If the bean info is available returns the bean info data object */
229:            DataObject getDataObject() {
230:                return biDataObject;
231:            }
232:
233:            DataObject getSourceDataObject() {
234:                return javaDataObject;
235:            }
236:
237:            /** opens the source */
238:            void open() {
239:                javaEditor.open();
240:            }
241:
242:            /** Sets the header and bottom of properties section */
243:            void setDescriptorSection(String header, String bottom) {
244:                setInteriorSection(DESCRIPTOR_SECTION, header, bottom);
245:            }
246:
247:            /** Gets the header of properties setion */
248:            String getDescriptorSection() {
249:                GuardedSectionManager guards = javaEditor
250:                        .getGuardedSectionManager();
251:                InteriorSection is = guards
252:                        .findInteriorSection(DESCRIPTOR_SECTION);
253:
254:                if (is != null) {
255:                    return is.getText();
256:                } else
257:                    return null;
258:
259:            }
260:
261:            /** Sets the header and bottom of properties section */
262:            void setPropertiesSection(String header, String bottom) {
263:                setInteriorSection(PROPERTIES_SECTION, header, bottom);
264:            }
265:
266:            /** Gets the header of properties setion */
267:            String getPropertiesSection() {
268:                return getInteriorSection(PROPERTIES_SECTION);
269:            }
270:
271:            /** Sets the header and bottom of methods section */
272:            void setMethodsSection(String header, String bottom) {
273:                setInteriorSection(METHODS_SECTION, header, bottom);
274:            }
275:
276:            /** Gets the header of properties setion */
277:            String getMethodsSection() {
278:                return getInteriorSection(METHODS_SECTION);
279:            }
280:
281:            /** Sets the header and bottom of event sets section */
282:            void setEventSetsSection(String header, String bottom) {
283:                setInteriorSection(EVENTSETS_SECTION, header, bottom);
284:            }
285:
286:            /** Gets the header of properties setion */
287:            String getEventSetsSection() {
288:                return getInteriorSection(EVENTSETS_SECTION);
289:            }
290:
291:            /** Gets the header of properties setion */
292:            String getIconsSection() {
293:                return getSimpleSection(ICONS_SECTION);
294:            }
295:
296:            /** Sets the header of properties setion */
297:            void setIconsSection(String text) {
298:                setSimpleSection(ICONS_SECTION, text);
299:            }
300:
301:            /** Gets the header of properties setion */
302:            String getDefaultIdxSection() {
303:                return getSimpleSection(IDX_SECTION);
304:            }
305:
306:            /** Sets the header of properties setion */
307:            void setDefaultIdxSection(String text) {
308:                setSimpleSection(IDX_SECTION, text);
309:            }
310:
311:            /** Sets the header and bottom of properties section */
312:            void setSuperclassSection(String header, String bottom) {
313:                setInteriorSection(SUPERCLASS_SECTION, header, bottom);
314:            }
315:
316:            /** Gets the header of properties setion */
317:            String getSuperclassSection() {
318:                return getInteriorSection(SUPERCLASS_SECTION);
319:            }
320:
321:            private void setInteriorSection(String section, String header,
322:                    String bottom) {
323:                GuardedSectionManager guards = javaEditor
324:                        .getGuardedSectionManager();
325:                if (guards == null) {
326:                    return;
327:                }
328:                InteriorSection is = guards.findInteriorSection(section);
329:
330:                if (is != null) {
331:                    is.setHeader(header);
332:                    is.setFooter(bottom);
333:                }
334:            }
335:
336:            private String getInteriorSection(String section) {
337:                GuardedSectionManager guards = javaEditor
338:                        .getGuardedSectionManager();
339:                if (guards == null) {
340:                    return null;
341:                }
342:                InteriorSection is = guards.findInteriorSection(section);
343:                return is == null ? null : is.getText();
344:            }
345:
346:            private void setSimpleSection(String section, String text) {
347:                GuardedSectionManager guards = javaEditor
348:                        .getGuardedSectionManager();
349:                if (guards == null) {
350:                    return;
351:                }
352:                SimpleSection ss = guards.findSimpleSection(section);
353:
354:                if (ss != null) {
355:                    ss.setText(text);
356:                }
357:            }
358:
359:            private String getSimpleSection(String section) {
360:                GuardedSectionManager guards = javaEditor
361:                        .getGuardedSectionManager();
362:                if (guards == null) {
363:                    return null;
364:                }
365:                SimpleSection ss = guards.findSimpleSection(section);
366:                return ss == null ? null : ss.getText();
367:            }
368:
369:            /*
370:            void regenerateMethods() {
371:              JavaEditor.InteriorSection is = javaEditor.findInteriorSection( "Events" );
372:              
373:              if ( is != null ) {
374:                is.setHeader( BeanInfoGenerator.generateMethods( classElement.getName().getName(), methods ) );
375:                is.setBottom( BeanInfoGenerator.generateMethodsBottom( methods ) );
376:              }
377:            }
378:             */
379:
380:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.