01: package org.geotools.xml.impl;
02:
03: import java.util.logging.Logger;
04:
05: import org.eclipse.xsd.XSDAttributeDeclaration;
06: import org.eclipse.xsd.XSDElementDeclaration;
07: import org.picocontainer.MutablePicoContainer;
08: import org.w3c.dom.Attr;
09: import org.w3c.dom.Document;
10: import org.w3c.dom.Element;
11:
12: /**
13: * Utility class to be used by bindings to encode an element or an attribute.
14: *
15: *
16: * @author Justin Deoliveira, The Open Planning Project
17: * TODO: rename this class, it is not just for element.s
18: *
19: */
20: public class ElementEncoder {
21:
22: /**
23: * The walker used to traverse bindings
24: */
25: private BindingWalker bindingWalker;
26: /**
27: * The binding context
28: */
29: private MutablePicoContainer context;
30: /**
31: * Logger
32: */
33: private Logger logger;
34:
35: public ElementEncoder(BindingWalker bindingWalker,
36: MutablePicoContainer context) {
37: this .bindingWalker = bindingWalker;
38: this .context = context;
39: }
40:
41: /**
42: * Sets the logger for the encoder to use.
43: * @param logger
44: */
45: public void setLogger(Logger logger) {
46: this .logger = logger;
47: }
48:
49: /**
50: * Encodes a value corresponding to an element in a schema.
51: *
52: * @param value The value to encode.
53: * @param element The declaration of the element corresponding to the value.
54: * @param document The document used to create the encoded element.
55: *
56: * @return The encoded value as an element.
57: */
58: public Element encode(Object value, XSDElementDeclaration element,
59: Document document) {
60:
61: ElementEncodeExecutor executor = new ElementEncodeExecutor(
62: value, element, document, logger);
63: bindingWalker.walk(element, executor, context);
64:
65: return executor.getEncodedElement();
66: }
67:
68: public Attr encode(Object value, XSDAttributeDeclaration attribute,
69: Document document) {
70:
71: AttributeEncodeExecutor executor = new AttributeEncodeExecutor(
72: value, attribute, document, logger);
73:
74: bindingWalker.walk(attribute, executor, context);
75:
76: return executor.getEncodedAttribute();
77: }
78:
79: public void setContext(MutablePicoContainer context) {
80: this.context = context;
81: }
82:
83: }
|