properties.put(prop.getName(), prop);
}
}
return null;
} else if(next.isAbstractCompositeCollectionMapping()) {
CompositeCollectionMapping mapping = (CompositeCollectionMapping)next;
XMLField field = (XMLField)mapping.getField();
XPathFragment frag = field.getXPathFragment();
String propName = getNameForFragment(frag);
//for paths, there may already be an existing property
prop = properties.get(propName);
if(prop == null) {
prop = new Property();
prop.setName(propName);
}
Property nestedProperty = getNestedPropertyForFragment(frag, prop);
nestedProperty.setType(JsonType.ARRAY);
nestedProperty.setItem(new Property());
nestedProperty.getItem().setRef(getReferenceForDescriptor((XMLDescriptor)mapping.getReferenceDescriptor()));
//populateProperties(nestedProperty.getItem().getProperties(), (XMLDescriptor)mapping.getReferenceDescriptor());
} else if(next.isAbstractCompositeDirectCollectionMapping()) {
DirectCollectionMapping mapping = (DirectCollectionMapping)next;
XMLField field = (XMLField)mapping.getField();
XPathFragment frag = field.getXPathFragment();
List<String> enumeration = null;
if(mapping.getValueConverter() instanceof JAXBEnumTypeConverter) {
JAXBEnumTypeConverter conv = (JAXBEnumTypeConverter)mapping.getValueConverter();
enumeration = new ArrayList<String>();
for(Object nextValue: conv.getAttributeToFieldValues().values()) {
enumeration.add(nextValue.toString());
}
}
String propertyName = getNameForFragment(frag);
if(frag.nameIsText()) {
propertyName = (String)this.contextProperties.get(MarshallerProperties.JSON_VALUE_WRAPPER);
}
if(frag.isAttribute() && this.attributePrefix != null) {
propertyName = attributePrefix + propertyName;
}
prop = properties.get(propertyName);
if(prop == null) {
prop = new Property();
prop.setName(propertyName);
}
Property nestedProperty = getNestedPropertyForFragment(frag, prop);
nestedProperty.setType(JsonType.ARRAY);
nestedProperty.setItem(new Property());
if(enumeration != null) {
nestedProperty.getItem().setEnumeration(enumeration);
}
nestedProperty.getItem().setType(getJsonTypeForJavaType(mapping.getAttributeElementClass()));
return prop;
} else if(next instanceof BinaryDataCollectionMapping) {
BinaryDataCollectionMapping mapping = (BinaryDataCollectionMapping)next;
XMLField field = (XMLField)mapping.getField();
XPathFragment frag = field.getXPathFragment();
String propertyName = getNameForFragment(frag);
if(frag.nameIsText()) {
propertyName = (String)this.contextProperties.get(MarshallerProperties.JSON_VALUE_WRAPPER);
}
if(frag.isAttribute() && this.attributePrefix != null) {
propertyName = attributePrefix + propertyName;
}
prop = properties.get(propertyName);
if(prop == null) {
prop = new Property();
prop.setName(propertyName);
}
Property nestedProperty = getNestedPropertyForFragment(frag, prop);
nestedProperty.setType(JsonType.ARRAY);
nestedProperty.setItem(new Property());
if(mapping.shouldInlineBinaryData()) {
nestedProperty.getItem().setType(JsonType.STRING);
} else {
nestedProperty.getItem().setAnyOf(getXopIncludeProperties());
}
return prop;
}
} else {
if(next.isAbstractDirectMapping()) {
//handle direct mapping
DirectMapping directMapping = (DirectMapping)next;
XMLField field = (XMLField)directMapping.getField();
XPathFragment frag = field.getXPathFragment();
List<String> enumeration = null;
if(directMapping.getConverter() instanceof JAXBEnumTypeConverter) {
JAXBEnumTypeConverter conv = (JAXBEnumTypeConverter)directMapping.getConverter();
enumeration = new ArrayList<String>();
for(Object nextValue: conv.getAttributeToFieldValues().values()) {
enumeration.add(nextValue.toString());
}
}
String propertyName = getNameForFragment(frag);
if(frag.nameIsText()) {
propertyName = Constants.VALUE_WRAPPER;
if(this.contextProperties != null) {
String valueWrapper = (String) this.contextProperties.get(MarshallerProperties.JSON_VALUE_WRAPPER);
if(valueWrapper != null) {
propertyName = valueWrapper;
}
}
}
if(frag.isAttribute() && this.attributePrefix != null) {
propertyName = attributePrefix + propertyName;
}
prop = properties.get(propertyName);
if(prop == null) {
prop = new Property();
prop.setName(propertyName);
}
Property nestedProperty = getNestedPropertyForFragment(frag, prop);
if(enumeration != null) {
nestedProperty.setEnumeration(enumeration);
}
if(directMapping instanceof BinaryDataMapping) {
BinaryDataMapping binaryMapping = (BinaryDataMapping)directMapping;
if(binaryMapping.shouldInlineBinaryData() || binaryMapping.isSwaRef()) {
nestedProperty.setType(JsonType.STRING);
} else {
if(this.xopIncludeProp == null) {
initXopIncludeProp();
}
nestedProperty.setAnyOf(this.xopIncludeProp);
}
} else {
nestedProperty.setType(getJsonTypeForJavaType(directMapping.getAttributeClassification()));
}
return prop;
} else if(next instanceof ObjectReferenceMapping) {
ObjectReferenceMapping mapping = (ObjectReferenceMapping)next;
Set<XMLField> sourceFields = mapping.getSourceToTargetKeyFieldAssociations().keySet();
XMLDescriptor reference = (XMLDescriptor) mapping.getReferenceDescriptor();
for(XMLField nextField: sourceFields) {
XPathFragment frag = nextField.getXPathFragment();
String propName = getNameForFragment(frag);
XMLField targetField = (XMLField) mapping.getSourceToTargetKeyFieldAssociations().get(nextField);
Class type = getTypeForTargetField(targetField, reference);
prop = properties.get(propName);
if(prop == null) {
prop = new Property();
prop.setName(propName);
}
Property nestedProperty = getNestedPropertyForFragment(frag, prop);
//nestedProperty.setType(JsonType.ARRAY);
//nestedProperty.setItem(new Property());
nestedProperty.setType(getJsonTypeForJavaType(type));
if(!properties.containsKey(prop.getName())) {
properties.put(prop.getName(), prop);
}
}
return null;
} else if(next.isAbstractCompositeObjectMapping()) {
CompositeObjectMapping mapping = (CompositeObjectMapping)next;
XMLDescriptor nextDescriptor = (XMLDescriptor)mapping.getReferenceDescriptor();
XMLField field = (XMLField)mapping.getField();
XPathFragment firstFragment = field.getXPathFragment();
String propName = getNameForFragment(firstFragment);
prop = properties.get(propName);
if(prop == null) {
prop = new Property();