# HG changeset patch # Parent 51fcad820237f79f3c751a7678135ce933d5b7ef diff --git a/j2ee.common/src/org/netbeans/modules/j2ee/common/method/MethodModel.java b/j2ee.common/src/org/netbeans/modules/j2ee/common/method/MethodModel.java --- a/j2ee.common/src/org/netbeans/modules/j2ee/common/method/MethodModel.java +++ b/j2ee.common/src/org/netbeans/modules/j2ee/common/method/MethodModel.java @@ -46,7 +46,9 @@ import com.sun.source.tree.ExpressionTree; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Set; import javax.lang.model.element.Modifier; import org.openide.util.Parameters; @@ -244,9 +246,9 @@ public static final class Annotation { private final String type; - private final List arguments; + private final Map arguments; - private Annotation(String type, List arguments) { + private Annotation(String type, Map arguments) { this.type = type; this.arguments = arguments; } @@ -269,16 +271,16 @@ * Creates new instance of a model of {@code Annotation} * * @param type name of annotation type, fully qualified name must be used - * @param arguments {@code List} of annotation arguments, for generation them see {@code GenerationUtils} class + * @param arguments {@code Map} of annotation arguments * @throws {@code NullPointerException} if any of the parameters is {@code null} * @throws {@code IllegalArgumentException} if the parameter type is not fully qualified * name of valid annotation * @return immutable model of {@code Annotation} */ - public static Annotation create(String type, List arguments) { + public static Annotation create(String type, Map arguments) { Parameters.notNull("type", type); //NOI18N Parameters.notNull("arguments", arguments); //NOI18N - return new MethodModel.Annotation(type, arguments); + return new MethodModel.Annotation(type, new HashMap(arguments)); } // @@ -287,13 +289,13 @@ return type; } - public List getArguments() { + public Map getArguments() { return arguments; } // } - + // /** diff --git a/j2ee.common/src/org/netbeans/modules/j2ee/common/method/MethodModelSupport.java b/j2ee.common/src/org/netbeans/modules/j2ee/common/method/MethodModelSupport.java --- a/j2ee.common/src/org/netbeans/modules/j2ee/common/method/MethodModelSupport.java +++ b/j2ee.common/src/org/netbeans/modules/j2ee/common/method/MethodModelSupport.java @@ -46,6 +46,7 @@ import com.sun.source.tree.AnnotationTree; import com.sun.source.tree.BlockTree; +import java.util.Map; import javax.lang.model.type.ArrayType; import org.netbeans.api.java.source.CompilationController; import com.sun.source.tree.ExpressionTree; @@ -236,7 +237,13 @@ if (annotation.getArguments() == null) { annotationTree = genUtils.createAnnotation(annotation.getType()); } else { - annotationTree = genUtils.createAnnotation(annotation.getType(), annotation.getArguments()); + List annotationArgs = new ArrayList(); + Iterator it = annotation.getArguments().entrySet().iterator(); + while (it.hasNext()) { + Map.Entry pairs = (Map.Entry)it.next(); + annotationArgs.add(genUtils.createAnnotationArgument((String) pairs.getKey(),pairs.getValue())); + } + annotationTree = genUtils.createAnnotation(annotation.getType(), annotationArgs); } annotationList.add(annotationTree); } diff --git a/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/action/AbstractMethodGenerator.java b/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/action/AbstractMethodGenerator.java --- a/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/action/AbstractMethodGenerator.java +++ b/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/action/AbstractMethodGenerator.java @@ -47,8 +47,12 @@ import com.sun.source.tree.ClassTree; import com.sun.source.tree.MethodTree; import java.io.IOException; +import java.util.Collections; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.Future; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.lang.model.element.ElementKind; import javax.lang.model.element.Modifier; import javax.lang.model.element.TypeElement; @@ -128,7 +132,7 @@ * Returns map of EJB interface class names, where keys are appropriate constants from {@link EntityAndSession} */ protected Map getInterfaces() throws IOException { - return ejbModule.getMetadataModel().runReadAction(new MetadataModelAction>() { + Future futureResult = ejbModule.getMetadataModel().runReadActionWhenReady(new MetadataModelAction>() { public Map run(EjbJarMetadata metadata) throws Exception { EntityAndSession ejb = (EntityAndSession) metadata.findByEjbClass(ejbClass); Map result = new HashMap(); @@ -141,6 +145,12 @@ return result; } }); + try { + return (Map) futureResult.get(); + } catch (Exception ex) { + Logger.getLogger(AbstractMethodGenerator.class.getName()).log(Level.WARNING, null, ex); + return Collections.emptyMap(); + } } private static String findCommonInterface(final String className1, final String className2) throws IOException { diff --git a/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/action/BusinessMethodGenerator.java b/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/action/BusinessMethodGenerator.java --- a/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/action/BusinessMethodGenerator.java +++ b/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/action/BusinessMethodGenerator.java @@ -144,13 +144,16 @@ addMethodToInterface(methodModelCopy, remote); } - // ejb class, add 'public' modifier, 'Override' annotation if required - List annotations; + // ejb class + // add all specified annothations and join Override if has local, remote interfaces + List annotations = new ArrayList(); + if (!methodModel.getAnnotations().isEmpty()) { + annotations.addAll(methodModel.getAnnotations()); + } if ((generateLocal && local != null) || (generateRemote && remote != null)) { - annotations = Collections.singletonList(MethodModel.Annotation.create("java.lang.Override")); //NOI18N - } else { - annotations = Collections.emptyList(); + annotations.add(MethodModel.Annotation.create("java.lang.Override")); //NOI18N } + // add 'public' modifier MethodModel methodModelCopy = MethodModel.create( methodModel.getName(), methodModel.getReturnType(), diff --git a/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/api/codegeneration/SessionGenerator.java b/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/api/codegeneration/SessionGenerator.java --- a/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/api/codegeneration/SessionGenerator.java +++ b/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/api/codegeneration/SessionGenerator.java @@ -44,12 +44,17 @@ package org.netbeans.modules.j2ee.ejbcore.api.codegeneration; +import java.util.List; +import org.netbeans.modules.j2ee.common.method.MethodModel.Annotation; import org.netbeans.modules.j2ee.core.api.support.java.GenerationUtils; import org.netbeans.modules.j2ee.ejbcore.EjbGenerationUtil; import java.io.IOException; +import java.util.Collections; import java.util.HashMap; import java.util.Map; +import java.util.logging.Level; import java.util.logging.Logger; +import javax.lang.model.element.Modifier; import org.netbeans.api.java.classpath.ClassPath; import org.netbeans.api.java.project.JavaProjectConstants; import org.netbeans.api.java.project.classpath.ProjectClassPathModifier; @@ -63,8 +68,11 @@ import org.netbeans.api.project.libraries.Library; import org.netbeans.api.project.libraries.LibraryManager; import org.netbeans.modules.j2ee.common.J2eeProjectCapabilities; +import org.netbeans.modules.j2ee.common.method.MethodModel; import org.netbeans.modules.j2ee.dd.api.ejb.AssemblyDescriptor; import org.netbeans.modules.j2ee.dd.api.ejb.ContainerTransaction; +import org.netbeans.modules.j2ee.ejbcore.action.BusinessMethodGenerator; +import org.netbeans.modules.j2ee.ejbcore.ejb.wizard.session.TimerOptions; import org.netbeans.modules.j2ee.ejbcore.naming.EJBNameOptions; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; @@ -103,6 +111,7 @@ private final boolean isSimplified; // private final boolean hasBusinessInterface; private final boolean isXmlBased; + private final TimerOptions timerOptions; // EJB naming options private final EJBNameOptions ejbNameOptions; @@ -119,13 +128,13 @@ private final Map templateParameters; - public static SessionGenerator create(String wizardTargetName, FileObject pkg, boolean hasRemote, boolean hasLocal, - String sessionType, boolean isSimplified, boolean hasBusinessInterface, boolean isXmlBased) { - return new SessionGenerator(wizardTargetName, pkg, hasRemote, hasLocal, sessionType, isSimplified, hasBusinessInterface, isXmlBased, false); - } + public static SessionGenerator create(String wizardTargetName, FileObject pkg, boolean hasRemote, boolean hasLocal, + String sessionType, boolean isSimplified, boolean hasBusinessInterface, boolean isXmlBased, TimerOptions timerOptions) { + return new SessionGenerator(wizardTargetName, pkg, hasRemote, hasLocal, sessionType, isSimplified, hasBusinessInterface, isXmlBased, timerOptions, false); + } protected SessionGenerator(String wizardTargetName, FileObject pkg, boolean hasRemote, boolean hasLocal, - String sessionType, boolean isSimplified, boolean hasBusinessInterface, boolean isXmlBased, boolean isTest) { + String sessionType, boolean isSimplified, boolean hasBusinessInterface, boolean isXmlBased, TimerOptions timerOptions, boolean isTest) { this.pkg = pkg; this.remotePkg = pkg; this.hasRemote = hasRemote; @@ -149,6 +158,8 @@ this.templateParameters.put("package", packageName); this.templateParameters.put("localInterface", packageNameWithDot + localName); this.templateParameters.put("remoteInterface", packageNameWithDot + remoteName); + // set timer options if available + this.timerOptions = timerOptions; if (isTest) { // set date, time and user to values used in goldenfiles this.templateParameters.put("date", "{date}"); @@ -260,6 +271,12 @@ if (hasLocal) { GenerationUtils.createClass(EJB30_LOCAL, pkg, localName, null, templateParameters); } + + // fill up the session bean with the timer method if needed + if (timerOptions != null) { + generateTimerMethodForBean(ejbClassFO, "myTimer", timerOptions); + } + return ejbClassFO; } @@ -318,6 +335,27 @@ private void generateEJB30Xml() throws IOException { throw new UnsupportedOperationException("Method not implemented yet."); } + + private void generateTimerMethodForBean(FileObject bean, String methodName, TimerOptions timerOptions) { + try { + MethodModel.Annotation annotation = MethodModel.Annotation.create( + "javax.ejb.Schedule", timerOptions.getTimerOptionsAsMap()); // NOI18N + MethodModel method = MethodModel.create( + methodName, + "void", // NOI18N + "System.out.println(\"Timer event: \" + new java.util.Date());", // NOI18N + Collections.emptyList(), + Collections.emptyList(), + Collections.emptySet(), + Collections.singletonList(annotation) + ); + + BusinessMethodGenerator generator = BusinessMethodGenerator.create(packageNameWithDot + ejbClassName, bean); + generator.generate(method, hasLocal, hasRemote); + } catch (IOException ex) { + Logger.getLogger(SessionGenerator.class.getName()).log(Level.SEVERE, null, ex); + } + } //TODO: RETOUCHE WS // /** diff --git a/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ejb/wizard/session/Bundle.properties b/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ejb/wizard/session/Bundle.properties --- a/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ejb/wizard/session/Bundle.properties +++ b/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ejb/wizard/session/Bundle.properties @@ -56,6 +56,7 @@ # wizard templates Templates/J2EE/Session=Session Bean +Templates/J2EE/TimerSession=Timer Session Bean LBL_Remote=Remote @@ -70,6 +71,7 @@ LBL_Singleton=Singleton LBL_SessionEJBWizardTitle=Session Bean +LBL_TimerSessionEJBWizardTitle=Timer Session Bean LBL_Interface=Create Interface\: LBL_EJB_Name=EJB Name: @@ -95,3 +97,18 @@ ERR_NoRemoteInterfaceProjectMaven=There is no suitable project available into which \ Remote interface could be stored. An open Maven based Java Class Library project is required. LBL_In_Project=Remote in project: +LBL_Schedule=Method schedule: +LBL_ScheduleSecondLabel=second +LBL_ScheduleMinuteLabel=minute +LBL_ScheduleHourLabel=hour +LBL_ScheduleMonthLabel=month +LBL_ScheduleYearLabel=year +LBL_ScheduleDayOfWeekLabel=dayOfWeek +LBL_ScheduleDayOfMonthLabel=dayOfMonth +MN_ScheduleSecond=e +MN_ScheduleMinute=m +MN_ScheduleHour=u +MN_ScheduleMonth=t +MN_ScheduleYear=y +MN_ScheduleDayOfWeek=w +MN_ScheduleDayOfMonth=d diff --git a/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ejb/wizard/session/SessionEJBWizard.java b/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ejb/wizard/session/SessionEJBWizard.java --- a/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ejb/wizard/session/SessionEJBWizard.java +++ b/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ejb/wizard/session/SessionEJBWizard.java @@ -58,7 +58,6 @@ import org.openide.filesystems.FileObject; import org.netbeans.modules.j2ee.core.api.support.SourceGroups; import org.netbeans.modules.j2ee.core.api.support.wizard.Wizards; -import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; import org.netbeans.modules.j2ee.ejbcore.ejb.wizard.MultiTargetChooserPanel; import org.openide.WizardDescriptor; import org.openide.util.Exceptions; @@ -69,20 +68,30 @@ * @author Chris Webster * @author Martin Adamek */ -public final class SessionEJBWizard implements WizardDescriptor.InstantiatingIterator{ +public final class SessionEJBWizard implements WizardDescriptor.AsynchronousInstantiatingIterator { private WizardDescriptor.Panel[] panels; private int index = 0; private SessionEJBWizardDescriptor ejbPanel; private WizardDescriptor wiz; + private TimerOptions timerOptions; + private String resourceWizardName; - public static SessionEJBWizard create () { - return new SessionEJBWizard (); + public SessionEJBWizard(String resourceWizardName, TimerOptions timerOptions) { + this.resourceWizardName = resourceWizardName; + this.timerOptions = timerOptions; } - public String name () { - return NbBundle.getMessage (SessionEJBWizard.class, - "LBL_SessionEJBWizardTitle"); + public static SessionEJBWizard createSession() { + return new SessionEJBWizard("LBL_SessionEJBWizardTitle", null); //NOI18N + } + + public static SessionEJBWizard createTimerSession() { + return new SessionEJBWizard("LBL_TimerSessionEJBWizardTitle", new TimerOptions()); //NOI18N + } + + public String name() { + return NbBundle.getMessage (SessionEJBWizard.class, resourceWizardName); } public void uninitialize(WizardDescriptor wiz) { @@ -92,7 +101,7 @@ wiz = wizardDescriptor; Project project = Templates.getProject(wiz); SourceGroup[] sourceGroups = SourceGroups.getJavaSourceGroups(project); - ejbPanel = new SessionEJBWizardDescriptor(project); + ejbPanel = new SessionEJBWizardDescriptor(project, timerOptions); WizardDescriptor.Panel wizardDescriptorPanel = new MultiTargetChooserPanel(project, sourceGroups, ejbPanel, true); panels = new WizardDescriptor.Panel[] {wizardDescriptorPanel}; @@ -113,7 +122,8 @@ ejbPanel.getSessionType(), isSimplified, true, // TODO: UI - add checkbox for creation of business interface - !isSimplified // TODO: UI - add checkbox for option XML (not annotation) usage + !isSimplified, // TODO: UI - add checkbox for option XML (not annotation) usage + ejbPanel.getTimerOptions() ); FileObject result = null; try { diff --git a/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ejb/wizard/session/SessionEJBWizardDescriptor.java b/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ejb/wizard/session/SessionEJBWizardDescriptor.java --- a/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ejb/wizard/session/SessionEJBWizardDescriptor.java +++ b/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ejb/wizard/session/SessionEJBWizardDescriptor.java @@ -65,6 +65,7 @@ private SessionEJBWizardPanel wizardPanel; private final EJBNameOptions ejbNames; private final Project project; + private final TimerOptions timerOptions; //TODO: RETOUCHE // private boolean isWaitingForScan = false; @@ -72,8 +73,9 @@ private WizardDescriptor wizardDescriptor; - public SessionEJBWizardDescriptor(Project project) { + public SessionEJBWizardDescriptor(Project project, TimerOptions timerOptions) { this.ejbNames = new EJBNameOptions(); + this.timerOptions = timerOptions; this.project = project; } @@ -83,7 +85,7 @@ public java.awt.Component getComponent() { if (wizardPanel == null) { - wizardPanel = new SessionEJBWizardPanel(project, this); + wizardPanel = new SessionEJBWizardPanel(project, this, timerOptions); // add listener to events which could cause valid status to change } return wizardPanel; @@ -191,6 +193,10 @@ public String getSessionType() { return wizardPanel.getSessionType(); } + + public TimerOptions getTimerOptions() { + return wizardPanel.getTimerOptions(); + } public boolean isFinishPanel() { return isValid(); diff --git a/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ejb/wizard/session/SessionEJBWizardPanel.form b/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ejb/wizard/session/SessionEJBWizardPanel.form --- a/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ejb/wizard/session/SessionEJBWizardPanel.form +++ b/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ejb/wizard/session/SessionEJBWizardPanel.form @@ -20,44 +20,36 @@ + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + - + @@ -67,13 +59,18 @@ - - - - - - + + + + + + + + + + + @@ -202,5 +199,223 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ejb/wizard/session/SessionEJBWizardPanel.java b/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ejb/wizard/session/SessionEJBWizardPanel.java --- a/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ejb/wizard/session/SessionEJBWizardPanel.java +++ b/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ejb/wizard/session/SessionEJBWizardPanel.java @@ -78,12 +78,14 @@ private final ChangeListener listener; private final Project project; private ComboBoxModel projectsList; + private final TimerOptions timerOptions; /** Creates new form SingleEJBWizardPanel */ - public SessionEJBWizardPanel(Project project, ChangeListener changeListener) { + public SessionEJBWizardPanel(Project project, ChangeListener changeListener, TimerOptions timerOptions) { this.listener = changeListener; this.project = project; + this.timerOptions = timerOptions; initComponents(); J2eeProjectCapabilities projectCap = J2eeProjectCapabilities.forProject(project); @@ -93,7 +95,19 @@ remoteCheckBox.setVisible(false); remoteCheckBox.setEnabled(false); } + // enable Schedule section if Timer Session EJB, disable otherwise + if (this.timerOptions == null) { + schedulePanel.setVisible(false); + schedulePanel.setEnabled(false); + } else { + statefulButton.setEnabled(false); + statefulButton.setVisible(false); + } } else { + // hide whole Schedule section + schedulePanel.setVisible(false); + schedulePanel.setEnabled(false); + // hide singleton radio button singletonButton.setVisible(false); singletonButton.setEnabled(false); localCheckBox.setSelected(true); @@ -199,6 +213,22 @@ localCheckBox = new javax.swing.JCheckBox(); singletonButton = new javax.swing.JRadioButton(); inProjectCombo = new javax.swing.JComboBox(); + schedulePanel = new javax.swing.JPanel(); + scheduleLabel = new javax.swing.JLabel(); + scheduleSecondLabel = new javax.swing.JLabel(); + scheduleSecondTextField = new javax.swing.JTextField(); + scheduleMinuteLabel = new javax.swing.JLabel(); + scheduleMinuteTextField = new javax.swing.JTextField(); + scheduleHourLabel = new javax.swing.JLabel(); + scheduleHourTextField = new javax.swing.JTextField(); + scheduleMonthLabel = new javax.swing.JLabel(); + scheduleMonthTextField = new javax.swing.JTextField(); + scheduleYearLabel = new javax.swing.JLabel(); + scheduleYearTextField = new javax.swing.JTextField(); + scheduleDayOfWeekLabel = new javax.swing.JLabel(); + scheduleDayOfWeekTextField = new javax.swing.JTextField(); + scheduleDayOfMonthLabel = new javax.swing.JLabel(); + scheduleDayOfMonthTextField = new javax.swing.JTextField(); org.openide.awt.Mnemonics.setLocalizedText(sessionTypeLabel, org.openide.util.NbBundle.getMessage(SessionEJBWizardPanel.class, "LBL_SessionType")); // NOI18N @@ -223,33 +253,137 @@ singletonButton.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ejbcore/ejb/wizard/session/Bundle").getString("MN_Singleton").charAt(0)); singletonButton.setText(org.openide.util.NbBundle.getMessage(SessionEJBWizardPanel.class, "LBL_Singleton")); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(scheduleLabel, org.openide.util.NbBundle.getMessage(SessionEJBWizardPanel.class, "LBL_Schedule")); // NOI18N + + scheduleSecondLabel.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ejbcore/ejb/wizard/session/Bundle").getString("MN_ScheduleSecond").charAt(0)); + scheduleSecondLabel.setLabelFor(scheduleSecondTextField); + org.openide.awt.Mnemonics.setLocalizedText(scheduleSecondLabel, org.openide.util.NbBundle.getMessage(SessionEJBWizardPanel.class, "LBL_ScheduleSecondLabel")); // NOI18N + + scheduleSecondTextField.setText("0"); // NOI18N + + scheduleMinuteLabel.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ejbcore/ejb/wizard/session/Bundle").getString("MN_ScheduleMinute").charAt(0)); + scheduleMinuteLabel.setLabelFor(scheduleMinuteTextField); + org.openide.awt.Mnemonics.setLocalizedText(scheduleMinuteLabel, org.openide.util.NbBundle.getMessage(SessionEJBWizardPanel.class, "LBL_ScheduleMinuteLabel")); // NOI18N + + scheduleMinuteTextField.setText("*"); // NOI18N + + scheduleHourLabel.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ejbcore/ejb/wizard/session/Bundle").getString("MN_ScheduleHour").charAt(0)); + scheduleHourLabel.setLabelFor(scheduleHourTextField); + org.openide.awt.Mnemonics.setLocalizedText(scheduleHourLabel, org.openide.util.NbBundle.getMessage(SessionEJBWizardPanel.class, "LBL_ScheduleHourLabel")); // NOI18N + + scheduleHourTextField.setText("9-17"); // NOI18N + + scheduleMonthLabel.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ejbcore/ejb/wizard/session/Bundle").getString("MN_ScheduleMonth").charAt(0)); + scheduleMonthLabel.setLabelFor(scheduleMonthTextField); + org.openide.awt.Mnemonics.setLocalizedText(scheduleMonthLabel, org.openide.util.NbBundle.getMessage(SessionEJBWizardPanel.class, "LBL_ScheduleMonthLabel")); // NOI18N + + scheduleMonthTextField.setText("*"); // NOI18N + + scheduleYearLabel.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ejbcore/ejb/wizard/session/Bundle").getString("MN_ScheduleYear").charAt(0)); + scheduleYearLabel.setLabelFor(scheduleYearTextField); + org.openide.awt.Mnemonics.setLocalizedText(scheduleYearLabel, org.openide.util.NbBundle.getMessage(SessionEJBWizardPanel.class, "LBL_ScheduleYearLabel")); // NOI18N + + scheduleYearTextField.setText("*"); // NOI18N + + scheduleDayOfWeekLabel.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ejbcore/ejb/wizard/session/Bundle").getString("MN_ScheduleDayOfWeek").charAt(0)); + scheduleDayOfWeekLabel.setLabelFor(scheduleDayOfWeekTextField); + org.openide.awt.Mnemonics.setLocalizedText(scheduleDayOfWeekLabel, org.openide.util.NbBundle.getMessage(SessionEJBWizardPanel.class, "LBL_ScheduleDayOfWeekLabel")); // NOI18N + + scheduleDayOfWeekTextField.setText("Mon-Fri"); // NOI18N + + scheduleDayOfMonthLabel.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ejbcore/ejb/wizard/session/Bundle").getString("MN_ScheduleDayOfMonth").charAt(0)); + scheduleDayOfMonthLabel.setLabelFor(scheduleDayOfMonthTextField); + org.openide.awt.Mnemonics.setLocalizedText(scheduleDayOfMonthLabel, org.openide.util.NbBundle.getMessage(SessionEJBWizardPanel.class, "LBL_ScheduleDayOfMonthLabel")); // NOI18N + + scheduleDayOfMonthTextField.setText("*"); // NOI18N + + org.jdesktop.layout.GroupLayout schedulePanelLayout = new org.jdesktop.layout.GroupLayout(schedulePanel); + schedulePanel.setLayout(schedulePanelLayout); + schedulePanelLayout.setHorizontalGroup( + schedulePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(schedulePanelLayout.createSequentialGroup() + .add(schedulePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(scheduleLabel) + .add(schedulePanelLayout.createSequentialGroup() + .addContainerGap() + .add(schedulePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(scheduleSecondLabel) + .add(schedulePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false) + .add(org.jdesktop.layout.GroupLayout.LEADING, schedulePanelLayout.createSequentialGroup() + .add(scheduleHourLabel) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .add(scheduleHourTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 70, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .add(org.jdesktop.layout.GroupLayout.LEADING, schedulePanelLayout.createSequentialGroup() + .add(scheduleMinuteLabel) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(schedulePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(scheduleSecondTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 70, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(scheduleMinuteTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 70, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))) + .add(18, 18, 18) + .add(schedulePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(scheduleMonthLabel) + .add(scheduleYearLabel) + .add(scheduleDayOfWeekLabel) + .add(scheduleDayOfMonthLabel)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(schedulePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(scheduleYearTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 70, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(scheduleDayOfWeekTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 70, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(scheduleDayOfMonthTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 70, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(scheduleMonthTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 70, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))) + .addContainerGap(12, Short.MAX_VALUE)) + ); + schedulePanelLayout.setVerticalGroup( + schedulePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(schedulePanelLayout.createSequentialGroup() + .add(scheduleLabel) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(schedulePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(scheduleSecondLabel) + .add(scheduleSecondTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(scheduleMonthLabel) + .add(scheduleMonthTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(schedulePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(scheduleMinuteLabel) + .add(scheduleMinuteTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(scheduleYearLabel) + .add(scheduleYearTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(schedulePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(scheduleHourLabel) + .add(scheduleHourTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(scheduleDayOfWeekLabel) + .add(scheduleDayOfWeekTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(schedulePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(scheduleDayOfMonthLabel) + .add(scheduleDayOfMonthTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))) + ); + org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(sessionTypeLabel) .add(layout.createSequentialGroup() + .addContainerGap() + .add(statelessButton)) + .add(layout.createSequentialGroup() + .addContainerGap() + .add(statefulButton)) + .add(layout.createSequentialGroup() + .addContainerGap() + .add(singletonButton)) + .add(interfaceLabel) + .add(schedulePanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .add(layout.createSequentialGroup() + .addContainerGap() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) - .add(sessionTypeLabel) - .add(layout.createSequentialGroup() - .addContainerGap() - .add(statelessButton)) - .add(layout.createSequentialGroup() - .addContainerGap() - .add(statefulButton)) - .add(layout.createSequentialGroup() - .addContainerGap() - .add(singletonButton)) - .add(interfaceLabel) - .add(layout.createSequentialGroup() - .addContainerGap() - .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) - .add(layout.createSequentialGroup() - .add(remoteCheckBox) - .add(6, 6, 6) - .add(inProjectCombo, 0, 129, Short.MAX_VALUE)) - .add(layout.createSequentialGroup() - .add(localCheckBox) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 152, Short.MAX_VALUE))))) + .add(remoteCheckBox) + .add(localCheckBox)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(inProjectCombo, 0, 232, Short.MAX_VALUE) .addContainerGap()) ); layout.setVerticalGroup( @@ -264,12 +398,16 @@ .add(singletonButton) .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) .add(interfaceLabel) - .add(0, 0, 0) - .add(localCheckBox) - .add(0, 0, 0) - .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) - .add(remoteCheckBox) - .add(inProjectCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) + .add(layout.createSequentialGroup() + .add(localCheckBox) + .add(2, 2, 2) + .add(remoteCheckBox)) + .add(inProjectCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 28, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .add(24, 24, 24) + .add(schedulePanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addContainerGap()) ); java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ejbcore/ejb/wizard/session/Bundle"); // NOI18N @@ -289,6 +427,22 @@ private javax.swing.JLabel interfaceLabel; private javax.swing.JCheckBox localCheckBox; private javax.swing.JCheckBox remoteCheckBox; + private javax.swing.JLabel scheduleDayOfMonthLabel; + private javax.swing.JTextField scheduleDayOfMonthTextField; + private javax.swing.JLabel scheduleDayOfWeekLabel; + private javax.swing.JTextField scheduleDayOfWeekTextField; + private javax.swing.JLabel scheduleHourLabel; + private javax.swing.JTextField scheduleHourTextField; + private javax.swing.JLabel scheduleLabel; + private javax.swing.JLabel scheduleMinuteLabel; + private javax.swing.JTextField scheduleMinuteTextField; + private javax.swing.JLabel scheduleMonthLabel; + private javax.swing.JTextField scheduleMonthTextField; + private javax.swing.JPanel schedulePanel; + private javax.swing.JLabel scheduleSecondLabel; + private javax.swing.JTextField scheduleSecondTextField; + private javax.swing.JLabel scheduleYearLabel; + private javax.swing.JTextField scheduleYearTextField; private javax.swing.ButtonGroup sessionStateButtons; private javax.swing.JLabel sessionTypeLabel; private javax.swing.JRadioButton singletonButton; @@ -316,6 +470,22 @@ return localCheckBox.isSelected(); } + public TimerOptions getTimerOptions() { + if (timerOptions == null) { + return null; + } else { + timerOptions.setTimerOptions( + scheduleSecondTextField.getText(), + scheduleMinuteTextField.getText(), + scheduleHourTextField.getText(), + scheduleMonthTextField.getText(), + scheduleYearTextField.getText(), + scheduleDayOfWeekTextField.getText(), + scheduleDayOfMonthTextField.getText()); + return timerOptions; + } + } + public Project getRemoteInterfaceProject() { if (projectsList == null) { return null; diff --git a/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ejb/wizard/session/TimerOptions.java b/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ejb/wizard/session/TimerOptions.java new file mode 100644 --- /dev/null +++ b/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ejb/wizard/session/TimerOptions.java @@ -0,0 +1,86 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2011 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2011 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.j2ee.ejbcore.ejb.wizard.session; + +import java.util.HashMap; +import java.util.Map; + +/** + * Class which is holding information for creation of {@code @Schedule} annotation + * + * @author Martin Fousek + */ +public final class TimerOptions { + + private Map timerOptions = new HashMap(); + + /** + * Get {@code Map} with entries of {@code @Schedule} annotation + * @return {@code Map} of entries + */ + public Map getTimerOptionsAsMap() { + return timerOptions; + } + + /** + * Set values into {@code Map} of {@code @Schedule} annotation entries + * @param second see cron syntax for details + * @param minute see cron syntax for details + * @param hour see cron syntax for details + * @param month see cron syntax for details + * @param year see cron syntax for details + * @param dayOfWeek see cron syntax for details + * @param dayOfMonth see cron syntax for details + */ + public void setTimerOptions(String second, String minute, String hour, String month, + String year, String dayOfWeek, String dayOfMonth) { + timerOptions.put("second", second); + timerOptions.put("minute", minute); + timerOptions.put("hour", hour); + timerOptions.put("dayOfMonth", dayOfMonth); + timerOptions.put("month", month); + timerOptions.put("dayOfWeek", dayOfWeek); + timerOptions.put("year", year); + } + +} diff --git a/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/resources/TimerSessionEJB.html b/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/resources/TimerSessionEJB.html new file mode 100644 --- /dev/null +++ b/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/resources/TimerSessionEJB.html @@ -0,0 +1,51 @@ + + + + + + + +Creates a example of Session Enterprise JavaBean (EJB) component with used +Schedule annotation at sample method. This template creates the Java classes +for a single session bean and registers the bean in the EJB module's DD. + diff --git a/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/resources/layer.xml b/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/resources/layer.xml --- a/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/resources/layer.xml +++ b/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/resources/layer.xml @@ -270,13 +270,23 @@ - + + + + + + + + + + +