All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.hisrc.jsonix.configuration.ElementInfoConfiguration Maven / Gradle / Ivy

There is a newer version: 2.3.9
Show newest version
package org.hisrc.jsonix.configuration;

import java.text.MessageFormat;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import javax.xml.namespace.QName;

import org.apache.commons.lang3.Validate;
import org.hisrc.jsonix.analysis.ModelInfoGraphAnalyzer;
import org.hisrc.jsonix.context.JsonixContext;
import org.jvnet.jaxb2_commons.xml.bind.model.MElementInfo;
import org.jvnet.jaxb2_commons.xml.bind.model.MPackageInfo;
import org.slf4j.Logger;

@XmlRootElement(name = ElementInfoConfiguration.LOCAL_ELEMENT_NAME)
@XmlType(propOrder = {})
public class ElementInfoConfiguration {

	public static final String LOCAL_ELEMENT_NAME = "element";

	private QName name;

	@XmlAttribute
	public QName getName() {
		return name;
	}

	public void setName(QName name) {
		this.name = name;
	}

	public  MElementInfo findElementInfo(
			JsonixContext context, ModelInfoGraphAnalyzer analyzer,
			MPackageInfo packageInfo) {
		Validate.notNull(context);
		Validate.notNull(analyzer);
		Validate.notNull(packageInfo);
		final Logger logger = Validate.notNull(context).getLoggerFactory()
				.getLogger(ElementInfoConfiguration.class.getName());

		final QName name = getName();
		if (name == null) {
			logger.warn(MessageFormat
					.format("The [{0}] element does not provide the required [name] attribute and will be ignored.",
							LOCAL_ELEMENT_NAME));
			return null;
		} else {
			final MElementInfo typeInfo = analyzer
					.findElementInfoByQName(name);
			if (typeInfo == null) {
				logger.warn(MessageFormat
						.format("Could not find the element [{0}] in the package [{1}], the declaring [{2}] element will be ignored.",
								name, packageInfo.getPackageName(),
								LOCAL_ELEMENT_NAME));
			}
			return typeInfo;
		}

	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy