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