Skip to content

Commit

Permalink
Updated Logger.critical
Browse files Browse the repository at this point in the history
As explained in my last comment on Issue #9, I have updated the `Logger.critical` method to include the list of installed modules in the error log.

I also added a `manifest.xml` file to the default package of all modules except for `com_pekinsoft_northwind`, as it only contains the `Startup` class.

Also, @jkovalsy, there is a logical issue with the following code:

```java
        // Let's customize the main menu bar by loaded modules
        while (modules.hasNext()) {
            Module module = modules.next();
            MenuProvider menuProvider = (MenuProvider) module.getInstanceOf("com.pekinsoft.northwind.basic.MenuProvider");
            jMenuBar1.add(menuProvider.getMenu(this.MainDesktop));
        }
```

The problem is that, with the other modules in the `${HOME}/.northwind/modules` folder, `NullPointerException`s are thrown if the module does not contain a `menuProvider` object. Since that is your block of code, I thought that I would let you know this and, perhaps, you can add a check for the `menuProvider` within this block.

I am calling it a night. Tomorrow, I will move the `Module` and `ModulesManager` classes back to the `com_pekinsoft_northwind_basic` module, and remove the `com_pekinsoft_northwind_basic_modules` module.
  • Loading branch information
SeanCarrick committed Mar 22, 2020
1 parent 7e39ed4 commit a01a3c7
Show file tree
Hide file tree
Showing 17 changed files with 240 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

package com.pekinsoft.northwind;

import com.pekinsoft.northwind.basic.ModulesManager;
import com.pekinsoft.northwind.basic.modules.ModulesManager;
import com.pekinsoft.northwind.accounting.exceptions.InvalidAccountingDataException;
import com.pekinsoft.northwind.accounting.Math;
import com.pekinsoft.northwind.basic.Application;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
module com_pekinsoft_northwind {
requires com_pekinsoft_northwind_accounting;
requires com_pekinsoft_northwind_basic;
requires com_pekinsoft_northwind_basic_modules;
requires com_pekinsoft_northwind_desktop;
requires com_pekinsoft_northwind_utils;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/**
* Dialog displaying basic information about the Northwind Traders application
*
* @author Jiří Kovalský
* @author Jiří Kovalský <jiri dot kovalsky at centrum dot cz>
*/
public class AboutDialog extends javax.swing.JInternalFrame {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
/**
* Class providing menu for the About module.
*
* @author Jiří Kovalský
* @author Jiří Kovalský <jiri dot kovalsky at centrum dot cz>
*/
public class AboutMenu implements MenuProvider {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2020 Jiří Kovalský
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->

<module>
<name>Accounting</name>
<version>0.1</version>
<masterClass>com.pekinsoft.northwind.accounting.Math</masterClass>
</module>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2020 Jiří Kovalský
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->

<module>
<name>Basic</name>
<version>0.1</version>
<masterClass>com.pekinsoft.northwind.basic.Application</masterClass>
</module>
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
* WHEN BY REASON
* ------------ ------------------- ------------------------------------------
* Mar 8, 2020 Sean Carrick Initial creation.
* Mar 21, 2020 Jiří Kovalský Added the `Module` and `ModuleManager`
* classes.
* *****************************************************************************
*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pekinsoft.northwind.basic;
package com.pekinsoft.northwind.basic.modules;

import com.pekinsoft.northwind.basic.Application;
import java.io.File;
import java.io.InputStream;
import java.lang.reflect.Constructor;
Expand All @@ -30,7 +31,7 @@
/**
* Class representing an additional Northwind Traders module.
*
* @author Jiří Kovalský
* @author Jiří Kovalský &lt;jiri dot kovalsky at centrum dot cz&gt;
*/
public class Module {

Expand Down Expand Up @@ -117,4 +118,14 @@ public Object getInstanceOf(String interfaceName) {
}
return null;
}

/**
* Provides a {@code String} representation of the class.
*
* @return
*/
@Override
public String toString() {
return this.name + "[ v. " + version + " ]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pekinsoft.northwind.basic;
package com.pekinsoft.northwind.basic.modules;

import com.pekinsoft.northwind.basic.Application;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;

/**
* Singleton for managing repository of additional Northwind Traders modules
*
* @author Jiří Kovalský
* @author Jiří Kovalský &lt;jiri dot kovalsky at centrum dot cz&gt;
*/
public class ModulesManager {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2020 Jiří Kovalský
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->

<module>
<name>Basic.Modules</name>
<version>0.1</version>
<masterClass>com.pekinsoft.northwind.basic.modules.ModulesManager</masterClass>
</module>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (C) 2020 PekinSOFT Systems
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* *****************************************************************************
* *****************************************************************************
* Project : Northwind-Basic
* Class : module-info.java
* Author : Sean Carrick
* Created : Mar 21, 2020 @ 8:43:45 PM
* Modified : Mar 21, 2020
*
* Purpose:
*
* Revision History:
*
* WHEN BY REASON
* ------------ ------------------- ------------------------------------------
* Mar 21, 2020 Sean Carrick Initial creation.
* *****************************************************************************
*/

module com_pekinsoft_northwind_basic_modules {
requires java.xml;
requires com_pekinsoft_northwind_basic;

exports com.pekinsoft.northwind.basic.modules;
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@

import com.pekinsoft.northwind.basic.Application;
import com.pekinsoft.northwind.basic.MenuProvider;
import com.pekinsoft.northwind.basic.ModulesManager;
import com.pekinsoft.northwind.basic.Module;
import com.pekinsoft.northwind.basic.modules.ModulesManager;
import com.pekinsoft.northwind.basic.modules.Module;
import com.pekinsoft.northwind.utils.Utils;
import com.pekinsoft.northwind.utils.enums.SysExits;
import java.awt.Toolkit;
import java.util.ArrayList;
import java.util.Iterator;
import javax.swing.JMenu;

/**
*
Expand Down Expand Up @@ -90,7 +90,7 @@ public MainFrame() {
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

StatusBar = new javax.swing.JToolBar();
Expand Down Expand Up @@ -274,7 +274,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
pack();
}// </editor-fold>

private void ExitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
private void ExitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
Application.log.enter(MainFrame.class.getName(), "ExitMenuItemAction"
+ "Performed", evt);
Application.log.debug("Setting the MainFrame to no longer being "
Expand All @@ -284,19 +284,19 @@ private void ExitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
Application.log.exit(MainFrame.class.getName(), "ExitMenuItemAction"
+ "Performed");
Application.exit(SysExits.EX_OK);
}
}

private void ExitMenuItemMouseEntered(java.awt.event.MouseEvent evt) {
private void ExitMenuItemMouseEntered(java.awt.event.MouseEvent evt) {
StatusLabel.setText("<html>Click this menu item to exit Northwind "
+ "Traders. <strong>Alternatively, press Alt+F4 on your "
+ "keyboard.");
}
}

private void ExitMenuItemMouseExited(java.awt.event.MouseEvent evt) {
private void ExitMenuItemMouseExited(java.awt.event.MouseEvent evt) {
StatusLabel.setText("<html>Watch here for helpful tips...");
}
}

private void NewCustomerMenuItem_Clicked(java.awt.event.ActionEvent evt) {
private void NewCustomerMenuItem_Clicked(java.awt.event.ActionEvent evt) {
Application.log.enter(MainFrame.class.getName(), "NewCustomerMenuItem"
+ "_Clicked", evt);
Application.log.debug("Creating an instance of the CustomerEntryDialog...");
Expand All @@ -310,9 +310,9 @@ private void NewCustomerMenuItem_Clicked(java.awt.event.ActionEvent evt) {
dlg.setVisible(true);
Application.log.exit(MainFrame.class.getName(), "NewCustomerMenuItem"
+ "_Clicked");
}
}

private void NewLoadMenuItem_Clicked(java.awt.event.ActionEvent evt) {
private void NewLoadMenuItem_Clicked(java.awt.event.ActionEvent evt) {
Application.log.enter(MainFrame.class.getName(), "NewLoadMenuItem"
+ "_Clicked", evt);
Application.log.debug("Creating an instance of the LoadEntryDialog...");
Expand All @@ -325,7 +325,7 @@ private void NewLoadMenuItem_Clicked(java.awt.event.ActionEvent evt) {
dlg.setLocation(Utils.getCenterPoint(this.MainDesktop.getSize(), dlg.getSize()));
dlg.setVisible(true);
Application.log.exit(MainFrame.class.getName(), "NewLoadMenuItem_Clicked");
}
}

/**
* @param args the command line arguments
Expand Down Expand Up @@ -365,12 +365,22 @@ public void run() {
MainFrame mainFrame = new MainFrame();
mainFrame.setLocationRelativeTo(null);
mainFrame.setVisible(true);
}
ArrayList<String> modules = new ArrayList();
ModulesManager.getDefault().loadModules();

Iterator<Module> mods = ModulesManager.getDefault().getModules();
while (mods.hasNext() ) {
String e = mods.next().toString();
modules.add(e);
}
Application.log.critical(new Exception("Testing modules listing..."), "com.pekinsoft.northwind.desktop", MainFrame.class.getName(), "main", Application.EDITION, Application.MAJOR + "." + Application.MINOR + "." + Application.REVISION, Application.BUILD, modules.toArray());

}
});
Application.log.exit(MainFrame.class.getCanonicalName(), "main");
}

// Variables declaration - do not modify
// Variables declaration - do not modify
private javax.swing.JMenuItem ExitMenuItem;
private javax.swing.JLabel ExpensesPerMileLabel;
private javax.swing.JLabel ExpensesPerMilePrompt;
Expand Down Expand Up @@ -399,5 +409,5 @@ public void run() {
private javax.swing.JToolBar.Separator jSeparator5;
private javax.swing.JToolBar.Separator jSeparator6;
private javax.swing.JPopupMenu.Separator jSeparator7;
// End of variables declaration
// End of variables declaration
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2020 Jiří Kovalský
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->

<module>
<name>Desktop</name>
<version>0.1</version>
<masterClass>com.pekinsoft.northwind.desktop.MainFrame</masterClass>
</module>
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
requires java.desktop;
requires java.logging;
requires com_pekinsoft_northwind_basic;
requires com_pekinsoft_northwind_basic_modules;

exports com.pekinsoft.northwind.desktop;
}
Loading

0 comments on commit a01a3c7

Please sign in to comment.