:::::::::::::: exp.xsd :::::::::::::: :::::::::::::: exp/X2J.cd :::::::::::::: import java.util.*; import java.io.*; // ************************************************************************* // The following section has been generated automatically by the XML to Java // conversion application. // ************************************************************************* XMLDoc = " String [ "encoding" "=" String ] "?>" "". Exp = ">" " E "". E : lookahead {{3}} S | lookahead {{3}} C. XMLpositiveInteger = int. S = "type" "=" "S" ">" [ "" XMLpositiveInteger "" ] "" int "". C = "type" "=" "C" ">" [ "" XMLpositiveInteger "" ] "" Op "" List(argsListUnit). argsListUnit = " Exp "". Op = String. Main = . Preprocessor = . List(S) ~ {S}. visitor ValidateVisitor = . // ************************************************************************* // End of automatically generated section. // ************************************************************************* :::::::::::::: exp/X2Jdoc.beh :::::::::::::: XMLDoc { public static XMLDoc XMLparse(String in) throws Exception {{ XMLDoc doc = parse(Preprocessor.process(in)); String errors = doc.validate(); if (!errors.equals("")) throw new ParseException(errors); return doc; }} public static XMLDoc XMLparse(InputStream in) throws Exception {{ return XMLparse(Preprocessor.process(readContent(in))); }} public static XMLDoc XMLparse(Reader in) throws Exception {{ return XMLparse(Preprocessor.process(readContent(in))); }} private static String readContent(InputStream in) throws Exception {{ String text = ""; try { byte buf[] = new byte[1000]; while (true) { int size = in.read(buf); if (size <= 0) break; String line = new String(buf, 0, size); if (!text.equals("")) text = text + "\n"; text = text + line; } in.close(); return text; } catch (IOException e) { throw new Exception("Error in reading input"); } }} private static String readContent(Reader in) throws Exception {{ BufferedReader r = new BufferedReader(in); String text = ""; try { while (true) { String line = r.readLine(); if (line == null) break; if (!text.equals("")) text = text + "\n"; text = text + line; } r.close(); return text; } catch (IOException e) { throw new Exception("Error in reading input"); } }} public String validate() bypassing -> *,tail,* to * (ValidateVisitor); } // end of class XMLDoc :::::::::::::: exp/X2Jpreprocessor.beh :::::::::::::: Preprocessor { public static String process(String in) {{ return in; }} } // end of class Preprocessor :::::::::::::: exp/X2Jvalidate.beh :::::::::::::: ValidateVisitor { {{ private String errors = ""; }} before S {{ if (host.get_depth() != null && host.get_depth().get_value() < 1) addError("Value (" + host.get_depth().get_value() + ") of element 'depth' is < 1"); }} before C {{ if (host.get_depth() != null && host.get_depth().get_value() < 1) addError("Value (" + host.get_depth().get_value() + ") of element 'depth' is < 1"); if (host.get_op() != null && new String("+*").indexOf("" + host.get_op().get_value() + "") < 0) addError("Value (" + host.get_op().get_value() + ") of element 'op' is not one of the enumerated values"); }} public String get_return_val() {{ return errors; }} private void addError(String errorText) {{ errors = errors + "\n" + errorText; }} } // end of class ValidateVisitor :::::::::::::: exp/exp.beh :::::::::::::: Main { public static void main(String args[]) throws Exception {{ XMLDoc d = XMLDoc.XMLparse(System.in); d.print(); System.out.println(""); }} } XMLDoc { public void print() bypassing -> *,tail,* to * (DisplayVisitor); }