2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2019 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2019 Amdocs
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=========================================================
21 package org.onap.aai.schemaif.oxm;
23 import java.util.HashMap;
26 import org.eclipse.persistence.dynamic.DynamicType;
27 import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
28 import org.eclipse.persistence.mappings.DatabaseMapping;
29 import org.eclipse.persistence.oxm.mappings.XMLAnyCollectionMapping;
30 import org.eclipse.persistence.oxm.mappings.XMLAnyObjectMapping;
31 import org.onap.aai.schemaif.SchemaProviderException;
32 import org.onap.aai.schemaif.definitions.PropertySchema;
33 import org.onap.aai.schemaif.definitions.VertexSchema;
35 import com.google.common.base.CaseFormat;
37 public class FromOxmVertexSchema extends VertexSchema {
38 public void fromOxm(String vertexType, DynamicJAXBContext jaxbContext, HashMap<String, DynamicType> xmlElementLookup) throws SchemaProviderException {
40 properties = new HashMap<String,PropertySchema>();
41 annotations = new HashMap<String,String>();
43 String javaTypeName = CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, vertexType);
44 DynamicType modelObjectType = jaxbContext.getDynamicType(javaTypeName);
46 if (modelObjectType == null) {
47 // Try to lookup by xml root element by exact match
48 modelObjectType = xmlElementLookup.get(vertexType);
51 if (modelObjectType == null) {
52 // Try to lookup by xml root element by lowercase
53 modelObjectType = xmlElementLookup.get(vertexType.toLowerCase());
56 if (modelObjectType == null) {
57 // Direct lookup as java-type name
58 modelObjectType = jaxbContext.getDynamicType(vertexType);
61 if (modelObjectType == null) {
62 // Vertex isn't found in the OXM
63 throw new SchemaProviderException("Vertex " + vertexType + " not found in OXM");
67 Map<String, Object> oxmProps = modelObjectType.getDescriptor().getProperties();
68 for (Map.Entry<String, Object> entry : oxmProps.entrySet()) {
69 if (entry.getValue() instanceof String) {
70 annotations.put(entry.getKey().toLowerCase(), (String)entry.getValue());
75 for (DatabaseMapping mapping : modelObjectType.getDescriptor().getMappings()) {
76 if (mapping instanceof XMLAnyObjectMapping)
78 if(mapping instanceof XMLAnyCollectionMapping)
80 FromOxmPropertySchema propSchema = new FromOxmPropertySchema();
81 propSchema.fromOxm(mapping, modelObjectType, false);
82 properties.put(propSchema.getName().toLowerCase(), propSchema);
86 final DynamicType reservedType = jaxbContext.getDynamicType("ReservedPropNames");
87 for (DatabaseMapping mapping : reservedType.getDescriptor().getMappings()) {
88 if (mapping.isAbstractDirectMapping()) {
89 FromOxmPropertySchema propSchema = new FromOxmPropertySchema();
90 propSchema.fromOxm(mapping, reservedType, true);
91 properties.put(propSchema.getName().toLowerCase(), propSchema);