type = CoreClassConstants.STRING;
}
nestedProperty.getItem().setType(getJsonTypeForJavaType(type));
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.isSelfFragment()) {
propertyName = Constants.VALUE_WRAPPER;
if(this.contextProperties != null) {
String valueWrapper = (String) this.contextProperties.get(JAXBContextProperties.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);
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) {
enumeration = getEnumeration((DatabaseMapping)directMapping);
}
String propertyName = getNameForFragment(frag);
if(frag.nameIsText()) {
propertyName = Constants.VALUE_WRAPPER;
if(this.contextProperties != null) {
String valueWrapper = (String) this.contextProperties.get(JAXBContextProperties.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 = CoreClassConstants.STRING;
if(reference != null) {
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 prop;
} else if(next.isAbstractCompositeObjectMapping()) {
CompositeObjectMapping mapping = (CompositeObjectMapping)next;
XMLDescriptor nextDescriptor = (XMLDescriptor)mapping.getReferenceDescriptor();
XMLField field = (XMLField)mapping.getField();
XPathFragment firstFragment = field.getXPathFragment();
if(firstFragment.isSelfFragment() || firstFragment.nameIsText()) {
if(nextDescriptor != null) {
populateProperties(properties, nextDescriptor);
}
} else {
String propName = getNameForFragment(firstFragment);
prop = properties.get(propName);
if(prop == null) {
prop = new Property();
prop.setName(propName);
}
//prop.setType(JsonType.OBJECT);
prop.setName(propName);
Property nestedProperty = getNestedPropertyForFragment(firstFragment, prop);
XMLDescriptor referenceDescriptor = (XMLDescriptor)mapping.getReferenceDescriptor();
if(referenceDescriptor != null && referenceDescriptor.hasInheritance()) {
//handle inheritence
//schema.setAnyOf(new Property[descriptor.getInheritancePolicy().getAllChildDescriptors().size()]);
List<ClassDescriptor> descriptors = getAllDescriptorsForInheritance(referenceDescriptor);
Property[] props = new Property[descriptors.size()];