2 * Copyright (C) 2015 Roland Haeder
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.pizzaapplication.application;
19 import java.lang.reflect.Field;
20 import java.text.MessageFormat;
21 import java.util.Iterator;
23 import java.util.SortedMap;
24 import java.util.TreeMap;
25 import javax.servlet.ServletContext;
26 import javax.servlet.ServletException;
27 import javax.servlet.http.HttpServletRequest;
28 import javax.servlet.http.HttpSession;
29 import org.mxchange.jcore.contact.Gender;
30 import org.mxchange.pizzaapplication.BasePizzaServiceSystem;
31 import org.mxchange.pizzaapplication.customer.Customer;
32 import org.mxchange.pizzaapplication.customer.PizzaServiceCustomer;
33 import org.mxchange.pizzaapplication.product.PizzaProduct;
34 import org.mxchange.pizzaapplication.product.Product;
38 * @author Roland Haeder
40 public class PizzaServiceApplication extends BasePizzaServiceSystem implements PizzaApplication {
44 public static final String MAIN_TITLE = "Pizza-Service";
49 private final SortedMap<String, Product> products;
52 * Some singleton getter for this instance. If the instance is not set in
53 * given application, it will be created.
55 * @param application Servlet context
56 * @return This instance
57 * @throws javax.servlet.ServletException If object is not set correctly
59 public static final PizzaApplication getInstance (final ServletContext application) throws ServletException {
60 // Check application instance
61 if (application == null) {
63 throw new NullPointerException("application is null"); //NOI18N
67 PizzaServiceApplication instance = null;
69 // Get instance from servlet
70 Object object = application.getAttribute("service"); //NOI18N
73 if (object instanceof PizzaServiceApplication) {
74 // Instance is set, so casting should work
75 instance = (PizzaServiceApplication) object;
76 } else if (object instanceof Object) {
77 // Not correct instance
78 throw new ServletException("service is not set correctly"); //NOI18N
80 // "service" is null, so initialize it
81 instance = new PizzaServiceApplication();
84 application.setAttribute("service", instance); //NOI18N
88 instance.getLogger().trace(MessageFormat.format("instance={0} - EXIT!", instance)); //NOI18N
97 private PizzaServiceApplication () {
98 // Init products instance
99 this.products = new TreeMap<>();
104 // Fill products list
105 this.fillProductsList();
109 public void doBootstrap () {
110 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
114 public void doMainLoop () {
115 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
119 public void doShutdown () {
120 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
124 * Getter for product (list) iterator
126 * @return An interator on all listed products
129 public Iterator<Map.Entry<String, Product>> getProductsIterator () {
130 assert(this.products instanceof SortedMap) : "this.products is not initialized"; //NOI18N
131 return this.products.entrySet().iterator();
135 * Adds given product to list or throws an exception if name is already found
137 * @param name Internal name of product
138 * @param title Product's title
141 private void addProduct (final String name, final String title, final float price) {
143 this.getLogger().trace(MessageFormat.format("name={0},title={1},price={2} - CALLED!", name, title, price)); //NOI18N
145 // Is the name already used?
146 if (this.isProductNameUsed(name)) {
147 // Something went wrong
148 throw new IllegalArgumentException(MessageFormat.format("product {0} is already used.", name)); //NOI18N
152 Product product = new PizzaProduct(name, title, price);
155 this.getLogger().debug(MessageFormat.format("Adding product={0} ...", product)); //NOI18N
158 this.products.put(product.getName(), product);
161 this.getLogger().trace("EXIT!"); //NOI18N
165 * Clears given parameter for product in session
167 * @param product Product instance
168 * @param session Session instance
169 * @param parameter Parameter to clear
171 private void clearSessionAttribute (final Product product, final HttpSession session, final String parameter) {
173 this.getLogger().trace(MessageFormat.format("produce={0},parameter={1},session={2} - CALLED!", product, parameter, session)); //NOI18N
176 this.getLogger().debug(MessageFormat.format("Clearing product={0},parameter={1} ...", product.getName(), parameter)); //NOI18N
177 this.setValueInSession(product, session, parameter, null);
180 this.getLogger().trace("EXIT!"); //NOI18N
184 * Fills products list
185 * @todo Very hard-coded stuff ...
187 private void fillProductsList () {
189 this.getLogger().trace("CALLED!"); //NOI18N
192 this.addProduct("italia", "Pizza Italia", 5.50f); //NOI18N
193 this.addProduct("diablo", "Pizza Diablo", 7.80f); //NOI18N
194 this.addProduct("bolognese", "Spagetti Bolognese", 11.95f); //NOI18N
197 this.getLogger().trace("EXIT!"); //NOI18N
201 * Some getter for value from session
203 * @param product Product instance
204 * @param session Session instance
205 * @param attribute Attribute to get value from
206 * @return Value from session
208 private Object getValueFromSession (final Product product, final HttpSession session, final String attribute) {
210 this.getLogger().trace(MessageFormat.format("product={0},session={1},attribute={2} - CALLED!", product, session, attribute)); //NOI18N
213 Object value = this.getValueFromSession(session, String.format(HTTP_PARAM_MASK, product.getName(), attribute));
215 this.getLogger().debug(MessageFormat.format("product={0},attribute={1},value={2}", product.getName(), attribute, value)); //NOI18N
218 this.getLogger().trace(MessageFormat.format("value={0} - EXIT!", value)); //NOI18N
225 * Some getter for value from session
227 * @param session Session instance
228 * @param key Key to get value from
229 * @return Value from session
231 private Object getValueFromSession (final HttpSession session, final String key) {
233 this.getLogger().trace(MessageFormat.format("session={043},key={1} - CALLED!", session, key)); //NOI18N
238 // Get it synchronized from session
239 synchronized (session) {
240 value = session.getAttribute(key);
244 this.getLogger().trace(MessageFormat.format("value={0} - EXIT!", value)); //NOI18N
251 * Checks whether given product is already used
253 * @param name Name of product
254 * @return Whether the given product's name is already used
256 private boolean isProductNameUsed (final String name) {
258 this.getLogger().trace(MessageFormat.format("name={0} - CALLED!", name)); //NOI18N
261 return this.products.containsKey(name);
265 * For debugging purpose
267 * @param args Arguments
269 public static void main (String[] args) {
270 // Get instance and start it
271 new PizzaServiceApplication().start();
275 * Checks if the product ordered?
281 private boolean isProductOrdered (final Product product, final HttpSession session) {
283 this.getLogger().trace(MessageFormat.format("product={0},session={1} - CALLED!", product, session)); //NOI18N
286 Object isOrdered = this.getValueFromSession(product, session, SESSION_ORDERED);
287 this.getLogger().debug(MessageFormat.format("product={0},isOrdered={1}", product.getName(), isOrdered)); //NOI18N
290 return ("true".equals(isOrdered)); //NOI18N
294 * Somewhat setter in session
296 * @param product Product instance
297 * @param session Session instance
298 * @param keyPart Key part to include in final key
299 * @param value Value to set
301 private void setValueInSession (final Product product, final HttpSession session, final String keyPart, final Object value) {
303 this.getLogger().trace(MessageFormat.format("product={0},session={1},keyPart={2},value={3} - CALLED!", product, session, keyPart, value)); //NOI18N
305 synchronized(session) {
307 this.getLogger().debug(MessageFormat.format("setValueInSession: Setting value={0} for product={1},keyPart={2}", value, product.getName(), keyPart)); //NOI18N
308 session.setAttribute(String.format(HTTP_PARAM_MASK, product.getName(), keyPart), value);
312 this.getLogger().trace("EXIT!"); //NOI18N
316 * Application starter
318 private void start () {
320 Iterator<Map.Entry<String, Product>> iterator = this.getProductsIterator();
323 while (iterator.hasNext()) {
324 // Get product instance
325 Map.Entry<String, Product> entry = iterator.next();
328 Product product = entry.getValue();
331 this.getLogger().debug(MessageFormat.format("Product {0}, {1}: {2}", product.getName(), product.getTitle(), product.getPrice())); //NOI18N
334 // Generate fake Customer instance
335 Customer customer = new PizzaServiceCustomer();
338 * Need a least a gender ... :( See, that is why I don't like default
339 * constructors, you can easily miss something important and bam! You
340 * get an NPE. The fix here is, to have construtors (or factories) which
341 * requires all required instances that needs to be set to get a
342 * consitent object back.
345 // Gender is MALE now
346 customer.setGender(Gender.MALE);
348 // Get iterator on all its fields
349 Iterator<Map.Entry<Field, Object>> it = customer.iterator();
352 while (it.hasNext()) {
353 Map.Entry<Field, Object> entry = it.next();
354 this.getLogger().debug(MessageFormat.format("entry {0}={1}", entry.getKey(), entry.getValue()));
359 * Some "getter" for amount from session
361 * @param product Product instance
362 * @param session Session instance
363 * @return Amount as string
366 public String getAmountFromSession (final Product product, final HttpSession session) {
368 this.getLogger().trace(MessageFormat.format("product={0},session={1} - CALLED!", product, session)); //NOI18N
370 // Is product and session set?
371 if (product == null) {
373 throw new NullPointerException("product is null"); //NOI18N
374 } else if (session == null) {
376 throw new NullPointerException("session is null"); //NOI18N
380 Object object = this.getValueFromSession(product, session, HTTP_PARAM_AMOUNT);
382 // Is the object null?
383 if (object == null) {
385 this.getLogger().trace("Returning 0 - EXIT!"); //NOI18N
392 this.getLogger().trace(MessageFormat.format("object={0} - EXIT!", object)); //NOI18N
394 // Cast to string and return it
395 return (String) object;
399 * Some "getter" for choose from session
401 * @param product Product instance
402 * @param session Session instance
403 * @return Choose as string
406 public String getChooseFromSession (final Product product, final HttpSession session) {
408 this.getLogger().trace(MessageFormat.format("product={0},session={1} - CALLED!", product, session)); //NOI18N
410 // Is product and session set?
411 if (product == null) {
413 throw new NullPointerException("product is null"); //NOI18N
414 } else if (session == null) {
416 throw new NullPointerException("session is null"); //NOI18N
420 Object object = this.getValueFromSession(product, session, HTTP_PARAM_CHOOSE);
422 // Is the object null?
423 if (object == null) {
425 this.getLogger().debug(MessageFormat.format("Returning empty string for product={0} ...", product.getName())); //NOI18N
430 this.getLogger().trace(MessageFormat.format("object={0} - CALLED!", object)); //NOI18N
432 // Cast to string and return it
433 return (String) object;
437 * Handler for amount from request or session
439 * @param product Product instance
440 * @param request Request instance
441 * @param session Session instance
442 * @return Amount as string
445 public String handleAmountFromRequestSession (final Product product, final HttpServletRequest request, final HttpSession session) {
447 this.getLogger().trace(MessageFormat.format("product={0},request={1},session={2} - CALLED!", product, request, session)); //NOI18N
449 // Is product and session set?
450 if (product == null) {
452 throw new NullPointerException("product is null"); //NOI18N
453 } else if (request == null) {
455 throw new NullPointerException("request is null"); //NOI18N
456 } else if (session == null) {
458 throw new NullPointerException("session is null"); //NOI18N
464 // Check request method
465 if (!"POST".equals(request.getMethod())) { //NOI18N
466 // Not POST, so get from session
467 return this.getAmountFromSession(product, session);
468 } else if (this.handleChooseFromRequestSession(product, request, session).isEmpty()) {
470 this.clearSessionAttribute(product, session, HTTP_PARAM_AMOUNT);
471 this.getLogger().debug(MessageFormat.format("Unsetting for product={0} in session, returning zero ...", product.getName())); //NOI18N
475 // Get attribute from request
476 object = request.getParameter(String.format(HTTP_PARAM_MASK, HTTP_PARAM_AMOUNT, product.getName()));
479 if (object instanceof String) {
480 // Try to parse it to integer
482 Integer value = Integer.valueOf((String) object);
483 } catch (final NumberFormatException ex) {
485 this.getLogger().warn(ex);
489 // Then set it in session
490 this.setValueInSession(product, session, HTTP_PARAM_AMOUNT, object);
493 return (String) object;
497 this.getLogger().trace("Calling getAmountFromSession() ..."); //NOI18N
499 // Get attribute from session
500 return this.getAmountFromSession(product, session);
504 * Handler for choosen (checkbox) from request or session
506 * @param product Product instance
507 * @param request Request instance
508 * @param session Session instance
509 * @return Amount as string
512 public String handleChooseFromRequestSession (final Product product, final HttpServletRequest request, final HttpSession session) {
514 this.getLogger().trace(MessageFormat.format("product={0},request={1},session={2} - CALLED!", product, request, session)); //NOI18N
516 // Is product and session set?
517 if (product == null) {
519 throw new NullPointerException("product is null"); //NOI18N
520 } else if (request == null) {
522 throw new NullPointerException("request is null"); //NOI18N
523 } else if (session == null) {
525 throw new NullPointerException("session is null"); //NOI18N
531 // Check request method
532 if (!"POST".equals(request.getMethod())) { //NOI18N
533 // Not POST, so get from session
534 return this.getChooseFromSession(product, session);
535 } else if (this.isProductOrdered(product, session)) {
536 // Product is ordered
537 return this.getChooseFromSession(product, session);
540 // Get reqzest element
541 object = request.getParameter(String.format(HTTP_PARAM_MASK, HTTP_PARAM_CHOOSE, product.getName()));
542 this.getLogger().debug(MessageFormat.format("product={0},object={1}", product.getName(), object)); //NOI18N
545 if (object == null) {
547 this.getLogger().debug(MessageFormat.format("Unsetting session for product={0} ...", product.getName())); //NOI18N
548 this.clearSessionAttribute(product, session, HTTP_PARAM_CHOOSE);
549 this.clearSessionAttribute(product, session, HTTP_PARAM_AMOUNT);
551 // Return empty string
555 // Then set it in session
556 this.setValueInSession(product, session, HTTP_PARAM_CHOOSE, object);
558 // Cast to string and return it
559 this.getLogger().debug(MessageFormat.format("product={0} - Returning {1} ...", product.getName(), object)); //NOI18N
560 return (String) object;
564 * Some "getter" for choosen (checkbox) from session
566 * @param product Product instance
567 * @param request Request instance
568 * @param session Session instance
569 * @return Amount as string
572 public String getPrintableChoosenFromRequestSession (final Product product, final HttpServletRequest request, final HttpSession session) {
574 this.getLogger().trace(MessageFormat.format("product={0},request={1},session={2} - CALLED!", product, request, session)); //NOI18N
576 // Is product and session set?
577 if (product == null) {
579 throw new NullPointerException("product is null"); //NOI18N
580 } else if (request == null) {
582 throw new NullPointerException("request is null"); //NOI18N
583 } else if (session == null) {
585 throw new NullPointerException("session is null"); //NOI18N
589 String choosen = this.handleChooseFromRequestSession(product, request, session);
590 this.getLogger().debug(MessageFormat.format("product={0},choosen={1}", product.getName(), choosen)); //NOI18N
593 assert(choosen instanceof String): "choosen is null"; //NOI18N
596 if (choosen.isEmpty()) {
602 String amount = this.handleAmountFromRequestSession(product, request, session);
603 this.getLogger().debug(MessageFormat.format("product={0},amount={1}", product.getName(), amount)); //NOI18N
606 assert(amount instanceof String): "amount is null"; //NOI18N
609 if (amount.isEmpty() || "0".equals(amount)) { //NOI18N
610 // Choosen, but no amount
619 * Some "getter" for total price of position from request or session.
620 * Single price and amount is multiplyed.
622 * @param product Product instance
623 * @param request Request instance
624 * @param session Session instance
625 * @return Amount as string
628 public float getTotalPositionPriceFromRequestSession (final Product product, final HttpServletRequest request, final HttpSession session) {
630 this.getLogger().trace(MessageFormat.format("product={0},request={1},session={2} - CALLED!", product, request, session)); //NOI18N
632 // Is product and session set?
633 if (product == null) {
635 throw new NullPointerException("product is null"); //NOI18N
636 } else if (request == null) {
638 throw new NullPointerException("request is null"); //NOI18N
639 } else if (session == null) {
641 throw new NullPointerException("session is null"); //NOI18N
645 String choosen = this.handleChooseFromRequestSession(product, request, session);
646 this.getLogger().debug(MessageFormat.format("product={0},choosen={1}", product.getName(), choosen)); //NOI18N
649 assert(choosen instanceof String): "choosen is null"; //NOI18N
652 if (choosen.isEmpty()) {
654 this.getLogger().debug(MessageFormat.format("product={0},choosen={1} - returning zero ...", product.getName(), choosen)); //NOI18N
659 String amount = this.handleAmountFromRequestSession(product, request, session);
660 this.getLogger().debug(MessageFormat.format("product={0},amount={1}", product.getName(), amount)); //NOI18N
663 assert(amount instanceof String): "amount is null"; //NOI18N
666 if (amount.isEmpty() || "0".equals(amount)) { //NOI18N
668 this.getLogger().debug(MessageFormat.format("product={0},amount={1} - returning zero ...", product.getName(), amount)); //NOI18N
673 Integer value = null;
677 // Get amount as integer
678 value = Integer.valueOf(amount);
679 } catch (final NumberFormatException e) {
681 throw new IllegalArgumentException(e);
685 float price = (product.getPrice() * value);
688 this.getLogger().trace(MessageFormat.format("product={0},price={1} - EXIT!", product.getName(), price)); //NOI18N
690 // Then multiply it with price
695 * Checks whether the given product is choosen, request overules session.
697 * @param product Product instance
698 * @param request Request instance
699 * @param session Session instance
700 * @return Whether the product is choosen
703 public boolean isProductChoosen (final Product product, final HttpServletRequest request, final HttpSession session) {
705 this.getLogger().trace(MessageFormat.format("product={0},request={1},session={2} - CALLED!", product, request, session)); //NOI18N
707 // Is product and session set?
708 if (product == null) {
710 throw new NullPointerException("product is null"); //NOI18N
711 } else if (request == null) {
713 throw new NullPointerException("request is null"); //NOI18N
714 } else if (session == null) {
716 throw new NullPointerException("session is null"); //NOI18N
720 String choosen = this.handleChooseFromRequestSession(product, request, session);
721 this.getLogger().debug(MessageFormat.format("product={0},choosen={1}", product.getName(), choosen)); //NOI18N
724 assert(choosen instanceof String): "choosen is null"; //NOI18N
726 // Is it not choosen?
727 if (choosen.isEmpty()) {
733 String amount = this.handleAmountFromRequestSession(product, request, session);
736 assert(amount instanceof String): "amount is not set"; //NOI18N
739 this.getLogger().trace(MessageFormat.format("amount={0} - EXIT!", amount)); //NOI18N
741 // Must not be empty and not 0
742 return (!amount.isEmpty() && !"0".equals(amount)); //NOI18N
746 * Calculates total price of all choosen products
748 * @param request Request instance
749 * @param session Session instance
750 * @return Total price of all choosen products
753 public float calculateTotalPrice (final HttpServletRequest request, final HttpSession session) {
755 this.getLogger().trace(MessageFormat.format("request={0},session={1} - CALLED!", request, session)); //NOI18N
757 // Is product and session set?
758 if (request == null) {
760 throw new NullPointerException("request is null"); //NOI18N
761 } else if (session == null) {
763 throw new NullPointerException("session is null"); //NOI18N
767 float totalPrice = 0.00f;
770 Iterator<Map.Entry<String, Product>> iterator = this.getProductsIterator();
772 // Walk through all products
773 while (iterator.hasNext()) {
775 Map.Entry<String, Product> entry = iterator.next();
777 // Get product instance
778 Product product = entry.getValue();
781 if (product.isChoosen()) {
782 // Then add product's total price
783 this.getLogger().debug(MessageFormat.format("Calling getTotalPositionPriceFromRequestSession({0},request,session) ...", product.getName())); //NOI18N
784 totalPrice += this.getTotalPositionPriceFromRequestSession(product, request, session);
786 this.getLogger().debug(MessageFormat.format("product={0},totalPrice={1}", product.getName(), totalPrice)); //NOI18N
790 this.getLogger().trace(MessageFormat.format(" totalPrice={0} - EXIT!", totalPrice)); //NOI18N
792 // Return total price
797 * Calculates total amount of all choosen products
799 * @param request Request instance
800 * @param session Session instance
801 * @return Total amount of all choosen products
804 public int calculateTotalAmount (final HttpServletRequest request, final HttpSession session) {
806 this.getLogger().trace(MessageFormat.format("request={0},session={1} - CALLED!", request, session)); //NOI18N
808 // Is product and session set?
809 if (request == null) {
811 throw new NullPointerException("request is null"); //NOI18N
812 } else if (session == null) {
814 throw new NullPointerException("session is null"); //NOI18N
821 Iterator<Map.Entry<String, Product>> iterator = this.getProductsIterator();
823 // Walk through all products
824 while (iterator.hasNext()) {
826 Map.Entry<String, Product> entry = iterator.next();
828 // Get product instance
829 Product product = entry.getValue();
832 if (product.isChoosen()) {
833 // Then add ordered amount
834 this.getLogger().debug(MessageFormat.format("Counting {0} ...", product.getName())); //NOI18N
837 String amount = this.getAmountFromSession(product, session);
840 this.getLogger().debug(MessageFormat.format("amount={0}", amount)); //NOI18N
841 totalAmount += Integer.valueOf(amount);
843 this.getLogger().debug(MessageFormat.format("product={0},totalAmount={1}", product.getName(), totalAmount)); //NOI18N
847 this.getLogger().trace(MessageFormat.format("totalAmount={0} - EXIT!", totalAmount)); //NOI18N
849 // Return total price
854 * Some "getter" for HTML code 'checked="checked"' if the product is choosen
856 * @param product Product instance
857 * @param request Request instance
858 * @param session Session instance
859 * @return Whether the product is choosen
862 public String getCheckedHtmlFromProduct (final Product product, final HttpServletRequest request, final HttpSession session) {
864 this.getLogger().trace(MessageFormat.format("product={0},request={1},session={2} - CALLED!", product, request, session)); //NOI18N
866 // Is product and session set?
867 if (product == null) {
869 throw new NullPointerException("product is null"); //NOI18N
870 } else if (request == null) {
872 throw new NullPointerException("request is null"); //NOI18N
873 } else if (session == null) {
875 throw new NullPointerException("session is null"); //NOI18N
878 // First let's check if the product is choosen
879 if (this.isProductChoosen(product, request, session)) {
881 this.getLogger().trace("Returning checked=\"checked\" - EXIT!"); //NOI18N
884 return "checked=\"checked\""; //NOI18N
887 this.getLogger().trace("Returning empty string - EXIT!"); //NOI18N
895 * Some "getter" for HTML code 'disabled="disabled"' for e.g. submit buttons
897 * @param request Request instance
898 * @param session Session instance
899 * @return Whether the product is choosen
902 public String getDisabledHtmlFromSession (final HttpServletRequest request, final HttpSession session) {
904 this.getLogger().trace(MessageFormat.format("request={0},session={1} - CALLED!", request, session)); //NOI18N
906 // Is product and session set?
907 if (request == null) {
909 throw new NullPointerException("request is null"); //NOI18N
910 } else if (session == null) {
912 throw new NullPointerException("session is null"); //NOI18N
915 // Is something selected?
916 if (this.calculateTotalAmount(request, session) > 0) {
918 this.getLogger().trace("Returning empty string - EXIT!"); //NOI18N
920 // Something has been choosen
924 this.getLogger().trace("Returning disabled=\"disabled\" - EXIT!"); //NOI18N
926 // Nothing choosen yet
927 return "disabled=\"disabled\""; //NOI18N
932 * Marks given product as ordered in session
934 * @param product Product to mark as ordered
935 * @param session Session instance
938 public void markProductAsOrdered(final Product product, final HttpSession session) {
940 this.getLogger().trace(MessageFormat.format("product={0},session={1} - CALLED!", product, session)); //NOI18N
942 // Is product and session set?
943 if (product == null) {
945 throw new NullPointerException("product is null"); //NOI18N
946 } else if (session == null) {
948 throw new NullPointerException("session is null"); //NOI18N
951 // Mark it as ordered by setting flag
952 this.getLogger().debug(MessageFormat.format("Marking product={0} as ordered.", product.getName())); //NOI18N
953 this.setValueInSession(product, session, SESSION_ORDERED, "true"); //NOI18N
956 this.getLogger().trace("EXIT!"); //NOI18N
960 * Unmarks given product as ordered in session
962 * @param product Product to unmark as ordered
963 * @param session Session instance
966 public void unmarkProductAsOrdered(final Product product, final HttpSession session) {
968 this.getLogger().trace(MessageFormat.format("product={0},session={1} - CALLED!", product, session)); //NOI18N
970 // Is product and session set?
971 if (product == null) {
973 throw new NullPointerException("product is null"); //NOI18N
974 } else if (session == null) {
976 throw new NullPointerException("session is null"); //NOI18N
979 // Mark it as ordered by setting flag
980 this.getLogger().debug(MessageFormat.format("Unmarking product={0} as ordered.", product.getName())); //NOI18N
981 this.clearSessionAttribute(product, session, SESSION_ORDERED);
984 this.getLogger().trace("EXIT!"); //NOI18N
988 * Some getter for printable value from session or an empty string for null.
990 * @param session Session instance
991 * @param key Key to get
992 * @return Value from key, empty string for null
995 public Object getPrintableValeFromSession (final HttpSession session, final String key) {
997 this.getLogger().trace(MessageFormat.format("session={0},key={1} - CALLED", session, key));
999 // Are both parameter not null?
1000 if (session == null) {
1002 throw new NullPointerException("session is null");
1003 } else if (key == null) {
1005 throw new NullPointerException("key is null");
1009 Object value = this.getValueFromSession(session, key);
1012 this.getLogger().debug(MessageFormat.format("value={0}", value));
1015 this.getLogger().trace(MessageFormat.format("Calling this.convertNullToEmpty({0}) ... - EXIT!", value));
1017 // Return actual value
1018 return this.convertNullToEmpty(value);