1 ;;; jde-ejb.el -- EJB Extensions to Java Development Environment for Emacs
4 ;; Author: David T. Smith
5 ;; Maintainers: David T. Smith, Yoon Kyung Koo
6 ;; Keywords: java, tools, ejb
8 ;; Copyright (C) 2002, 2003, 2004, David T. Smith
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; Gnu Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
25 ;; This module uses the concept of an Enterprise Java Bean as a component
26 ;; comprised of a class (xxxBean.java), a Remote Interface (xxx.java), a home
27 ;; interface (xxxHome.java), and a deployment descriptor (xxxEJB.xml). These
28 ;; files are all interrelated and therefore, changes to one should be
29 ;; propagated to all. The obvious thing is to treat it as an entity
30 ;; with appropriate linkages between the files. In this version however,
31 ;; I will simply provide a wizard to create all three elements and
32 ;; leave referential integrity alone.
39 "JDE EJB Electric Class Builder"
43 (defvar jde-current-ejb-name ""
44 "Name used by all EJB components.")
46 (defvar jde-current-ejb-package ""
47 "Package that contains all EJB components.")
49 (defvar jde-ejb-dir nil
50 "Directory containing all EJB components.")
53 ;; (makunbound 'jde-ejb-remote-format)
54 (defcustom jde-ejb-remote-format "%s.java"
55 "*Default format for EJB Remote Interface"
59 ;; (makunbound 'jde-ejb-home-format)
60 (defcustom jde-ejb-home-format "%sHome.java"
61 "*Default format for EJB Home Interface
62 Setting this also resets jde-ejb-home to the
63 name portion of the filename string."
66 :set '(lambda (sym val)
67 (set-default 'jde-ejb-home
68 (file-name-sans-extension val))
69 (set-default sym val)))
71 ;; (makunbound 'jde-ejb-local-format)
72 (defcustom jde-ejb-local-format "%sLocal.java"
73 "*Default format for EJB Local Interface"
76 :set '(lambda (sym val)
77 (set-default 'jde-ejb-local
78 (file-name-sans-extension val))
79 (set-default sym val)))
81 ;; (makunbound 'jde-ejb-local-home-format)
82 (defcustom jde-ejb-local-home-format "%sLocalHome.java"
83 "*Default format for EJB LocalHome Interface
84 Setting this also resets jde-ejb-local-home to the
85 name portion of the filename string."
88 :set '(lambda (sym val)
89 (set-default 'jde-ejb-local-home
90 (file-name-sans-extension val))
91 (set-default sym val)))
94 ;; (makunbound 'jde-ejb-class-format)
95 (defcustom jde-ejb-class-format "%sBean.java"
96 "*Default format for EJB Class.
97 Setting this also resets jde-ejb-class to the
98 name portion of the filename string."
101 :set '(lambda (sym val)
102 (set-default 'jde-ejb-class
103 (file-name-sans-extension val))
104 (set-default sym val)))
106 ;; (makunbound 'jde-ejb-descriptor-format)
107 (defcustom jde-ejb-descriptor-format "%sEJB.xml"
108 "*Default format for EJB Deployment Descriptor"
112 (defun jde-ejb-format-filename (fmt name &optional dir)
113 (let ((thisdir (or dir default-directory)))
114 (format "%s/%s" thisdir (format fmt name))))
116 ;; (makunbound 'jde-ejb-remote-buffer-template)
117 (defcustom jde-ejb-remote-buffer-template
119 "(funcall jde-gen-boilerplate-function)"
120 "jde-ejb-package '>'n"
122 "\"public interface \""
123 "(file-name-sans-extension (file-name-nondirectory buffer-file-name))"
124 "\" extends javax.ejb.EJBObject \""
131 ;;;Add standard interface components for Remote Interface
135 "(file-name-sans-extension (file-name-nondirectory buffer-file-name))"
137 "*Template for new EJB Remote interface.
138 This is the interface that contains all user methods.
139 Setting this variable defines a template instantiation
140 command `jde-ejb-remote', as a side-effect."
142 :type '(repeat string)
143 :set '(lambda (sym val)
144 (defalias 'jde-ejb-remote
145 (tempo-define-template "java-ejb-remote-buffer-template"
146 (jde-gen-read-template val)
148 "Insert a generic Java class buffer skeleton."))
149 (set-default sym val)))
151 ;; (makunbound 'jde-ejb-home-buffer-template)
152 (defcustom jde-ejb-home-buffer-template
154 "(funcall jde-gen-boilerplate-function)"
155 "jde-ejb-package '>'n"
157 "\"public interface \""
158 "(file-name-sans-extension (file-name-nondirectory buffer-file-name))"
159 "\" extends javax.ejb.EJBHome \""
166 ;;;Add standard interface components for Home Interface
170 "(file-name-sans-extension (file-name-nondirectory buffer-file-name))"
172 "*Template for new EJB Home interface.
173 This interface defines the create/find (for entity beans)/remove
174 methods. Setting this variable defines a template instantiation
175 command `jde-ejb-home', as a side-effect."
177 :type '(repeat string)
178 :set '(lambda (sym val)
179 (defalias 'jde-ejb-home
180 (tempo-define-template "java-ejb-home-buffer-template"
181 (jde-gen-read-template val)
183 "Insert a generic Java class buffer skeleton."))
184 (set-default sym val)))
186 ;;;;;;; start - by yoonforh 2003-01-15 17:09:14
187 ;; (makunbound 'jde-ejb-local-buffer-template)
188 (defcustom jde-ejb-local-buffer-template
190 "(funcall jde-gen-boilerplate-function)"
191 "jde-ejb-package '>'n"
193 "\"public interface \""
194 "(file-name-sans-extension (file-name-nondirectory buffer-file-name))"
195 "\" extends javax.ejb.EJBLocalObject \""
202 ;;;Add standard interface components for Remote Interface
206 "(file-name-sans-extension (file-name-nondirectory buffer-file-name))"
208 "*Template for new EJB Local interface.
209 This is the interface that contains all user methods.
210 Setting this variable defines a template instantiation
211 command `jde-ejb-local', as a side-effect."
213 :type '(repeat string)
214 :set '(lambda (sym val)
215 (defalias 'jde-ejb-local
216 (tempo-define-template "java-ejb-local-buffer-template"
217 (jde-gen-read-template val)
219 "Insert a generic Java class buffer skeleton."))
220 (set-default sym val)))
222 ;; (makunbound 'jde-ejb-local-home-buffer-template)
223 (defcustom jde-ejb-local-home-buffer-template
225 "(funcall jde-gen-boilerplate-function)"
226 "jde-ejb-package '>'n"
228 "\"public interface \""
229 "(file-name-sans-extension (file-name-nondirectory buffer-file-name))"
230 "\" extends javax.ejb.EJBLocalHome \""
237 ;;;Add standard interface components for LocalHome Interface
241 "(file-name-sans-extension (file-name-nondirectory buffer-file-name))"
243 "*Template for new EJB LocalHome interface.
244 This interface defines the create/find (for entity beans)/remove
245 methods. Setting this variable defines a template instantiation
246 command `jde-ejb-local-home', as a side-effect."
248 :type '(repeat string)
249 :set '(lambda (sym val)
250 (defalias 'jde-ejb-local-home
251 (tempo-define-template "java-ejb-local-home-buffer-template"
252 (jde-gen-read-template val)
254 "Insert a generic Java class buffer skeleton."))
255 (set-default sym val)))
258 ;;;;;;;;;;; end - by yoonforh 2003-01-15 17:09:19
260 ;; (makunbound 'jde-ejb-entity-bean-template)
261 (defcustom jde-ejb-entitiy-bean-template
263 "(funcall jde-gen-boilerplate-function)"
264 "jde-ejb-package '>'n"
268 "(file-name-sans-extension (file-name-nondirectory buffer-file-name))"
269 " \" implements EntityBean \" "
278 "(jde-gen-method-signature"
283 " \"CreateException\""
293 "(jde-gen-method-signature"
302 ;;we open the bracket according to k&r style or not
310 "(jde-gen-method-signature"
325 "(jde-gen-method-signature"
340 "(jde-gen-method-signature"
355 "(jde-gen-method-signature"
360 " \"RemoveException\""
370 "(jde-gen-method-signature"
373 " \"setEntityContext\""
374 " \"EntityContext ctx\""
385 "(jde-gen-method-signature"
388 " \"unsetEntityContext\""
401 "(file-name-sans-extension (file-name-nondirectory buffer-file-name))"
403 "*Template for new Entity Bean class.
404 Entity beans must have a Find method using a primary key.
405 The method is defined in the Home interface and implemented
406 here under a slightly different name (see EJB specifications for details.
407 Similarly, any create methods defined in the Home interface
408 will also be instantiated here, but under a slightly different name.
409 Setting this variable defines a template instantiation
410 command `jde-ejb-entity-bean', as a side-effect."
412 :type '(repeat string)
413 :set '(lambda (sym val)
414 (defalias 'jde-ejb-entity-bean
415 (tempo-define-template "java-ejb-entity-bean-template"
416 (jde-gen-read-template val)
418 "Insert a generic Entity Bean skeleton."))
419 (set-default sym val)))
422 ;; (makunbound 'jde-ejb-session-bean-template)
423 (defcustom jde-ejb-session-bean-template
425 "(funcall jde-gen-boilerplate-function)"
426 "jde-ejb-package '>'n"
430 "(file-name-sans-extension (file-name-nondirectory buffer-file-name))"
431 " \" implements SessionBean \" "
433 ;;we open the bracket according to k&r style or not
440 "(jde-gen-method-signature"
445 " \"CreateException\""
449 ;;we open the bracket according to k&r style or not
456 "(jde-gen-method-signature"
465 ;;we open the bracket according to k&r style or not
472 "(jde-gen-method-signature"
481 ;;we open the bracket according to k&r style or not
488 "(jde-gen-method-signature"
497 ;;we open the bracket according to k&r style or not
504 "(jde-gen-method-signature"
507 " \"setSessionContext\""
508 " \"SessionContext ctx\""
513 ;; ;;we open the bracket according to k&r style or not
514 ;; "(if jde-gen-k&r "
520 ;; "(jde-gen-method-signature"
523 ;; " \"unsetSessionContext\""
525 ;; " \"RemoteException\""
529 ;;we open the bracket according to k&r style or not
539 "(file-name-sans-extension (file-name-nondirectory buffer-file-name))"
541 "*Template for new Session Bean class.
542 This creates the class for a session bean. It includes the
543 necessary interface implementations.
544 Setting this variable defines a template instantiation
545 command `jde-ejb-session-bean', as a side-effect."
547 :type '(repeat string)
548 :set '(lambda (sym val)
549 (defalias 'jde-ejb-session-bean
550 (tempo-define-template "java-ejb-session-bean-template"
551 (jde-gen-read-template val)
553 "Insert a generic Session Bean skeleton."))
554 (set-default sym val)))
557 ;; (makunbound 'jde-ejb-session-descriptor-buffer-template)
558 (defcustom jde-ejb-session-descriptor-buffer-template
560 "\"<?xml version=\\\"1.0\\\"?>\"'n"
561 "\"<!DOCTYPE ejb-jar PUBLIC \\\"-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN\\\" \" "
562 "\" \\\"http://java.sun.com/dtd/ejb-jar_2_0.dtd\\\" > \"'>'n'n"
564 "\"<enterprise-beans>\" '>'n"
567 "(format jde-ejb-class jde-current-ejb-name)"
568 "\"</ejb-name>\"'>'n"
570 "(format (concat \"%s.\" jde-ejb-home) jde-current-ejb-package jde-current-ejb-name)"
573 "(format \"%s.%s\" jde-current-ejb-package jde-current-ejb-name)"
576 "(format (concat \"%s.\" jde-ejb-local-home) jde-current-ejb-package jde-current-ejb-name)"
577 "\"</local-home>\"'>'n"
579 "(format (concat \"%s.\" jde-ejb-local) jde-current-ejb-package jde-current-ejb-name)"
582 "(format \"%s.%s\" jde-current-ejb-package (format jde-ejb-class jde-current-ejb-name))"
583 "\"</ejb-class>\"'>'n"
584 "\"<session-type>Stateless</session-type>\"'>'n"
585 "\"<transaction-type>Container</transaction-type>\"'>'n"
587 "\"</enterprise-beans>\"'>'n"
588 "\"<ejb-client-jar>\""
589 "(format \"%sClient.jar\" jde-current-ejb-name )"
590 "\"</ejb-client-jar>\"'>'n"
593 "*Template for new EJB Session Bean Deployment Descriptor interface.
594 This template uses internal functions to get the package and ejb names
595 interpolated when the XML file is generated from the template.
596 Setting this variable defines a template instantiation
597 command `jde-ejb-session-descriptor', as a side-effect."
599 :type '(repeat string)
600 :set '(lambda (sym val)
601 (defalias 'jde-ejb-session-descriptor
602 (tempo-define-template "java-ejb-session-descriptor-buffer-template"
603 (jde-gen-read-template val)
605 "Insert a generic XML Deployment Descriptor buffer skeleton."))
606 (set-default sym val)))
608 ;; (makunbound 'jde-ejb-entity-descriptor-buffer-template)
609 (defcustom jde-ejb-entity-descriptor-buffer-template
611 "\"<?xml version=\\\"1.0\\\"?>\"'n"
612 "\"<!DOCTYPE ejb-jar PUBLIC \\\"-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN\\\" \" "
613 "\" \\\"http://java.sun.com/dtd/ejb-jar_2_0.dtd\\\" > \"'>'n'n"
615 "\"<enterprise-beans>\" '>'n"
618 "(format jde-ejb-class jde-current-ejb-name)"
619 "\"</ejb-name>\"'>'n"
621 "(format (concat \"%s.\" jde-ejb-home) jde-current-ejb-package jde-current-ejb-name)"
624 "(format \"%s.%s\" jde-current-ejb-package jde-current-ejb-name)"
627 "(format (concat \"%s.\" jde-ejb-local-home) jde-current-ejb-package jde-current-ejb-name)"
628 "\"</local-home>\"'>'n"
630 "(format (concat \"%s.\" jde-ejb-local) jde-current-ejb-package jde-current-ejb-name)"
633 "(format \"%s.%s\" jde-current-ejb-package (format jde-ejb-class jde-current-ejb-name))"
634 "\"</ejb-class>\"'>'n"
635 "\"<persistence-type>Container</persistence-type>\"'>'n"
636 "\"<prim-key-class>\""
637 "(format \"%s.%sPK\" jde-current-ejb-package jde-current-ejb-name)"
638 "\"</prim-key-class>\"'>'n"
639 "\"<reentrant>False</reentrant>\"'>'n"
641 "\"</enterprise-beans>\"'>'n"
642 "\"<assembly-descriptor>\"'>'n"
643 "\"<container-transaction>\"'>'n"
646 "(format jde-ejb-class jde-current-ejb-name)"
647 "\"</ejb-name>\"'>'n"
648 "\"<method-intf>Local</method-intf>\"'>'n"
649 "\"<method-name>*</method-name>\"'>'n"
653 "(format jde-ejb-class jde-current-ejb-name)"
654 "\"</ejb-name>\"'>'n"
655 "\"<method-intf>Remote</method-intf>\"'>'n"
656 "\"<method-name>*</method-name>\"'>'n"
658 "\"<trans-attribute>Required</trans-attribute>\"'>'n"
659 "\"</container-transaction>\"'>'n"
660 "\"</assembly-descriptor>\"'>'n"
663 "*Template for new EJB Entity Bean Deployment Descriptor interface.
664 This template uses internal functions to get the package and ejb names
665 interpolated when the XML file is generated from the template.
666 Setting this variable defines a template instantiation
667 command `jde-ejb-session-descriptor', as a side-effect."
669 :type '(repeat string)
670 :set '(lambda (sym val)
671 (defalias 'jde-ejb-entity-descriptor
672 (tempo-define-template "java-ejb-entity-descriptor-buffer-template"
673 (jde-gen-read-template val)
675 "Insert a generic XML Deployment Descriptor buffer skeleton."))
676 (set-default sym val)))
679 (defun jde-ejb-session-bean-buffer (ejb-name)
680 "Create a new Java buffer containing an EJB session bean class of the same name.
681 This command also creates buffers with the EJB Home and EJB Remote interfaces
682 and the XML Deployment descriptor defined
683 by the jde-ejb templates. This includes naming the files according
684 to the EJB naming convention."
686 (let* ((insert-default-directory t)
687 (file (read-file-name "EJB Name (no extension): ")))
688 (setq jde-ejb-dir (file-name-directory file))
689 (list (file-name-sans-extension (file-name-nondirectory file)))))
691 ;; Find the package name
692 (setq jde-current-ejb-name ejb-name)
693 (jde-ejb-gen-bean 'session))
696 (defun jde-ejb-entity-bean-buffer ( ejb-name)
697 "Create a new Java buffer containing an EJB entity bean class of the same name.
698 This command also creates buffers with the EJB Home and EJB Remote interfaces
699 and the XML Deployment descriptor defined
700 by the jde-ejb templates. This includes naming the files according
701 to the EJB naming convention."
703 (let* ((insert-default-directory t)
704 (file (read-file-name "EJB Name (no extension): ")))
705 (setq jde-ejb-dir (file-name-directory file))
706 (list (file-name-sans-extension (file-name-nondirectory file)))))
708 ;; Find the package name
709 (setq jde-current-ejb-name ejb-name)
710 (jde-ejb-gen-bean 'entity))
712 (defun jde-ejb-gen-bean (beantype)
713 "Internal function used by session and entity bean creators.
714 This command uses jde package wizards and template commands to build
715 the bean skeleton using the Bean name and package name supplied by the
716 Bean-specific interactive function"
717 (let* ((jde-ejb-package (jde-gen-get-package-statement))
718 (jde-bean (format "jde-ejb-%s-bean" beantype))
719 (jde-desc (format "jde-ejb-%s-descriptor" beantype)))
721 ;; We use the package to generate a default directory
722 (setq jde-current-ejb-package (cadr (split-string jde-ejb-package "[ ;]+")))
723 (find-file (jde-ejb-format-filename jde-ejb-remote-format jde-current-ejb-name jde-ejb-dir))
724 (tempo-template-java-ejb-remote-buffer-template)
725 (find-file (jde-ejb-format-filename jde-ejb-home-format jde-current-ejb-name jde-ejb-dir ))
726 (tempo-template-java-ejb-home-buffer-template)
727 (find-file (jde-ejb-format-filename jde-ejb-local-format jde-current-ejb-name jde-ejb-dir))
728 (tempo-template-java-ejb-local-buffer-template)
729 (find-file (jde-ejb-format-filename jde-ejb-local-home-format jde-current-ejb-name jde-ejb-dir ))
730 (tempo-template-java-ejb-local-home-buffer-template)
731 (find-file (jde-ejb-format-filename jde-ejb-descriptor-format jde-current-ejb-name jde-ejb-dir))
732 (funcall (intern-soft jde-desc))
733 (find-file (jde-ejb-format-filename jde-ejb-class-format jde-current-ejb-name jde-ejb-dir))
734 (funcall (intern-soft jde-bean))
735 (beginning-of-buffer)
739 (tempo-forward-mark)))
745 ;; $Log: jde-ejb.el,v $
746 ;; Revision 1.7 2004/07/06 04:03:40 paulk
747 ;; Replace calls to template aliases to the actual template function
748 ;; names. This is intended to eliminate undefined function messages when
749 ;; byte-compiling this library.
751 ;; Revision 1.6 2004/07/06 03:43:56 paulk
752 ;; Provide defvars and jde- prefixes for global variables used in
753 ;; templates, e.g., jde-current-ejb-name. This eliminates
754 ;; byte-compilation warnings about undefined variables. Also, replace
755 ;; references to functions that get the values of these variables with
756 ;; the values themselves as this eliminates a function evaluation that
757 ;; seems to serve no useful purpose.
759 ;; Revision 1.5 2003/03/28 05:33:29 andyp
760 ;; XEmacs optimizations for JDEbug and efc.
762 ;; Revision 1.4 2003/01/19 05:11:36 paulk
763 ;; Updated to reflect EJB 2.x. Thanks to Yoon Kyung Koo.
765 ;; Revision 1.3 2002/12/02 14:38:17 jslopez
766 ;; Changes current-ejb-name to a function from a macro to fix byte-compilation.
768 ;; Revision 1.2 2002/09/30 04:40:23 paulk
769 ;; Made jde-ejb commands autoloadable.
771 ;; Revision 1.1 2002/09/26 06:12:27 paulk