Source Code Cross Referenced for BusinessMethod.java in  » J2EE » jag » com » finalist » jaggenerator » modules » 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 » J2EE » jag » com.finalist.jaggenerator.modules 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*   Copyright (C) 2005 Finalist IT Group
002:         *
003:         *   This file is part of JAG - the Java J2EE Application Generator
004:         *
005:         *   JAG is free software; you can redistribute it and/or modify
006:         *   it under the terms of the GNU General Public License as published by
007:         *   the Free Software Foundation; either version 2 of the License, or
008:         *   (at your option) any later version.
009:         *   JAG is distributed in the hope that it will be useful,
010:         *   but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012:         *   GNU General Public License for more details.
013:         *   You should have received a copy of the GNU General Public License
014:         *   along with JAG; if not, write to the Free Software
015:         *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
016:         */
017:
018:        package com.finalist.jaggenerator.modules;
019:
020:        import com.finalist.jaggenerator.*;
021:        import com.finalist.jag.util.TemplateString;
022:
023:        import java.util.*;
024:        import java.awt.event.ActionListener;
025:        import java.awt.event.ActionEvent;
026:        import javax.swing.*;
027:        import javax.swing.table.DefaultTableModel;
028:        import javax.swing.tree.*;
029:        import javax.xml.parsers.*;
030:
031:        import org.w3c.dom.*;
032:        import org.apache.commons.logging.Log;
033:        import org.apache.commons.logging.LogFactory;
034:
035:        /**
036:         * Helper class for representing business methods.
037:         *
038:         * @author Rudie Ekkelenkamp - Finalist IT Group
039:         * @version $Revision: 1.6 $, $Date: 2005/11/25 12:45:19 $
040:         */
041:        public class BusinessMethod extends DefaultMutableTreeNode implements 
042:                JagBean {
043:
044:            static Log log = LogFactory.getLog(BusinessMethod.class);
045:
046:            private Session parentEntity;
047:
048:            /** Creates new form BeanForm */
049:            public BusinessMethod(Session parent) {
050:                initComponents();
051:                parentEntity = parent;
052:            }
053:
054:            public BusinessMethod() {
055:                initComponents();
056:            }
057:
058:            /** Use for building up the entity field gui component */
059:            public BusinessMethod(Session parent, Element node) {
060:                initComponents();
061:                parentEntity = parent;
062:                try {
063:                    NodeList rt = node.getElementsByTagName("return-type");
064:                    if (rt.getLength() == 1) {
065:                        String returnType = "";
066:                        if (rt.item(0).getFirstChild() != null) {
067:                            returnType = rt.item(0).getFirstChild()
068:                                    .getNodeValue();
069:                        }
070:                        log.debug("The return type is: " + returnType);
071:                        setReturnType(returnType);
072:                    }
073:                    NodeList mn = node.getElementsByTagName("method-name");
074:                    if (mn.getLength() == 1) {
075:                        String methodName = "";
076:                        if (mn.item(0).getFirstChild() != null) {
077:                            methodName = mn.item(0).getFirstChild()
078:                                    .getNodeValue();
079:                        }
080:                        log.debug("The method name is: " + methodName);
081:                        setMethodName(methodName);
082:                    }
083:                    NodeList md = node.getElementsByTagName("description");
084:                    if (md.getLength() == 1) {
085:
086:                        String methodDescription = "";
087:                        if (md.item(0).getFirstChild() != null) {
088:                            methodDescription = md.item(0).getFirstChild()
089:                                    .getNodeValue();
090:                        }
091:                        log.debug("The method description is: "
092:                                + methodDescription);
093:                        setDescription(methodDescription);
094:                    }
095:                    ArrayList businessArguments = new ArrayList();
096:                    NodeList params = node.getElementsByTagName("parameter");
097:                    for (int k = 0; k < params.getLength(); k++) {
098:                        BusinessArgument businessArgument = new BusinessArgument();
099:                        Element param = (Element) params.item(k);
100:                        NodeList type = param.getElementsByTagName("type");
101:                        if (type.getLength() == 1) {
102:                            String baType = "";
103:                            if (type.item(0).getFirstChild() != null) {
104:                                baType = type.item(0).getFirstChild()
105:                                        .getNodeValue();
106:                            }
107:                            log.debug("The param type is: " + baType);
108:                            businessArgument.setType(baType);
109:                        }
110:                        NodeList name = param.getElementsByTagName("name");
111:                        if (name.getLength() == 1) {
112:                            String baName = "";
113:                            if (name.item(0).getFirstChild() != null) {
114:                                baName = name.item(0).getFirstChild()
115:                                        .getNodeValue();
116:                            }
117:                            log.debug("The param name is: " + baName);
118:                            businessArgument.setName(baName);
119:                        }
120:                        businessArguments.add(businessArgument);
121:                    }
122:                    setArgumentList(businessArguments);
123:                    log.debug("Added a businessmethod to the list");
124:                } catch (Exception e) {
125:                    e.printStackTrace();
126:                }
127:            }
128:
129:            public javax.swing.JPanel getPanel() {
130:                return panel;
131:            }
132:
133:            public String getRefName() {
134:                return getSignature();
135:            }
136:
137:            public String getSignature() {
138:                StringBuffer signature = new StringBuffer();
139:                signature.append(getReturnType());
140:                signature.append(" ");
141:                signature.append(getMethodName());
142:                signature.append("(");
143:                for (Iterator i = getArgumentList().iterator(); i.hasNext();) {
144:                    BusinessArgument next = (BusinessArgument) i.next();
145:                    signature.append(next.getType());
146:                    signature.append(" ");
147:                    signature.append(next.getName());
148:                    if (i.hasNext()) {
149:                        signature.append(",");
150:                    }
151:                }
152:                signature.append(")");
153:                return signature.toString();
154:            }
155:
156:            public void getXML(Element el) throws ParserConfigurationException {
157:                Document doc = el.getOwnerDocument();
158:                Element businessMethod = doc.createElement("business-method");
159:
160:                Element returnType = doc.createElement("return-type");
161:                if (getReturnType() == null) {
162:                    returnType.appendChild(doc.createTextNode("void"));
163:                } else {
164:                    returnType.appendChild(doc.createTextNode(getReturnType()));
165:                }
166:                businessMethod.appendChild(returnType);
167:
168:                Element methodName = doc.createElement("method-name");
169:                String methodString = getMethodName();
170:                if (methodString == null) {
171:                    methodString = "";
172:                }
173:                methodName.appendChild(doc.createTextNode(methodString));
174:                businessMethod.appendChild(methodName);
175:
176:                Element desc = doc.createElement("description");
177:                String descString = getDescription();
178:                if (descString == null) {
179:                    descString = "";
180:                }
181:                desc.appendChild(doc.createTextNode(descString));
182:                businessMethod.appendChild(desc);
183:
184:                for (int j = 0; j < getArgumentList().size(); j++) {
185:                    Element parameter = doc.createElement("parameter");
186:                    BusinessArgument arg = (BusinessArgument) getArgumentList()
187:                            .get(j);
188:
189:                    Element type = doc.createElement("type");
190:                    String typeString = arg.getType();
191:                    if (typeString == null) {
192:                        typeString = "";
193:                    }
194:
195:                    type.appendChild(doc.createTextNode(typeString));
196:                    parameter.appendChild(type);
197:
198:                    Element pname = doc.createElement("name");
199:                    String nameString = arg.getName();
200:                    if (nameString == null) {
201:                        nameString = "";
202:                    }
203:                    pname.appendChild(doc.createTextNode(nameString));
204:                    parameter.appendChild(pname);
205:
206:                    businessMethod.appendChild(parameter);
207:                }
208:                el.appendChild(businessMethod);
209:            }
210:
211:            /**
212:             * the return type of the method.
213:             * @return
214:             */
215:            public String getReturnType() {
216:                return returnTypeInput.getText();
217:            }
218:
219:            /**
220:             * Set the return type of the business method.
221:             *
222:             * @param returnType
223:             */
224:            public void setReturnType(String returnType) {
225:                returnTypeInput.setText(returnType);
226:            }
227:
228:            /**
229:             * Get the business method name.
230:             *
231:             * @return the name.
232:             */
233:            public String getMethodName() {
234:                return methodNameInput.getText();
235:            }
236:
237:            /**
238:             * Get the business method name in uppercase notation.
239:             *
240:             * @return the name.
241:             */
242:            public String getMethodNameUpper() {
243:                String methodName = getMethodName();
244:                if (methodName == null) {
245:                    return methodName;
246:                }
247:                if (methodName.length() > 1) {
248:                    return new String(methodName.substring(0, 1).toUpperCase()
249:                            + methodName.substring(1));
250:                }
251:                return methodName.toUpperCase();
252:
253:            }
254:
255:            /**
256:             * Set the method name.
257:             *
258:             * @param methodName the name.
259:             */
260:            public void setMethodName(String methodName) {
261:                methodNameInput.setText(methodName);
262:            }
263:
264:            /**
265:             * Get the method description.
266:             * @return description.
267:             */
268:            public String getDescription() {
269:                return descriptionInput.getText();
270:            }
271:
272:            /**
273:             * Set the method description.
274:             *
275:             * @param description
276:             */
277:            public void setDescription(String description) {
278:                descriptionInput.setText(description);
279:            }
280:
281:            /**
282:             * get a list of all arguments of the BusinessArgument class.
283:             *
284:             * @return Collection of BusinessArgument classes.
285:             */
286:            public ArrayList getArgumentList() {
287:                DefaultTableModel model = (DefaultTableModel) parametersTable
288:                        .getModel();
289:
290:                ArrayList argumentList = new ArrayList();
291:
292:                for (int count = 0; count < model.getRowCount(); count++) {
293:                    BusinessArgument argument = new BusinessArgument();
294:                    if (model.getValueAt(count, 0) != null) {
295:                        argument.setName(model.getValueAt(count, 0).toString());
296:                    }
297:                    if (model.getValueAt(count, 1) != null) {
298:                        argument.setType(model.getValueAt(count, 1).toString());
299:                    }
300:                    argumentList.add(argument);
301:                }
302:
303:                return argumentList;
304:            }
305:
306:            /**
307:             * Set the argument list.
308:             * @param argumentList
309:             */
310:            public void setArgumentList(ArrayList argumentList) {
311:                Object data[][] = new Object[argumentList.size()][2];
312:
313:                for (int count = 0; count < argumentList.size(); count++) {
314:                    BusinessArgument arg = (BusinessArgument) argumentList
315:                            .get(count);
316:                    data[count][0] = arg.getName();
317:                    data[count][1] = arg.getType();
318:                }
319:
320:                parametersTable
321:                        .setModel(new javax.swing.table.DefaultTableModel(data,
322:                                new String[] { "Parameter", "Type" }));
323:            }
324:
325:            public String toString() {
326:                return getRefName();
327:            }
328:
329:            /** This method is called from within the constructor to
330:             * initialize the form.
331:             * WARNING: Do NOT modify this code. The content of this method is
332:             * always regenerated by the Form Editor.
333:             */
334:            private void initComponents() {//GEN-BEGIN:initComponents
335:                panel = new javax.swing.JPanel();
336:                returnTypeLabel = new javax.swing.JLabel();
337:                methodNameLabel = new javax.swing.JLabel();
338:                descriptionLabel = new javax.swing.JLabel();
339:                parametersLabel = new javax.swing.JLabel();
340:                returnTypeInput = new javax.swing.JTextArea();
341:                methodNameScrollPane = new javax.swing.JScrollPane();
342:                methodNameInput = new javax.swing.JTextArea();
343:                descriptionScrollPane = new javax.swing.JScrollPane();
344:                descriptionInput = new javax.swing.JTextArea();
345:                parametersScrollPane = new javax.swing.JScrollPane();
346:                parametersTable = new javax.swing.JTable();
347:                addParameterButton = new javax.swing.JButton();
348:                deleteParameterButton = new javax.swing.JButton();
349:
350:                panel.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
351:
352:                returnTypeLabel
353:                        .setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
354:                returnTypeLabel.setText("Return type:");
355:                panel.add(returnTypeLabel,
356:                        new org.netbeans.lib.awtextra.AbsoluteConstraints(20,
357:                                10, 90, -1));
358:
359:                methodNameLabel
360:                        .setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
361:                methodNameLabel.setText("Method name:");
362:                panel.add(methodNameLabel,
363:                        new org.netbeans.lib.awtextra.AbsoluteConstraints(20,
364:                                40, 90, -1));
365:
366:                descriptionLabel
367:                        .setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
368:                descriptionLabel.setText("Description:");
369:                panel.add(descriptionLabel,
370:                        new org.netbeans.lib.awtextra.AbsoluteConstraints(20,
371:                                100, 90, -1));
372:
373:                parametersLabel
374:                        .setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
375:                parametersLabel.setText("Parameters:");
376:                panel.add(parametersLabel,
377:                        new org.netbeans.lib.awtextra.AbsoluteConstraints(20,
378:                                190, 90, -1));
379:
380:                returnTypeInput.setFont(new java.awt.Font(
381:                        "Microsoft Sans Serif", 0, 11));
382:                returnTypeInput.setAutoscrolls(false);
383:                returnTypeInput
384:                        .setBorder(new javax.swing.border.EtchedBorder());
385:                returnTypeInput.addKeyListener(new java.awt.event.KeyAdapter() {
386:                    public void keyReleased(java.awt.event.KeyEvent evt) {
387:                        inputKeyReleased(evt);
388:                    }
389:                });
390:
391:                panel.add(returnTypeInput,
392:                        new org.netbeans.lib.awtextra.AbsoluteConstraints(120,
393:                                10, 260, -1));
394:
395:                methodNameScrollPane.setBorder(null);
396:                methodNameInput.setFont(new java.awt.Font(
397:                        "Microsoft Sans Serif", 0, 11));
398:                methodNameInput.setLineWrap(true);
399:                methodNameInput.setWrapStyleWord(true);
400:                methodNameInput
401:                        .setBorder(new javax.swing.border.EtchedBorder());
402:                methodNameScrollPane.setViewportView(methodNameInput);
403:
404:                panel.add(methodNameScrollPane,
405:                        new org.netbeans.lib.awtextra.AbsoluteConstraints(120,
406:                                40, 260, 40));
407:
408:                descriptionScrollPane.setBorder(null);
409:                descriptionScrollPane.setFocusable(false);
410:                descriptionScrollPane
411:                        .setHorizontalScrollBar(descriptionScrollPane
412:                                .getHorizontalScrollBar());
413:                descriptionInput.setFont(new java.awt.Font(
414:                        "Microsoft Sans Serif", 0, 11));
415:                descriptionInput.setLineWrap(true);
416:                descriptionInput.setWrapStyleWord(true);
417:                descriptionInput
418:                        .setBorder(new javax.swing.border.EtchedBorder());
419:                descriptionScrollPane.setViewportView(descriptionInput);
420:
421:                panel.add(descriptionScrollPane,
422:                        new org.netbeans.lib.awtextra.AbsoluteConstraints(120,
423:                                100, 260, 80));
424:
425:                parametersTable
426:                        .setModel(new javax.swing.table.DefaultTableModel(
427:                                new Object[][] {
428:
429:                                }, new String[] { "Parameter", "Type" }));
430:                parametersScrollPane.setViewportView(parametersTable);
431:
432:                panel.add(parametersScrollPane,
433:                        new org.netbeans.lib.awtextra.AbsoluteConstraints(120,
434:                                190, 260, 110));
435:
436:                addParameterButton.setText("Add");
437:                addParameterButton
438:                        .addActionListener(new java.awt.event.ActionListener() {
439:                            public void actionPerformed(
440:                                    java.awt.event.ActionEvent evt) {
441:                                addParameterButtonActionPerformed(evt);
442:                            }
443:                        });
444:
445:                panel.add(addParameterButton,
446:                        new org.netbeans.lib.awtextra.AbsoluteConstraints(120,
447:                                310, -1, -1));
448:
449:                deleteParameterButton.setText("Delete");
450:                deleteParameterButton
451:                        .addActionListener(new java.awt.event.ActionListener() {
452:                            public void actionPerformed(
453:                                    java.awt.event.ActionEvent evt) {
454:                                deleteParameterButtonActionPerformed(evt);
455:                            }
456:                        });
457:
458:                panel.add(deleteParameterButton,
459:                        new org.netbeans.lib.awtextra.AbsoluteConstraints(180,
460:                                310, -1, -1));
461:
462:            }//GEN-END:initComponents
463:
464:            private void inputKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_inputKeyReleased
465:                JagGenerator.stateChanged(false);
466:            }//GEN-LAST:event_inputKeyReleased
467:
468:            private void deleteParameterButtonActionPerformed(
469:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteParameterButtonActionPerformed
470:                int selectedRows[] = parametersTable.getSelectedRows();
471:
472:                ArrayList argumentList = getArgumentList();
473:                for (int count = selectedRows.length - 1; count >= 0; count--) {
474:                    int deleteCol = selectedRows[count];
475:                    System.out.println("deleting: " + deleteCol);
476:
477:                    argumentList.remove(deleteCol);
478:                }
479:                setArgumentList(argumentList);
480:                JagGenerator.stateChanged(false);
481:
482:            }//GEN-LAST:event_deleteParameterButtonActionPerformed
483:
484:            private void addParameterButtonActionPerformed(
485:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addParameterButtonActionPerformed
486:                BusinessArgument ba = new BusinessArgument();
487:                ArrayList argumentList = getArgumentList();
488:                argumentList.add(ba);
489:                setArgumentList(argumentList);
490:                JagGenerator.stateChanged(false);
491:
492:            }//GEN-LAST:event_addParameterButtonActionPerformed
493:
494:            private void refNameTextFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_refNameTextFocusLost
495:                JagGenerator.stateChanged(false);
496:            }//GEN-LAST:event_refNameTextFocusLost
497:
498:            private void rootPackageTextFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_rootPackageTextFocusLost
499:                JagGenerator.stateChanged(false);
500:            }//GEN-LAST:event_rootPackageTextFocusLost
501:
502:            private void descriptionTextFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_descriptionTextFocusLost
503:                JagGenerator.stateChanged(false);
504:            }//GEN-LAST:event_descriptionTextFocusLost
505:
506:            private void nameTextFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_nameTextFocusLost
507:                JagGenerator.stateChanged(false);
508:
509:            }//GEN-LAST:event_nameTextFocusLost
510:
511:            private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addButtonActionPerformed
512:            }//GEN-LAST:event_addButtonActionPerformed
513:
514:            private void removeButtonActionPerformed(
515:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeButtonActionPerformed
516:            }//GEN-LAST:event_removeButtonActionPerformed
517:
518:            // Variables declaration - do not modify//GEN-BEGIN:variables
519:            private javax.swing.JButton addParameterButton;
520:            private javax.swing.JButton deleteParameterButton;
521:            private javax.swing.JTextArea descriptionInput;
522:            private javax.swing.JLabel descriptionLabel;
523:            private javax.swing.JScrollPane descriptionScrollPane;
524:            private javax.swing.JTextArea methodNameInput;
525:            private javax.swing.JLabel methodNameLabel;
526:            private javax.swing.JScrollPane methodNameScrollPane;
527:            private javax.swing.JPanel panel;
528:            private javax.swing.JLabel parametersLabel;
529:            private javax.swing.JScrollPane parametersScrollPane;
530:            private javax.swing.JTable parametersTable;
531:            private javax.swing.JTextArea returnTypeInput;
532:            private javax.swing.JLabel returnTypeLabel;
533:            // End of variables declaration//GEN-END:variables
534:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.