org.hisrc.jsonix.definition.MappingDependency Maven / Gradle / Ivy
package org.hisrc.jsonix.definition;
import java.util.Collection;
import java.util.HashSet;
import org.apache.commons.lang3.Validate;
import org.hisrc.jsonix.analysis.DefaultInfoVertexVisitor;
import org.hisrc.jsonix.analysis.ElementInfoVertex;
import org.hisrc.jsonix.analysis.InfoVertex;
import org.hisrc.jsonix.analysis.InfoVertexVisitor;
import org.hisrc.jsonix.analysis.PropertyInfoVertex;
import org.hisrc.jsonix.analysis.TypeInfoVertex;
import org.jvnet.jaxb2_commons.xml.bind.model.MClassInfo;
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.MPackageInfo;
import org.jvnet.jaxb2_commons.xml.bind.model.MPropertyInfo;
import org.jvnet.jaxb2_commons.xml.bind.model.MTypeInfo;
import org.jvnet.jaxb2_commons.xml.bind.model.MTypeInfoVisitor;
import org.jvnet.jaxb2_commons.xml.bind.model.util.DefaultTypeInfoVisitor;
public class MappingDependency {
private final MPackageInfo packageInfo;
private final Collection> classInfos = new HashSet>();
private final Collection> propertyInfos = new HashSet>();
private final Collection> enumLeafInfos = new HashSet>();
private final Collection> elementInfos = new HashSet>();
public MappingDependency(MPackageInfo packageInfo) {
this.packageInfo = Validate.notNull(packageInfo);
}
public MPackageInfo getPackageInfo() {
return packageInfo;
}
public Collection> getClassInfos() {
return classInfos;
}
public Collection> getElementInfos() {
return elementInfos;
}
public Collection> getEnumLeafInfos() {
return enumLeafInfos;
}
public Collection> getPropertyInfos() {
return propertyInfos;
}
private void addTypeInfo(MTypeInfo typeInfo) {
Validate.notNull(typeInfo);
typeInfo.acceptTypeInfoVisitor(typeInfoAdder);
}
private void addElementInfo(MElementInfo elementInfo) {
Validate.notNull(elementInfo);
this.elementInfos.add(elementInfo);
}
private void addClassInfo(MClassInfo classInfo) {
Validate.notNull(classInfo);
Validate.isTrue(this.packageInfo.equals(classInfo.getPackageInfo()));
this.classInfos.add(classInfo);
}
private void addEnumLeafInfo(MEnumLeafInfo enumLeafInfo) {
Validate.notNull(enumLeafInfo);
Validate.isTrue(this.packageInfo.equals(enumLeafInfo.getPackageInfo()));
this.enumLeafInfos.add(enumLeafInfo);
}
private void addPropertyInfo(MPropertyInfo propertyInfo) {
Validate.notNull(propertyInfo);
Validate.isTrue(this.packageInfo.equals(propertyInfo.getClassInfo()
.getPackageInfo()));
this.propertyInfos.add(propertyInfo);
}
public void addInfoVertex(InfoVertex vertex) {
Validate.notNull(vertex);
vertex.accept(infoVertexAdder);
}
private final InfoVertexVisitor infoVertexAdder = new DefaultInfoVertexVisitor() {
@Override
public Void visitTypeInfoVertex(TypeInfoVertex vertex) {
addTypeInfo(vertex.getTypeInfo());
return null;
}
@Override
public Void visitElementInfoVertex(ElementInfoVertex vertex) {
addElementInfo(vertex.getElementInfo());
return null;
}
@Override
public Void visitPropertyInfoVertex(PropertyInfoVertex vertex) {
addPropertyInfo(vertex.getPropertyInfo());
return null;
}
};
private final MTypeInfoVisitor typeInfoAdder = new DefaultTypeInfoVisitor() {
@Override
public Void visitClassInfo(MClassInfo info) {
addClassInfo(info);
return null;
}
@Override
public Void visitEnumLeafInfo(MEnumLeafInfo info) {
addEnumLeafInfo(info);
return null;
}
};
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy