01: package org.conform.mdl;
02:
03: import org.xml.sax.AttributeList;
04: import org.xml.sax.SAXException;
05: import org.xml.sax.SAXParseException;
06: import org.conform.*;
07: import org.apache.commons.logging.LogFactory;
08:
09: import java.beans.ExceptionListener;
10:
11: public class AttributeHandler extends ScopeHandler implements
12: ObjectScope {
13: private static org.apache.commons.logging.Log LOG = LogFactory
14: .getLog(Meta.class);
15:
16: private String attributeName;
17: private Object object;
18:
19: public AttributeHandler(ExceptionListener exceptionListener) {
20: super (exceptionListener);
21: }
22:
23: public void startElement(String name, AttributeList attributes)
24: throws SAXException {
25: if ("attribute".equals(name)) {
26: attributeName = attributes.getValue("name");
27: LOG.trace("attribute name = " + attributeName);
28: } else {
29: getHandler("java").setScope(this );
30: getHandler("java").startElement(name, attributes);
31: }
32: }
33:
34: public void endElement(String name) throws SAXException {
35: if ("attribute".equals(name)) {
36: if (getScope() instanceof PropertyMeta) {
37: PropertyMeta propertyMeta = (PropertyMeta) getScope();
38: propertyMeta.setAttribute(attributeName, object);
39: } else if (getScope() instanceof BeanMeta) {
40: BeanMeta beanMeta = (BeanMeta) getScope();
41: beanMeta.setAttribute(attributeName, object);
42: }
43: } else
44: getHandler("java").endElement(name);
45: }
46:
47: public void characters(char ch[], int start, int length)
48: throws SAXException {
49: if (attributeName != null)
50: getHandler("java").characters(ch, start, length);
51: else
52: exceptionListener.exceptionThrown(new SAXParseException(
53: "don't extpect characters", locator));
54: }
55:
56: public void setObject(Object object) {
57: LOG.debug("attribute value = " + object);
58: this .object = object;
59: }
60:
61: public Object getObject() {
62: return object;
63: }
64: }
|