/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.me.forms;
import com.holidaywebservice.holidayservice_v2.ArrayOfCountryCode;
import com.holidaywebservice.holidayservice_v2.ArrayOfHoliday;
import com.holidaywebservice.holidayservice_v2.ArrayOfHolidayCode;
import com.holidaywebservice.holidayservice_v2.Country;
import com.holidaywebservice.holidayservice_v2.HolidayCode;
import java.lang.reflect.Array;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Locale;
import javax.swing.JOptionPane;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
/**
* MainForm provides the interface and functionality for a GUI that allows a
* user to request holiday information from the HolidayService web service.
* @author krusniak
*/
public class MainForm extends javax.swing.JFrame {
/**
* Creates new form MainForm
*/
public MainForm() {
initComponents();
clear();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jCheckBox1 = new javax.swing.JCheckBox();
jLabel1 = new javax.swing.JLabel();
jButton2 = new javax.swing.JButton();
jButton1 = new javax.swing.JButton();
jCheckBox2 = new javax.swing.JCheckBox();
jTextField1 = new javax.swing.JTextField();
jCheckBox3 = new javax.swing.JCheckBox();
jTextField2 = new javax.swing.JTextField();
jTextField3 = new javax.swing.JTextField();
jTextField4 = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jCheckBox4 = new javax.swing.JCheckBox();
jLabel5 = new javax.swing.JLabel();
jTextField5 = new javax.swing.JTextField();
jLabel6 = new javax.swing.JLabel();
jTextField6 = new javax.swing.JTextField();
jLabel7 = new javax.swing.JLabel();
jTextField7 = new javax.swing.JTextField();
jCheckBox5 = new javax.swing.JCheckBox();
jLabel8 = new javax.swing.JLabel();
jTextField8 = new javax.swing.JTextField();
jLabel9 = new javax.swing.JLabel();
jTextField9 = new javax.swing.JTextField();
jCheckBox6 = new javax.swing.JCheckBox();
jLabel10 = new javax.swing.JLabel();
jTextField10 = new javax.swing.JTextField();
jLabel11 = new javax.swing.JLabel();
jTextField11 = new javax.swing.JTextField();
jLabel12 = new javax.swing.JLabel();
jTextField12 = new javax.swing.JTextField();
jLabel13 = new javax.swing.JLabel();
jLabel14 = new javax.swing.JLabel();
jLabel15 = new javax.swing.JLabel();
jLabel16 = new javax.swing.JLabel();
jLabel17 = new javax.swing.JLabel();
jLabel18 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jCheckBox1.setText("See Country Codes");
jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jCheckBox1ActionPerformed(evt);
}
});
jLabel1.setFont(new java.awt.Font("Ubuntu", 1, 16)); // NOI18N
jLabel1.setText("Holiday Date Service");
jButton2.setText("Quit");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jButton1.setText("Clear All Selections");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jCheckBox2.setText("View Holidays for a specific country:");
jCheckBox2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jCheckBox2ActionPerformed(evt);
}
});
jTextField1.setText("jTextField1");
jCheckBox3.setText("Find a specific Holiday date:");
jCheckBox3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jCheckBox3ActionPerformed(evt);
}
});
jTextField2.setText("jTextField2");
jTextField3.setText("jTextField3");
jTextField4.setText("jTextField4");
jLabel2.setText("Country:");
jLabel3.setText("Holiday:");
jLabel4.setText("Year:");
jCheckBox4.setText("View Holidays for date range:");
jCheckBox4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jCheckBox4ActionPerformed(evt);
}
});
jLabel5.setText("Country:");
jTextField5.setText("jTextField5");
jLabel6.setText("Start:");
jTextField6.setText("jTextField6");
jLabel7.setText("End:");
jTextField7.setText("jTextField7");
jCheckBox5.setText("View all Holidays for a particular Year:");
jCheckBox5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jCheckBox5ActionPerformed(evt);
}
});
jLabel8.setText("Country:");
jTextField8.setText("jTextField8");
jLabel9.setText("Year:");
jTextField9.setText("jTextField9");
jCheckBox6.setText("View Holidays for a particular Month:");
jCheckBox6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jCheckBox6ActionPerformed(evt);
}
});
jLabel10.setText("Country:");
jTextField10.setText("jTextField10");
jLabel11.setText("Year:");
jTextField11.setText("jTextField11");
jLabel12.setText("Month:");
jTextField12.setText("jTextField12");
jLabel13.setText("(ex: UnitedStates, Scotland)");
jLabel14.setText("(ex: HALLOWEEN, MOTHERS-DAY)");
jLabel15.setText("(ex: 2012)");
jLabel16.setText("(ex: January 1, 2012)");
jLabel17.setText("(use numeric representation, ex: 10)");
jLabel18.setText("(ex: Canada, GreatBritain)");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jCheckBox1)
.addGroup(layout.createSequentialGroup()
.addGap(10, 10, 10)
.addComponent(jLabel1))
.addComponent(jCheckBox3)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel5, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel6))
.addComponent(jLabel7))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jTextField7, javax.swing.GroupLayout.DEFAULT_SIZE, 244, Short.MAX_VALUE)
.addComponent(jTextField5)
.addComponent(jTextField6))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel16)
.addComponent(jLabel18)))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel8)
.addComponent(jLabel9))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTextField8, javax.swing.GroupLayout.PREFERRED_SIZE, 244, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField9, javax.swing.GroupLayout.PREFERRED_SIZE, 244, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel10)
.addComponent(jLabel11)
.addComponent(jLabel12))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jTextField12, javax.swing.GroupLayout.PREFERRED_SIZE, 245, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel17))
.addComponent(jTextField11, javax.swing.GroupLayout.PREFERRED_SIZE, 245, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField10, javax.swing.GroupLayout.PREFERRED_SIZE, 245, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 244, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jCheckBox2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel13)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jButton1)
.addGap(28, 28, 28)
.addComponent(jButton2))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addComponent(jLabel3)
.addComponent(jLabel4))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 248, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 248, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel15))
.addGroup(layout.createSequentialGroup()
.addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 248, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel14))))
.addComponent(jCheckBox4)
.addComponent(jCheckBox5)
.addComponent(jCheckBox6))
.addGap(0, 0, Short.MAX_VALUE))))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addGap(18, 18, 18)
.addComponent(jCheckBox1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jCheckBox2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel13))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jCheckBox3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3)
.addComponent(jLabel14))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel4)
.addComponent(jLabel15))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jCheckBox4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel5)
.addComponent(jLabel18))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel6)
.addComponent(jLabel16))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel7))
.addGap(18, 18, 18)
.addComponent(jCheckBox5)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel8))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel9))
.addGap(18, 18, 18)
.addComponent(jCheckBox6)
.addGap(11, 11, 11)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel10)
.addComponent(jTextField10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel11))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField12, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel12)
.addComponent(jLabel17))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 11, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2))
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
/**
* Detects an event at jCheckBox1 and makes the getCountriesAvailable request
* to the HolidayService web service.
* @return list of possible Country Codes accepted in holiday requests
* @see listed Country Codes in the console window
* @exception displays an error box containing the exception error message
*/
private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed
try {
ArrayOfCountryCode countries = new ArrayOfCountryCode();
countries = getCountriesAvailable();
int listSize = countries.getCountryCode().size();
System.out.println("Country codes: ");
for (int i = 0; i < listSize; i++) {
System.out.println(countries.getCountryCode().get(i).getCode());
}
} catch (Exception e) {
JOptionPane.showMessageDialog(this, "Exception: " + e
, "ERROR", JOptionPane.ERROR_MESSAGE);
System.out.println("Exception: " + e);
}
}//GEN-LAST:event_jCheckBox1ActionPerformed
/**
* Closes the GUI window and terminates the program when jButton2 is selected.
* @see window closes and program terminates
*/
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
dispose();
System.exit(0);
}//GEN-LAST:event_jButton2ActionPerformed
/**
* This helper function removes all checkmarks and text from checkboxes and
* textfields. The service is provided to the MainForm upon instantiation.
* Tool generated code for the textfields supplies initial text in all textfields,
* which is immediately removed after instantiation of the GUI. jButton1 also
* uses this function for manual clearing of the GUI form by the user.
* @see all checkmarks and text are removed from the GUI form
*/
private void clear() {
jCheckBox1.setSelected(false);
jCheckBox2.setSelected(false);
jTextField1.setText("");
jCheckBox3.setSelected(false);
jTextField2.setText("");
jTextField3.setText("");
jTextField4.setText("");
jCheckBox4.setSelected(false);
jTextField5.setText("");
jTextField6.setText("");
jTextField7.setText("");
jCheckBox5.setSelected(false);
jTextField8.setText("");
jTextField9.setText("");
jCheckBox6.setSelected(false);
jTextField10.setText("");
jTextField11.setText("");
jTextField12.setText("");
}
/**
* This button provides the user the option to manually clear all checkmarks
* and text from the GUI form.
* @see all checkmarks and text are removed from the GUI form
*/
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
clear();
}//GEN-LAST:event_jButton1ActionPerformed
/**
* Detects an event at jCheckBox2 and makes the getHolidaysAvailable request
* to the HolidayService web service.
* @param country Code for the country whose holidays are requested
* @return list of holidays for the specified country
* @see listed holidays in the console window
* @exception displays an error box containing the exception error message
*/
private void jCheckBox2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox2ActionPerformed
try {
Country country = Country.fromValue(jTextField1.getText());
ArrayOfHolidayCode dates = getHolidaysAvailable(country);
int dateSize = dates.getHolidayCode().size();
System.out.println("Holidays for " + country + ":");
for (int i = 0; i < dateSize; i++) {
System.out.println(dates.getHolidayCode().get(i).getCode());
System.out.println(dates.getHolidayCode().get(i).getDescription());
}
} catch (Exception e) {
JOptionPane.showMessageDialog(this, "Exception: " + e
, "ERROR", JOptionPane.ERROR_MESSAGE);
System.out.println("Exception: " + e);
}
}//GEN-LAST:event_jCheckBox2ActionPerformed
/**
* Detects an event at jCheckBox3 and makes the getHolidayDate request
* to the HolidayService web service.
* @param countryCode Code for the country whose holiday is requested
* @param holiday String for the specific holiday to find
* @param year Int for the year in which to search
* @return the date for the specified country, holiday and year
* @see date listed in the console window
* @exception displays an error box containing the exception error message
*/
private void jCheckBox3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox3ActionPerformed
String holiday;
int year;
try {
Country countryCode = Country.fromValue(jTextField2.getText());
holiday = jTextField3.getText();
year = Integer.parseInt(jTextField4.getText());
XMLGregorianCalendar date = getHolidayDate(countryCode, holiday, year);
System.out.println("The Holiday date for " + countryCode + "-" + holiday + "-" + year + " is: ");
System.out.print(date.getMonth() + " " + date.getDay() + " " + date.getYear());
} catch (Exception e) {
JOptionPane.showMessageDialog(this, "Exception: " + e
, "ERROR", JOptionPane.ERROR_MESSAGE);
System.out.println("Exception: " + e);
}
}//GEN-LAST:event_jCheckBox3ActionPerformed
/**
* Detects an event at jCheckBox4 and makes the getHolidaysForDateRange request
* to the HolidayService web service.
* @param coCode Code for the country whose holiday is requested
* @param startGC Date to start search for holidays
* @param endGC Date to end search for holidays
* @return a list of holidays and associated details that occur within
* the specified date range
* @see list of holidays and holiday details in the console window
* @exception displays an error box containing the exception error message
*/
private void jCheckBox4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox4ActionPerformed
String start, end;
Date startDate, endDate;
try {
Country coCode = Country.fromValue(jTextField5.getText());
start = jTextField6.getText();
end = jTextField7.getText();
startDate = new SimpleDateFormat("MMMM d, yyyy", Locale.ENGLISH) {}.parse(start);
endDate = new SimpleDateFormat("MMMM d, yyyy", Locale.ENGLISH).parse(end);
GregorianCalendar sD = new GregorianCalendar();
sD.setTime(startDate);
XMLGregorianCalendar startGC = DatatypeFactory.newInstance().newXMLGregorianCalendar(sD);
GregorianCalendar eD = new GregorianCalendar();
eD.setTime(endDate);
XMLGregorianCalendar endGC = DatatypeFactory.newInstance().newXMLGregorianCalendar(eD);
ArrayOfHoliday holidayRange = getHolidaysForDateRange(coCode, startGC, endGC);
int rangeSize = holidayRange.getHoliday().size();
System.out.println("Holidays for " + coCode + ", " + startGC + " to " + endGC + ":");
for (int i = 0; i < rangeSize; i++) {
System.out.println(holidayRange.getHoliday().get(i).getHolidayCode());
System.out.println(holidayRange.getHoliday().get(i).getDescriptor());
System.out.println(holidayRange.getHoliday().get(i).getHolidayType());
System.out.println(holidayRange.getHoliday().get(i).getDateType());
System.out.println(holidayRange.getHoliday().get(i).getBankHoliday());
System.out.println(holidayRange.getHoliday().get(i).getDate());
System.out.println(holidayRange.getHoliday().get(i).getRelatedHolidayCode());
System.out.println(holidayRange.getHoliday().get(i).getApplicableRegions());
System.out.println();
}
} catch (Exception e) {
JOptionPane.showMessageDialog(this, "Exception: " + e
, "ERROR", JOptionPane.ERROR_MESSAGE);
System.out.println("Exception: " + e);
}
}//GEN-LAST:event_jCheckBox4ActionPerformed
/**
* Detects an event at jCheckBox5 and makes the getHolidaysForYear request
* to the HolidayService web service.
* @param cCode Code for the country whose holiday is requested
* @param holidayYear Int for the year to search
* @return all holidays for the given country within the specified year
* @see list of holidays and holiday details in the console window
* @exception displays an error box containing the exception error message
*/
private void jCheckBox5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox5ActionPerformed
int holidayYear;
try {
Country cCode = Country.fromValue(jTextField8.getText());
holidayYear = Integer.parseInt(jTextField9.getText());
ArrayOfHoliday holidays = getHolidaysForYear(cCode, holidayYear);
int holidaySize = holidays.getHoliday().size();
System.out.println("The Holiday dates for " + cCode + ":" + holidayYear + " are: ");
for (int i = 0; i < holidaySize; i++) {
System.out.println(holidays.getHoliday().get(i).getHolidayCode());
System.out.println(holidays.getHoliday().get(i).getDescriptor());
System.out.println(holidays.getHoliday().get(i).getHolidayType());
System.out.println(holidays.getHoliday().get(i).getDateType());
System.out.println(holidays.getHoliday().get(i).getBankHoliday());
System.out.println(holidays.getHoliday().get(i).getDate());
System.out.println(holidays.getHoliday().get(i).getRelatedHolidayCode());
System.out.println(holidays.getHoliday().get(i).getApplicableRegions());
System.out.println();
}
} catch (Exception e) {
JOptionPane.showMessageDialog(this, "Exception: " + e
, "ERROR", JOptionPane.ERROR_MESSAGE);
System.out.println("Exception: " + e);
}
}//GEN-LAST:event_jCheckBox5ActionPerformed
/**
* Detects an event at jCheckBox6 and makes the getHolidaysForMonth request
* to the HolidayService web service.
* @param cCode Code for the country whose holiday is requested
* @param holiYear Int for the year in which to search
* @param holiMonth Int for the month in which to search
* @return the holidays for the specified country, year and month
* @see holidays and holiday details listed in the console window
* @exception displays an error box containing the exception error message
*/
private void jCheckBox6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox6ActionPerformed
int holiYear, holiMonth;
try {
Country cCode = Country.fromValue(jTextField10.getText());
holiYear = Integer.parseInt(jTextField11.getText());
holiMonth = Integer.parseInt(jTextField12.getText());
ArrayOfHoliday holidayByMonth = getHolidaysForMonth(cCode, holiYear, holiMonth);
int holiSize = holidayByMonth.getHoliday().size();
System.out.println("The Holiday dates for " + cCode + ":" + holiYear + ":" + holiMonth + " are: ");
for (int i = 0; i < holiSize; i++) {
System.out.println(holidayByMonth.getHoliday().get(i).getHolidayCode());
System.out.println(holidayByMonth.getHoliday().get(i).getDescriptor());
System.out.println(holidayByMonth.getHoliday().get(i).getHolidayType());
System.out.println(holidayByMonth.getHoliday().get(i).getDateType());
System.out.println(holidayByMonth.getHoliday().get(i).getBankHoliday());
System.out.println(holidayByMonth.getHoliday().get(i).getDate());
System.out.println(holidayByMonth.getHoliday().get(i).getRelatedHolidayCode());
System.out.println(holidayByMonth.getHoliday().get(i).getApplicableRegions());
System.out.println();
}
} catch (Exception e) {
JOptionPane.showMessageDialog(this, "Exception: " + e
, "ERROR", JOptionPane.ERROR_MESSAGE);
System.out.println("Exception: " + e);
}
}//GEN-LAST:event_jCheckBox6ActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MainForm().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JCheckBox jCheckBox1;
private javax.swing.JCheckBox jCheckBox2;
private javax.swing.JCheckBox jCheckBox3;
private javax.swing.JCheckBox jCheckBox4;
private javax.swing.JCheckBox jCheckBox5;
private javax.swing.JCheckBox jCheckBox6;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel11;
private javax.swing.JLabel jLabel12;
private javax.swing.JLabel jLabel13;
private javax.swing.JLabel jLabel14;
private javax.swing.JLabel jLabel15;
private javax.swing.JLabel jLabel16;
private javax.swing.JLabel jLabel17;
private javax.swing.JLabel jLabel18;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField10;
private javax.swing.JTextField jTextField11;
private javax.swing.JTextField jTextField12;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
private javax.swing.JTextField jTextField4;
private javax.swing.JTextField jTextField5;
private javax.swing.JTextField jTextField6;
private javax.swing.JTextField jTextField7;
private javax.swing.JTextField jTextField8;
private javax.swing.JTextField jTextField9;
// End of variables declaration//GEN-END:variables
/**
* Helper function to create pop-up boxes for caught Exceptions
*/
public static void infoBox(String infoMessage, String location)
{
JOptionPane.showMessageDialog(null, infoMessage, "InfoBox: " + location, JOptionPane.INFORMATION_MESSAGE);
}
/**
* Operation provided by the published HolidayService WSDL
*/
private static ArrayOfCountryCode getCountriesAvailable() {
com.holidaywebservice.holidayservice_v2.HolidayService2 service = new com.holidaywebservice.holidayservice_v2.HolidayService2();
com.holidaywebservice.holidayservice_v2.HolidayService2Soap port = service.getHolidayService2Soap();
return port.getCountriesAvailable();
}
/**
* Operation provided by the published HolidayService WSDL
*/
private static XMLGregorianCalendar getHolidayDate(com.holidaywebservice.holidayservice_v2.Country countryCode, java.lang.String holidayCode, int year) {
com.holidaywebservice.holidayservice_v2.HolidayService2 service = new com.holidaywebservice.holidayservice_v2.HolidayService2();
com.holidaywebservice.holidayservice_v2.HolidayService2Soap port = service.getHolidayService2Soap();
return port.getHolidayDate(countryCode, holidayCode, year);
}
/**
* Operation provided by the published HolidayService WSDL
*/
private static ArrayOfHolidayCode getHolidaysAvailable(com.holidaywebservice.holidayservice_v2.Country countryCode) {
com.holidaywebservice.holidayservice_v2.HolidayService2 service = new com.holidaywebservice.holidayservice_v2.HolidayService2();
com.holidaywebservice.holidayservice_v2.HolidayService2Soap port = service.getHolidayService2Soap();
return port.getHolidaysAvailable(countryCode);
}
/**
* Operation provided by the published HolidayService WSDL
*/
private static ArrayOfHoliday getHolidaysForDateRange(com.holidaywebservice.holidayservice_v2.Country countryCode, javax.xml.datatype.XMLGregorianCalendar startDate, javax.xml.datatype.XMLGregorianCalendar endDate) {
com.holidaywebservice.holidayservice_v2.HolidayService2 service = new com.holidaywebservice.holidayservice_v2.HolidayService2();
com.holidaywebservice.holidayservice_v2.HolidayService2Soap port = service.getHolidayService2Soap();
return port.getHolidaysForDateRange(countryCode, startDate, endDate);
}
/**
* Operation provided by the published HolidayService WSDL
*/
private static ArrayOfHoliday getHolidaysForMonth(com.holidaywebservice.holidayservice_v2.Country countryCode, int year, int month) {
com.holidaywebservice.holidayservice_v2.HolidayService2 service = new com.holidaywebservice.holidayservice_v2.HolidayService2();
com.holidaywebservice.holidayservice_v2.HolidayService2Soap port = service.getHolidayService2Soap();
return port.getHolidaysForMonth(countryCode, year, month);
}
/**
* Operation provided by the published HolidayService WSDL
*/
private static ArrayOfHoliday getHolidaysForYear(com.holidaywebservice.holidayservice_v2.Country countryCode, int year) {
com.holidaywebservice.holidayservice_v2.HolidayService2 service = new com.holidaywebservice.holidayservice_v2.HolidayService2();
com.holidaywebservice.holidayservice_v2.HolidayService2Soap port = service.getHolidayService2Soap();
return port.getHolidaysForYear(countryCode, year);
}
}