2d1cfa1aa7315ab930f9189d5fd55c3e8678aef5
[aaf/cadi.git] / core / src / main / java / com / att / cadi / ServletContextAccess.java
1 /*******************************************************************************\r
2  * ============LICENSE_START====================================================\r
3  * * org.onap.aaf\r
4  * * ===========================================================================\r
5  * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
6  * * ===========================================================================\r
7  * * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * * you may not use this file except in compliance with the License.\r
9  * * You may obtain a copy of the License at\r
10  * * \r
11  *  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * * \r
13  *  * Unless required by applicable law or agreed to in writing, software\r
14  * * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * * See the License for the specific language governing permissions and\r
17  * * limitations under the License.\r
18  * * ============LICENSE_END====================================================\r
19  * *\r
20  * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
21  * *\r
22  ******************************************************************************/\r
23 package com.att.cadi;\r
24 import java.util.Enumeration;\r
25 import javax.servlet.FilterConfig;\r
26 import javax.servlet.ServletContext;\r
27 \r
28 import com.att.cadi.config.Config;\r
29 \r
30 public class ServletContextAccess extends PropAccess {\r
31 \r
32         private ServletContext context;\r
33 \r
34         public ServletContextAccess(FilterConfig filterConfig) {\r
35                 super(filterConfig); // protected contstructor... does not have "init" called.\r
36                 context = filterConfig.getServletContext();\r
37 \r
38                 for(Enumeration<?> en = filterConfig.getInitParameterNames();en.hasMoreElements();) {\r
39                         String name = (String)en.nextElement();\r
40                         setProperty(name, filterConfig.getInitParameter(name));\r
41                 }\r
42                 init(getProperties());\r
43                 Config.getDME2Props(this);\r
44         }\r
45 \r
46         /* (non-Javadoc)\r
47          * @see com.att.cadi.PropAccess#log(com.att.cadi.Access.Level, java.lang.Object[])\r
48          */\r
49         @Override\r
50         public void log(Level level, Object... elements) {\r
51                 if(willLog(level)) {\r
52                         StringBuilder sb = buildMsg(level, elements);\r
53                         context.log(sb.toString());\r
54                 }\r
55         }\r
56 \r
57         /* (non-Javadoc)\r
58          * @see com.att.cadi.PropAccess#log(java.lang.Exception, java.lang.Object[])\r
59          */\r
60         @Override\r
61         public void log(Exception e, Object... elements) {\r
62                 StringBuilder sb = buildMsg(Level.ERROR, elements);\r
63                 context.log(sb.toString(),e);\r
64         }\r
65 \r
66         public ServletContext context() {\r
67                 return context;\r
68         }\r
69 }\r