2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-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.xacml.custom;
23 import com.att.research.xacml.api.Identifier;
24 import com.att.research.xacml.std.IdentifierImpl;
25 import com.att.research.xacml.std.datatypes.DataTypes;
26 import com.att.research.xacmlatt.pdp.policy.FunctionDefinition;
27 import com.att.research.xacmlatt.pdp.policy.FunctionDefinitionFactory;
28 import com.att.research.xacmlatt.pdp.std.StdFunctions;
30 import java.lang.reflect.Field;
31 import java.lang.reflect.Modifier;
32 import java.util.HashMap;
35 import org.onap.policy.common.logging.flexlogger.FlexLogger;
36 import org.onap.policy.common.logging.flexlogger.Logger;
37 import org.onap.policy.xacml.pdp.std.functions.FunctionDefinitionCustomRegexpMatch;
39 public class OnapFunctionDefinitionFactory extends FunctionDefinitionFactory {
40 private static Logger logger = FlexLogger.getLogger(OnapFunctionDefinitionFactory.class);
41 private static Map<Identifier, FunctionDefinition> mapFunctionDefinitions = new HashMap<>();
42 private static boolean needMapInit = true;
44 public static final Identifier ID_FUNCTION_CUSTOM_REGEXP_MATCH =
45 new IdentifierImpl("org.onap.function.regex-match");
47 private static final FunctionDefinition FD_CUSTOM_REGEXP_MATCH =
48 new FunctionDefinitionCustomRegexpMatch<>(ID_FUNCTION_CUSTOM_REGEXP_MATCH, DataTypes.DT_STRING);
50 private static void register(final FunctionDefinition functionDefinition) {
51 mapFunctionDefinitions.put(functionDefinition.getId(), functionDefinition);
54 private static void initMap() {
56 synchronized (mapFunctionDefinitions) {
59 final Field[] declaredFields = StdFunctions.class.getDeclaredFields();
60 for (final Field field : declaredFields) {
61 if (Modifier.isStatic(field.getModifiers()) && field.getName().startsWith(StdFunctions.FD_PREFIX)
62 && FunctionDefinition.class.isAssignableFrom(field.getType())
63 && Modifier.isPublic(field.getModifiers())) {
65 register((FunctionDefinition) (field.get(null)));
66 } catch (final IllegalAccessException ex) {
67 logger.error(ex.getMessage() + ex);
72 // Our custom function
74 // register(FunctionDefinitionCustomRegexpMatch);
75 register(FD_CUSTOM_REGEXP_MATCH);
80 public OnapFunctionDefinitionFactory() {
85 public FunctionDefinition getFunctionDefinition(final Identifier functionId) {
86 return mapFunctionDefinitions.get(functionId);