/** * The pattern we have is to generate the schema through an implementation of thie schema() * function which will be invoked by the client. */ public static void generate(IndentWriter writer) throws IOException { writer.write("namespace NDDL {\n"); writer.indent(); // Implement expected initialization hooks writer.write("// Boot-strap code to initialize schema\n"); writer.write( "extern \"C\" SchemaId loadSchema(const SchemaId& schema,const RuleSchemaId& ruleSchema)\n{\n"); writer.indent(); String modelName = ModelAccessor.getModelName(); if (modelName == null) throw new RuntimeException("Failed to set model name. Bug in NddlCompiler"); writer.write("SchemaId id = schema;\n"); // Register Constraints writer.write("// Register Constraints\n"); for (Iterator it = s_constraintRegistrations.iterator(); it.hasNext(); ) { String constraint = (String) it.next(); writer.write(constraint + ";\n"); } writer.write("// Invoke commands to populate schema with type definitions\n"); // Iterate over all type definition commands for (int i = 0; i < s_objectTypeCommands.size(); i++) { writer.write("id->" + s_objectTypeCommands.elementAt(i) + ";\n"); } // Iterate over all type definition commands for (int i = 0; i < s_commands.size(); i++) { writer.write("id->" + s_commands.elementAt(i) + ";\n"); } // Force allocation of type factories. This should do a mapping for external names // to internal writer.write("// Force allocation of model specific type factories\n"); // Allocate Factories writer.write("// Allocate factories\n"); for (Iterator it = s_factoryAllocations.iterator(); it.hasNext(); ) { String command = (String) it.next(); writer.write(command); } // Iterate over all rules and allocate singletons - this registers rules writer.write("// Allocate rules\n"); Set ruleNames = RuleWriter.getRules(); for (Iterator it = ruleNames.iterator(); it.hasNext(); ) { String ruleName = (String) it.next(); writer.write("ruleSchema->registerRule((new " + ruleName + "())->getId());\n"); } writer.write("return id;\n"); writer.unindent(); writer.write("}\n\n"); writer.unindent(); writer.write("}\n"); }