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