Package org.dmd.util.codegen

Examples of org.dmd.util.codegen.ImportManager


        out.close();
  }
 
  public static void formatPlaceHistoryMapper(String outdir, WebApplication app, TreeMap<CamelCaseName, Place> places) throws IOException {
        BufferedWriter   out = FileUpdateManager.instance().getWriter(outdir, app.getAppName() + "PlaceHistoryMapper.java");
        ImportManager imports = new ImportManager();
        getImports(imports,app,places);

        out.write("package " + app.getDefinedInModule().getGenPackage() + ".generated.mvw.places;\n\n");
       
        out.write("\n");
        out.write(imports.getFormattedImports());
        out.write("\n");
        out.write("@WithTokenizers({\n");
        int count = 1;
        for(Place place: places.values()){
          out.write("                    " + place.getPlaceName() + ".Tokenizer.class");
View Full Code Here


    static void dumpExtendedReferenceType(String header, String od, ExtendedReferenceTypeDefinition ertd) throws IOException, ResultException {
      String       ctn       = ertd.getName().getNameString();
      String       fieldSeparator   = ertd.getFieldSeparator();
        Iterator<Field>  fields       = null;
        ImportManager  imports      = new ImportManager();
       
      if (fieldSeparator == null)
        fieldSeparator = " ";
     
      if (header == null)
        header = "";
     
//        BufferedWriter out = new BufferedWriter(new FileWriter(od + "/" + ctn + ".java"));
        BufferedWriter out = FileUpdateManager.instance().getWriter(od, ctn + ".java");
       
//DebugInfo.debug("Generating: " + od + "/" + ctn + ".java");
       
        fields = ertd.getField();
       
        // Determine if we have any reference fields
        boolean hasRefs = false;
        ArrayList<String> refFields = new ArrayList<String>();
        while(fields.hasNext()){
          Field field = fields.next();
          TypeDefinitionDMO type = field.getType().getObject();
         
          if (type == null){
            DebugInfo.debug("Unknown type in ExtendedReferenceTypeDefinition: " + field.getType().getObjectName());
            System.exit(1);
          }

          if (type.getIsRefType()){
            hasRefs = true;
            refFields.add(field.getName());
          }
        }
       
        out.write(header);
       
        out.write("package " + ertd.getDefinedIn().getSchemaPackage() + ".generated.types;\n\n");
       
        String nameBaseImport = ertd.getExtendedReferenceClass().getIsNamedBy().getType().getDefinedIn().getSchemaPackage() + ".generated.types.DmcType";
        String nameImport = ertd.getExtendedReferenceClass().getIsNamedBy().getType().getName().getNameString() + "SV";
        String staticNameType = ertd.getExtendedReferenceClass().getIsNamedBy().getType().getName().getNameString() + "STATIC";

        imports.addImport(nameBaseImport + nameImport, "Name type");
        imports.addImport(ertd.getExtendedReferenceClass().getIsNamedBy().getType().getPrimitiveType(), "Name type");
       
        imports.addImport(nameBaseImport + staticNameType, "Static type for name");
       
        imports.addImport(ertd.getExtendedReferenceClass().getDmoImport(), "Object based constructor");

        imports.addImport("org.dmd.dmc.DmcExtendedReferenceIF", "Marker interface for extended references");

//        out.write("import java.io.Serializable;\n");
//        out.write("import org.dmd.dmc.DmcInputStreamIF;\n");
//        out.write("import org.dmd.dmc.DmcOutputStreamIF;\n");
//        out.write("import org.dmd.dmc.types.IntegerVar;\n");
       
        imports.addImport("java.io.Serializable", "Serialization support");
        imports.addImport("org.dmd.dmc.DmcInputStreamIF", "Serialization support");
        imports.addImport("org.dmd.dmc.DmcOutputStreamIF", "Serialization support");
        imports.addImport("org.dmd.dmc.types.IntegerVar", "Parsing support");
       
        if (hasRefs){
//            out.write("import org.dmd.dmc.DmcNameResolverIF;\n");
//            out.write("import org.dmd.dmc.DmcNamedObjectIF;\n");
//            out.write("import org.dmd.dmc.DmcNamedObjectREF;\n");
//            out.write("import org.dmd.dmc.DmcContainerIF;\n");
           
            imports.addImport("org.dmd.dmc.DmcNameResolverIF", "Object reference support");
            imports.addImport("org.dmd.dmc.DmcNamedObjectIF", "Object reference support");
            imports.addImport("org.dmd.dmc.DmcNamedObjectREF", "Object reference support");
            imports.addImport("org.dmd.dmc.DmcContainerIF", "Object reference support");
        }

//        out.write("import org.dmd.dmc.DmcValueException;\n\n");
       
        imports.addImport("org.dmd.dmc.DmcValueException", "Value exceptions");
       
//        out.write(getComplexTypeImports(ertd));
       
        getComplexTypeImports(ertd, imports);
       
        out.write(imports.getFormattedImports() + "\n\n");
       
        out.write("@SuppressWarnings(\"serial\")\n");

        out.write("/**\n * The " + ctn + " class.\n");
        out.write(" * This code was auto-generated and shouldn't be alterred manually.\n");
View Full Code Here

 
  ///////////////////////////////////////////////////////////////////////////
 
  void dumpMetaSchemaNew(String od) throws IOException, ResultException {
    BufferedWriter out = null;
    ImportManager    imports = new ImportManager();
   
    imports.addImport("org.dmd.dmc.DmcValueException", "To handle potential value exceptions.");
    imports.addImport("org.dmd.dms.generated.dmo.*", "Access to meta schema DMOs");

    // out = new BufferedWriter(new FileWriter(od + "/MetaSchemaAG.java"));
    out = FileUpdateManager.instance().getWriter(od, "MetaSchemaAG.java");

//    // Strip the nameAttribute from all name types so that we don't cause
//    // problems
//    // when loading the meta schema
//    for (DmcUncheckedObject type : typeDefs.values()) {
//      type.rem("nameAttributeDef");
//      type.rem("filterAttributeDef");
//    }

    out.write(LGPL.toString());
    out.write("package org.dmd.dms;\n\n");

    out.write(imports.getFormattedImports() + "\n\n");
   
    out.write("/**\n");
    out.write("  * This class creates the basic definitions that allow for the definition of schemas.\n");
    out.write("  * Generated from: " + DebugInfo.getWhereWeAreNow() + "\n");
    out.write("  */\n");
 
View Full Code Here

              .getWriter(od, cn + "DMO.java");

          out.write(LGPL.toString());
          out.write("package org.dmd.dms.generated.dmo;\n\n");

          ImportManager imports = new ImportManager();

          imports.addImport("java.io.Serializable",
              "Serializable marker interface");
          imports.addImport("java.util.*", "Attribute info support");

          // out.write("import java.io.Serializable;\n\n");
          // out.write("import java.util.*;\n\n");

          boolean needBasicTypes = getAllMustAndMay(go, must, may);

          // HACK HACK HACK
          if (!cn.equals("DmwWrapper")) {
            // Only include if the type of an attribute has a
            // primitive type specified
            if (needBasicTypes)
              imports.addImport("org.dmd.dmc.types.*",
                  "Basic type access");
            // out.write("import org.dmd.dmc.types.*;\n");
          }
          if (cn.endsWith("RuleData")) {
            // if (needBasicTypes)
            imports.addImport("org.dmd.dmc.types.*",
                "Basic type access");
          }

          imports.addImport("org.dmd.dmc.*", "Dark matter core");
          // imports.addImport("org.dmd.dms.generated.dmo.MetaVCAG",
          // "Old validation framework - obsolete");

          // out.write("import org.dmd.dmc.*;\n");
          // out.write("import org.dmd.dms.generated.dmo.MetaVCAG;\n");

          if (cn.equals("EnumDefinition")) {
            imports.addImport("org.dmd.dms.types.*", "Enum support");
            // out.write("import org.dmd.dms.types.*;\n");
          }

          imports.addImport("org.dmd.dms.generated.types.*",
              "Generated type access");

          // out.write("import org.dmd.dms.generated.types.*;\n");

          if (hasAnyEnumAttributes(go)) {
            imports.addImport("org.dmd.dms.generated.enums.*",
                "Has enum attributes");
            // out.write("import org.dmd.dms.generated.enums.*;\n");
          }

          out.write(imports.getFormattedImports() + "\n");

          out.write("\n");

          out.write("/**\n");

 
View Full Code Here

   * @throws ResultException
   * @throws IOException
   */
  public void dumpBaseImplementations(String schemaName, String schemaPackage, TreeMap<String,DmcUncheckedObject> ruleDefs, TreeMap<String,DmcUncheckedObject> ruleCategoryDefs, String rulesDir) throws ResultException, IOException{
   
    ImportManager factoryImports = new ImportManager();
   
    for(DmcUncheckedObject rule: ruleDefs.values()){
        String name = GenUtility.capTheName(rule.getSV("name"));
        NamedStringArray categories = rule.get("ruleCategory");
       
        String scope = rule.getSV("ruleScope");
        String type = rule.getSV("ruleType");
       
        ImportManager baseImports = new ImportManager();
        StringBuffer interfaces = new StringBuffer();
           
//        baseImports.addImport("org.dmd.dms.generated.enums.RuleScopeEnum", "Rule scope");
        baseImports.addImport("org.dmd.dms.generated.enums.RuleTypeEnum", "Rule type");
        baseImports.addImport("org.dmd.dmc.rules.RuleIF", "All rules implement this");
        baseImports.addImport("java.util.ArrayList", "To store category IDs");
        baseImports.addImport("java.util.Iterator", "To access category IDs");
        interfaces.append("RuleIF");

       
        baseImports.addImport(schemaPackage + ".generated.dmo." + name + "DataDMO", "Rule parameters object");
       
        StringBuffer categoryInit = new StringBuffer();
       
        for(String cname: categories){
          DmcUncheckedObject category = ruleCategoryDefs.get(cname);
         
          if (category == null){
            ResultException ex = new ResultException("Unknown rule category: " + cname);
            throw(ex);
          }
         
          String categoryID = category.getSV("ruleCategoryID");
          categoryInit.append("            categories.add(" + categoryID + ");\n");
           
          String ruleInterface = category.getSV("ruleInterface");
          baseImports.addImport(ruleInterface, "Required by RuleCategory " + cname);
         
          if (interfaces.length() > 0)
            interfaces.append(", ");
         
          int lastDot = ruleInterface.lastIndexOf(".");
          interfaces.append(ruleInterface.substring(lastDot + 1));
        }
       
        factoryImports.addImport(schemaPackage + ".extended.rules." + name, "The implementation of the " + name);
       
      BufferedWriter   out = FileUpdateManager.instance().getWriter(rulesDir, name + "BaseImpl.java");
     
      out.write("package " + schemaPackage + ".generated.rules;\n\n");
     
      out.write(baseImports.getFormattedImports() + "\n\n");
     
      out.write("// Generated from: " + DebugInfo.getWhereWeAreNow() + "\n");
      out.write("abstract public class " + name + "BaseImpl implements " + interfaces + " {\n\n");
     
      out.write("    static RuleScopeEnum      scope = RuleScopeEnum." + scope + ";\n");
View Full Code Here

        if (ruleType.equals("ATTRIBUTE"))
          isAttributeRule = true;
       
        NamedStringArray categories = category.get("ruleParam");
               
        ImportManager baseImports = new ImportManager();
           
        baseImports.addImport("org.dmd.dmc.rules.DmcRuleExceptionSet", "Rule type");
        baseImports.addImport("org.dmd.dmc.rules.RuleIF", "All rules implement this");
       
        StringBuffer  params = new StringBuffer();
        StringBuffer  args = new StringBuffer();
        StringBuffer  argValues = new StringBuffer();
        boolean      first = true;
       
        for(String p : categories){
          RuleParam param;
        try {
          param = new RuleParam(p);
            baseImports.addImport(param.getImportStatement(), "Required for " + param.getName());
            int lastDot = param.getImportStatement().lastIndexOf(".");
            String ptype = param.getImportStatement().substring(lastDot + 1);
           
            if (!first){
//              params.append(", ");
              args.append(", ");
              argValues.append(", ");
            }
           
            params.append("     * @param " + param.getName() + " " + param.getDescription() + "\n");
           
            args.append(ptype + param.getGenericArgs() + " " + param.getName());
           
            argValues.append(param.getName());
             
            first = false;
        } catch (DmcValueException e) {
          System.err.println(e.toString());
          e.printStackTrace();
          System.err.println(category.toOIF());
          System.exit(1);
        }
         
         
        }
       
      BufferedWriter   out = FileUpdateManager.instance().getWriter(rulesDir, name + "IF.java");
     
      out.write("package " + schemaPackage + ".generated.rulesdmo;\n\n");
     
      out.write(baseImports.getFormattedImports() + "\n\n");
     
      out.write("// Generated from: " + DebugInfo.getWhereWeAreNow() + "\n");
      out.write("public interface " + name + "IF extends RuleIF {\n\n");
     
      out.write("    /**\n");
      out.write(params.toString());
      out.write("     */\n");
      out.write("    public void execute(" + args + ") throws DmcRuleExceptionSet;\n\n");
     
      out.write("}\n\n");
     
      out.close();
     
      ///////////////////////////////////////////////////////////////////
     
//      baseImports = new ImportManager();
     
        baseImports.addImport("org.dmd.dmc.rules.DmcRuleExceptionSet", "Rule type");
        baseImports.addImport("org.dmd.dmc.rules.RuleIF", "All rules implement this");
//        baseImports.addImport("org.dmd.dmc.rules.RuleList", "Rules with flag to indicate that we've gathered info up the class hierarchy");
//        baseImports.addImport("org.dmd.dms.generated.enums.RuleTypeEnum", "To determine the type of a rule");
//        baseImports.addImport("org.dmd.dmc.rules.ClassRuleKey", "To determine the type of a rule");
//        baseImports.addImport("org.dmd.dmc.rules.AttributeRuleKey", "To determine the type of a rule");
        baseImports.addImport("java.util.ArrayList", "Storage for the rules");
//        baseImports.addImport("java.util.TreeMap", "Storage for the rules");
//        baseImports.addImport("org.dmd.dmc.rules.RuleKey", "Generic rule key");
        baseImports.addImport("org.dmd.dmc.DmcOmni", "Rule tracing support");
        baseImports.addImport("org.dmd.dmc.DmcClassInfo", "Handle to class info");
       
        if (ruleImports != null){
          for(String ri: ruleImports)
            baseImports.addImport(ri, "Additional rule import");
        }
       
        if (isAttributeRule){
            baseImports.addImport("org.dmd.dmc.rules.AttributeRuleCollection", "Attribute rule");
            baseImports.addImport("org.dmd.dmc.DmcAttributeInfo", "Organizing global attribute rules");
//            baseImports.addImport("java.util.HashMap", "Storage for the rules");
        }
        else
            baseImports.addImport("org.dmd.dmc.rules.ClassRuleCollection", "Class rule");
       
       
        out = FileUpdateManager.instance().getWriter(rulesDir, name + "RuleCollection.java");
     
      out.write("package " + schemaPackage + ".generated.rulesdmo;\n\n");
     
      out.write(baseImports.getFormattedImports() + "\n");
     
      if (isAttributeRule){
        out.write("public class " + name + "RuleCollection extends AttributeRuleCollection<" + name + "IF> {" + "\n\n");
        out.write("    public " + name + "RuleCollection(){\n");
//        out.write("        globalRules = new HashMap<DmcAttributeInfo, ArrayList<" + name + "IF>>();\n");
View Full Code Here

      else{
        if (rd.isDMOCompliant())
          continue;
      }
     
        ImportManager baseImports = new ImportManager();
        StringBuffer interfaces = new StringBuffer();
     

        baseImports.addImport("org.dmd.dms.generated.enums.RuleTypeEnum", "Rule type");
        baseImports.addImport("org.dmd.dmc.rules.RuleIF", "All rules implement this");
        baseImports.addImport("java.util.ArrayList", "To store category IDs");
        baseImports.addImport("java.util.Iterator", "To access category IDs");
        baseImports.addImport("org.dmd.dmc.DmcOmni", "To map class and attribute names to info");
        baseImports.addImport("org.dmd.dmc.DmcObject", "To support the dynamic constructor");
        baseImports.addImport("org.dmd.dmc.DmcClassInfo", "To support retrieval of rule class");
        baseImports.addImport("org.dmd.dmc.DmcAttributeInfo", "To support retrieval of attribute info");
        baseImports.addImport("org.dmd.dmc.rules.RuleKey", "To allow rule sorting");
        baseImports.addImport("org.dmd.dmc.rules.DynamicInitIF", "To allow for dynamic initialization of rule data");
        baseImports.addImport("org.dmd.dms.generated.dmo.RuleDataDMO", "To allow access to the rule data DMO");
       
        if (isAttributeRule)
            baseImports.addImport("org.dmd.dmc.rules.AttributeRuleKey", "To allow rule sorting");
        else
            baseImports.addImport("org.dmd.dmc.rules.ClassRuleKey", "To allow rule sorting");

        interfaces.append("RuleIF, DynamicInitIF");
     
        baseImports.addImport(sd.getSchemaPackage() + ".generated.dmo." + rd.getName() + "DataDMO", "Rule parameters object");
       
        StringBuffer categoryInit = new StringBuffer();
       
        for (RuleCategory rc : rd.getRuleCategory()){
          categoryInit.append("            categories.add(" + rc.getRuleCategoryID() + ");\n");
          baseImports.addImport(rc.getRuleInterface(), "The interface for the " + rc.getName() + " category");
          interfaces.append(",");
          interfaces.append(GenUtility.getClassFromImport(rc.getRuleInterface()));
        }

      BufferedWriter   out = FileUpdateManager.instance().getWriter(subfolder, rd.getName() + "BaseImpl.java");
     
      out.write("package " + genpackage + ";\n\n");
     
      out.write(baseImports.getFormattedImports() + "\n\n");
     
      out.write("// Generated from: " + DebugInfo.getWhereWeAreNow() + "\n");
      out.write("abstract public class " + rd.getName() + "BaseImpl implements " + interfaces + " {\n\n");
     
      out.write("    static RuleTypeEnum       type  = RuleTypeEnum." + rd.getRuleType() + ";\n\n");
View Full Code Here

        if (header != null)
          out.write(header);
       
        out.write("package " + ctd.getDefinedIn().getSchemaPackage() + ".generated.types;\n\n");

    ImportManager imports = new ImportManager();

    imports.addImport("java.io.Serializable", "To prevent serialization warnings");
    imports.addImport("org.dmd.dmc.DmcInputStreamIF", "Standard serialization techniques");
    imports.addImport("org.dmd.dmc.DmcOutputStreamIF", "Standard serialization techniques");
    imports.addImport("org.dmd.dmc.types.IntegerVar", "To support getNextField()");
//    out.write("import java.io.Serializable;\n");
//        out.write("import org.dmd.dmc.DmcInputStreamIF;\n");
//        out.write("import org.dmd.dmc.DmcOutputStreamIF;\n");
//        out.write("import org.dmd.dmc.types.IntegerVar;\n");
       
        if (hasRefs){
        imports.addImport("org.dmd.dmc.DmcNameResolverIF", "To support object references");
        imports.addImport("org.dmd.dmc.DmcNamedObjectIF", "To support object references");
        imports.addImport("org.dmd.dmc.DmcNamedObjectREF", "To support object references");
        imports.addImport("org.dmd.dmc.DmcContainerIF", "To support object references");

//        out.write("import org.dmd.dmc.DmcNameResolverIF;\n");
//            out.write("import org.dmd.dmc.DmcNamedObjectIF;\n");
//            out.write("import org.dmd.dmc.DmcNamedObjectREF;\n");
//            out.write("import org.dmd.dmc.DmcContainerIF;\n");
        }

//        out.write("import org.dmd.dmc.DmcAttribute;\n");
//        out.write("import org.dmd.dmc.DmcAttributeInfo;\n");
       
    imports.addImport("org.dmd.dmc.DmcValueException", "Standard value exception");

//        out.write("import org.dmd.dmc.DmcValueException;\n\n");
       
    getComplexTypeImports(ctd, imports);
//        out.write(getComplexTypeImports(ctd));
   
    out.write(imports.getFormattedImports());
       
        out.write("@SuppressWarnings(\"serial\")\n");

        out.write("/**\n * The " + ctn + " class.\n");
        out.write(" * This code was auto-generated and shouldn't be alterred manually.\n");
View Full Code Here

        String       typefmt   = "%-" + rcic.getLongestTypeName() + "s";
        PrintfFormat  typeformat   = new PrintfFormat(typefmt);

        out.write("package " + module.getGenPackage() + ".generated.mvw;\n\n");
       
        ImportManager manager = new ImportManager();
       
        it = module.getItems();
        while(it.hasNext()){
          RunContextItem rci = it.next();
          rci.addInterfaceImports(manager);
        }
        out.write(manager.getFormattedImports());
       
        out.write("\n\n");
        out.write("// Generated from: " + DebugInfo.getWhereWeAreNow() + "\n");
        out.write("public interface " + interfaceName + "RunContextIF {\n\n");
       
View Full Code Here

       
        out.close();
  }
 
  static public void formatAppRunContextInterface(String outdir, WebApplication app, RunContextItemCollection rcic) throws IOException{
        ImportManager   manager   = new ImportManager();
        String       typefmt   = "%-" + rcic.getLongestTypeName() + "s";
        PrintfFormat  typeformat   = new PrintfFormat(typefmt);
   
        String rcName = app.getAppName() + "RunContextIF";
        BufferedWriter   out = FileUpdateManager.instance().getWriter(outdir, rcName + ".java");

        out.write("package " + app.getDefinedInModule().getGenPackage() + ".generated.mvw;\n\n");

        for (RunContextItem rci :rcic.byOrder.values()){
          // Note: we only need the imports required by the view implementation, not the full run context impl
          rci.addUsageImplImports(manager, true);
        }
        out.write(manager.getFormattedImports() + "\n");
       
        out.write("// Generated from: " + DebugInfo.getWhereWeAreNow() + "\n");
        out.write("public interface " + rcName + " extends " + rcic.getAllInterfaces() + " {\n\n");
               
        for (RunContextItem rci :rcic.byName.values()){
View Full Code Here

TOP

Related Classes of org.dmd.util.codegen.ImportManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.