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

org.xdef.util.XDChecker Maven / Gradle / Ivy

There is a newer version: 42.2.13
Show newest version
package org.xdef.util;

import java.util.Properties;
import org.xdef.XDBuilder;
import org.xdef.XDConstants;
import org.xdef.XDDocument;
import org.xdef.XDFactory;
import org.xdef.XDParseResult;
import org.xdef.XDPool;
import org.xdef.msg.XDEF;
import org.xdef.proc.XXElement;
import org.xdef.sys.ArrayReporter;
import org.xdef.sys.SRuntimeException;
import org.xdef.sys.SUtils;

/** Provides checking of X-definition types and values.
 * @author Vaclav Trojan
 */
public class XDChecker {

//	private final Class[] _classes;
	private final String _options;
	private final String _methods;
	private final String _declarations;
	private final Properties _properties;

	/** Constructor of XDChecker.*/
	public XDChecker() {
//		_classes = null;
		_methods = null;
		_declarations = null;
		_options = null;
		_properties = new Properties();
	}

	/** Constructor of XDChecker.
	 * @param classes array with external classes or null.
	 * @param methods string with methods or null.
	 * (see "methods attribute in X-definitions").
	 * @param declarations string with declaration of variables,
	 * types and methods or null.
	 * @param options string with options list null.
	 * @throws SRuntimeException if there is an error.
	 */
	public XDChecker(Class[] classes,
		String methods,
		String declarations,
		String options) throws SRuntimeException {
//		_classes = classes;
		_methods = methods;
		_declarations = declarations;
		_options = options;
		_properties = new Properties();
		// just check if all parameters are correct
		String xdef =
"\n";
		if (_declarations != null || _methods != null) {
			xdef +=	"\n";
			if (_methods != null) {
				xdef +=	"external method {\n" + _methods + "\n}\n";
			}
			if (_declarations != null) {
				xdef += _declarations +"\n";
			}
			xdef += "\n";
		}
		xdef += " 0) {
//				xb.setExternals(_classes);
//			}
			String xdef =
"";
		if (_declarations != null || _methods != null) {
			xdef +=	"\n";
			if (_methods != null) {
				xdef +=	"external method {\n" + _methods + "\n}\n";
			}
			if (_declarations != null) {
				xdef += _declarations +"\n";
			}
			xdef += "\n";
		}
		xdef += "\n";
			xb.setSource(xdef);
			xp = xb.compileXD();
			if (ar.errors()) {
				result = XDFactory.createParseResult(value);
				result.addReports(ar);
				return result;
			}
		} catch (Exception ex) {
			result = XDFactory.createParseResult(value);
			result.addReports(ar);
			return result;
		}
		XDDocument xd = xp.createXDDocument();
		XXElement xel = xd.prepareRootXXElement("a", true);
		if (value == null) {
			result = XDFactory.createParseResult(null);
			if (xel.getXMElement().getAttr("a").getOccurence().isRequired()) {
				//Missing required attribute &{0}
				result.error(XDEF.XDEF526, "a");
			} else {
				result = XDFactory.createParseResult("");
//				result.setSourceBuffer(null);
			}
		} else {
			xel.addAttribute("a", value);
			result = xel.getParseResult();
			if (result == null) {
				result = XDFactory.createParseResult(value);
			}
		}
		if (xd.errors()) {
			result.addReports(
				(ArrayReporter) xd.getReporter().getReportWriter());
		}
		return result;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy