1 package com.loribel.commons.business.abstraction;
2
3 import java.io.*;
4 import java.util.*;
5
6 import org.w3c.dom.*;
7
8 import com.loribel.commons.exception.*;
9
10 /***
11 * Factory to produce BusinessObject.
12 *
13 * @author Grégory Borelli
14 */
15 public interface GB_BOFactory
16 {
17 /***
18 * Add a prototype to this factory.
19 *
20 * @param a_prototype GB_BusinessObjectPrototype - a BusinessObject prototype
21 */
22 void addPrototype(
23 GB_BOPrototype a_prototype);
24
25 /***
26 * Clear the factory.
27 */
28 void clear();
29
30 /***
31 * Return the Prototype for a Business Object.
32 */
33 GB_BOPrototype getPrototype(
34 String a_boName);
35
36 /***
37 * Returns the type of the BusinessObject with boName.
38 */
39 Class getType(
40 String a_boName);
41
42 /***
43 * Load BusinessObjects from XML Document and XPath.
44 * <p>
45 * xPath defines the nodes to be loaded and to transform to BusinessObject.
46 * <p>
47 * Exemples :
48 * <ul>
49 * <li>body/ : to use all children of body
50 * <li> : to use all children of the root
51 * <li>Person : to use only all Person Node (children of the root)
52 * <li>Person[@name='Toto'] : to use only Persons 'Toto'
53 * </ul>
54 *
55 * @param a_document Document -
56 * @param a_xPath String -
57 *
58 * @return GB_SimpleBusinessObject[]
59 */
60 GB_SimpleBusinessObject[] loadFromDocument(
61 Document a_document,
62 String a_xPath)
63 throws GB_LoadException;
64
65 /***
66 * Load BusinessObjects from XML Node and XPath.
67 * <p>
68 * xPath defines the nodes to be loaded and to transform to BusinessObject.
69 * <p>
70 * Exemples :
71 * <ul>
72 * <li>xml/body/* : to use all children of body
73 * <li>xml/* : to use all children of the root xml
74 * <li>xml/Person : to use only all Person nodes (children of the xml)
75 * <li>//Person : to use all Person nodes (deep search)
76 * <li>xml/Person[@name='Toto'] : to use only Person 'Toto'
77 * </ul>
78 *
79 * @param a_node Node - the node to analyse
80 * @param a_xPath String - the xpath to filter element to create
81 * @param a_list GB_BusinessObjectList - the list to complete (null not accepted)
82 *
83 * @return int the number of loaded BusinessObject.
84 */
85 int loadFromNodeIntoList(
86 Node a_node,
87 String a_xPath,
88 Collection a_list)
89 throws GB_LoadException;
90
91 /***
92 * Load BusinessObject from XML
93 * <p>
94 * This method use all children of the <body> Element.
95 * See {@link #loadFromXmlFile(File, String)} for details and options.
96 *
97 * @param a_xmlFile File -
98 *
99 * @return GB_SimpleBusinessObject[]
100 */
101 GB_SimpleBusinessObject[] loadFromXmlFile(
102 File a_xmlFile)
103 throws GB_LoadException;
104
105
106 /***
107 * Load BusinessObject from XML ressource.
108 */
109 GB_SimpleBusinessObject[] loadFromXmlResource(
110 Class a_loader,
111 String a_filename)
112 throws GB_LoadException;
113
114 /***
115 * Load BusinessObject from a reader
116 */
117 GB_SimpleBusinessObject[] loadFromReader(
118 Reader a_reader)
119 throws GB_LoadException;
120
121 /***
122 * Load BusinessObjects from XML and XPath.
123 * <p>
124 * See {@link #loadFromDocument(Document, String)} for details.
125 *
126 * @param a_xmlFile File -
127 * @param a_xPath String -
128 *
129 * @return GB_SimpleBusinessObject[]
130 */
131 GB_SimpleBusinessObject[] loadFromXmlFile(
132 File a_xmlFile,
133 String a_xPath)
134 throws GB_LoadException;
135
136 /***
137 * Create a {@link GB_SimpleBusinessObject} from a Node.
138 * By default we use {@link GB_BOXmlParsor}.
139 *
140 * @param a_xmlNode Node -
141 *
142 * @return GB_SimpleBusinessObject
143 */
144 GB_SimpleBusinessObject newBusinessObject(
145 Node a_xmlNode)
146 throws GB_BOException;
147
148 GB_SimpleBusinessObject newBusinessObject(
149 Node a_xmlNode,
150 String a_boName)
151 throws GB_BOException;
152
153 /***
154 * Return a new instance of a BusinessObject by this BOName.
155 * Try to create from the map of prototype.
156 * If no prototype found, use the default builder with method {@link
157 * #newBusinessObjectDefault()}
158 *
159 * @param a_boName String - the name of BusinessObject
160 *
161 * @return GB_SimpleBusinessObject - a new instance of a BusinessObject
162 */
163 GB_SimpleBusinessObject newBusinessObject(
164 String a_boName);
165
166 /***
167 * Convert a {@link GB_SimpleBusinessObject} to a XML {@link Node}.
168 * The default implementation use {@link GB_BONodeRepresentable}. If you
169 * want to use other
170 * conversion, subclass this method to build the Node.
171 * This method must generate a Node with all properties of BusinessObject,
172 * even the properties with multi values and complex values.
173 *
174 * @param a_businessObject GB_SimpleBusinessObject -
175 * @param a_document Document -
176 *
177 * @return Node
178 */
179 Node newNode(
180 GB_SimpleBusinessObject a_businessObject,
181 Document a_document);
182
183 /***
184 * Write a businessObject to an xml file.
185 * @param a_xmlFile File -
186 * @param a_businessObjects GB_SimpleBusinessObject -
187 * @param a_encoding TODO
188 */
189 void writeXmlFile(
190 File a_xmlFile,
191 GB_SimpleBusinessObject a_businessObjects,
192 String a_encoding)
193 throws IOException;
194
195 /***
196 * Save BusinessObject to XML.
197 * @param a_xmlFile File -
198 * @param a_businessObjects GB_SimpleBusinessObject[] -
199 * @param a_encoding TODO
200 */
201 void writeXmlFile(
202 File a_xmlFile,
203 GB_SimpleBusinessObject[] a_businessObjects,
204 String a_encoding)
205 throws IOException;
206
207 /***
208 * Save BusinessObject to XML.
209 * @param a_businessObjects GB_SimpleBusinessObject[] -
210 */
211 void writeXmlFile(
212 Writer a_writer,
213 GB_SimpleBusinessObject[] a_businessObjects,
214 String a_encoding)
215 throws IOException;
216
217 /***
218 * Save BusinessObjects to XML.
219 */
220 void writeXmlFile(
221 OutputStream a_os,
222 GB_SimpleBusinessObject[] a_businessObjects,
223 String a_encoding)
224 throws IOException;
225
226 /***
227 * Save BusinessObject to XML.
228 *
229 * @param a_xmlFile File -
230 * @param a_businessObjects GB_SimpleBusinessObject[] -
231 */
232
233
234
235
236 }