Source Code Cross Referenced for BusinessObjectList.java in  » Web-Framework » JAT » com » jat » business » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Framework » JAT » com.jat.business 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.jat.business;
002:
003:        import java.io.IOException;
004:        import java.util.Enumeration;
005:        import javax.xml.parsers.ParserConfigurationException;
006:
007:        import org.w3c.dom.Document;
008:        import org.xml.sax.SAXException;
009:        import com.jat.core.config.Config;
010:        import com.jat.core.log.LogManager;
011:        import com.jat.integration.DataSource;
012:        import com.jat.integration.DataSourceFactory;
013:        import com.jat.integration.IntegrationException;
014:        import com.jat.util.OrderVector;
015:        import com.jat.util.xml.XMLUtil;
016:        import com.jat.util.xml.XMLable;
017:        import java.io.Serializable;
018:
019:        /**
020:         * <p>Title: JAT</p>
021:         * <p>Description: This class is a list of Business Object ({@link com.jat.business.BusinessObject}).
022:         * <br>Is possible to sort the Business Objects by {@link orderBy} method
023:         * or get the XML format of an instance of this class ({@link toXML} and {@link getXmlDocument} methods).
024:         * </p>
025:         * <p>
026:         * If you want to build your own Business Object, you must create:
027:         * <ul>
028:         * <li>The Business Object extending {@link com.jat.business.BusinessObject} class</li>
029:         * <li>The Business Object Factory extending {@link com.jat.business.BusinessObjectFactory} class</li>
030:         * <li>The Business Object List object extending {@link com.jat.business.BusinessObjectList} class</li>
031:         * </ul>
032:         * </p>
033:         * <p>Copyright: Copyright (c) 2004 -2005 Stefano Fratini (stefano.fratini@gmail.com)</p>
034:         * <p>Distributed under the terms of the GNU Lesser General Public License, v2.1 or later</p>
035:         * @author stf
036:         * @version 1.2
037:         * @since 1.0
038:         * @see com.com.jat.business.BusinessObject
039:         * @see com.com.jat.business.BusinessObjectFactory
040:         */
041:
042:        public abstract class BusinessObjectList implements  XMLable,
043:                Serializable {
044:
045:            public BusinessObjectList(String dataSourceName) {
046:                this .dataSourceName = dataSourceName;
047:                this .events = new OrderVector();
048:            }
049:
050:            public BusinessObjectList(String dataSourceName,
051:                    BusinessObjectPropertyList props) {
052:                this (dataSourceName);
053:                for (Enumeration e = props.elements(); e.hasMoreElements();) {
054:                    BusinessObjectProperties prop = (BusinessObjectProperties) e
055:                            .nextElement();
056:                    BusinessObject item = this .getBusinessObject(prop);
057:                    this .addElement(item);
058:                }
059:            }
060:
061:            public BusinessObject firstElement() {
062:                return (BusinessObject) this .events.firstElement();
063:            }
064:
065:            public BusinessObject elementAt(int index) {
066:                return (BusinessObject) this .events.elementAt(index);
067:            }
068:
069:            public Enumeration elements() {
070:                return this .events.elements();
071:            }
072:
073:            public int size() {
074:                return this .events.size();
075:            }
076:
077:            public void orderBy(String field, boolean ascendent)
078:                    throws Exception {
079:                if (ascendent)
080:                    this .events = OrderVector
081:                            .orderAscendent(this .events, field);
082:                else
083:                    this .events = OrderVector.orderDescendent(this .events,
084:                            field);
085:            }
086:
087:            public String getDataSourceName() {
088:                return this .dataSourceName;
089:            }
090:
091:            /**
092:             * Execute the configured operation (execName) for all Business Object in the list
093:             * and return the result list of each pperation
094:             * @param execName the name of an operation configured
095:             * @return the list of {@link  com.jat.business.BusinessObjectProperties}
096:             * containing the exection result for each operation
097:             * @throws BusinessException if an exception occours
098:             */
099:            public BusinessObjectPropertyList persist(String execName)
100:                    throws BusinessException {
101:                try {
102:                    MultiBusinessObjectProperties multi = new MultiBusinessObjectProperties();
103:                    for (Enumeration e = this .elements(); e.hasMoreElements();)
104:                        multi.put(execName, (BusinessObject) e.nextElement());
105:                    return DataSourceFactory.getFactory().getDataSource(
106:                            this .getDataSourceName()).execute(multi);
107:                } catch (IntegrationException ex) {
108:                    throw new BusinessException(ex);
109:                }
110:            }
111:
112:            /**
113:             * Refresh the list of {@link com.jat.business.BusinessObject} reloading from the same data source
114:             * and using the same parameters (query name and properties) of the current instance was loaded.
115:             * Before use this method be sure that this object has been instanced throw a {@link com.jat.business.BusinessObjectFactory} object,
116:             * otherwise a {@link com.jat.business.BusinessException} will be thrown.
117:             * @return the {@link com.jat.business.BusinessObjectList} reloaded from the data source
118:             * @throws BusinessException if this class has not been instanced throw a {@link com.jat.business.BusinessObjectFactory} object
119:             * @throws IntegrationException whenever an Integration error occours
120:             */
121:            public BusinessObjectList refresh() throws BusinessException,
122:                    IntegrationException {
123:                if (this .requestName == null)
124:                    throw new BusinessException(
125:                            this .getClass().getName()
126:                                    + "::refresh: Operation name is not defined: impossible to refresh the list");
127:                BusinessObjectList bol = this .getBusinessObjectList(
128:                        this .factory, this .getDataSourceName(),
129:                        this .requestName, this .requestProperties);
130:                this .events = bol.events;
131:                return bol;
132:            }
133:
134:            /**
135:             * Return a list of business object loaded from a data source by an operation using the specific properties
136:             * @param factory the {@link com.jat.business.BusinessObjectFactory} instance
137:             * @param dataSourceName the configured data source (see {@link com.jat.integration.DataSource} configuration)
138:             * @param name the operation name of the data source (see {@link com.jat.integration.DataSource} configuration)
139:             * @param properties the list of property used by the specified operation. It can be null.
140:             * @return the list of Business Object matching with properties in the operation of the data source
141:             * @throws java.lang.Exception if an error occours
142:             */
143:            public static BusinessObjectList getBusinessObjectList(
144:                    BusinessObjectFactory factory, String dataSourceName,
145:                    String name, BusinessObjectProperties properties)
146:                    throws BusinessException, IntegrationException {
147:                if (factory == null)
148:                    throw new BusinessException(
149:                            "Business Factory cannot be null");
150:                DataSource ds = DataSourceFactory.getFactory().getDataSource(
151:                        dataSourceName);
152:                if (ds == null)
153:                    throw new BusinessException("Data Source '"
154:                            + dataSourceName + "' not found");
155:                BusinessObjectPropertyList props = ds.getData(name, properties);
156:                BusinessObjectList bol = factory.getBusinessObjectList(
157:                        dataSourceName, props);
158:                bol.setRequestProperties(factory, name, properties);
159:                return bol;
160:            }
161:
162:            public void addElement(BusinessObject item) {
163:                //this.remove(item);
164:                this .events.addAscElement(item);
165:                LogManager.sendDebug(this .getClass().getName()
166:                        + ":: addElement: event: " + item.toString());
167:            }
168:
169:            public String toString() {
170:                String ret = getClass().getName() + ": ";
171:                for (Enumeration e = this .elements(); e.hasMoreElements();) {
172:                    ret += "{" + e.nextElement().toString() + "}";
173:                }
174:                return ret;
175:            }
176:
177:            public boolean remove(BusinessObject item) {
178:                if (item == null)
179:                    return false;
180:                return this .events.removeElement(item);
181:            }
182:
183:            public void add(BusinessObjectList list) {
184:                for (Enumeration e = list.elements(); e.hasMoreElements();)
185:                    this .events.add(e.nextElement());
186:                this .events = OrderVector.orderAscendent(this .events);
187:            }
188:
189:            protected void setRequestProperties(BusinessObjectFactory factory,
190:                    String requestName,
191:                    BusinessObjectProperties requestProperties) {
192:                this .factory = factory;
193:                this .requestName = requestName;
194:                this .requestProperties = requestProperties;
195:            }
196:
197:            /**
198:             * return a Business Object from a set of properties.
199:             * <br/>Implement this method to build a new instance of your Business Object
200:             * using the constructor with data source name and {@link com.jat.businessBusinessObjectProperties}
201:             * @param props the list of properties
202:             * @return a new instance of a Business Object implementation
203:             */
204:            protected abstract BusinessObject getBusinessObject(
205:                    BusinessObjectProperties props);
206:
207:            /* From XMLable interface */
208:            public Document getXmlDocument(boolean validate)
209:                    throws SAXException, ParserConfigurationException,
210:                    IOException {
211:                String xml = this .toXML();
212:                return XMLUtil.getXMLDocument(xml, validate, false)
213:                        .getDocument();
214:            }
215:
216:            public String toXML() {
217:                initXml();
218:                String xml = "";
219:                if (schema != null && !schema.equals(""))
220:                    xml = "<"
221:                            + list
222:                            + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\""
223:                            + schema + "\">";
224:                else
225:                    xml = "<" + list + ">";
226:                for (Enumeration e = this .elements(); e.hasMoreElements();) {
227:                    BusinessObject obj = (BusinessObject) e.nextElement();
228:                    xml += obj.toXML();
229:                }
230:                xml += "</" + list + ">";
231:                return xml;
232:            }
233:
234:            private void initXml() {
235:                try {
236:                    list = Config.getCurrent().getValue("xml_object", "list");
237:                } catch (Exception ex) {
238:                    list = "list";
239:                    LogManager.sendWarning(this .getClass().getName()
240:                            + "::toXML: exception: " + ex);
241:                }
242:                try {
243:                    schema = Config.getCurrent().getValue("xml_object",
244:                            "schema");
245:                } catch (Exception ex) {
246:                    schema = "";
247:                    LogManager.sendWarning(this .getClass().getName()
248:                            + "::toXML: exception: " + ex);
249:                }
250:            }
251:
252:            static String list = null;
253:            static String schema = null;
254:
255:            private OrderVector events;
256:            private String dataSourceName;
257:            private BusinessObjectProperties requestProperties = null;
258:            private BusinessObjectFactory factory = null;
259:            private String requestName = null;
260:
261:            /** @link dependency
262:             * @stereotype instantiate
263:             * @label objects*/
264:            /*# BusinessObject lnkBusinessObject; */
265:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.