Re-encrypt drools-pdp properties
[policy/drools-pdp.git] / feature-pooling-dmaap / src / main / java / org / onap / policy / drools / pooling / extractor / MethodExtractor.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP
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 package org.onap.policy.drools.pooling.extractor;
22
23 import java.lang.reflect.InvocationTargetException;
24 import java.lang.reflect.Method;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27
28 /**
29  * Used to extract an object by invoking a method on the container.
30  */
31 public class MethodExtractor implements Extractor {
32
33     private static final Logger logger = LoggerFactory.getLogger(MethodExtractor.class);
34
35     /**
36      * Method to invoke to extract the contained object.
37      */
38     private final Method method;
39
40     /**
41      * Constructor.
42      * 
43      * @param method method to invoke to extract the contained object
44      */
45     public MethodExtractor(Method method) {
46         this.method = method;
47     }
48
49     @Override
50     public Object extract(Object object) {
51         try {
52             return method.invoke(object);
53
54         } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
55             logger.warn("cannot invoke {} on {}", method.getName(), object.getClass(), e);
56             return null;
57         }
58     }
59 }