Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.sapia.util.xml.confix;
  
  
  // Import of Sapia's utility classes
  // ---------------------------------
  
 // Imports of David Meggison's SAX classes
 // ---------------------------------------
Implements a HandlerStateIF that is used by the SAXProcessor.

Author(s):
JC Desrochers
Copyright:
Copyright &.169; 2002-2003 Sapia Open Source Software. All Rights Reserved.
License:
Read the license.txt file of the jar or visit the license page at the Sapia OSS web site
 
 public class ConfixHandlerState implements HandlerStateIF {
   /////////////////////////////////////////////////////////////////////////////////////////
   /////////////////////////////////  INSTANCE ATTRIBUTES  /////////////////////////////////
   /////////////////////////////////////////////////////////////////////////////////////////
 
  
Indicates if this handler state is currently parsing.
 
   private boolean _isParsing;

  
Indicates if this handler state is currently parsing a child element.
 
   private boolean _isParsingChild;

  
The SAX processor that manage this handler state.
 
   private SAXProcessor _theProcessor;

  
Buffer that contains the characters of the element beign parsed.
 
   private StringBuffer _theContent;

  
The parent object that represent the parent element beign parsed.
 
   private Object _theParentObject;

  
The current object that represent the element beign parsed.
 
   private Object _theCurrentObject;

  
Indicates if the current object has been assigned to its parent.
 
   private boolean _isCurrentObjectAssigned;
 
   /////////////////////////////////////////////////////////////////////////////////////////
   ////////////////////////////////////  CONSTRUCTORS  /////////////////////////////////////
   /////////////////////////////////////////////////////////////////////////////////////////
 
  
Creates a new ConfixHandlerState instance
 
   public ConfixHandlerState(SAXProcessor aProcessorObject aParentObject) {
     if (aParentObject == null) {
       throw new IllegalArgumentException("The parent object passed in is null");
     }
 
             = new StringBuffer();
           = aProcessor;
        = aParentObject;
   }

  
Creates a new ConfixHandlerState instance
 
   public ConfixHandlerState(SAXProcessor aProcessor) {
          = new StringBuffer();
        = aProcessor;
   }
 
   /////////////////////////////////////////////////////////////////////////////////////////
   //////////////////////////////////  ACCESSOR METHODS  ///////////////////////////////////
   /////////////////////////////////////////////////////////////////////////////////////////
 
  
Returns the result object of this handler state.

Returns:
The result object of this handler state.
Throws:
java.lang.IllegalStateException If this handler state is currently parsing.
 
   public Object getResult() {
     if ( == true) {
       throw new IllegalStateException("This handler state is currently parsing");
     }
 
     return ;
   }
 
   /////////////////////////////////////////////////////////////////////////////////////////
   ///////////////////////////////  INTERACE IMPLEMENTATION  ///////////////////////////////
   /////////////////////////////////////////////////////////////////////////////////////////
 
  
Receives the notification of the the start of an element.

Parameters:
aContext The handler context.
anUri The namespace URI associated with the element
aLocalName The element type local name.
aQualifiedName The element type qualified name.
someAttributes The specified or defaulted attributes.
Throws:
org.xml.sax.SAXException If an exception occurs.
  public void startElement(HandlerContextIF aContextString anUri,
    String aLocalNameString aQualifiedNameAttributes someAttributes)
    throws SAXException {
    if (!) {
       = true;
      CreationStatus aStatus = null;
      String         prefix = XmlUtil.extractPrefix(aQualifiedName);
      try {
        // Creating the object
        aStatus   = .getObjectFactory().newObjectFor(prefix,
            anUriaLocalName);
                  = aStatus.getCreated();
           = aStatus.wasAssigned();
        // Process the attributes of the element
        for (int i = 0; i < someAttributes.getLength(); i++) {
          String anAttributeName  = someAttributes.getLocalName(i);
          String anAttributeValue = someAttributes.getValue(i);
          AbstractXMLProcessor.invokeSetter(aLocalName,
            anAttributeNameanAttributeValue);
        }
      } catch (ObjectCreationException oce) {
        if ( == null) {
          String aMessage = "Unable to create an object for the element " +
            aQualifiedName;
          throw new SAXException(aMessageoce);
        }
      } catch (ConfigurationException ce) {
        String aMessage = "Unable to process the content of the element " +
          aLocalName;
        throw new SAXException(aMessagece);
      }
    } else {
      HandlerStateIF aChildHandler;
      if ( instanceof HandlerStateIF) {
        aChildHandler = (HandlerStateIF;
      } else {
        aChildHandler = new ConfixHandlerState();
      }
       = true;
      aContext.setCurrentState(aChildHandleranUriaLocalName,
        aQualifiedNamesomeAttributes);
    }
  }

  
Receives the notification of the the end of an element.

Parameters:
aContext The handler context.
anUri The namespace URI associated with the element
aLocalName The element type local name.
aQualifiedName The element type qualified name.
Throws:
org.xml.sax.SAXException If an exception occurs.
  public void endElement(HandlerContextIF aContextString anUri,
    String aLocalNameString aQualifiedNamethrows SAXException {
    if () {
       = false;
    } else {
      String aValue = .toString().trim();
      if (aValue.length() > 0) {
        if ( != null) {
          try {
            AbstractXMLProcessor.invokeSetter(aLocalName,
              "Text"aValue);
          } catch (ConfigurationException ce) {
            String aMessage = "The object " +
              .getClass().getName() +
              " does not accept free text";
            throw new SAXException(aMessagece);
          }
        } else {
          try {
            AbstractXMLProcessor.invokeSetter(.getClass()
                                                              .getName(),
              aLocalNameaValue);
             = true;
          } catch (ConfigurationException ce) {
            String aMessage = "Unable to process the content of the element " +
              aLocalName;
            throw new SAXException(aMessagece);
          }
        }
      } else if ( == null) {
        String aMessage = "Unable to create an object for the element " +
          aQualifiedName;
        throw new SAXException(aMessage);
      }
      if ( instanceof ObjectCreationCallback) {
        try {
        } catch (ConfigurationException e) {
          throw new SAXException("Could not create object"e);
        }
      }
      if ( instanceof NullObject) {
         = null;
      }
      else  if ( instanceof NullObject) {
      }
      // assign obj to parent through setXXX or addXXX
      else  if (( != null) && ! &&
            !( instanceof NullObject)) {
        try {
          AbstractXMLProcessor.assignToParent(,
            aLocalName);
        } catch (ConfigurationException ce) {
          StringBuffer aBuffer = new StringBuffer(
              "Unable to assign the object ").append()
                                             .append(" to the parent ")
                                             .append(.getClass()
                                                                                                         .getName());
          throw new SAXException(aBuffer.toString(), ce);
        }
      }
       = false;
      aContext.removeCurrentState(anUriaLocalNameaQualifiedName);
    }
  }

  
Receives the notification of character data inside an element.

Parameters:
aContext The handler context.
someChars The characters.
anOffset The start position in the character array.
aLength The number of characters to use from the character array.
Throws:
org.xml.sax.SAXException If an exception occurs.
  public void characters(HandlerContextIF aContextchar[] someChars,
    int anOffsetint lengththrows SAXException {
    .append(someCharsanOffsetlength);
  }

  
Receives the notification of ignorable whitespace in element content.

Parameters:
aContext The handler context.
someChars The whitespace characters.
anOffset The start position in the character array.
aLength The number of characters to use from the character array.
Throws:
org.xml.sax.SAXException If an exception occurs.
  public void ignorableWhitespace(HandlerContextIF aContextchar[] someChars,
    int anOffsetint aLengththrows SAXException {
    // IGNORING WHITESPACES...
  }
New to GrepCode? Check out our FAQ X