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 PizzaApplication instance = null;
69 // Get instance from servlet application (aka. "application scope")
70 Object object = application.getAttribute("app"); //NOI18N
73 if (object instanceof PizzaApplication) {
74 // Instance is set, so casting should work
75 instance = (PizzaApplication) object;
76 } else if (object instanceof Object) {
77 // Not correct instance
78 throw new ServletException("app is not set correctly"); //NOI18N
80 // "service" is null, so initialize it
81 instance = new PizzaServiceApplication();
84 application.setAttribute("app", 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("Setting value={0} for product={1},keyPart={2}", value, product.getName(), keyPart)); //NOI18N
308 this.setValueInSession(session, String.format(HTTP_PARAM_MASK, product.getName(), keyPart), value);
312 this.getLogger().trace("EXIT!"); //NOI18N
316 * Somewhat setter in session
318 * @param session Session instance
319 * @param key Session key to set
320 * @param value Value to set
323 public void setValueInSession (final HttpSession session, final String key, final Object value) {
325 this.getLogger().trace(MessageFormat.format("session={0},key={1},value={2} - CALLED!", session, key, value)); //NOI18N
327 synchronized(session) {
329 session.setAttribute(key, value);
333 this.getLogger().trace("EXIT!"); //NOI18N
337 * Application starter
339 private void start () {
341 Iterator<Map.Entry<String, Product>> iterator = this.getProductsIterator();
344 while (iterator.hasNext()) {
345 // Get product instance
346 Map.Entry<String, Product> entry = iterator.next();
349 Product product = entry.getValue();
352 this.getLogger().debug(MessageFormat.format("Product {0}, {1}: {2}", product.getName(), product.getTitle(), product.getPrice())); //NOI18N
355 // Generate fake Customer instance
356 Customer customer = new PizzaServiceCustomer();
359 * Need a least a gender ... :( See, that is why I don't like default
360 * constructors, you can easily miss something important and bam! You
361 * get an NPE. The fix here is, to have construtors (or factories) which
362 * requires all required instances that needs to be set to get a
363 * consitent object back.
366 // Gender is MALE now
367 customer.setGender(Gender.MALE);
369 // Get iterator on all its fields
370 Iterator<Map.Entry<Field, Object>> it = customer.iterator();
373 while (it.hasNext()) {
374 Map.Entry<Field, Object> entry = it.next();
375 this.getLogger().debug(MessageFormat.format("entry {0}={1}", entry.getKey(), entry.getValue()));
380 * Some "getter" for amount from session
382 * @param product Product instance
383 * @param session Session instance
384 * @return Amount as string
387 public String getAmountFromSession (final Product product, final HttpSession session) {
389 this.getLogger().trace(MessageFormat.format("product={0},session={1} - CALLED!", product, session)); //NOI18N
391 // Is product and session set?
392 if (product == null) {
394 throw new NullPointerException("product is null"); //NOI18N
395 } else if (session == null) {
397 throw new NullPointerException("session is null"); //NOI18N
401 Object object = this.getValueFromSession(product, session, HTTP_PARAM_AMOUNT);
403 // Is the object null?
404 if (object == null) {
406 this.getLogger().trace("Returning 0 - EXIT!"); //NOI18N
413 this.getLogger().trace(MessageFormat.format("object={0} - EXIT!", object)); //NOI18N
415 // Cast to string and return it
416 return (String) object;
420 * Some "getter" for choose from session
422 * @param product Product instance
423 * @param session Session instance
424 * @return Choose as string
427 public String getChooseFromSession (final Product product, final HttpSession session) {
429 this.getLogger().trace(MessageFormat.format("product={0},session={1} - CALLED!", product, session)); //NOI18N
431 // Is product and session set?
432 if (product == null) {
434 throw new NullPointerException("product is null"); //NOI18N
435 } else if (session == null) {
437 throw new NullPointerException("session is null"); //NOI18N
441 Object object = this.getValueFromSession(product, session, HTTP_PARAM_CHOOSE);
443 // Is the object null?
444 if (object == null) {
446 this.getLogger().debug(MessageFormat.format("Returning empty string for product={0} ...", product.getName())); //NOI18N
451 this.getLogger().trace(MessageFormat.format("object={0} - CALLED!", object)); //NOI18N
453 // Cast to string and return it
454 return (String) object;
458 * Handler for amount from request or session
460 * @param product Product instance
461 * @param request Request instance
462 * @param session Session instance
463 * @return Amount as string
466 public String handleAmountFromRequestSession (final Product product, final HttpServletRequest request, final HttpSession session) {
468 this.getLogger().trace(MessageFormat.format("product={0},request={1},session={2} - CALLED!", product, request, session)); //NOI18N
470 // Is product and session set?
471 if (product == null) {
473 throw new NullPointerException("product is null"); //NOI18N
474 } else if (request == null) {
476 throw new NullPointerException("request is null"); //NOI18N
477 } else if (session == null) {
479 throw new NullPointerException("session is null"); //NOI18N
485 // Check request method
486 if (!"POST".equals(request.getMethod())) { //NOI18N
487 // Not POST, so get from session
488 return this.getAmountFromSession(product, session);
489 } else if (this.handleChooseFromRequestSession(product, request, session).isEmpty()) {
491 this.clearSessionAttribute(product, session, HTTP_PARAM_AMOUNT);
492 this.getLogger().debug(MessageFormat.format("Unsetting for product={0} in session, returning zero ...", product.getName())); //NOI18N
496 // Get attribute from request
497 object = request.getParameter(String.format(HTTP_PARAM_MASK, HTTP_PARAM_AMOUNT, product.getName()));
500 if (object instanceof String) {
501 // Try to parse it to integer
503 Integer value = Integer.valueOf((String) object);
504 } catch (final NumberFormatException ex) {
506 this.getLogger().warn(ex);
510 // Then set it in session
511 this.setValueInSession(product, session, HTTP_PARAM_AMOUNT, object);
514 return (String) object;
518 this.getLogger().trace("Calling getAmountFromSession() ..."); //NOI18N
520 // Get attribute from session
521 return this.getAmountFromSession(product, session);
525 * Handler for choosen (checkbox) from request or session
527 * @param product Product instance
528 * @param request Request instance
529 * @param session Session instance
530 * @return Amount as string
533 public String handleChooseFromRequestSession (final Product product, final HttpServletRequest request, final HttpSession session) {
535 this.getLogger().trace(MessageFormat.format("product={0},request={1},session={2} - CALLED!", product, request, session)); //NOI18N
537 // Is product and session set?
538 if (product == null) {
540 throw new NullPointerException("product is null"); //NOI18N
541 } else if (request == null) {
543 throw new NullPointerException("request is null"); //NOI18N
544 } else if (session == null) {
546 throw new NullPointerException("session is null"); //NOI18N
552 // Check request method
553 if (!"POST".equals(request.getMethod())) { //NOI18N
554 // Not POST, so get from session
555 return this.getChooseFromSession(product, session);
556 } else if (this.isProductOrdered(product, session)) {
557 // Product is ordered
558 return this.getChooseFromSession(product, session);
561 // Get reqzest element
562 object = request.getParameter(String.format(HTTP_PARAM_MASK, HTTP_PARAM_CHOOSE, product.getName()));
563 this.getLogger().debug(MessageFormat.format("product={0},object={1}", product.getName(), object)); //NOI18N
566 if (object == null) {
568 this.getLogger().debug(MessageFormat.format("Unsetting session for product={0} ...", product.getName())); //NOI18N
569 this.clearSessionAttribute(product, session, HTTP_PARAM_CHOOSE);
570 this.clearSessionAttribute(product, session, HTTP_PARAM_AMOUNT);
572 // Return empty string
576 // Then set it in session
577 this.setValueInSession(product, session, HTTP_PARAM_CHOOSE, object);
579 // Cast to string and return it
580 this.getLogger().debug(MessageFormat.format("product={0} - Returning {1} ...", product.getName(), object)); //NOI18N
581 return (String) object;
585 * Some "getter" for choosen (checkbox) from session
587 * @param product Product instance
588 * @param request Request instance
589 * @param session Session instance
590 * @return Amount as string
593 public String getPrintableChoosenFromRequestSession (final Product product, final HttpServletRequest request, final HttpSession session) {
595 this.getLogger().trace(MessageFormat.format("product={0},request={1},session={2} - CALLED!", product, request, session)); //NOI18N
597 // Is product and session set?
598 if (product == null) {
600 throw new NullPointerException("product is null"); //NOI18N
601 } else if (request == null) {
603 throw new NullPointerException("request is null"); //NOI18N
604 } else if (session == null) {
606 throw new NullPointerException("session is null"); //NOI18N
610 String choosen = this.handleChooseFromRequestSession(product, request, session);
611 this.getLogger().debug(MessageFormat.format("product={0},choosen={1}", product.getName(), choosen)); //NOI18N
614 assert(choosen instanceof String): "choosen is null"; //NOI18N
617 if (choosen.isEmpty()) {
623 String amount = this.handleAmountFromRequestSession(product, request, session);
624 this.getLogger().debug(MessageFormat.format("product={0},amount={1}", product.getName(), amount)); //NOI18N
627 assert(amount instanceof String): "amount is null"; //NOI18N
630 if (amount.isEmpty() || "0".equals(amount)) { //NOI18N
631 // Choosen, but no amount
640 * Some "getter" for total price of position from request or session.
641 * Single price and amount is multiplyed.
643 * @param product Product instance
644 * @param request Request instance
645 * @param session Session instance
646 * @return Amount as string
649 public float getTotalPositionPriceFromRequestSession (final Product product, final HttpServletRequest request, final HttpSession session) {
651 this.getLogger().trace(MessageFormat.format("product={0},request={1},session={2} - CALLED!", product, request, session)); //NOI18N
653 // Is product and session set?
654 if (product == null) {
656 throw new NullPointerException("product is null"); //NOI18N
657 } else if (request == null) {
659 throw new NullPointerException("request is null"); //NOI18N
660 } else if (session == null) {
662 throw new NullPointerException("session is null"); //NOI18N
666 String choosen = this.handleChooseFromRequestSession(product, request, session);
667 this.getLogger().debug(MessageFormat.format("product={0},choosen={1}", product.getName(), choosen)); //NOI18N
670 assert(choosen instanceof String): "choosen is null"; //NOI18N
673 if (choosen.isEmpty()) {
675 this.getLogger().debug(MessageFormat.format("product={0},choosen={1} - returning zero ...", product.getName(), choosen)); //NOI18N
680 String amount = this.handleAmountFromRequestSession(product, request, session);
681 this.getLogger().debug(MessageFormat.format("product={0},amount={1}", product.getName(), amount)); //NOI18N
684 assert(amount instanceof String): "amount is null"; //NOI18N
687 if (amount.isEmpty() || "0".equals(amount)) { //NOI18N
689 this.getLogger().debug(MessageFormat.format("product={0},amount={1} - returning zero ...", product.getName(), amount)); //NOI18N
694 Integer value = null;
698 // Get amount as integer
699 value = Integer.valueOf(amount);
700 } catch (final NumberFormatException e) {
702 throw new IllegalArgumentException(e);
706 float price = (product.getPrice() * value);
709 this.getLogger().trace(MessageFormat.format("product={0},price={1} - EXIT!", product.getName(), price)); //NOI18N
711 // Then multiply it with price
716 * Checks whether the given product is choosen, request overules session.
718 * @param product Product instance
719 * @param request Request instance
720 * @param session Session instance
721 * @return Whether the product is choosen
724 public boolean isProductChoosen (final Product product, final HttpServletRequest request, final HttpSession session) {
726 this.getLogger().trace(MessageFormat.format("product={0},request={1},session={2} - CALLED!", product, request, session)); //NOI18N
728 // Is product and session set?
729 if (product == null) {
731 throw new NullPointerException("product is null"); //NOI18N
732 } else if (request == null) {
734 throw new NullPointerException("request is null"); //NOI18N
735 } else if (session == null) {
737 throw new NullPointerException("session is null"); //NOI18N
741 String choosen = this.handleChooseFromRequestSession(product, request, session);
742 this.getLogger().debug(MessageFormat.format("product={0},choosen={1}", product.getName(), choosen)); //NOI18N
745 assert(choosen instanceof String): "choosen is null"; //NOI18N
747 // Is it not choosen?
748 if (choosen.isEmpty()) {
754 String amount = this.handleAmountFromRequestSession(product, request, session);
757 assert(amount instanceof String): "amount is not set"; //NOI18N
760 this.getLogger().trace(MessageFormat.format("amount={0} - EXIT!", amount)); //NOI18N
762 // Must not be empty and not 0
763 return (!amount.isEmpty() && !"0".equals(amount)); //NOI18N
767 * Calculates total price of all choosen products
769 * @param request Request instance
770 * @param session Session instance
771 * @return Total price of all choosen products
774 public float calculateTotalPrice (final HttpServletRequest request, final HttpSession session) {
776 this.getLogger().trace(MessageFormat.format("request={0},session={1} - CALLED!", request, session)); //NOI18N
778 // Is product and session set?
779 if (request == null) {
781 throw new NullPointerException("request is null"); //NOI18N
782 } else if (session == null) {
784 throw new NullPointerException("session is null"); //NOI18N
788 float totalPrice = 0.00f;
791 Iterator<Map.Entry<String, Product>> iterator = this.getProductsIterator();
793 // Walk through all products
794 while (iterator.hasNext()) {
796 Map.Entry<String, Product> entry = iterator.next();
798 // Get product instance
799 Product product = entry.getValue();
802 if (product.isChoosen()) {
803 // Then add product's total price
804 this.getLogger().debug(MessageFormat.format("Calling getTotalPositionPriceFromRequestSession({0},request,session) ...", product.getName())); //NOI18N
805 totalPrice += this.getTotalPositionPriceFromRequestSession(product, request, session);
807 this.getLogger().debug(MessageFormat.format("product={0},totalPrice={1}", product.getName(), totalPrice)); //NOI18N
811 this.getLogger().trace(MessageFormat.format(" totalPrice={0} - EXIT!", totalPrice)); //NOI18N
813 // Return total price
818 * Calculates total amount of all choosen products
820 * @param request Request instance
821 * @param session Session instance
822 * @return Total amount of all choosen products
825 public int calculateTotalAmount (final HttpServletRequest request, final HttpSession session) {
827 this.getLogger().trace(MessageFormat.format("request={0},session={1} - CALLED!", request, session)); //NOI18N
829 // Is product and session set?
830 if (request == null) {
832 throw new NullPointerException("request is null"); //NOI18N
833 } else if (session == null) {
835 throw new NullPointerException("session is null"); //NOI18N
842 Iterator<Map.Entry<String, Product>> iterator = this.getProductsIterator();
844 // Walk through all products
845 while (iterator.hasNext()) {
847 Map.Entry<String, Product> entry = iterator.next();
849 // Get product instance
850 Product product = entry.getValue();
853 if (product.isChoosen()) {
854 // Then add ordered amount
855 this.getLogger().debug(MessageFormat.format("Counting {0} ...", product.getName())); //NOI18N
858 String amount = this.getAmountFromSession(product, session);
861 this.getLogger().debug(MessageFormat.format("amount={0}", amount)); //NOI18N
862 totalAmount += Integer.valueOf(amount);
864 this.getLogger().debug(MessageFormat.format("product={0},totalAmount={1}", product.getName(), totalAmount)); //NOI18N
868 this.getLogger().trace(MessageFormat.format("totalAmount={0} - EXIT!", totalAmount)); //NOI18N
870 // Return total price
875 * Some "getter" for HTML code 'checked="checked"' if the product is choosen
877 * @param product Product instance
878 * @param request Request instance
879 * @param session Session instance
880 * @return Whether the product is choosen
883 public String getCheckedHtmlFromProduct (final Product product, final HttpServletRequest request, final HttpSession session) {
885 this.getLogger().trace(MessageFormat.format("product={0},request={1},session={2} - CALLED!", product, request, session)); //NOI18N
887 // Is product and session set?
888 if (product == null) {
890 throw new NullPointerException("product is null"); //NOI18N
891 } else if (request == null) {
893 throw new NullPointerException("request is null"); //NOI18N
894 } else if (session == null) {
896 throw new NullPointerException("session is null"); //NOI18N
899 // First let's check if the product is choosen
900 if (this.isProductChoosen(product, request, session)) {
902 this.getLogger().trace("Returning checked=\"checked\" - EXIT!"); //NOI18N
905 return "checked=\"checked\""; //NOI18N
908 this.getLogger().trace("Returning empty string - EXIT!"); //NOI18N
916 * Some "getter" for HTML code 'disabled="disabled"' for e.g. submit buttons
918 * @param request Request instance
919 * @param session Session instance
920 * @return Whether the product is choosen
923 public String getDisabledHtmlFromSession (final HttpServletRequest request, final HttpSession session) {
925 this.getLogger().trace(MessageFormat.format("request={0},session={1} - CALLED!", request, session)); //NOI18N
927 // Is product and session set?
928 if (request == null) {
930 throw new NullPointerException("request is null"); //NOI18N
931 } else if (session == null) {
933 throw new NullPointerException("session is null"); //NOI18N
936 // Is something selected?
937 if (this.calculateTotalAmount(request, session) > 0) {
939 this.getLogger().trace("Returning empty string - EXIT!"); //NOI18N
941 // Something has been choosen
945 this.getLogger().trace("Returning disabled=\"disabled\" - EXIT!"); //NOI18N
947 // Nothing choosen yet
948 return "disabled=\"disabled\""; //NOI18N
953 * Marks given product as ordered in session
955 * @param product Product to mark as ordered
956 * @param session Session instance
959 public void markProductAsOrdered(final Product product, final HttpSession session) {
961 this.getLogger().trace(MessageFormat.format("product={0},session={1} - CALLED!", product, session)); //NOI18N
963 // Is product and session set?
964 if (product == null) {
966 throw new NullPointerException("product is null"); //NOI18N
967 } else if (session == null) {
969 throw new NullPointerException("session is null"); //NOI18N
972 // Mark it as ordered by setting flag
973 this.getLogger().debug(MessageFormat.format("Marking product={0} as ordered.", product.getName())); //NOI18N
974 this.setValueInSession(product, session, SESSION_ORDERED, "true"); //NOI18N
977 this.getLogger().trace("EXIT!"); //NOI18N
981 * Unmarks given product as ordered in session
983 * @param product Product to unmark as ordered
984 * @param session Session instance
987 public void unmarkProductAsOrdered(final Product product, final HttpSession session) {
989 this.getLogger().trace(MessageFormat.format("product={0},session={1} - CALLED!", product, session)); //NOI18N
991 // Is product and session set?
992 if (product == null) {
994 throw new NullPointerException("product is null"); //NOI18N
995 } else if (session == null) {
997 throw new NullPointerException("session is null"); //NOI18N
1000 // Mark it as ordered by setting flag
1001 this.getLogger().debug(MessageFormat.format("Unmarking product={0} as ordered.", product.getName())); //NOI18N
1002 this.clearSessionAttribute(product, session, SESSION_ORDERED);
1005 this.getLogger().trace("EXIT!"); //NOI18N
1009 * Some getter for printable value from session or an empty string for null.
1011 * @param session Session instance
1012 * @param key Key to get
1013 * @return Value from key, empty string for null
1016 public Object getPrintableValeFromSession (final HttpSession session, final String key) {
1018 this.getLogger().trace(MessageFormat.format("session={0},key={1} - CALLED", session, key));
1020 // Are both parameter not null?
1021 if (session == null) {
1023 throw new NullPointerException("session is null");
1024 } else if (key == null) {
1026 throw new NullPointerException("key is null");
1030 Object value = this.getValueFromSession(session, key);
1033 this.getLogger().debug(MessageFormat.format("value={0}", value));
1036 this.getLogger().trace(MessageFormat.format("Calling this.convertNullToEmpty({0}) ... - EXIT!", value));
1038 // Return actual value
1039 return this.convertNullToEmpty(value);