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=========================================================
22 package org.onap.aai.schemaif.oxm;
24 import com.google.common.base.CaseFormat;
26 import java.util.HashMap;
29 import org.eclipse.persistence.dynamic.DynamicType;
30 import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
31 import org.eclipse.persistence.mappings.DatabaseMapping;
32 import org.eclipse.persistence.oxm.mappings.XMLAnyCollectionMapping;
33 import org.eclipse.persistence.oxm.mappings.XMLAnyObjectMapping;
34 import org.onap.aai.schemaif.SchemaProviderException;
35 import org.onap.aai.schemaif.definitions.PropertySchema;
36 import org.onap.aai.schemaif.definitions.VertexSchema;
38 public class FromOxmVertexSchema extends VertexSchema {
39 public void fromOxm(String vertexType, DynamicJAXBContext jaxbContext,
40 HashMap<String, DynamicType> xmlElementLookup) throws SchemaProviderException {
42 properties = new HashMap<String, PropertySchema>();
43 annotations = new HashMap<String, String>();
45 String javaTypeName = CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, vertexType);
46 DynamicType modelObjectType = jaxbContext.getDynamicType(javaTypeName);
48 if (modelObjectType == null) {
49 // Try to lookup by xml root element by exact match
50 modelObjectType = xmlElementLookup.get(vertexType);
53 if (modelObjectType == null) {
54 // Try to lookup by xml root element by lowercase
55 modelObjectType = xmlElementLookup.get(vertexType.toLowerCase());
58 if (modelObjectType == null) {
59 // Direct lookup as java-type name
60 modelObjectType = jaxbContext.getDynamicType(vertexType);
63 if (modelObjectType == null) {
64 // Vertex isn't found in the OXM
65 throw new SchemaProviderException("Vertex " + vertexType + " not found in OXM");
69 Map<String, Object> oxmProps = modelObjectType.getDescriptor().getProperties();
70 for (Map.Entry<String, Object> entry : oxmProps.entrySet()) {
71 if (entry.getValue() instanceof String) {
72 annotations.put(entry.getKey().toLowerCase(), (String) entry.getValue());
77 for (DatabaseMapping mapping : modelObjectType.getDescriptor().getMappings()) {
78 if (mapping instanceof XMLAnyObjectMapping)
80 if (mapping instanceof XMLAnyCollectionMapping)
82 FromOxmPropertySchema propSchema = new FromOxmPropertySchema();
83 propSchema.fromOxm(mapping, modelObjectType, false);
84 properties.put(propSchema.getName().toLowerCase(), propSchema);
88 final DynamicType reservedType = jaxbContext.getDynamicType("ReservedPropNames");
89 for (DatabaseMapping mapping : reservedType.getDescriptor().getMappings()) {
90 if (mapping.isAbstractDirectMapping()) {
91 FromOxmPropertySchema propSchema = new FromOxmPropertySchema();
92 propSchema.fromOxm(mapping, reservedType, true);
93 properties.put(propSchema.getName().toLowerCase(), propSchema);