]> git.mxchange.org Git - pizzaservice-war.git/blob - src/java/org/mxchange/pizzaapplication/BasePizzaServiceSystem.java
Continued with project:
[pizzaservice-war.git] / src / java / org / mxchange / pizzaapplication / BasePizzaServiceSystem.java
1 /*
2  * Copyright (C) 2015 Roland Haeder
3  *
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.
8  *
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.
13  *
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/>.
16  */
17 package org.mxchange.pizzaapplication;
18
19 import java.text.MessageFormat;
20 import javax.servlet.ServletContext;
21 import org.mxchange.jcore.BaseFrameworkSystem;
22
23 /**
24  * A general class for whole pizza application.
25  *
26  * @author Roland Haeder
27  */
28 public class BasePizzaServiceSystem extends BaseFrameworkSystem {
29         /**
30          * Initializes properties from given servlet configuration
31          * @param context Servlet context instance
32          */
33         protected void initProperties (final ServletContext context) {
34                 // Trace message
35                 this.getLogger().trace(MessageFormat.format("context={0} - CALLED!", context)); //NOI18N
36
37                 // context shall not be null
38                 if (null == context) {
39                         // Abort here
40                         throw new NullPointerException("context is null");
41                 }
42
43                 // We need some properties that needs to be set
44                 for (final String name : this.getPropertyNames()) {
45                         // Debug log
46                         this.getLogger().debug(MessageFormat.format("name={0}", name)); //NOI18N
47
48                         // Get value
49                         String value = context.getInitParameter(name);
50
51                         // Debug message
52                         this.getLogger().debug(MessageFormat.format("value={0}", value)); //NOI18N
53
54                         // Is it null?
55                         if (null == value) {
56                                 // Value is null
57                                 throw new NullPointerException(MessageFormat.format("value for {0} is null, maybe invalid context parameter?", name)); //NOI18N
58                         } else if (name.equals("database.backend.storagepath")) { //NOI18N
59                                 // Need to expand this path
60                                 value = context.getRealPath(String.format("../../%s", value.trim())); //NOI18N
61                         }
62
63                         // Debug log
64                         this.getLogger().debug(MessageFormat.format("{0}={1}", name, value)); //NOI18N
65
66                         // Set property
67                         this.setProperty(name, value);
68                 }
69
70                 // Trace message
71                 this.getLogger().trace("EXIT!"); //NOI18N
72         }
73 }