Java Code Examples for com.sun.xml.xsom.XSComponent#visit()

The following examples show how to use com.sun.xml.xsom.XSComponent#visit() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CreateTypeInfoCompiler.java    From jsonix-schema-compiler with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public TypeInfoCompiler<T, C> visitBuiltinLeafInfo(MBuiltinLeafInfo<T, C> info) {

		final O origin = this.originated.getOrigin();

		final List<QName> simpleTypeNames = new LinkedList<QName>();
		if (origin instanceof SchemaComponentAware) {
			final XSComponent component = ((SchemaComponentAware) origin).getSchemaComponent();
			if (component != null) {
				final CollectSimpleTypeNamesVisitor visitor = new CollectSimpleTypeNamesVisitor();
				component.visit(visitor);
				simpleTypeNames.addAll(visitor.getTypeNames());
			}
		}

		simpleTypeNames.add(info.getTypeName());

		for (QName candidateName : simpleTypeNames) {
			final TypeInfoCompiler<T, C> typeInfoCompiler = XSD_TYPE_MAPPING.get(candidateName);
			if (typeInfoCompiler != null) {
				return typeInfoCompiler;
			}
		}
		return null;
	}
 
Example 2
Source File: CreateTypeInfoProducer.java    From jsonix-schema-compiler with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public TypeInfoProducer<T, C> visitBuiltinLeafInfo(MBuiltinLeafInfo<T, C> info) {

		final O origin = this.originated.getOrigin();

		final List<QName> simpleTypeNames = new LinkedList<QName>();
		if (origin instanceof SchemaComponentAware) {
			final XSComponent component = ((SchemaComponentAware) origin).getSchemaComponent();
			if (component != null) {
				final CollectSimpleTypeNamesVisitor visitor = new CollectSimpleTypeNamesVisitor();
				component.visit(visitor);
				simpleTypeNames.addAll(visitor.getTypeNames());
			}
		}

		simpleTypeNames.add(info.getTypeName());

		for (QName candidateName : simpleTypeNames) {
			final TypeInfoProducer<T, C> typeInfoProducer = XSD_TYPE_MAPPING.get(candidateName);
			if (typeInfoProducer != null) {
				return typeInfoProducer;
			}
		}
		return null;
	}
 
Example 3
Source File: XJCCMElementTypeRefOrigin.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public XJCCMElementTypeRefOrigin(CElementPropertyInfo source,
		CTypeRef typeRef) {
	super(source, typeRef);
	final XSComponent schemaComponent = source.getSchemaComponent();
	if (schemaComponent != null) {
		final FindXSElementDeclVisitor visitor = new FindXSElementDeclVisitor(
				typeRef.getTagName());
		schemaComponent.visit(visitor);
		this.component = visitor.getElementDecl();
	} else {
		this.component = null;
	}
}
 
Example 4
Source File: CreateTypeInfoDelaration.java    From jsonix-schema-compiler with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void appendEnumerationValues(final TypeInfoCompiler<T, C> typeInfoCompiler) {
	if (info instanceof MOriginated) {
		MOriginated<?> originated = (MOriginated<?>) info;
		Object origin = originated.getOrigin();
		if (origin instanceof SchemaComponentAware) {
			final XSComponent component = ((SchemaComponentAware) origin).getSchemaComponent();
			if (component != null) {

				final CollectEnumerationValuesVisitor collectEnumerationValuesVisitor = new CollectEnumerationValuesVisitor();
				component.visit(collectEnumerationValuesVisitor);
				final List<XmlString> enumerationValues = collectEnumerationValuesVisitor.getValues();
				if (enumerationValues != null && !enumerationValues.isEmpty()) {
					final JSArrayLiteral values = mappingCompiler.getCodeModel().array();
					boolean valueSupported = true;
					for (XmlString enumerationValue : enumerationValues) {
						final JSAssignmentExpression value = typeInfoCompiler.createValue(this.mappingCompiler,
								enumerationValue);
						if (value == null) {
							valueSupported = false;
							break;
						} else {
							values.append(value);
						}
					}
					if (valueSupported) {
						options.append(mappingCompiler.getNaming().values(), values);
					}
				}
			}
		}
	}
}
 
Example 5
Source File: CreateTypeInfoSchema.java    From jsonix-schema-compiler with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public JsonSchemaBuilder visitBuiltinLeafInfo(MBuiltinLeafInfo<T, C> typeInfo) {
	final TypeInfoProducer<T, C> typeInfoCompiler = mappingCompiler.getTypeInfoProducer(info, typeInfo);
	final JsonSchemaBuilder typeInfoSchemaRef = typeInfoCompiler.createTypeInfoSchemaRef(mappingCompiler);

	if (info instanceof MOriginated) {
		MOriginated<?> originated = (MOriginated<?>) info;
		Object origin = originated.getOrigin();
		if (origin instanceof SchemaComponentAware) {
			final XSComponent component = ((SchemaComponentAware) origin).getSchemaComponent();
			if (component != null) {

				final CollectEnumerationValuesVisitor collectEnumerationValuesVisitor = new CollectEnumerationValuesVisitor();
				component.visit(collectEnumerationValuesVisitor);
				final List<XmlString> enumerationValues = collectEnumerationValuesVisitor.getValues();
				if (enumerationValues != null && !enumerationValues.isEmpty()) {
					final JsonSchemaBuilder values = new JsonSchemaBuilder();
					boolean valueSupported = true;
					for (XmlString enumerationValue : enumerationValues) {
						final JsonValue value = typeInfoCompiler.createValue(this.mappingCompiler,
								enumerationValue);
						if (value == null) {
							valueSupported = false;
							break;
						} else {
							values.addEnum(value);
						}
					}
					if (valueSupported) {
						final JsonSchemaBuilder typeInfoSchemaRefWithEnums = new JsonSchemaBuilder();
						typeInfoSchemaRefWithEnums.addAllOf(typeInfoSchemaRef);
						typeInfoSchemaRefWithEnums.addAllOf(values);
						return typeInfoSchemaRefWithEnums;
					}
				}
			}
		}
	}
	return typeInfoSchemaRef;
}
 
Example 6
Source File: TypeUtils.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public static List<QName> getTypeNames(XSComponent component) {
	Validate.notNull(component);
	final SimpleTypeVisitor visitor = new SimpleTypeVisitor();
	component.visit(visitor);
	return visitor.getTypeNames();
}