out.println("    my"+sname+"=null;"); } else { out.println("    my"+sname+"="+sd.getInit()+"; } } out.println("  }"); out.println();
println(out,"    my"+sname+"=null;"); } else { println(out,"    my"+sname+"="+sd.getInit()+"; } } println(out,"  }"); println(out);
    public void write() {      for (Enumeration cds = classds.elements();           cds.hasMoreElements(); ) {        ClassD cd = (ClassD) cds.nextElement();        // write the class        String path = cd.getName() + ".java";        debug("Writing "+cd+" to "+path);        if (cleanp) {          (new File(path)).delete();          continue;        }        try {          noteFile(path);          PrintWriter out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(new File(getTargetDir(),path))));          writeCR(out);	  out.println("package " + asset_package + ";");          out.println("import org.cougaar.domain.planning.ldm.asset.*;");          out.println("import java.io.ObjectOutputStream;");          out.println("import java.io.ObjectInputStream;");          out.println("import java.io.IOException;");          out.println("import java.util.Vector;");          out.println("import java.beans.PropertyDescriptor;" );          out.println("import java.beans.IndexedPropertyDescriptor;" );          out.println("import java.beans.IntrospectionException;" );          for (Enumeration imps = cd.getImports().elements();               imps.hasMoreElements(); ) {            out.println("import "+imps.nextElement()+";");          }          String doc = cd.getDoc();          if (doc != null) {            out.println("/** "+doc+" **/");            out.println();          }          String name = cd.getName();          out.print("public class "+name);          String ext = cd.getBase();          if (ext != null && ! ext.equals("")) {            out.print(" extends "+ext);          }          out.println(" {");          out.println();                    // constructor          // is public so that anyone can construct assets.          // may be a problem if we reintroduce internal links to cluster          // state.          out.println("  public "+name+"() {");          for (Enumeration sls = cd.getSlotDs(); sls.hasMoreElements(); ) {              SlotD sd = (SlotD) sls.nextElement();            String sname = sd.getName();            //String stype = sd.getType();            String init = sd.getInit();            // for time phased, want snameSchedule            if (!sd.getTimePhased()) {              out.println("    my"+sname+" = null;");             } else {              out.println("    my"+sname+"Schedule = null;");             }          }                    out.println("  }");          out.println();          // Prototype constructor          out.println("  public "+name+"("+name+" prototype) {");          out.println("    super(prototype);");          for (Enumeration sls = cd.getSlotDs(); sls.hasMoreElements(); ) {              SlotD sd = (SlotD) sls.nextElement();            String sname = sd.getName();            String stype = sd.getType();            if (sd.getTimePhased()) {              sname = sname+"Schedule";            }            if (! sd.getTrans()) {              // values default to prototype              out.println("    my"+sname+"=null;");            } else {              out.println("    my"+sname+"="+sd.getInit()+";  //non-property");            }          }          out.println("  }");          out.println();          // clone - used by copy          out.println("  /** For infrastructure only - use org.cougaar.domain.planning.ldm.Factory.copyInstance instead. **/");          out.println("  public Object clone() throws CloneNotSupportedException {\n"+                      "    "+name+" _thing = ("+name+") super.clone();");          for (Enumeration sls = cd.getSlotDs(); sls.hasMoreElements(); ) {              SlotD sd = (SlotD) sls.nextElement();            String sname = sd.getName();            String stype = sd.getType();            boolean stimephased = sd.getTimePhased();            String vname = "my"+sname;            String vv = vname;            if (!stimephased) {              if (!sd.getExact()) { // if it's a property, we'll need to lock it                vv = vv+".lock()";              }              out.println("    if ("+vname+"!=null) _thing.set"+sname+"("+vv+");");            } else {              vname = vname+"Schedule";              out.println("    if (_thing."+vname+"!=null) _thing."+vname+".lockPGs();");            }          }          out.println("    return _thing;\n"+                      "  }\n");          // create the base instance for copies.          out.println("  /** create an instance of the right class for copy operations **/\n"+                      "  public Asset instanceForCopy() {\n"+                      "    return new "+name+"();\n"+                      "  }\n");          // create the base instance for copies.          out.println("  /** create an instance of this prototype **/\n"+                      "  public Asset createInstance() {\n"+                      "    return new "+name+"(this);\n"+                      "  }\n");          // property filler          out.println("  protected void fillAllPropertyGroups(Vector v) {");          out.println("    super.fillAllPropertyGroups(v);");          for (Enumeration sls = cd.getSlotDs(); sls.hasMoreElements(); ) {             SlotD sd = (SlotD) sls.nextElement();            String sname = sd.getName();            if (sd.getTimePhased()) {              sname = sname+"Schedule";            }            String stype = sd.getType();            if (!sd.hasInit()) {              out.println("    { Object _tmp = get"+sname+"();\n"+                          // LATE?                          "    if (_tmp != null && !(_tmp instanceof Null_PG)) {\n"+                          "      v.addElement(_tmp);\n"+                          "    } }");            }          }          out.println("  }");          out.println();          // slot hackery          for (Enumeration sls = cd.getSlotDs(); sls.hasMoreElements(); ) {             SlotD sd = (SlotD) sls.nextElement();            String sname = sd.getName();            String stype = sd.getType();            boolean stimephased = sd.getTimePhased();            String sdoc = sd.getDoc();            boolean exact = sd.getExact();            String var = "my"+sname;            if (stimephased) {              var = var+"Schedule";              out.println("  private transient PropertyGroupSchedule "+var+";");            } else {              out.println("  private transient "+stype+" "+var+";");            }            out.println();                        if (sdoc != null) {              out.println("  /** "+sdoc+" **/");            }            String argType = "";            String argName = "";            String argStr = "";            if (stimephased) {              argType = "long";              argName = "time";              argStr = argType+" "+argName;            }                          out.println("  public "+stype+" get"+sname+"("+argStr+") {");            if (exact) {              out.println("    if ("+var+" != null) return "+var+";");              out.println("    if (myPrototype instanceof "+name+")\n"+                          "      return (("+name+")myPrototype).get"+sname+"("+argName+");");              out.println("    return null;");            } else {              out.println("    "+sname+" _tmp = ("+var+" != null) ?");              if (stimephased) {                out.println("      ("+sname+")"+var+".intersects(time) :");                out.println("      ("+sname+")resolvePG("+sname+".class, time);");              } else {                out.println("      "+var+" : ("+sname+")resolvePG("+sname+".class);");              }              out.println("    return (_tmp == "+sname+".nullPG)?null:_tmp;");            }            out.println("  }");            if (stimephased) {              String fname = "get"+sname+"Schedule";              out.println("  public PropertyGroupSchedule "+fname+"() {");              out.println("    if ("+var+"==null) {\n"+                          "      if (myPrototype != null) {");              if (exact) {                out.println("         // exact slots must delegate to same class proto");                out.println("         if (myPrototype instanceof "+name+")");                out.println("           return (("+name+")myPrototype)."+fname+"();");                out.println("         else");                out.println("           return null;");              } else {                out.println("         if (myPrototype instanceof "+name+") {\n"+                            "           return (("+name+")myPrototype)."+fname+"();\n"+                            "         } else {\n"+                            "           return myPrototype.searchForPropertyGroupSchedule("+stype+".class);\n"+                            "         }");              }              out.println("      } else {\n"+                          "         "+var+" = "+sd.getInit()+";\n"+                          "      }\n"+                          "    }");              out.println("    return ("+var+" instanceof Null_PG)?null:"+var+";");              out.println("  }");              out.println();            }            String arg = "arg_"+sname;            if (exact) {              // exact slots aren't PropertyGroups              out.println("  public void set"+sname+"("+stype+" "+arg+") {");              out.println("    my"+sname+"= "+arg+";");              out.println("  }");            } else {              // non-exact slots have setters which just take PropertyGroup              out.println("  public void set"+sname+"(PropertyGroup "+arg+") {");              out.println("    if (!("+arg+" instanceof "+stype+"))\n"+                          "      throw new IllegalArgumentException(\"set"+                          sname+" requires a "+stype+" argument.\");");              if (stimephased) {                out.println("    if ("+var+" == null) {");                out.println("      "+var+" = get"+sname+"Schedule();");                out.println("    }");                out.println();                out.println("    "+var+".add("+arg+");");              } else {                out.println("    "+var+" = ("+stype+") "+arg+";");              }              out.println("  }");              out.println();            }                        if (stimephased) {              arg = "arg_"+name+"Schedule";              // non-exact slots have setters which just take PropertyGroup              out.println("  public void set"+sname+"Schedule(PropertyGroupSchedule "+arg+") {");              out.println("    if (!("+arg+".getPGClass() != "+stype+".class))\n"+                          "      throw new IllegalArgumentException(\"set"+                          sname+"Schedule requires a PropertyGroupSchedule of"+sname+"s.\");");              out.println();              out.println("    "+var+" = "+arg+";");              out.println("  }");              out.println();            }          }          out.println("  // generic search methods");          out.println("  public PropertyGroupSchedule searchForPropertyGroupSchedule(Class c) {");          for (Enumeration sls = cd.getSlotDs(); sls.hasMoreElements(); ) {              SlotD sd = (SlotD) sls.nextElement();            String sname = sd.getName();            String init = sd.getInit();            // for time phased, want snameSchedule            if (!sd.getExact() && sd.getTimePhased()) {              out.println("    if ("+sname+".class.equals(c)) return get"+sname+                          "Schedule();");            }          }          out.println("    return super.searchForPropertyGroupSchedule(c);");          out.println("  }");          out.println();          out.println("  public PropertyGroup getLocalPG(Class c, long t) {");          for (Enumeration sls = cd.getSlotDs(); sls.hasMoreElements(); ) {              SlotD sd = (SlotD) sls.nextElement();            if (!sd.getExact()) {              String sname = sd.getName();              // for time phased, want snameSchedule              String var = "my"+sname;              out.println("    if ("+sname+".class.equals(c)) {");              if (!sd.getTimePhased()) {                out.println("      return ("+var+"=="+sname+".nullPG)?null:"+var+";");              } else {                var = var+"Schedule";                out.println("      if ("+var+"==null) {\n"+                            "        return null;\n"+                            "      } else {\n"+                            "        if (t == UNSPECIFIED_TIME) {\n"+                            "          return ("+sname+")"+var+".getDefault();\n"+                            "        } else {\n"+                            "          return ("+sname+")"+var+".intersects(t);\n"+                            "        }\n"+                            "      }");              }              out.println("    }");            }          }          out.println("    return super.getLocalPG(c,t);");          out.println("  }");          out.println();          out.println("  public void setLocalPG(Class c, PropertyGroup pg) {");          for (Enumeration sls = cd.getSlotDs(); sls.hasMoreElements(); ) {              SlotD sd = (SlotD) sls.nextElement();            if (!sd.getExact()) {              String sname = sd.getName();              // for time phased, want snameSchedule              String var = "my"+sname;              out.println("    if ("+sname+".class.equals(c)) {");              if (!sd.getTimePhased()) {                out.println("      "+var+"=("+sname+")pg;");              } else {                var = var+"Schedule";                out.println("      if ("+var+"==null) "+var+" = "+sd.getInit()+";\n"+                            "      "+var+".add(pg);");              }              out.println("    } else");            }          }          out.println("      super.setLocalPG(c,pg);");          out.println("  }");          out.println();           out.println("  public PropertyGroup generateDefaultPG(Class c) {");          for (Enumeration sls = cd.getSlotDs(); sls.hasMoreElements(); ) {              SlotD sd = (SlotD) sls.nextElement();            if (!sd.getExact()) {              String sname = sd.getName();              // for time phased, want snameSchedule              String var = "my"+sname;              out.println("    if ("+sname+".class.equals(c)) {");              if (!sd.getTimePhased()) {                out.println("      return ("+var+"= new "+sname+"Impl());");              } else {                out.println("      return null;");              }              out.println("    } else");            }          }          out.println("      return super.generateDefaultPG(c);");          out.println("  }");          out.println();           out.println("  // dumb serialization methods");          out.println();                    // writer          out.println("  private void writeObject(ObjectOutputStream out) throws IOException {");          out.println("    out.defaultWriteObject();");          for (Enumeration sls = cd.getSlotDs(); sls.hasMoreElements(); ) {              SlotD sd = (SlotD) sls.nextElement();            if (! sd.getTrans()) {              String sname = sd.getName();              String stype = sd.getType();                            String var = "my"+sname;              if (sd.getTimePhased()) {                var = var+"Schedule";              }              out.println("      if ("+var+" instanceof Null_PG || "+var+" instanceof Future_PG) {\n"+                          "        out.writeObject(null);\n"+                          "      } else {\n"+                          "        out.writeObject("+var+");\n"+                          "      }");            }          }          out.println("  }");          out.println();          // reader          out.println("  private void readObject(ObjectInputStream in) throws ClassNotFoundException, IOException {");          out.println("    in.defaultReadObject();");          for (Enumeration sls = cd.getSlotDs(); sls.hasMoreElements(); ) {              SlotD sd = (SlotD) sls.nextElement();            String sname = sd.getName();            String stype = sd.getType();            String var = "my"+sname;            if (sd.getTimePhased()) {              var = var+"Schedule";              stype = "PropertyGroupSchedule";            }            if (! sd.getTrans()) {              out.println("      "+var+"=("+stype+")in.readObject();");            } else {              out.println("      "+var+"="+sd.getInit()+";");            }          }          out.println("  }");          out.println("  // beaninfo support");          writeBeanInfoBody(out,cd);          out.println("}");                    out.close();        } catch (Exception e) {          System.err.println("Caught Exception while writing "+path);          e.printStackTrace();        }       }    }