1. /*
  2. * Copyright 2001-2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.apache.commons.betwixt.digester;
  17. import org.apache.commons.betwixt.XMLBeanInfo;
  18. import org.apache.commons.logging.Log;
  19. import org.apache.commons.logging.LogFactory;
  20. import org.xml.sax.Attributes;
  21. import org.xml.sax.SAXException;
  22. /** <p><code>InfoRule</code> the digester Rule for parsing the info element.</p>
  23. *
  24. * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  25. * @version $Revision: 1.9 $
  26. */
  27. public class InfoRule extends RuleSupport {
  28. /** Logger */
  29. private static final Log log = LogFactory.getLog( InfoRule.class );
  30. /** <code>XMLBeanInfo</code> being created */
  31. private XMLBeanInfo xmlBeanInfo;
  32. /** Base constructor */
  33. public InfoRule() {
  34. }
  35. // Rule interface
  36. //-------------------------------------------------------------------------
  37. /**
  38. * Process the beginning of this element.
  39. *
  40. * @param attributes The attribute list of this element
  41. * @throws SAXException if the primitiveTypes attribute contains an invalid value
  42. */
  43. public void begin(String name, String namespace, Attributes attributes) throws SAXException {
  44. Class beanClass = getBeanClass();
  45. xmlBeanInfo = new XMLBeanInfo( beanClass );
  46. String value = attributes.getValue( "primitiveTypes" );
  47. if ( value != null ) {
  48. if ( value.equalsIgnoreCase( "element" ) ) {
  49. getXMLInfoDigester().setAttributesForPrimitives( false );
  50. } else if ( value.equalsIgnoreCase( "attribute" ) ) {
  51. getXMLInfoDigester().setAttributesForPrimitives( true );
  52. } else {
  53. throw new SAXException(
  54. "Invalid value inside element <info> for attribute 'primitiveTypes'."
  55. + " Value should be 'element' or 'attribute'" );
  56. }
  57. }
  58. getDigester().push(xmlBeanInfo);
  59. }
  60. /**
  61. * Process the end of this element.
  62. */
  63. public void end(String name, String namespace) {
  64. Object top = getDigester().pop();
  65. }
  66. }