Program: 75306
Project: 75306
Buggy source:
/** 
 * Start an element. This is called at the beginning of each XML element.  By the time it is called, all of the attributes for the element will already have been reported using the attribute() method.  Unrecognized elements are ignored.
 * @param elementName The element type name.
 * @exception XmlException If the element produces an errorin constructing the model.
 */
public void startElement(String elementName) throws XmlException {
  try {
    if (_skipElement <= 0) {
      if (_configureNesting > 0 || _docNesting > 0) {
        if (elementName.equals("String_Node_Str")) {
          _configureNesting++;
        }
 else         if (elementName.equals("String_Node_Str")) {
          _docNesting++;
        }
        _currentCharData.append(_getCurrentElement(elementName));
        _attributes.clear();
        _attributeNameList.clear();
        return;
      }
    }
    if (_skipRendition) {
      return;
    }
    boolean undoEnabled=_undoEnabled && _isUndoableElement(elementName);
    if (undoEnabled) {
      boolean childNodesUndoable=true;
      if (_undoContext != null) {
        _undoContexts.push(_undoContext);
        childNodesUndoable=_undoContext.hasUndoableChildren();
      }
      _undoContext=new UndoContext(childNodesUndoable);
      if (_undoDebug) {
        System.out.println("String_Node_Str" + elementName);
      }
    }
    if (_skipElement > 0) {
      if (elementName.equals(_skipElementName)) {
        if (_skipElementIsNew) {
          _skipElementIsNew=false;
        }
 else {
          _skipElement++;
        }
      }
      return;
    }
    if (elementName.equals("String_Node_Str")) {
      String className=(String)_attributes.get("String_Node_Str");
      String entityName=(String)_attributes.get("String_Node_Str");
      String source=(String)_attributes.get("String_Node_Str");
      _checkForNull(entityName,"String_Node_Str");
      Entity entity=_searchForEntity(entityName,_current);
      boolean existedAlready=(entity != null);
      if (!existedAlready) {
        NamedObj candidate=_createEntity(className,entityName,source);
        if (candidate instanceof Entity) {
          entity=(Entity)candidate;
        }
 else {
          throw new IllegalActionException(_current,"String_Node_Str" + entityName + "String_Node_Str"+ "String_Node_Str"+ className);
        }
      }
      if (_linkRequests != null) {
        _linkRequestStack.push(_linkRequests);
      }
      _linkRequests=new LinkedList();
      if (_current != null) {
        _pushContext();
      }
 else       if (_toplevel == null) {
        _toplevel=entity.toplevel();
        _toplevel.setDeferringChangeRequests(true);
        if (_xmlFile != null) {
          URIAttribute attribute=new URIAttribute(_toplevel,"String_Node_Str");
          attribute.setURL(_xmlFile);
        }
      }
      boolean converted=false;
      if (!existedAlready) {
        entity.setClassDefinition(true);
        entity.setClassName(className);
      }
 else {
        if (!entity.isClassDefinition()) {
          entity.setClassDefinition(true);
          converted=true;
        }
      }
      _current=entity;
      _namespace=_DEFAULT_NAMESPACE;
      if (undoEnabled && _undoContext.isUndoable()) {
        if (existedAlready) {
          if (!converted) {
            _undoContext.appendUndoMoML("String_Node_Str" + entityName + "String_Node_Str");
            _undoContext.appendClosingUndoMoML("String_Node_Str");
          }
 else {
            _undoContext.appendUndoMoML("String_Node_Str" + entityName + "String_Node_Str");
            _undoContext.appendClosingUndoMoML("String_Node_Str");
          }
          _undoContext.setChildrenUndoable(true);
        }
 else {
          _undoContext.appendUndoMoML("String_Node_Str" + entityName + "String_Node_Str");
          _undoContext.setChildrenUndoable(false);
        }
      }
    }
 else     if (elementName.equals("String_Node_Str")) {
      _checkClass(_current,Configurable.class,"String_Node_Str" + "String_Node_Str" + _current);
      _configureSource=(String)_attributes.get("String_Node_Str");
      _currentCharData=new StringBuffer();
      _configureNesting++;
    }
 else     if (elementName.equals("String_Node_Str")) {
      String entityName=(String)_attributes.get("String_Node_Str");
      _checkForNull(entityName,"String_Node_Str");
      NamedObj deletedEntity=_deleteEntity(entityName);
      if (_current != null) {
        _pushContext();
      }
      _current=deletedEntity;
      _namespace=_DEFAULT_NAMESPACE;
      if (undoEnabled && _undoContext.isUndoable()) {
        _undoContext.setChildrenUndoable(false);
      }
    }
 else     if (elementName.equals("String_Node_Str")) {
      String portName=(String)_attributes.get("String_Node_Str");
      _checkForNull(portName,"String_Node_Str");
      String entityName=(String)_attributes.get("String_Node_Str");
      NamedObj deletedPort=_deletePort(portName,entityName);
      if (_current != null) {
        _pushContext();
      }
      _current=deletedPort;
      _namespace=_DEFAULT_NAMESPACE;
      if (undoEnabled && _undoContext.isUndoable()) {
        _undoContext.setChildrenUndoable(false);
      }
    }
 else     if (elementName.equals("String_Node_Str")) {
      String propName=(String)_attributes.get("String_Node_Str");
      _checkForNull(propName,"String_Node_Str");
      NamedObj deletedProp=_deleteProperty(propName);
      if (_current != null) {
        _pushContext();
      }
      _current=deletedProp;
      _namespace=_DEFAULT_NAMESPACE;
      if (undoEnabled && _undoContext.isUndoable()) {
        _undoContext.setChildrenUndoable(false);
      }
    }
 else     if (elementName.equals("String_Node_Str")) {
      String relationName=(String)_attributes.get("String_Node_Str");
      _checkForNull(relationName,"String_Node_Str");
      NamedObj deletedRelation=_deleteRelation(relationName);
      if (_current != null) {
        _pushContext();
      }
      _current=deletedRelation;
      _namespace=_DEFAULT_NAMESPACE;
      if (undoEnabled && _undoContext.isUndoable()) {
        _undoContext.setChildrenUndoable(false);
      }
    }
 else     if (elementName.equals("String_Node_Str")) {
      String className=(String)_attributes.get("String_Node_Str");
      _checkForNull(className,"String_Node_Str");
      String dirName=(String)_attributes.get("String_Node_Str");
      _checkForNull(dirName,"String_Node_Str");
      _checkClass(_current,CompositeActor.class,"String_Node_Str" + "String_Node_Str" + _current);
      Object[] arguments=new Object[2];
      arguments[0]=_current;
      arguments[1]=dirName;
      _pushContext();
      Class newClass=Class.forName(className,true,_classLoader);
      _current=_createInstance(newClass,arguments);
      _namespace=_DEFAULT_NAMESPACE;
    }
 else     if (elementName.equals("String_Node_Str")) {
      _currentDocName=(String)_attributes.get("String_Node_Str");
      _currentCharData=new StringBuffer();
      _docNesting++;
    }
 else     if (elementName.equals("String_Node_Str") || elementName.equals("String_Node_Str")) {
      String className=(String)_attributes.get("String_Node_Str");
      String entityName=(String)_attributes.get("String_Node_Str");
      _checkForNull(entityName,"String_Node_Str");
      String source=(String)_attributes.get("String_Node_Str");
      Entity entity=_searchForEntity(entityName,_current);
      boolean existedAlready=(entity != null);
      boolean converted=false;
      if (existedAlready) {
        if (entity.isClassDefinition()) {
          entity.setClassDefinition(false);
          converted=true;
        }
      }
 else {
        NamedObj candidate=_createEntity(className,entityName,source);
        if (candidate instanceof Entity) {
          entity=(Entity)candidate;
          entity.setClassName(className);
        }
 else {
          throw new IllegalActionException(_current,"String_Node_Str" + entityName + "String_Node_Str"+ "String_Node_Str"+ className);
        }
      }
      if (_linkRequests != null) {
        _linkRequestStack.push(_linkRequests);
      }
      _linkRequests=new LinkedList();
      if (_current != null) {
        _pushContext();
      }
 else       if (_toplevel == null) {
        _toplevel=entity.toplevel();
        _toplevel.setDeferringChangeRequests(true);
        if (_xmlFile != null) {
          URIAttribute attribute=new URIAttribute(_toplevel,"String_Node_Str");
          attribute.setURL(_xmlFile);
        }
      }
      _current=entity;
      _namespace=_DEFAULT_NAMESPACE;
      if (undoEnabled && _undoContext.isUndoable()) {
        if (existedAlready) {
          if (!converted) {
            _undoContext.appendUndoMoML("String_Node_Str" + entityName + "String_Node_Str");
            _undoContext.appendClosingUndoMoML("String_Node_Str");
          }
 else {
            _undoContext.appendUndoMoML("String_Node_Str" + entityName + "String_Node_Str");
            _undoContext.appendClosingUndoMoML("String_Node_Str");
          }
          _undoContext.setChildrenUndoable(true);
        }
 else {
          _undoContext.appendUndoMoML("String_Node_Str" + entityName + "String_Node_Str");
          _undoContext.setChildrenUndoable(false);
        }
      }
    }
 else     if (elementName.equals("String_Node_Str")) {
      String groupName=(String)_attributes.get("String_Node_Str");
      if (groupName != null) {
        _namespaces.push(_namespace);
        _namespaceTranslations.push(_namespaceTranslationTable);
        if (groupName.equals("String_Node_Str")) {
          _namespace=_AUTO_NAMESPACE;
          _namespaceTranslationTable=new HashMap();
        }
 else {
          _namespace=groupName;
        }
      }
 else {
        _namespaces.push(_DEFAULT_NAMESPACE);
        _namespaceTranslations.push(_namespaceTranslationTable);
        _namespace=_DEFAULT_NAMESPACE;
      }
      if (undoEnabled && _undoContext.isUndoable()) {
        _undoContext.appendUndoMoML("String_Node_Str");
        _undoContext.appendClosingUndoMoML("String_Node_Str");
        _undoContext.setChildrenUndoable(true);
      }
    }
 else     if (elementName.equals("String_Node_Str")) {
      String source=(String)_attributes.get("String_Node_Str");
      _checkForNull(source,"String_Node_Str");
      boolean skip=false;
      if (inputFileNamesToSkip != null) {
        Iterator inputFileNames=inputFileNamesToSkip.iterator();
        while (inputFileNames.hasNext()) {
          String inputFileName=(String)inputFileNames.next();
          if (source.endsWith(inputFileName)) {
            skip=true;
            break;
          }
        }
      }
      if (!skip) {
        MoMLParser newParser=new MoMLParser(_workspace,_classLoader);
        newParser.setContext(_current);
        _parse(newParser,_base,source);
      }
    }
 else     if (elementName.equals("String_Node_Str")) {
      String portName=(String)_attributes.get("String_Node_Str");
      _checkForNull(portName,"String_Node_Str");
      String relationName=(String)_attributes.get("String_Node_Str");
      String insertAtSpec=(String)_attributes.get("String_Node_Str");
      String insertInsideAtSpec=(String)_attributes.get("String_Node_Str");
      LinkRequest request=new LinkRequest(portName,relationName,insertAtSpec,insertInsideAtSpec);
      if (_linkRequests != null) {
        _linkRequests.add(request);
      }
 else {
        request.execute();
      }
    }
 else     if (elementName.equals("String_Node_Str")) {
      String className=(String)_attributes.get("String_Node_Str");
      String portName=(String)_attributes.get("String_Node_Str");
      _checkForNull(portName,"String_Node_Str");
      _checkClass(_current,Entity.class,"String_Node_Str" + "String_Node_Str" + _current);
      Entity container=(Entity)_current;
      Class newClass=null;
      if (className != null && !className.trim().equals("String_Node_Str")) {
        newClass=Class.forName(className,true,_classLoader);
      }
      Port port=container.getPort(portName);
      boolean alreadyExisted=(port != null);
      if (port != null) {
        if (newClass != null) {
          _checkClass(port,newClass,"String_Node_Str" + portName + "String_Node_Str"+ className);
        }
      }
 else {
        List heritageList=container.getDerivedList();
        Iterator heritage=heritageList.iterator();
        while (heritage.hasNext()) {
          Entity inherited=(Entity)heritage.next();
          if (inherited.getPort(portName) != null) {
            throw new IllegalActionException(container,"String_Node_Str" + "String_Node_Str" + inherited.getPort(portName).getFullName());
          }
        }
        if (newClass == null) {
          port=container.newPort(portName);
          heritage=heritageList.iterator();
          while (heritage.hasNext()) {
            Entity inherited=(Entity)heritage.next();
            Port newPort=inherited.newPort(portName);
            newPort.setDerived(true);
          }
        }
 else {
          Object[] arguments=new Object[2];
          arguments[0]=container;
          arguments[1]=portName;
          port=(Port)_createInstance(newClass,arguments);
          heritage=heritageList.iterator();
          while (heritage.hasNext()) {
            Entity inherited=(Entity)heritage.next();
            arguments[0]=inherited;
            NamedObj propagatedPort=_createInstance(newClass,arguments);
            propagatedPort.setDerived(true);
          }
        }
      }
      _pushContext();
      _current=port;
      _namespace=_DEFAULT_NAMESPACE;
      if (undoEnabled && _undoContext.isUndoable()) {
        if (alreadyExisted) {
          _undoContext.appendUndoMoML("String_Node_Str" + portName + "String_Node_Str");
          if (className != null) {
            _undoContext.appendUndoMoML("String_Node_Str" + className + "String_Node_Str");
          }
          _undoContext.appendUndoMoML("String_Node_Str");
          _undoContext.appendClosingUndoMoML("String_Node_Str");
          _undoContext.setChildrenUndoable(true);
        }
 else {
          _undoContext.appendUndoMoML("String_Node_Str" + portName + "String_Node_Str");
          _undoContext.setChildrenUndoable(false);
        }
      }
      if (port instanceof IOPort) {
        String direction=(String)_attributes.get("String_Node_Str");
        if (direction != null) {
          IOPort ioport=(IOPort)port;
          boolean isOutput=direction.equals("String_Node_Str") || direction.equals("String_Node_Str");
          boolean isInput=direction.equals("String_Node_Str") || direction.equals("String_Node_Str");
          if (alreadyExisted && ioport.isDerived()) {
            if (ioport.isInput() != isInput || ioport.isOutput() != isOutput) {
              throw new IllegalActionException(ioport,"String_Node_Str" + "String_Node_Str" + "String_Node_Str");
            }
          }
          ioport.setOutput(isOutput);
          ioport.setInput(isInput);
        }
      }
    }
 else     if (elementName.equals("String_Node_Str")) {
      String className=(String)_attributes.get("String_Node_Str");
      String propertyName=(String)_attributes.get("String_Node_Str");
      _checkForNull(propertyName,"String_Node_Str");
      String value=(String)_attributes.get("String_Node_Str");
      _handlePropertyElement(className,propertyName,value);
    }
 else     if (elementName.equals("String_Node_Str")) {
      String className=(String)_attributes.get("String_Node_Str");
      String relationName=(String)_attributes.get("String_Node_Str");
      _checkForNull(relationName,"String_Node_Str");
      _checkClass(_current,CompositeEntity.class,"String_Node_Str" + "String_Node_Str" + _current);
      CompositeEntity container=(CompositeEntity)_current;
      Class newClass=null;
      if (className != null) {
        newClass=Class.forName(className,true,_classLoader);
      }
      Relation relation=container.getRelation(relationName);
      boolean alreadyExisted=(relation != null);
      if (relation == null) {
        List heritageList=container.getDerivedList();
        Iterator heritage=heritageList.iterator();
        while (heritage.hasNext()) {
          CompositeEntity inherited=(CompositeEntity)heritage.next();
          if (inherited.getRelation(relationName) != null) {
            throw new IllegalActionException(container,"String_Node_Str" + "String_Node_Str" + inherited.getRelation(relationName).getFullName());
          }
        }
        NamedObj newRelation=null;
        _pushContext();
        if (newClass == null) {
          newRelation=container.newRelation(relationName);
          heritage=heritageList.iterator();
          while (heritage.hasNext()) {
            CompositeEntity inherited=(CompositeEntity)heritage.next();
            Relation propagatedRelation=inherited.newRelation(relationName);
            propagatedRelation.setDerived(true);
          }
        }
 else {
          Object[] arguments=new Object[2];
          arguments[0]=(CompositeEntity)_current;
          arguments[1]=relationName;
          newRelation=_createInstance(newClass,arguments);
          heritage=heritageList.iterator();
          while (heritage.hasNext()) {
            CompositeEntity inherited=(CompositeEntity)heritage.next();
            arguments[0]=inherited;
            NamedObj propagatedRelation=_createInstance(newClass,arguments);
            propagatedRelation.setDerived(true);
          }
        }
        _namespace=_DEFAULT_NAMESPACE;
        _current=newRelation;
      }
 else {
        if (newClass != null) {
          _checkClass(relation,newClass,"String_Node_Str" + relationName + "String_Node_Str"+ className);
        }
        _pushContext();
        _current=relation;
        _namespace=_DEFAULT_NAMESPACE;
      }
      if (undoEnabled && _undoContext.isUndoable()) {
        if (alreadyExisted) {
          _undoContext.appendUndoMoML("String_Node_Str" + relationName + "String_Node_Str");
          if (className != null) {
            _undoContext.appendUndoMoML("String_Node_Str" + className + "String_Node_Str");
          }
          _undoContext.appendUndoMoML("String_Node_Str");
          _undoContext.appendClosingUndoMoML("String_Node_Str");
          _undoContext.setChildrenUndoable(true);
        }
 else {
          _undoContext.appendUndoMoML("String_Node_Str" + relationName + "String_Node_Str");
          _undoContext.setChildrenUndoable(false);
        }
      }
    }
 else     if (elementName.equals("String_Node_Str")) {
      String newName=(String)_attributes.get("String_Node_Str");
      _checkForNull(newName,"String_Node_Str");
      if (_current != null) {
        String oldName=_current.getName();
        if (!oldName.equals(newName) && _current.isDerived()) {
          throw new IllegalActionException(_current,"String_Node_Str" + newName + "String_Node_Str");
        }
        Iterator heritage=_current.getDerivedList().iterator();
        Set changedName=new HashSet();
        HashMap changedClassName=new HashMap();
        NamedObj inherited=null;
        try {
          while (heritage.hasNext()) {
            inherited=(NamedObj)heritage.next();
            if (inherited.getName().equals(oldName)) {
              inherited.setName(newName);
              changedName.add(inherited);
            }
            if (inherited instanceof Instantiable) {
              Instantiable parent=((Instantiable)inherited).getParent();
              if (parent != null && (parent == _current || changedName.contains(parent))) {
                String previousClassName=inherited.getClassName();
                int last=previousClassName.lastIndexOf(oldName);
                if (last < 0) {
                  throw new InternalErrorException("String_Node_Str" + inherited.getFullName() + "String_Node_Str"+ oldName+ "String_Node_Str"+ previousClassName);
                }
                String newClassName=newName;
                if (last > 0) {
                  newClassName=previousClassName.substring(0,last) + newName;
                }
                inherited.setClassName(newClassName);
                changedClassName.put(inherited,previousClassName);
              }
            }
          }
        }
 catch (        NameDuplicationException ex) {
          Iterator toUndo=changedName.iterator();
          while (toUndo.hasNext()) {
            NamedObj revert=(NamedObj)toUndo.next();
            revert.setName(oldName);
          }
          Iterator classNameFixes=changedClassName.entrySet().iterator();
          while (classNameFixes.hasNext()) {
            Map.Entry revert=(Map.Entry)classNameFixes.next();
            NamedObj toFix=(NamedObj)revert.getKey();
            String previousClassName=(String)revert.getValue();
            toFix.setClassName(previousClassName);
          }
          throw new IllegalActionException(_current,ex,"String_Node_Str" + "String_Node_Str" + inherited.getFullName());
        }
        _current.setName(newName);
        if (undoEnabled && _undoContext.isUndoable()) {
          UndoContext parentContext=(UndoContext)_undoContexts.peek();
          parentContext.applyRename(newName);
          _undoContext.appendUndoMoML("String_Node_Str" + oldName + "String_Node_Str");
          _undoContext.setChildrenUndoable(false);
        }
        if ((_current instanceof Instantiable) && ((Instantiable)_current).isClassDefinition()) {
          List deferredFrom=((Instantiable)_current).getChildren();
          if (deferredFrom != null) {
            Iterator deferrers=deferredFrom.iterator();
            while (deferrers.hasNext()) {
              WeakReference reference=(WeakReference)deferrers.next();
              Prototype deferrer=(Prototype)reference.get();
              if (deferrer != null) {
                String replacementName=newName;
                if (deferrer.getClassName().startsWith("String_Node_Str")) {
                  replacementName=_current.getFullName();
                }
                deferrer.setClassName(replacementName);
              }
            }
          }
        }
      }
    }
 else     if (elementName.equals("String_Node_Str")) {
      _skipRendition=true;
    }
 else     if (elementName.equals("String_Node_Str")) {
      String portName=(String)_attributes.get("String_Node_Str");
      _checkForNull(portName,"String_Node_Str");
      String relationName=(String)_attributes.get("String_Node_Str");
      String indexSpec=(String)_attributes.get("String_Node_Str");
      String insideIndexSpec=(String)_attributes.get("String_Node_Str");
      UnlinkRequest request=new UnlinkRequest(portName,relationName,indexSpec,insideIndexSpec);
      if (_linkRequests != null) {
        _linkRequests.add(request);
      }
 else {
        request.execute();
      }
    }
 else     if (elementName.equals("String_Node_Str")) {
      String vertexName=(String)_attributes.get("String_Node_Str");
      _checkForNull(vertexName,"String_Node_Str");
      _checkClass(_current,Relation.class,"String_Node_Str" + "String_Node_Str" + _current);
      Vertex previous=(Vertex)_current.getAttribute(vertexName);
      String previousValue=null;
      if (previous != null) {
        previousValue=previous.getExpression();
      }
      Vertex vertex=previous;
      if (vertex == null) {
        vertex=new Vertex((Relation)_current,vertexName);
        Iterator heritage=_current.getDerivedList().iterator();
        while (heritage.hasNext()) {
          Relation inherited=(Relation)heritage.next();
          Vertex propagatedVertex=new Vertex(inherited,vertexName);
          propagatedVertex.setDerived(true);
        }
      }
      String value=(String)_attributes.get("String_Node_Str");
      if (value != null && !value.equals(previousValue)) {
        vertex.setExpression(value);
        vertex.setOverrideDepth(0);
        _paramsToParse.add(vertex);
        List depthList=new LinkedList();
        Iterator heritage=vertex.getShadowedDerivedList(depthList).iterator();
        Iterator depths=depthList.iterator();
        while (heritage.hasNext()) {
          int depth=((Integer)depths.next()).intValue();
          Vertex inherited=(Vertex)heritage.next();
          inherited.setExpression(value);
          inherited.setOverrideDepth(depth);
          _paramsToParse.add(inherited);
        }
      }
      _pushContext();
      _current=vertex;
      _namespace=_DEFAULT_NAMESPACE;
      if (undoEnabled && _undoContext.isUndoable()) {
        _undoContext.appendUndoMoML("String_Node_Str" + vertexName + "String_Node_Str");
        if (previousValue != null) {
          _undoContext.appendUndoMoML("String_Node_Str" + previousValue + "String_Node_Str");
        }
        _undoContext.appendUndoMoML("String_Node_Str");
        _undoContext.setChildrenUndoable(true);
        _undoContext.appendClosingUndoMoML("String_Node_Str");
      }
    }
 else {
      if (_unrecognized == null) {
        _unrecognized=new LinkedList();
      }
      _unrecognized.add(elementName);
    }
  }
 catch (  InvocationTargetException ex) {
    if (_handler != null) {
      int reply=_handler.handleError(_getCurrentElement(elementName),_current,ex.getTargetException());
      if (reply == ErrorHandler.CONTINUE) {
        _attributes.clear();
        _attributeNameList.clear();
        _skipElement=1;
        _skipElementName=elementName;
        return;
      }
 else       if (reply == ErrorHandler.CANCEL) {
        throw new XmlException("String_Node_Str",_currentExternalEntity(),_parser.getLineNumber(),_parser.getColumnNumber());
      }
    }
    throw new XmlException("String_Node_Str" + elementName + "String_Node_Str"+ ex.getTargetException(),_currentExternalEntity(),_parser.getLineNumber(),_parser.getColumnNumber(),ex.getTargetException());
  }
catch (  Exception ex) {
    if (_handler != null) {
      int reply=_handler.handleError(_getCurrentElement(elementName),_current,ex);
      if (reply == ErrorHandler.CONTINUE) {
        _attributes.clear();
        _attributeNameList.clear();
        _skipElement=1;
        _skipElementName=elementName;
        return;
      }
 else       if (reply == ErrorHandler.CANCEL) {
        throw new XmlException("String_Node_Str",_currentExternalEntity(),_parser.getLineNumber(),_parser.getColumnNumber());
      }
    }
    if (ex instanceof XmlException) {
      throw (XmlException)ex;
    }
 else {
      throw new XmlException("String_Node_Str" + elementName + "String_Node_Str",_currentExternalEntity(),_parser.getLineNumber(),_parser.getColumnNumber(),ex);
    }
  }
  _attributes.clear();
  _attributeNameList.clear();
}

Fixed version (ground truth):
/** 
 * Start an element. This is called at the beginning of each XML element.  By the time it is called, all of the attributes for the element will already have been reported using the attribute() method.  Unrecognized elements are ignored.
 * @param elementName The element type name.
 * @exception XmlException If the element produces an errorin constructing the model.
 */
public void startElement(String elementName) throws XmlException {
  try {
    if (_skipElement <= 0) {
      if (_configureNesting > 0 || _docNesting > 0) {
        if (elementName.equals("String_Node_Str")) {
          _configureNesting++;
        }
 else         if (elementName.equals("String_Node_Str")) {
          _docNesting++;
        }
        _currentCharData.append(_getCurrentElement(elementName));
        _attributes.clear();
        _attributeNameList.clear();
        return;
      }
    }
    if (_skipRendition) {
      return;
    }
    boolean undoEnabled=_undoEnabled && _isUndoableElement(elementName);
    if (undoEnabled) {
      boolean childNodesUndoable=true;
      if (_undoContext != null) {
        _undoContexts.push(_undoContext);
        childNodesUndoable=_undoContext.hasUndoableChildren();
      }
      _undoContext=new UndoContext(childNodesUndoable);
      if (_undoDebug) {
        System.out.println("String_Node_Str" + elementName);
      }
    }
    if (_skipElement > 0) {
      if (elementName.equals(_skipElementName)) {
        if (_skipElementIsNew) {
          _skipElementIsNew=false;
        }
 else {
          _skipElement++;
        }
      }
      return;
    }
    if (elementName.equals("String_Node_Str")) {
      String className=(String)_attributes.get("String_Node_Str");
      String entityName=(String)_attributes.get("String_Node_Str");
      String source=(String)_attributes.get("String_Node_Str");
      _checkForNull(entityName,"String_Node_Str");
      Entity entity=_searchForEntity(entityName,_current);
      boolean existedAlready=(entity != null);
      if (!existedAlready) {
        NamedObj candidate=_createEntity(className,entityName,source);
        if (candidate instanceof Entity) {
          entity=(Entity)candidate;
        }
 else {
          throw new IllegalActionException(_current,"String_Node_Str" + entityName + "String_Node_Str"+ "String_Node_Str"+ className);
        }
      }
      if (_linkRequests != null) {
        _linkRequestStack.push(_linkRequests);
      }
      _linkRequests=new LinkedList();
      if (_current != null) {
        _pushContext();
      }
 else       if (_toplevel == null) {
        _toplevel=entity.toplevel();
        _toplevel.setDeferringChangeRequests(true);
        if (_xmlFile != null) {
          URIAttribute attribute=new URIAttribute(_toplevel,"String_Node_Str");
          attribute.setURL(_xmlFile);
        }
      }
      boolean converted=false;
      if (!existedAlready) {
        entity.setClassDefinition(true);
        entity.setClassName(className);
      }
 else {
        if (!entity.isClassDefinition()) {
          entity.setClassDefinition(true);
          converted=true;
        }
      }
      _current=entity;
      _namespace=_DEFAULT_NAMESPACE;
      if (undoEnabled && _undoContext.isUndoable()) {
        if (existedAlready) {
          if (!converted) {
            _undoContext.appendUndoMoML("String_Node_Str" + entityName + "String_Node_Str");
            _undoContext.appendClosingUndoMoML("String_Node_Str");
          }
 else {
            _undoContext.appendUndoMoML("String_Node_Str" + entityName + "String_Node_Str");
            _undoContext.appendClosingUndoMoML("String_Node_Str");
          }
          _undoContext.setChildrenUndoable(true);
        }
 else {
          _undoContext.appendUndoMoML("String_Node_Str" + entityName + "String_Node_Str");
          _undoContext.setChildrenUndoable(false);
        }
      }
    }
 else     if (elementName.equals("String_Node_Str")) {
      _checkClass(_current,Configurable.class,"String_Node_Str" + "String_Node_Str" + _current);
      _configureSource=(String)_attributes.get("String_Node_Str");
      _currentCharData=new StringBuffer();
      _configureNesting++;
    }
 else     if (elementName.equals("String_Node_Str")) {
      String entityName=(String)_attributes.get("String_Node_Str");
      _checkForNull(entityName,"String_Node_Str");
      _deleteEntity(entityName);
    }
 else     if (elementName.equals("String_Node_Str")) {
      String portName=(String)_attributes.get("String_Node_Str");
      _checkForNull(portName,"String_Node_Str");
      String entityName=(String)_attributes.get("String_Node_Str");
      _deletePort(portName,entityName);
    }
 else     if (elementName.equals("String_Node_Str")) {
      String propName=(String)_attributes.get("String_Node_Str");
      _checkForNull(propName,"String_Node_Str");
      _deleteProperty(propName);
    }
 else     if (elementName.equals("String_Node_Str")) {
      String relationName=(String)_attributes.get("String_Node_Str");
      _checkForNull(relationName,"String_Node_Str");
      _deleteRelation(relationName);
    }
 else     if (elementName.equals("String_Node_Str")) {
      String className=(String)_attributes.get("String_Node_Str");
      _checkForNull(className,"String_Node_Str");
      String dirName=(String)_attributes.get("String_Node_Str");
      _checkForNull(dirName,"String_Node_Str");
      _checkClass(_current,CompositeActor.class,"String_Node_Str" + "String_Node_Str" + _current);
      Object[] arguments=new Object[2];
      arguments[0]=_current;
      arguments[1]=dirName;
      _pushContext();
      Class newClass=Class.forName(className,true,_classLoader);
      _current=_createInstance(newClass,arguments);
      _namespace=_DEFAULT_NAMESPACE;
    }
 else     if (elementName.equals("String_Node_Str")) {
      _currentDocName=(String)_attributes.get("String_Node_Str");
      _currentCharData=new StringBuffer();
      _docNesting++;
    }
 else     if (elementName.equals("String_Node_Str") || elementName.equals("String_Node_Str")) {
      String className=(String)_attributes.get("String_Node_Str");
      String entityName=(String)_attributes.get("String_Node_Str");
      _checkForNull(entityName,"String_Node_Str");
      String source=(String)_attributes.get("String_Node_Str");
      Entity entity=_searchForEntity(entityName,_current);
      boolean existedAlready=(entity != null);
      boolean converted=false;
      if (existedAlready) {
        if (entity.isClassDefinition()) {
          entity.setClassDefinition(false);
          converted=true;
        }
      }
 else {
        NamedObj candidate=_createEntity(className,entityName,source);
        if (candidate instanceof Entity) {
          entity=(Entity)candidate;
          entity.setClassName(className);
        }
 else {
          throw new IllegalActionException(_current,"String_Node_Str" + entityName + "String_Node_Str"+ "String_Node_Str"+ className);
        }
      }
      if (_linkRequests != null) {
        _linkRequestStack.push(_linkRequests);
      }
      _linkRequests=new LinkedList();
      if (_current != null) {
        _pushContext();
      }
 else       if (_toplevel == null) {
        _toplevel=entity.toplevel();
        _toplevel.setDeferringChangeRequests(true);
        if (_xmlFile != null) {
          URIAttribute attribute=new URIAttribute(_toplevel,"String_Node_Str");
          attribute.setURL(_xmlFile);
        }
      }
      _current=entity;
      _namespace=_DEFAULT_NAMESPACE;
      if (undoEnabled && _undoContext.isUndoable()) {
        if (existedAlready) {
          if (!converted) {
            _undoContext.appendUndoMoML("String_Node_Str" + entityName + "String_Node_Str");
            _undoContext.appendClosingUndoMoML("String_Node_Str");
          }
 else {
            _undoContext.appendUndoMoML("String_Node_Str" + entityName + "String_Node_Str");
            _undoContext.appendClosingUndoMoML("String_Node_Str");
          }
          _undoContext.setChildrenUndoable(true);
        }
 else {
          _undoContext.appendUndoMoML("String_Node_Str" + entityName + "String_Node_Str");
          _undoContext.setChildrenUndoable(false);
        }
      }
    }
 else     if (elementName.equals("String_Node_Str")) {
      String groupName=(String)_attributes.get("String_Node_Str");
      if (groupName != null) {
        _namespaces.push(_namespace);
        _namespaceTranslations.push(_namespaceTranslationTable);
        if (groupName.equals("String_Node_Str")) {
          _namespace=_AUTO_NAMESPACE;
          _namespaceTranslationTable=new HashMap();
        }
 else {
          _namespace=groupName;
        }
      }
 else {
        _namespaces.push(_DEFAULT_NAMESPACE);
        _namespaceTranslations.push(_namespaceTranslationTable);
        _namespace=_DEFAULT_NAMESPACE;
      }
      if (undoEnabled && _undoContext.isUndoable()) {
        _undoContext.appendUndoMoML("String_Node_Str");
        _undoContext.appendClosingUndoMoML("String_Node_Str");
        _undoContext.setChildrenUndoable(true);
      }
    }
 else     if (elementName.equals("String_Node_Str")) {
      String source=(String)_attributes.get("String_Node_Str");
      _checkForNull(source,"String_Node_Str");
      boolean skip=false;
      if (inputFileNamesToSkip != null) {
        Iterator inputFileNames=inputFileNamesToSkip.iterator();
        while (inputFileNames.hasNext()) {
          String inputFileName=(String)inputFileNames.next();
          if (source.endsWith(inputFileName)) {
            skip=true;
            break;
          }
        }
      }
      if (!skip) {
        MoMLParser newParser=new MoMLParser(_workspace,_classLoader);
        newParser.setContext(_current);
        _parse(newParser,_base,source);
      }
    }
 else     if (elementName.equals("String_Node_Str")) {
      String portName=(String)_attributes.get("String_Node_Str");
      _checkForNull(portName,"String_Node_Str");
      String relationName=(String)_attributes.get("String_Node_Str");
      String insertAtSpec=(String)_attributes.get("String_Node_Str");
      String insertInsideAtSpec=(String)_attributes.get("String_Node_Str");
      LinkRequest request=new LinkRequest(portName,relationName,insertAtSpec,insertInsideAtSpec);
      if (_linkRequests != null) {
        _linkRequests.add(request);
      }
 else {
        request.execute();
      }
    }
 else     if (elementName.equals("String_Node_Str")) {
      String className=(String)_attributes.get("String_Node_Str");
      String portName=(String)_attributes.get("String_Node_Str");
      _checkForNull(portName,"String_Node_Str");
      _checkClass(_current,Entity.class,"String_Node_Str" + "String_Node_Str" + _current);
      Entity container=(Entity)_current;
      Class newClass=null;
      if (className != null && !className.trim().equals("String_Node_Str")) {
        newClass=Class.forName(className,true,_classLoader);
      }
      Port port=container.getPort(portName);
      boolean alreadyExisted=(port != null);
      if (port != null) {
        if (newClass != null) {
          _checkClass(port,newClass,"String_Node_Str" + portName + "String_Node_Str"+ className);
        }
      }
 else {
        List heritageList=container.getDerivedList();
        Iterator heritage=heritageList.iterator();
        while (heritage.hasNext()) {
          Entity inherited=(Entity)heritage.next();
          if (inherited.getPort(portName) != null) {
            throw new IllegalActionException(container,"String_Node_Str" + "String_Node_Str" + inherited.getPort(portName).getFullName());
          }
        }
        if (newClass == null) {
          port=container.newPort(portName);
          heritage=heritageList.iterator();
          while (heritage.hasNext()) {
            Entity inherited=(Entity)heritage.next();
            Port newPort=inherited.newPort(portName);
            newPort.setDerived(true);
          }
        }
 else {
          Object[] arguments=new Object[2];
          arguments[0]=container;
          arguments[1]=portName;
          port=(Port)_createInstance(newClass,arguments);
          heritage=heritageList.iterator();
          while (heritage.hasNext()) {
            Entity inherited=(Entity)heritage.next();
            arguments[0]=inherited;
            NamedObj propagatedPort=_createInstance(newClass,arguments);
            propagatedPort.setDerived(true);
          }
        }
      }
      _pushContext();
      _current=port;
      _namespace=_DEFAULT_NAMESPACE;
      if (undoEnabled && _undoContext.isUndoable()) {
        if (alreadyExisted) {
          _undoContext.appendUndoMoML("String_Node_Str" + portName + "String_Node_Str");
          if (className != null) {
            _undoContext.appendUndoMoML("String_Node_Str" + className + "String_Node_Str");
          }
          _undoContext.appendUndoMoML("String_Node_Str");
          _undoContext.appendClosingUndoMoML("String_Node_Str");
          _undoContext.setChildrenUndoable(true);
        }
 else {
          _undoContext.appendUndoMoML("String_Node_Str" + portName + "String_Node_Str");
          _undoContext.setChildrenUndoable(false);
        }
      }
      if (port instanceof IOPort) {
        String direction=(String)_attributes.get("String_Node_Str");
        if (direction != null) {
          IOPort ioport=(IOPort)port;
          boolean isOutput=direction.equals("String_Node_Str") || direction.equals("String_Node_Str");
          boolean isInput=direction.equals("String_Node_Str") || direction.equals("String_Node_Str");
          if (alreadyExisted && ioport.isDerived()) {
            if (ioport.isInput() != isInput || ioport.isOutput() != isOutput) {
              throw new IllegalActionException(ioport,"String_Node_Str" + "String_Node_Str" + "String_Node_Str");
            }
          }
          ioport.setOutput(isOutput);
          ioport.setInput(isInput);
        }
      }
    }
 else     if (elementName.equals("String_Node_Str")) {
      String className=(String)_attributes.get("String_Node_Str");
      String propertyName=(String)_attributes.get("String_Node_Str");
      _checkForNull(propertyName,"String_Node_Str");
      String value=(String)_attributes.get("String_Node_Str");
      _handlePropertyElement(className,propertyName,value);
    }
 else     if (elementName.equals("String_Node_Str")) {
      String className=(String)_attributes.get("String_Node_Str");
      String relationName=(String)_attributes.get("String_Node_Str");
      _checkForNull(relationName,"String_Node_Str");
      _checkClass(_current,CompositeEntity.class,"String_Node_Str" + "String_Node_Str" + _current);
      CompositeEntity container=(CompositeEntity)_current;
      Class newClass=null;
      if (className != null) {
        newClass=Class.forName(className,true,_classLoader);
      }
      Relation relation=container.getRelation(relationName);
      boolean alreadyExisted=(relation != null);
      if (relation == null) {
        List heritageList=container.getDerivedList();
        Iterator heritage=heritageList.iterator();
        while (heritage.hasNext()) {
          CompositeEntity inherited=(CompositeEntity)heritage.next();
          if (inherited.getRelation(relationName) != null) {
            throw new IllegalActionException(container,"String_Node_Str" + "String_Node_Str" + inherited.getRelation(relationName).getFullName());
          }
        }
        NamedObj newRelation=null;
        _pushContext();
        if (newClass == null) {
          newRelation=container.newRelation(relationName);
          heritage=heritageList.iterator();
          while (heritage.hasNext()) {
            CompositeEntity inherited=(CompositeEntity)heritage.next();
            Relation propagatedRelation=inherited.newRelation(relationName);
            propagatedRelation.setDerived(true);
          }
        }
 else {
          Object[] arguments=new Object[2];
          arguments[0]=(CompositeEntity)_current;
          arguments[1]=relationName;
          newRelation=_createInstance(newClass,arguments);
          heritage=heritageList.iterator();
          while (heritage.hasNext()) {
            CompositeEntity inherited=(CompositeEntity)heritage.next();
            arguments[0]=inherited;
            NamedObj propagatedRelation=_createInstance(newClass,arguments);
            propagatedRelation.setDerived(true);
          }
        }
        _namespace=_DEFAULT_NAMESPACE;
        _current=newRelation;
      }
 else {
        if (newClass != null) {
          _checkClass(relation,newClass,"String_Node_Str" + relationName + "String_Node_Str"+ className);
        }
        _pushContext();
        _current=relation;
        _namespace=_DEFAULT_NAMESPACE;
      }
      if (undoEnabled && _undoContext.isUndoable()) {
        if (alreadyExisted) {
          _undoContext.appendUndoMoML("String_Node_Str" + relationName + "String_Node_Str");
          if (className != null) {
            _undoContext.appendUndoMoML("String_Node_Str" + className + "String_Node_Str");
          }
          _undoContext.appendUndoMoML("String_Node_Str");
          _undoContext.appendClosingUndoMoML("String_Node_Str");
          _undoContext.setChildrenUndoable(true);
        }
 else {
          _undoContext.appendUndoMoML("String_Node_Str" + relationName + "String_Node_Str");
          _undoContext.setChildrenUndoable(false);
        }
      }
    }
 else     if (elementName.equals("String_Node_Str")) {
      String newName=(String)_attributes.get("String_Node_Str");
      _checkForNull(newName,"String_Node_Str");
      if (_current != null) {
        String oldName=_current.getName();
        if (!oldName.equals(newName) && _current.isDerived()) {
          throw new IllegalActionException(_current,"String_Node_Str" + newName + "String_Node_Str");
        }
        Iterator heritage=_current.getDerivedList().iterator();
        Set changedName=new HashSet();
        HashMap changedClassName=new HashMap();
        NamedObj inherited=null;
        try {
          while (heritage.hasNext()) {
            inherited=(NamedObj)heritage.next();
            if (inherited.getName().equals(oldName)) {
              inherited.setName(newName);
              changedName.add(inherited);
            }
            if (inherited instanceof Instantiable) {
              Instantiable parent=((Instantiable)inherited).getParent();
              if (parent != null && (parent == _current || changedName.contains(parent))) {
                String previousClassName=inherited.getClassName();
                int last=previousClassName.lastIndexOf(oldName);
                if (last < 0) {
                  throw new InternalErrorException("String_Node_Str" + inherited.getFullName() + "String_Node_Str"+ oldName+ "String_Node_Str"+ previousClassName);
                }
                String newClassName=newName;
                if (last > 0) {
                  newClassName=previousClassName.substring(0,last) + newName;
                }
                inherited.setClassName(newClassName);
                changedClassName.put(inherited,previousClassName);
              }
            }
          }
        }
 catch (        NameDuplicationException ex) {
          Iterator toUndo=changedName.iterator();
          while (toUndo.hasNext()) {
            NamedObj revert=(NamedObj)toUndo.next();
            revert.setName(oldName);
          }
          Iterator classNameFixes=changedClassName.entrySet().iterator();
          while (classNameFixes.hasNext()) {
            Map.Entry revert=(Map.Entry)classNameFixes.next();
            NamedObj toFix=(NamedObj)revert.getKey();
            String previousClassName=(String)revert.getValue();
            toFix.setClassName(previousClassName);
          }
          throw new IllegalActionException(_current,ex,"String_Node_Str" + "String_Node_Str" + inherited.getFullName());
        }
        _current.setName(newName);
        if (undoEnabled && _undoContext.isUndoable()) {
          UndoContext parentContext=(UndoContext)_undoContexts.peek();
          parentContext.applyRename(newName);
          _undoContext.appendUndoMoML("String_Node_Str" + oldName + "String_Node_Str");
          _undoContext.setChildrenUndoable(false);
        }
        if ((_current instanceof Instantiable) && ((Instantiable)_current).isClassDefinition()) {
          List deferredFrom=((Instantiable)_current).getChildren();
          if (deferredFrom != null) {
            Iterator deferrers=deferredFrom.iterator();
            while (deferrers.hasNext()) {
              WeakReference reference=(WeakReference)deferrers.next();
              Prototype deferrer=(Prototype)reference.get();
              if (deferrer != null) {
                String replacementName=newName;
                if (deferrer.getClassName().startsWith("String_Node_Str")) {
                  replacementName=_current.getFullName();
                }
                deferrer.setClassName(replacementName);
              }
            }
          }
        }
      }
    }
 else     if (elementName.equals("String_Node_Str")) {
      _skipRendition=true;
    }
 else     if (elementName.equals("String_Node_Str")) {
      String portName=(String)_attributes.get("String_Node_Str");
      _checkForNull(portName,"String_Node_Str");
      String relationName=(String)_attributes.get("String_Node_Str");
      String indexSpec=(String)_attributes.get("String_Node_Str");
      String insideIndexSpec=(String)_attributes.get("String_Node_Str");
      UnlinkRequest request=new UnlinkRequest(portName,relationName,indexSpec,insideIndexSpec);
      if (_linkRequests != null) {
        _linkRequests.add(request);
      }
 else {
        request.execute();
      }
    }
 else     if (elementName.equals("String_Node_Str")) {
      String vertexName=(String)_attributes.get("String_Node_Str");
      _checkForNull(vertexName,"String_Node_Str");
      _checkClass(_current,Relation.class,"String_Node_Str" + "String_Node_Str" + _current);
      Vertex previous=(Vertex)_current.getAttribute(vertexName);
      String previousValue=null;
      if (previous != null) {
        previousValue=previous.getExpression();
      }
      Vertex vertex=previous;
      if (vertex == null) {
        vertex=new Vertex((Relation)_current,vertexName);
        Iterator heritage=_current.getDerivedList().iterator();
        while (heritage.hasNext()) {
          Relation inherited=(Relation)heritage.next();
          Vertex propagatedVertex=new Vertex(inherited,vertexName);
          propagatedVertex.setDerived(true);
        }
      }
      String value=(String)_attributes.get("String_Node_Str");
      if (value != null && !value.equals(previousValue)) {
        vertex.setExpression(value);
        vertex.setOverrideDepth(0);
        _paramsToParse.add(vertex);
        List depthList=new LinkedList();
        Iterator heritage=vertex.getShadowedDerivedList(depthList).iterator();
        Iterator depths=depthList.iterator();
        while (heritage.hasNext()) {
          int depth=((Integer)depths.next()).intValue();
          Vertex inherited=(Vertex)heritage.next();
          inherited.setExpression(value);
          inherited.setOverrideDepth(depth);
          _paramsToParse.add(inherited);
        }
      }
      _pushContext();
      _current=vertex;
      _namespace=_DEFAULT_NAMESPACE;
      if (undoEnabled && _undoContext.isUndoable()) {
        _undoContext.appendUndoMoML("String_Node_Str" + vertexName + "String_Node_Str");
        if (previousValue != null) {
          _undoContext.appendUndoMoML("String_Node_Str" + previousValue + "String_Node_Str");
        }
        _undoContext.appendUndoMoML("String_Node_Str");
        _undoContext.setChildrenUndoable(true);
        _undoContext.appendClosingUndoMoML("String_Node_Str");
      }
    }
 else {
      if (_unrecognized == null) {
        _unrecognized=new LinkedList();
      }
      _unrecognized.add(elementName);
    }
  }
 catch (  InvocationTargetException ex) {
    if (_handler != null) {
      int reply=_handler.handleError(_getCurrentElement(elementName),_current,ex.getTargetException());
      if (reply == ErrorHandler.CONTINUE) {
        _attributes.clear();
        _attributeNameList.clear();
        _skipElement=1;
        _skipElementName=elementName;
        return;
      }
 else       if (reply == ErrorHandler.CANCEL) {
        throw new XmlException("String_Node_Str",_currentExternalEntity(),_parser.getLineNumber(),_parser.getColumnNumber());
      }
    }
    throw new XmlException("String_Node_Str" + elementName + "String_Node_Str"+ ex.getTargetException(),_currentExternalEntity(),_parser.getLineNumber(),_parser.getColumnNumber(),ex.getTargetException());
  }
catch (  Exception ex) {
    if (_handler != null) {
      int reply=_handler.handleError(_getCurrentElement(elementName),_current,ex);
      if (reply == ErrorHandler.CONTINUE) {
        _attributes.clear();
        _attributeNameList.clear();
        _skipElement=1;
        _skipElementName=elementName;
        return;
      }
 else       if (reply == ErrorHandler.CANCEL) {
        throw new XmlException("String_Node_Str",_currentExternalEntity(),_parser.getLineNumber(),_parser.getColumnNumber());
      }
    }
    if (ex instanceof XmlException) {
      throw (XmlException)ex;
    }
 else {
      throw new XmlException("String_Node_Str" + elementName + "String_Node_Str",_currentExternalEntity(),_parser.getLineNumber(),_parser.getColumnNumber(),ex);
    }
  }
  _attributes.clear();
  _attributeNameList.clear();
}