2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Modified Copyright (C) 2018 Samsung Electronics Co., Ltd.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.xacml.custom;
24 import com.att.research.xacml.api.Identifier;
25 import com.att.research.xacml.std.IdentifierImpl;
26 import com.att.research.xacml.std.datatypes.DataTypes;
27 import com.att.research.xacmlatt.pdp.policy.FunctionDefinition;
28 import com.att.research.xacmlatt.pdp.policy.FunctionDefinitionFactory;
29 import com.att.research.xacmlatt.pdp.std.StdFunctions;
31 import java.lang.reflect.Field;
32 import java.lang.reflect.Modifier;
33 import java.util.HashMap;
36 import org.onap.policy.common.logging.flexlogger.FlexLogger;
37 import org.onap.policy.common.logging.flexlogger.Logger;
38 import org.onap.policy.xacml.pdp.std.functions.FunctionDefinitionCustomRegexpMatch;
40 public class OnapFunctionDefinitionFactory extends FunctionDefinitionFactory {
41 private static Logger logger = FlexLogger.getLogger(OnapFunctionDefinitionFactory.class);
42 private static Map<Identifier, FunctionDefinition> mapFunctionDefinitions = new HashMap<>();
43 private static boolean needMapInit = true;
45 public static final Identifier ID_FUNCTION_CUSTOM_REGEXP_MATCH =
46 new IdentifierImpl("org.onap.function.regex-match");
48 private static final FunctionDefinition FD_CUSTOM_REGEXP_MATCH =
49 new FunctionDefinitionCustomRegexpMatch<>(ID_FUNCTION_CUSTOM_REGEXP_MATCH, DataTypes.DT_STRING);
51 private static void register(final FunctionDefinition functionDefinition) {
52 mapFunctionDefinitions.put(functionDefinition.getId(), functionDefinition);
55 private static void initMap() {
57 synchronized (mapFunctionDefinitions) {
60 final Field[] declaredFields = StdFunctions.class.getDeclaredFields();
61 for (final Field field : declaredFields) {
62 registerFunctionDefinition(field);
64 register(FD_CUSTOM_REGEXP_MATCH);
69 private static void registerFunctionDefinition(Field field) {
70 if (Modifier.isStatic(field.getModifiers()) && field.getName().startsWith(StdFunctions.FD_PREFIX)
71 && FunctionDefinition.class.isAssignableFrom(field.getType())
72 && Modifier.isPublic(field.getModifiers())) {
74 register((FunctionDefinition) (field.get(null)));
75 } catch (final IllegalAccessException ex) {
76 logger.error(ex.getMessage() + ex);
81 public OnapFunctionDefinitionFactory() {
86 public FunctionDefinition getFunctionDefinition(final Identifier functionId) {
87 return mapFunctionDefinitions.get(functionId);