- private void processTypeDef(final TypeDefinition<?> leafTypeDef, final JSONObject property) throws JSONException {
- if (leafTypeDef instanceof BinaryTypeDefinition) {
- processBinaryType((BinaryTypeDefinition) leafTypeDef, property);
- } else if (leafTypeDef instanceof BitsTypeDefinition) {
- processBitsType((BitsTypeDefinition) leafTypeDef, property);
- } else if (leafTypeDef instanceof EnumTypeDefinition) {
- processEnumType((EnumTypeDefinition) leafTypeDef, property);
- } else if (leafTypeDef instanceof IdentityrefTypeDefinition) {
- property.putOpt(TYPE_KEY,
- ((IdentityrefTypeDefinition) leafTypeDef).getIdentity().getQName().getLocalName());
- } else if (leafTypeDef instanceof StringTypeDefinition) {
- processStringType((StringTypeDefinition) leafTypeDef, property);
- } else if (leafTypeDef instanceof UnionTypeDefinition) {
- processUnionType((UnionTypeDefinition) leafTypeDef, property);
- } else {
- String jsonType = jsonTypeFor(leafTypeDef);
- if (jsonType == null) {
- jsonType = "object";
+ private String processTypeDef(final TypeDefinition<?> leafTypeDef, final DataSchemaNode node,
+ final JSONObject property, final SchemaContext schemaContext) throws JSONException {
+ final String jsonType;
+ if (leafTypeDef.getDefaultValue() == null) {
+ if (leafTypeDef instanceof BinaryTypeDefinition) {
+ jsonType = processBinaryType(property);
+
+ } else if (leafTypeDef instanceof BitsTypeDefinition) {
+ jsonType = processBitsType((BitsTypeDefinition) leafTypeDef, property);
+
+ } else if (leafTypeDef instanceof EnumTypeDefinition) {
+ jsonType = processEnumType((EnumTypeDefinition) leafTypeDef, property);
+
+ } else if (leafTypeDef instanceof IdentityrefTypeDefinition) {
+ final String name = topLevelModule.getName();
+ jsonType = name + ":" + ((IdentityrefTypeDefinition) leafTypeDef).getIdentity().getQName().getLocalName();
+
+ } else if (leafTypeDef instanceof StringTypeDefinition) {
+ jsonType = processStringType(leafTypeDef, property, node.getQName().getLocalName());
+
+ } else if (leafTypeDef instanceof UnionTypeDefinition) {
+ jsonType = processUnionType((UnionTypeDefinition) leafTypeDef, property, schemaContext, node);
+
+ } else if (leafTypeDef instanceof EmptyTypeDefinition) {
+ jsonType = UNIQUE_EMPTY_IDENTIFIER;
+
+ } else if (leafTypeDef instanceof LeafrefTypeDefinition) {
+ return processLeafRef(node, property, schemaContext, leafTypeDef);
+
+ } else if (leafTypeDef instanceof BooleanTypeDefinition) {
+ jsonType = "true";
+
+ } else if (leafTypeDef instanceof DecimalTypeDefinition) {
+ jsonType = String.valueOf(((DecimalTypeDefinition) leafTypeDef).getRangeConstraints()
+ .iterator().next().getMin());
+
+ } else if (leafTypeDef instanceof IntegerTypeDefinition) {
+ jsonType = String.valueOf(((IntegerTypeDefinition) leafTypeDef).getRangeConstraints()
+ .iterator().next().getMin());
+
+ } else if (leafTypeDef instanceof UnsignedIntegerTypeDefinition) {
+ jsonType = String.valueOf(((UnsignedIntegerTypeDefinition) leafTypeDef).getRangeConstraints()
+ .iterator().next().getMin());
+
+ } else {
+ jsonType = OBJECT_TYPE;
+