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

org.hisrc.jsonix.xml.xsom.ParticleMultiplicityCounter Maven / Gradle / Ivy

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

import java.math.BigInteger;

import org.hisrc.xml.xsom.DefaultFunctionImpl;

import com.sun.tools.xjc.model.Multiplicity;
import com.sun.xml.xsom.XSAttributeUse;
import com.sun.xml.xsom.XSParticle;
import com.sun.xml.xsom.visitor.XSTermFunction;

public class ParticleMultiplicityCounter extends
		DefaultFunctionImpl {

	public static final ParticleMultiplicityCounter INSTANCE = new ParticleMultiplicityCounter();

	private final XSTermFunction counter = MultiplicityCounterNG.INSTANCE;

	protected ParticleMultiplicityCounter() {
		super();
	}

	@Override
	public Multiplicity particle(XSParticle p) {

		Multiplicity m = p.getTerm().apply(this.counter);

		BigInteger max;
		if (m.max == null
				|| (BigInteger.valueOf(XSParticle.UNBOUNDED).equals(p
						.getMaxOccurs())))
			max = null;
		else
			max = p.getMaxOccurs();

		return Multiplicity.multiply(m,
				Multiplicity.create(p.getMinOccurs(), max));
	}

	@Override
	public Multiplicity attributeUse(XSAttributeUse use) {
		return use.isRequired() ? Multiplicity.ONE : Multiplicity.OPTIONAL;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy