/*!
  @header ECXMLEventHandler
  @abstract Module of Encore
 
  @availability OS X, GNUstep
  @copyright 2004, 2005, 2006 Oliver Langer

  Author: Oliver Langer

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA

  <pre>
  -------------------------------------------------------------------------
  Modification history

  27.11.05 ola     initial version
  22.08.06 ola     license changed
  -------------------------------------------------------------------------
  </pre>
*/

#include <ECXMLEventHandler.h>
#include <ECXMLControl.h>


@implementation ECXMLEventHandler

- initWithXMLControl: (ECXMLControl *) aControl {
  self = [super init];
  
  self->xmlControl = [aControl retain];
  
  
  return self;
}


- (void) dealloc { 
  if( nil != self->xmlControl ) {
    [self->xmlControl release];
  }
  
  [super dealloc];
}


- (NSData*) parser: (NSXMLParser*)aParser
  resolveExternalEntityName: (NSString*)aName
  systemID: (NSString*)aSystemID {

  return nil;
}


- (void) parser: (NSXMLParser*)aParser
  didEndElement: (NSString*)anElementName
  namespaceURI: (NSString*)aNamespaceURI
  qualifiedName: (NSString*)aQualifierName {

  NSLog( @"Element %@ ended...", anElementName );
}


- (void) parser: (NSXMLParser*)aParser
  didEndMappingPrefix: (NSString*)aPrefix {
}


- (void) parser: (NSXMLParser*)aParser
  didStartElement: (NSString*)anElementName
  namespaceURI: (NSString*)aNamespaceURI
  qualifiedName: (NSString*)aQualifierName
  attributes: (NSDictionary*)anAttributeDict {

#if 0
  Class classToGet;
  id object;

  NSLog( @"Element %@ start...", anElementName );

  classToGet = NSClassFromString( anElementName );

  if( nil == classToGet ) {
    NSLog( @"Unable to find class for %@", anElementName );
  } else {
    id instance = [[classToGet alloc] init];
    
    if( nil != instance ) {
      id top = [self->stack lastObject];

      if( nil != top ) {
        NSString *setMethod;
        SEL methodToCall;

        setMethod = [[[NSString alloc] initWithFormat: @"set%@:", anElementName]
          autorelease];

        NSLog( @"Looking for method: %@", setMethod );

        methodToCall = NSSelectorFromString( setMethod );
       
        if( [top respondsToSelector: methodToCall] ) {
          NSLog( @"Sending method call..." );
          [top performSelector: methodToCall withObject: instance];
        }
      }
      
      NSLog( @"PUSH object!" );
      [self->stack addObject: instance];
    }
  }
  
#endif
}


- (void) parser: (NSXMLParser*)aParser
  didStartMappingPrefix: (NSString*)aPrefix
  toURI: (NSString*)aNamespaceURI {
}


- (void) parser: (NSXMLParser*)aParser
  foundAttributeDeclarationWithName: (NSString*)anAttributeName
  forElement: (NSString*)anElementName
  type: (NSString*)aType
  defaultValue: (NSString*)aDefaultValue {
}


- (void) parser: (NSXMLParser*)aParser
  foundCDATA: (NSData*)aBlock {
}


- (void) parser: (NSXMLParser*)aParser
  foundCharacters: (NSString*)aString {
}


- (void) parser: (NSXMLParser*)aParser
  foundComment: (NSString*)aComment {
}


- (void) parser: (NSXMLParser*)aParser
  foundElementDeclarationWithName: (NSString*)anElementName
  model: (NSString*)aModel {
}


- (void) parser: (NSXMLParser*)aParser
  foundExternalEntityDeclarationWithName: (NSString*)aName
  publicID: (NSString*)aPublicID
  systemID: (NSString*)aSystemID {
}


- (void) parser: (NSXMLParser*)aParser
  foundIgnorableWhitespace: (NSString*)aWhitespaceString {
}


- (void) parser: (NSXMLParser*)aParser
  foundInternalEntityDeclarationWithName: (NSString*)aName
  value: (NSString*)aValue {
}


- (void) parser: (NSXMLParser*)aParser
  foundNotationDeclarationWithName: (NSString*)aName
  publicID: (NSString*)aPublicID
  systemID: (NSString*)aSystemID {
}


- (void) parser: (NSXMLParser*)aParser
  foundProcessingInstructionWithTarget: (NSString*)aTarget
  data: (NSString*)aData {
}


- (void) parser: (NSXMLParser*)aParser
  foundUnparsedEntityDeclarationWithName: (NSString*)aName
  publicID: (NSString*)aPublicID
  systemID: (NSString*)aSystemID
  notationName: (NSString*)aNotationName {
}


- (void) parser: (NSXMLParser*)aParser
  parseErrorOccurred: (NSError*)anError {
}


- (void) parser: (NSXMLParser*)aParser
  validationErrorOccurred: (NSError*)anError {
}


- (void) parserDidEndDocument: (NSXMLParser*)aParser {
}


- (void) parserDidStartDocument: (NSXMLParser*)aParser {
}

@end
