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=========================================================
21 package org.onap.policy.pdp.test.custom;
23 import java.util.HashMap;
26 import com.att.research.xacml.api.DataType;
27 import com.att.research.xacml.api.DataTypeFactory;
28 import com.att.research.xacml.api.Identifier;
29 import com.att.research.xacml.std.datatypes.DataTypes;
31 public class CustomDataTypeFactory extends DataTypeFactory {
32 private static final Map<Identifier,DataType<?>> mapIdentifiersToDataTypes = new HashMap<>();
33 private static boolean mapNeedsInit = true;
35 public static final DataTypePrivateKey DT_PRIVATEKEY = DataTypePrivateKey.newInstance();
36 public static final DataTypePublicKey DT_PUBLICKEY = DataTypePublicKey.newInstance();
38 private static void registerDataType(DataType<?> dataType) {
39 if (dataType != null && dataType.getId() != null) {
40 mapIdentifiersToDataTypes.put(dataType.getId(), dataType);
44 private static void initMap() {
46 synchronized(mapIdentifiersToDataTypes) {
48 registerDataType(DataTypes.DT_ANYURI);
49 registerDataType(DataTypes.DT_BASE64BINARY);
50 registerDataType(DataTypes.DT_BOOLEAN);
51 registerDataType(DataTypes.DT_DATE);
52 registerDataType(DataTypes.DT_DATETIME);
53 registerDataType(DataTypes.DT_DAYTIMEDURATION);
54 registerDataType(DataTypes.DT_DNSNAME);
55 registerDataType(DataTypes.DT_DOUBLE);
56 registerDataType(DataTypes.DT_HEXBINARY);
57 registerDataType(DataTypes.DT_INTEGER);
58 registerDataType(DataTypes.DT_IPADDRESS);
59 registerDataType(DataTypes.DT_RFC822NAME);
60 registerDataType(DataTypes.DT_STRING);
61 registerDataType(DataTypes.DT_TIME);
62 registerDataType(DataTypes.DT_X500NAME);
63 registerDataType(DataTypes.DT_XPATHEXPRESSION);
64 registerDataType(DataTypes.DT_YEARMONTHDURATION);
66 // These are the custom data types!
68 registerDataType(DT_PRIVATEKEY);
69 registerDataType(DT_PUBLICKEY);
79 public CustomDataTypeFactory() {
84 public DataType<?> getDataType(Identifier dataTypeId) {
85 return mapIdentifiersToDataTypes.get(dataTypeId);