"    return "+var+".contains(_element);\n"+
"    return ("+var+"==null)?false:("+var+".contains(_element));\n"+
    void writeImpl(PrintWriter out, String context, String className) {      println(out,"/** Implementation of "+className+".");      println(out," *  @see "+className);      println(out," *  @see New"+className);      println(out," **/");      println(out);      doPackaging(out, context);      println(out,"import java.io.ObjectOutputStream;");      println(out,"import java.io.ObjectInputStream;");      println(out,"import java.io.IOException;");      println(out,"import java.beans.PropertyDescriptor;");      println(out,"import java.beans.IndexedPropertyDescriptor;");      String importstr=(String)p.get(context,"import");      if (importstr!=null) {        Vector v = explode(importstr, ',');        Enumeration ves = v.elements();        while (ves.hasMoreElements()) {          String ve=(String)ves.nextElement();          println(out,"import "+ve+";");        }      }      println(out);      // figure out what we're supposed to extend      String exts = p.get(context, "extends");      String extendstring = "";      if (exts != null) {        extendstring = extendstring+", "+exts;      }            String adapter = p.get(context, "adapter");      if (adapter == null)        adapter = "java.beans.SimpleBeanInfo";      String implclassName = className+"Impl";      String newclassName = "New"+className;      // dataquality requires a subclass      println(out,"public"+(hasDQ(context)?"":" final")+" class "+implclassName+" extends "+adapter+"\n"+                  "  implements "+newclassName+", Cloneable\n{");      // constructor      println(out,"  public "+implclassName+"() {");      Vector v = getAllDelegateSpecs(context);      if (v != null) {        for (int i =0; i<v.size(); i++) {          Argument dv = (Argument) v.elementAt(i);          // define delegate getter and setter if non-automatic          String autop = (String)p.get(context, dv.name+".auto");          // if it is automatic, pre-initialize it          if (autop != null && Boolean.valueOf(autop).booleanValue()) {            println(out,"    "+dv.name+" = new "+dv.type+"(this);");          }        }      }      println(out,"  }");      println(out);            boolean timephased = isTimePhased(context);      if (timephased) {        //handle time phased support separately because getters != setters        println(out,NewTimeSpanText);      }              Vector slotspecs = getAllSlotSpecs(context);      // declare the slots (including "inherited" ones)      println(out,"  // Slots\n");      Enumeration se = slotspecs.elements();      while (se.hasMoreElements()) {        String slotspec = ((String)se.nextElement()).trim();        int s = slotspec.indexOf(" ");        String type = slotspec.substring(0,s);        String name = slotspec.substring(s+1);        ActiveSlot as = parseActiveSlot(slotspec);        if (as != null) {          name = as.name;        }        String etype = null;        CollectionType ct = parseCollectionType(type);        if (ct != null) {          type = ct.ctype;          etype = ct.etype;        }        String var = (String)p.get(context,name+".var");        if (var == null) { var = "the"+toClassName(name); } // set the default        if (var.equals("")) { var = null; } // unset if specified as empty                  String getter =  (String)p.get(context,name+".getter");        String setter =  (String)p.get(context,name+".setter");        if (as != null) {          // active slot - write dispatchers          String htype = as.handlerName();          var = "the"+htype;          // storage for the handler          println(out,"  private transient "+className+"."+htype+" "+var+" = null;");                    // handler installation          println(out,"  public void set"+htype+"("+className+"."+htype+" handler) {\n"+                      "    "+var+" = handler;\n"+                      "  }");          println(out,"  public "+className+"."+htype+" get"+htype+"() {\n"+                      "    return "+var+";\n"+                      "  }");          // get dispatcher          if (getter != null){            println(out,getter);          } else {            println(out,"  public "+type+" "+as.getter(var));          }          // set dispatcher          if (setter != null){            println(out,setter);          } else {            println(out,"  public void "+as.setter(var));          }                  } else {          // storage          if (var != null) {            String init = (String)p.get(context,name+".init");            print(out,"  private "+type+" "+var);            if (init != null) {              print(out," = new "+init+"()");            }            println(out,";");            // Normal getter            if (getter != null) {              println(out,getter);            } else {              println(out, "  public "+type+" get"+toClassName(name)+"(){ "+                           "return "+var+"; }");            }            // test for Collection types            if (etype != null) {              String clname = toClassName(name);              println(out,"  public boolean in"+clname+"("+etype+" _element) {\n"+                          "    return "+var+".contains(_element);\n"+                          "  }");              println(out,"  public "+etype+"[] get"+clname+"AsArray() {");              println(out,"    if ("+var+" == null) return new "+etype+"[0];");              println(out,"    int l = "+var+".size();");              println(out,"    "+etype+"[] v = new "+etype+"[l];");              println(out,"    int i=0;");              println(out,"    for (Iterator n="+var+".iterator(); n.hasNext(); ) {");              println(out,"      v[i]=("+etype+") n.next();");              println(out,"      i++;");              println(out,"    }");              println(out,"    return v;");              println(out,"  }");                        println(out,"  public "+etype+" getIndexed"+clname+"(int _index) {");              println(out,"    if ("+var+" == null) return null;");              println(out,"    for (Iterator _i = "+var+".iterator(); _i.hasNext();) {");              println(out,"      "+etype+" _e = ("+etype+") _i.next();");              println(out,"      if (_index == 0) return _e;");              println(out,"      _index--;");              println(out,"    }");              println(out,"    return null;");              println(out,"  }");            }            // setter            if (setter != null) {              println(out,setter);            } else {              println(out,"  public void set"+toClassName(name)+"("+type+" "+name+") {");              // special handling for string setters              String isUnique = p.get(context, name+".unique");              if (type.equals("String") &&                  (isUnique == null || isUnique.equals("false"))){                println(out,"    if ("+name+"!=null) "+name+"="+name+".intern();");              }              println(out,"    "+var+"="+name+";");              println(out,"  }");            }            // mutators for collection types            if (etype != null) {              println(out,"  public void clear"+toClassName(name)+"() {\n"+                          "    "+var+".clear();\n"+                          "  }");              println(out,"  public boolean removeFrom"+toClassName(name)+"("+etype+" _element) {\n"+                          "    return "+var+".remove(_element);\n"+                          "  }");              println(out,"  public boolean addTo"+toClassName(name)+"("+etype+" _element) {\n"+                          "    return "+var+".add(_element);\n"+                          "  }");            }          } else {                // var is specified as empty            if (getter != null) println(out,getter);            if (setter != null) println(out,setter);          }        }      }      // delgates      {        Vector vs = getAllDelegateSpecs(context);        if (vs != null) {          println(out);          for (int i =0; i<vs.size(); i++) {            Argument dv = (Argument) vs.elementAt(i);            println(out,"  private "+dv.type+" "+dv.name+" = null;");            // define delegate getter and setter if non-automatic            String autop = (String)p.get(context, dv.name+".auto");            // if it isn't automatic, define the setter and getter            if (!(autop != null && Boolean.valueOf(autop).booleanValue())) {              println(out,"  public "+dv.type+" get"+toClassName(dv.name)+"() {\n"+                          "    return "+dv.name+";\n"+                          "  }");              println(out,"  public void set"+toClassName(dv.name)+"("+dv.type+" _"+dv.name+") {\n"+                          "    if ("+dv.name+" != null) throw new IllegalArgumentException(\""+                          dv.name+" already set\");\n"+                          "    "+dv.name+" = _"+dv.name+";\n"+                          "  }");            }            Vector dsv = parseDelegateSpecs(p.get(context, dv.name+".delegate"));            for (int j=0; j<dsv.size(); j++) {              DelegateSpec ds = (DelegateSpec) dsv.elementAt(j);              println(out,"  public "+ds.type+" "+ds.name+                          "("+unparseArguments(ds.args,true)+") {"+                          " "+ ("void".equals(ds.type)?"":"return ")+dv.name+"."+ds.name+                          "("+unparseArguments(ds.args,false)+");"+                          "  }");            }          }        }      }      // copy constructor      println(out);      println(out,"  public "+implclassName+"("+className+" original) {");            if (timephased) {        // copy TimeSpan info        println(out, "    setTimeSpan(original.getStartTime(), original.getEndTime());");      }      // Copy slot info      se = slotspecs.elements();      while (se.hasMoreElements()) {        String slotspec = ((String)se.nextElement()).trim();        int s = slotspec.indexOf(" ");        String type = slotspec.substring(0,s);        String name = slotspec.substring(s+1);        ActiveSlot as = parseActiveSlot(slotspec);        if (as != null) {          name = as.name;        }        String etype = null;        CollectionType ct = parseCollectionType(type);        if (ct != null) {          type = ct.ctype;          etype = ct.etype;        }        if (as != null) {          // do nothing - clones don't get the handler automatically.        } else {          String var = (String)p.get(context,name+".var");          if (var == null) { var = "the"+toClassName(name); } // set the default          if (var.equals("")) { var = null; } // unset if specified as empty          if (var != null) {            println(out,"    "+var+" = original.get"+toClassName(name)+"();");          }        }      }      println(out,"  }");      println(out);      if (hasDQ(context)) {        println(out,"  public boolean hasDataQuality() { return false; }");        println(out,"  public org.cougaar.planning.ldm.dq.DataQuality getDataQuality() { return null; }");        /*          // classes without runtime support do not implement NewHasDataQuality!        println(out,"  public void setDataQuality(org.cougaar.planning.ldm.dq.DataQuality dq) {\n"+                    "    throw new IllegalArgumentException(\"This instance does not support setting of DataQuality.\");\n"+                    "  }");        */        println(out);        println(out,"  // static inner extension class for real DataQuality Support");        println(out,"  public final static class DQ extends "+className+"Impl implements org.cougaar.planning.ldm.dq.NewHasDataQuality {");        println(out,"   public DQ() {\n"+ // never copy data quality                    "    super();\n"+                    "   }");        println(out,"   public DQ("+className+" original) {\n"+ // never copy data quality                    "    super(original);\n"+                    "   }");        println(out,"   public Object clone() { return new DQ(this); }");        println(out,"   private transient org.cougaar.planning.ldm.dq.DataQuality _dq = null;");        println(out,"   public boolean hasDataQuality() { return (_dq!=null); }");        println(out,"   public org.cougaar.planning.ldm.dq.DataQuality getDataQuality() { return _dq; }");        println(out,"   public void setDataQuality(org.cougaar.planning.ldm.dq.DataQuality dq) { _dq=dq; }");        println(out,"   private void writeObject(ObjectOutputStream out) throws IOException {\n"+                    "    out.defaultWriteObject();\n"+                    "    if (out instanceof org.cougaar.core.persist.PersistenceOutputStream) out.writeObject(_dq);\n"+                    "   }");        println(out,"   private void readObject(ObjectInputStream in) throws ClassNotFoundException, IOException {\n"+                    "    in.defaultReadObject();\n"+                    "    if (in instanceof org.cougaar.core.persist.PersistenceInputStream) _dq=(org.cougaar.planning.ldm.dq.DataQuality)in.readObject();\n"+                    "   }");        println(out,"    ");        println(out,"    private final static PropertyDescriptor properties[]=new PropertyDescriptor[1];\n"+                    "    static {\n"+                    "      try {\n"+                    "        properties[0]= new PropertyDescriptor(\"dataQuality\", DQ.class, \"getDataQuality\", null);\n"+                    "      } catch (Exception e) { e.printStackTrace(); }\n"+                    "    }\n"+                    "    public PropertyDescriptor[] getPropertyDescriptors() {\n"+                    "      PropertyDescriptor[] pds = super.properties;\n"+                    "      PropertyDescriptor[] ps = new PropertyDescriptor[pds.length+properties.length];\n"+                    "      System.arraycopy(pds, 0, ps, 0, pds.length);\n"+                    "      System.arraycopy(properties, 0, ps, pds.length, properties.length);\n"+                    "      return ps;\n"+                    "    }");        println(out,"  }");        println(out);      } else {        println(out,"  public final boolean hasDataQuality() { return false; }");      }      println(out);      // lock and unlock methods      println(out,"  private transient "+className+" _locked = null;");      println(out,"  public PropertyGroup lock(Object key) {");      println(out,"    if (_locked == null)");      println(out,"      _locked = new _Locked(key);");      println(out,"    return _locked; }");      println(out,"  public PropertyGroup lock() "+                  "{ return lock(null); }");      println(out,"  public NewPropertyGroup unlock(Object key) "+                  "{ return this; }");      println(out);      // clone method      writeCloneMethod(out, context, implclassName, "  ");      println(out);      println(out,"  public PropertyGroup copy() {\n"+                  "    try {\n"+                  "      return (PropertyGroup) clone();\n"+                  "    } catch (CloneNotSupportedException cnse) { return null;}\n"+                  "  }");      println(out);      // introspection methods      println(out,"  public Class getPrimaryClass() {\n"+                  "    return primaryClass;\n"+                  "  }");      println(out,"  public String getAssetGetMethod() {\n"+                  "    return assetGetter;\n"+                  "  }");      println(out,"  public String getAssetSetMethod() {\n"+                  "    return assetSetter;\n"+                  "  }");      println(out);            // Serialization      boolean needSerialization = false;      se = slotspecs.elements();      while (se.hasMoreElements()) {        String slotspec = ((String)se.nextElement()).trim();        int s = slotspec.indexOf(" ");        String type = slotspec.substring(0,s);        String name = slotspec.substring(s+1);        ActiveSlot as = parseActiveSlot(slotspec);        if (as != null) {          name = as.name;        }        String etype = null;        CollectionType ct = parseCollectionType(type);        if (ct != null) {          type = ct.ctype;          etype = ct.etype;        }        String isUnique = p.get(context, name+".unique");        if (type.equals("String") &&            (isUnique == null || isUnique.equals("false"))){          needSerialization = true;          break;        }      }      if (needSerialization) {        println(out,"  private void readObject(ObjectInputStream in) throws ClassNotFoundException, IOException {");        println(out,"    in.defaultReadObject();");        se = slotspecs.elements();        while (se.hasMoreElements()) {          String slotspec = ((String)se.nextElement()).trim();          int s = slotspec.indexOf(" ");          String type = slotspec.substring(0,s);          String name = slotspec.substring(s+1);          ActiveSlot as = parseActiveSlot(slotspec);          if (as != null) {            name = as.name;          }          String etype = null;          CollectionType ct = parseCollectionType(type);          if (ct != null) {            type = ct.ctype;            etype = ct.etype;          }          if (as != null) {            // serialized copies can't get the active slot remotely.            continue;                     }          String var = (String)p.get(context,name+".var");          if (var == null) { var = "the"+toClassName(name); } // set the default          if (var.equals("")) { var = null; } // unset if specified as empty          if (var != null) {            String isUnique = p.get(context, name+".unique");            if (type.equals("String") &&                (isUnique == null || isUnique.equals("false"))){              println(out,"    if ("+var+"!= null) "+var+"="+var+".intern();");            }          }        }        println(out,"  }");        println(out);      }      writeBeanInfoBody(out, context, className);      // inner (locked) class      println(out,"  private final class _Locked extends java.beans.SimpleBeanInfo\n"+                  "    implements "+className+", Cloneable, LockedPG\n"+                  "  {");      println(out,"    private transient Object theKey = null;");      println(out,"    _Locked(Object key) { ");      println(out,"      if (this.theKey == null){  ");      println(out,"        this.theKey = key; ");      println(out,"      } ");      println(out,"    }  ");      println(out);      println(out,"    /** public constructor for beaninfo - probably wont work**/");      println(out,"    public _Locked() {}");      println(out);      println(out,"    public PropertyGroup lock() { return this; }");      println(out,"    public PropertyGroup lock(Object o) { return this; }");      println(out);      println(out,"    public NewPropertyGroup unlock(Object key) "+                  "throws IllegalAccessException {");      println(out,"       if( theKey.equals(key) )");      println(out,"         return "+implclassName+".this;");      println(out,"       else ");      println(out,"         throw new IllegalAccessException(\"unlock: mismatched internal and provided keys!\");");      println(out,"    }");      println(out);      /*      println(out,"    public PropertyGroup copy() {\n"+                  "      return new "+implclassName+"("+implclassName+".this);\n"+                  "    }");      */      println(out,"    public PropertyGroup copy() {\n"+                  "      try {\n"+                  "        return (PropertyGroup) clone();\n"+                  "      } catch (CloneNotSupportedException cnse) { return null;}\n"+                  "    }");      println(out);      println(out);      writeCloneMethod(out, context, implclassName, "    ");      println(out);      if (timephased) {        println(out,"    public long getStartTime() { return " +                     implclassName + ".this.getStartTime(); }");        println(out,"    public long getEndTime() { return " +                    implclassName + ".this.getEndTime(); }");      }      // dispatch getters      se = slotspecs.elements();      while (se.hasMoreElements()) {        String slotspec = ((String)se.nextElement()).trim();        int s = slotspec.indexOf(" ");        String type = slotspec.substring(0,s);        String name = slotspec.substring(s+1);        ActiveSlot as = parseActiveSlot(slotspec);        if (as != null) {          name = as.name;        }        String etype = null;        CollectionType ct = parseCollectionType(type);        if (ct != null) {          type = ct.ctype;          etype = ct.etype;        }        String getter = "get"+toClassName(name);        if (as != null) {          println(out,"    public "+as.rtype+" "+as.getterSpec()+" {\n"+                      "      return "+implclassName+".this."+as.getterCall()+";\n"+                      "    }");        } else {          println(out,"    public "+type+" "+getter+"() { "+                      "return "+implclassName+".this."+getter+"(); }");        }        // test for Collection types        if (etype != null) {          String clname = toClassName(name);          String ref = implclassName+".this.";          println(out,"  public boolean in"+clname+"("+etype+" _element) {\n"+                      "    return "+ref+"in"+clname+"(_element);\n"+                      "  }");          println(out,"  public "+etype+"[] get"+clname+"AsArray() {");          println(out,"    return "+ref+"get"+clname+"AsArray();");          println(out,"  }");                    println(out,"  public "+etype+" getIndexed"+clname+"(int _index) {");          println(out,"    return "+ref+"getIndexed"+clname+"(_index);");          println(out,"  }");        }      }      {        Vector vs = getAllDelegateSpecs(context);        if (vs != null) {          for (int i =0; i<vs.size(); i++) {            Argument dv = (Argument) vs.elementAt(i);            Vector dsv = parseDelegateSpecs(p.get(context, dv.name+".delegate"));            for (int j=0; j<dsv.size(); j++) {              DelegateSpec ds = (DelegateSpec) dsv.elementAt(j);              println(out,"  public "+ds.type+" "+ds.name+                          "("+unparseArguments(ds.args,true)+") {\n"+                          "    "+("void".equals(ds.type)?"":"return ")+implclassName+".this."+ds.name+                          "("+unparseArguments(ds.args,false)+");\n"+                          "  }");            }          }        }      }      if (hasDQ(context)) {        println(out,"  public final boolean hasDataQuality() { return "+                    implclassName+".this.hasDataQuality(); }");        println(out,"  public final org.cougaar.planning.ldm.dq.DataQuality getDataQuality() { return "+                    implclassName+".this.getDataQuality(); }");      } else {        println(out,"  public final boolean hasDataQuality() { return false; }");      }      // introspection method of locked      println(out,"    public Class getPrimaryClass() {\n"+                  "      return primaryClass;\n"+                  "    }");      println(out,"    public String getAssetGetMethod() {\n"+                  "      return assetGetter;\n"+                  "    }");      println(out,"    public String getAssetSetMethod() {\n"+                  "      return assetSetter;\n"+                  "    }");      println(out);      // BeanInfo dispatchers      println(out,"    public PropertyDescriptor[] getPropertyDescriptors() {");      println(out,"      return properties;");      println(out,"    }");      println(out);      println(out,"    public Class getIntrospectionClass() {");      println(out,"      return "+className+"Impl.class;");      println(out,"    }");      println(out);            println(out,"  }");      println(out);      println(out,"}");    }