Skip to content

Commit

Permalink
Issue #67 WIP. Still getting double allOf.allOf generated.
Browse files Browse the repository at this point in the history
  • Loading branch information
highsource committed Jul 19, 2016
1 parent 3343dd5 commit f9b631c
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.jvnet.jaxb2_commons.xml.bind.model.MElementInfo;
import org.jvnet.jaxb2_commons.xml.bind.model.MEnumLeafInfo;
import org.jvnet.jaxb2_commons.xml.bind.model.MTypeInfo;
import org.jvnet.jaxb2_commons.xml.bind.model.origin.MElementInfoOrigin;
import org.jvnet.jaxb2_commons.xml.bind.model.origin.MOriginated;

public class JsonSchemaMappingCompiler<T, C extends T> {
Expand Down Expand Up @@ -86,7 +87,7 @@ private void addElementInfos(final JsonSchemaBuilder schema) {
new JsonSchemaBuilder().addAllOf(qNameRef).addAllOf(nameConstant));

elementInfoSchema.addProperty(JsonixConstants.VALUE_PROPERTY_NAME,
getTypeInfoProducer(elementInfo, typeInfo).createTypeInfoSchemaRef(this));
typeInfo.acceptTypeInfoVisitor(new CreateTypeInfoSchema<T, C, MElementInfo<T, C>, MElementInfoOrigin>(this, elementInfo)));

elementInfoSchema.add(JsonixJsonSchemaConstants.ELEMENT_NAME_PROPERTY_NAME,
new JsonSchemaBuilder()
Expand Down Expand Up @@ -119,11 +120,6 @@ private void addClassInfoSchemas(final JsonSchemaBuilder schema) {
}
}

public <M extends MOriginated<O>, O> JsonSchemaBuilder createTypeInfoSchemaRef(M originated,
MTypeInfo<T, C> typeInfo) {
return getTypeInfoProducer(originated, typeInfo).createTypeInfoSchemaRef(this);
}

public <M extends MOriginated<O>, O> TypeInfoProducer<T, C> getTypeInfoProducer(M originated,
MTypeInfo<T, C> typeInfo) {
return typeInfo.acceptTypeInfoVisitor(new CreateTypeInfoProducer<T, C, O>(originated));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,6 @@ private JsonSchemaBuilder createPossiblyCollectionTypeSchema(MPropertyInfo<T, C>
}

private <M extends MOriginated<O>, O> JsonSchemaBuilder createTypeSchema(M originated, MTypeInfo<T, C> typeInfo) {
return mappingCompiler.getTypeInfoProducer(originated, typeInfo).createTypeInfoSchemaRef(mappingCompiler);
return typeInfo.acceptTypeInfoVisitor(new CreateTypeInfoSchema<T, C, MOriginated<O>, O>(mappingCompiler, originated));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import org.jvnet.jaxb2_commons.xml.bind.model.MEnumLeafInfo;
import org.jvnet.jaxb2_commons.xml.bind.model.MTypeInfo;

import com.sun.xml.xsom.XmlString;

public class EnumLeafInfoProducer<T, C extends T> extends PackagedTypeInfoProducer<T, C> {

private MEnumLeafInfo<T, C> enumLeafInfo;
Expand All @@ -36,8 +38,7 @@ public JsonSchemaBuilder compile(JsonSchemaMappingCompiler<T, C> mappingCompiler
final JsonSchemaBuilder baseTypeInfoSchema = baseTypeInfoProducer.createTypeInfoSchemaRef(mappingCompiler);
typeInfoSchema = new JsonSchemaBuilder();
typeInfoSchema.addAllOf(baseTypeInfoSchema);



final JsonSchemaBuilder enumsTypeInfoSchema = new JsonSchemaBuilder();

boolean valuesSupported = true;
Expand Down Expand Up @@ -66,4 +67,20 @@ public JsonSchemaBuilder compile(JsonSchemaMappingCompiler<T, C> mappingCompiler

return typeInfoSchema;
}

@Override
public JsonValue createValue(JsonSchemaMappingCompiler<T, C> mappingCompiler, String item) {
final MTypeInfo<T, C> baseTypeInfo = enumLeafInfo.getBaseTypeInfo();
final TypeInfoProducer<T, C> baseTypeInfoProducer = mappingCompiler.getTypeInfoProducer(enumLeafInfo,
baseTypeInfo);
return baseTypeInfoProducer.createValue(mappingCompiler, item);
}

@Override
public JsonValue createValue(JsonSchemaMappingCompiler<T, C> mappingCompiler, XmlString item) {
final MTypeInfo<T, C> baseTypeInfo = enumLeafInfo.getBaseTypeInfo();
final TypeInfoProducer<T, C> baseTypeInfoProducer = mappingCompiler.getTypeInfoProducer(enumLeafInfo,
baseTypeInfo);
return baseTypeInfoProducer.createValue(mappingCompiler, item);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -253,23 +253,6 @@ private JSMemberExpression createNameExpression(final QName name, final String d
}
}

public TypeInfoCompiler<T, C> getTypeInfoCompiler(MClassInfo<T, C> classInfo, MTypeInfo<T, C> typeInfo) {
return getTypeInfoCompiler((MOriginated<MClassInfoOrigin>) classInfo, typeInfo);
}

public TypeInfoCompiler<T, C> getTypeInfoCompiler(MEnumLeafInfo<T, C> enumLeafInfo, MTypeInfo<T, C> typeInfo) {
return getTypeInfoCompiler((MOriginated<MEnumLeafInfoOrigin>) enumLeafInfo, typeInfo);
}

public TypeInfoCompiler<T, C> getTypeInfoCompiler(MPropertyInfo<T, C> propertyInfo, MTypeInfo<T, C> typeInfo) {
return getTypeInfoCompiler((MOriginated<MPropertyInfoOrigin>) propertyInfo, typeInfo);
}

public <M extends MElementTypeInfo<T, C, O>, O> TypeInfoCompiler<T, C> getTypeInfoCompiler(M elementInfo,
MTypeInfo<T, C> typeInfo) {
return getTypeInfoCompiler((MOriginated<O>) elementInfo, typeInfo);
}

public <O> TypeInfoCompiler<T, C> getTypeInfoCompiler(MOriginated<O> originated, MTypeInfo<T, C> typeInfo) {

return typeInfo.acceptTypeInfoVisitor(new CreateTypeInfoCompiler<T, C, O>(originated));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import org.jvnet.jaxb2_commons.xml.bind.model.MClassInfo;
import org.jvnet.jaxb2_commons.xml.bind.model.MClassTypeInfo;
import org.jvnet.jaxb2_commons.xml.bind.model.MPropertyInfo;
import org.jvnet.jaxb2_commons.xml.bind.model.origin.MClassInfoOrigin;
import org.jvnet.jaxb2_commons.xml.bind.model.origin.MOriginated;

public class ClassInfoCompiler<T, C extends T> extends PackagedTypeInfoCompiler<T, C> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import org.jvnet.jaxb2_commons.xml.bind.model.MEnumConstantInfo;
import org.jvnet.jaxb2_commons.xml.bind.model.MEnumLeafInfo;
import org.jvnet.jaxb2_commons.xml.bind.model.MTypeInfo;
import org.jvnet.jaxb2_commons.xml.bind.model.origin.MEnumLeafInfoOrigin;
import org.jvnet.jaxb2_commons.xml.bind.model.origin.MOriginated;

import com.sun.xml.xsom.XmlString;

Expand Down Expand Up @@ -59,7 +61,8 @@ public JSObjectLiteral compile(MappingCompiler<T, C> mappingCompiler) {
final JSArrayLiteral values = codeModel.array();
boolean valuesSupported = true;
for (MEnumConstantInfo<T, C> enumConstantInfo : enumLeafInfo.getConstants()) {
final JSAssignmentExpression value = baseTypeInfoCompiler.createValue(mappingCompiler, enumConstantInfo.getLexicalValue());
final JSAssignmentExpression value = baseTypeInfoCompiler.createValue(mappingCompiler,
enumConstantInfo.getLexicalValue());
if (value == null) {
valuesSupported = false;
break;
Expand Down

0 comments on commit f9b631c

Please sign in to comment.