2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.policy.drools.pooling.extractor;
23 import java.lang.reflect.InvocationTargetException;
24 import java.lang.reflect.Method;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
29 * Used to extract an object by invoking a method on the container.
31 public class MethodExtractor implements Extractor {
33 private static final Logger logger = LoggerFactory.getLogger(MethodExtractor.class);
36 * Method to invoke to extract the contained object.
38 private final Method method;
43 * @param method method to invoke to extract the contained object
45 public MethodExtractor(Method method) {
50 public Object extract(Object object) {
52 return method.invoke(object);
54 } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
55 logger.warn("cannot invoke {} on {}", method.getName(), object.getClass(), e);