a677fb84911dd02b4c9967380d9c6cace8d81854
[policy/engine.git] / ECOMP-PDP / src / test / java / org / openecomp / policy / pdp / test / custom / CustomDataTypeFactory.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ECOMP-PDP
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.policy.pdp.test.custom;
22
23 import java.util.HashMap;
24 import java.util.Map;
25
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;
30
31 public class CustomDataTypeFactory extends DataTypeFactory {
32         private static final Map<Identifier,DataType<?>> mapIdentifiersToDataTypes      = new HashMap<Identifier,DataType<?>>();
33         private static boolean mapNeedsInit                                                                                             = true;
34         
35         public static final DataTypePrivateKey                          DT_PRIVATEKEY                           = DataTypePrivateKey.newInstance();
36         public static final DataTypePublicKey                           DT_PUBLICKEY                            = DataTypePublicKey.newInstance();
37         
38         private static void registerDataType(DataType<?> dataType) {
39                 if (dataType != null && dataType.getId() != null) {
40                         mapIdentifiersToDataTypes.put(dataType.getId(), dataType);
41                 }
42         }
43         
44         private static void initMap() {
45                 if (mapNeedsInit) {
46                         synchronized(mapIdentifiersToDataTypes) {
47                                 if (mapNeedsInit) {
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);
65                                         //
66                                         // These are the custom data types!
67                                         //
68                                         registerDataType(DT_PRIVATEKEY);
69                                         registerDataType(DT_PUBLICKEY);
70                                         //
71                                         // Done
72                                         //
73                                         mapNeedsInit    = false;
74                                 }
75                         }
76                 }
77         }
78
79         public CustomDataTypeFactory() {
80                 initMap();
81         }
82
83         @Override
84         public DataType<?> getDataType(Identifier dataTypeId) {
85                 return mapIdentifiersToDataTypes.get(dataTypeId);
86         }
87
88 }