Source Code Cross Referenced for ContentTutorialExample.java in  » J2EE » fleXive » com » flexive » tutorial » persistance » 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 » J2EE » fleXive » com.flexive.tutorial.persistance 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /***************************************************************
002:         *  This file is part of the [fleXive](R) project.
003:         *
004:         *  Copyright (c) 1999-2008
005:         *  UCS - unique computing solutions gmbh (http://www.ucs.at)
006:         *  All rights reserved
007:         *
008:         *  The [fleXive](R) project is free software; you can redistribute
009:         *  it and/or modify it under the terms of the GNU General Public
010:         *  License as published by the Free Software Foundation;
011:         *  either version 2 of the License, or (at your option) any
012:         *  later version.
013:         *
014:         *  The GNU General Public License can be found at
015:         *  http://www.gnu.org/copyleft/gpl.html.
016:         *  A copy is found in the textfile GPL.txt and important notices to the
017:         *  license from the author are found in LICENSE.txt distributed with
018:         *  these libraries.
019:         *
020:         *  This library is distributed in the hope that it will be useful,
021:         *  but WITHOUT ANY WARRANTY; without even the implied warranty of
022:         *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
023:         *  GNU General Public License for more details.
024:         *
025:         *  For further information about UCS - unique computing solutions gmbh,
026:         *  please see the company website: http://www.ucs.at
027:         *
028:         *  For further information about [fleXive](R), please see the
029:         *  project website: http://www.flexive.org
030:         *
031:         *
032:         *  This copyright notice MUST APPEAR in all copies of the file!
033:         ***************************************************************/package com.flexive.tutorial.persistance;
034:
035:        import com.flexive.shared.CacheAdmin;
036:        import com.flexive.shared.EJBLookup;
037:        import com.flexive.shared.content.FxContent;
038:        import com.flexive.shared.content.FxPK;
039:        import com.flexive.shared.exceptions.FxApplicationException;
040:        import com.flexive.shared.interfaces.AssignmentEngine;
041:        import com.flexive.shared.interfaces.ContentEngine;
042:        import com.flexive.shared.interfaces.TypeEngine;
043:        import com.flexive.shared.structure.FxType;
044:        import com.flexive.shared.value.FxString;
045:        import com.flexive.shared.workflow.Step;
046:
047:        /**
048:         * Tutorial on how to work with FxContents
049:         *
050:         * @author Markus Plesser (markus.plesser@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
051:         */
052:        public class ContentTutorialExample {
053:
054:            //Customer FxType
055:            public final static String CUSTOMER = "Customer";
056:            //Hardware FxType
057:            public final static String HARDWARE = "Hardware";
058:            //Software FxType
059:            public final static String SOFTWARE = "Software";
060:            //Relation Customer->Hardware,Software
061:            public final static String CUSTOMER_PRODUCT = "CustProd";
062:
063:            //ContentEngine reference
064:            private ContentEngine ce;
065:            //AssignmentEngine reference
066:            private AssignmentEngine ae;
067:            //TypeEngine reference
068:            private TypeEngine te;
069:
070:            //used types
071:            private FxType customerType, hardwareType, softwareType,
072:                    relationType;
073:
074:            /**
075:             * Initialize references to needed 'engines'
076:             */
077:            public ContentTutorialExample() {
078:                this .ce = EJBLookup.getContentEngine();
079:                this .ae = EJBLookup.getAssignmentEngine();
080:                this .te = EJBLookup.getTypeEngine();
081:                this .customerType = CacheAdmin.getEnvironment().getType(
082:                        CUSTOMER);
083:                this .hardwareType = CacheAdmin.getEnvironment().getType(
084:                        HARDWARE);
085:                this .softwareType = CacheAdmin.getEnvironment().getType(
086:                        SOFTWARE);
087:                this .relationType = CacheAdmin.getEnvironment().getType(
088:                        CUSTOMER_PRODUCT);
089:            }
090:
091:            /**
092:             * Create a new customer instance
093:             *
094:             * @return primary key of the customer
095:             * @throws FxApplicationException on errors
096:             */
097:            public FxPK createInstance() throws FxApplicationException {
098:                FxContent customer = ce.initialize(customerType.getId());
099:                customer.setValue("/Name", new FxString(false, "John Doe"));
100:                customer.setValue("/BillingAddress/Street", new FxString(false,
101:                        "Downingstreet 42"));
102:                customer.setValue("/BillingAddress/ZIP", new FxString(false,
103:                        "0815"));
104:                return ce.save(customer);
105:            }
106:
107:            /**
108:             * Create a new version for Customer
109:             *
110:             * @param pk primary key
111:             * @return primary key of the new version
112:             * @throws FxApplicationException on errors
113:             */
114:            public FxPK createVersion(FxPK pk) throws FxApplicationException {
115:                FxContent customer = ce.load(pk);
116:                return ce.createNewVersion(customer);
117:            }
118:
119:            /**
120:             * Change the step of the customer identified by its primary key
121:             * to the first step available from his workflow routing.
122:             * If no route is available, do nothing.
123:             *
124:             * @param pk primary key of the customer
125:             * @throws FxApplicationException on errors
126:             */
127:            public void changeWorkflowStep(FxPK pk)
128:                    throws FxApplicationException {
129:                FxContent customer = ce.load(pk);
130:                //get the step the customer should be set to
131:                //we just retrieve the first available from the customers
132:                //valid target steps
133:                Step[] targets = EJBLookup.getWorkflowRouteEngine().getTargets(
134:                        customer.getStepId());
135:                if (targets.length > 0) {
136:                    customer.setStepId(targets[0].getId());
137:                    ce.save(customer);
138:                }
139:            }
140:
141:            /**
142:             * Add a delivery address to a customer
143:             *
144:             * @param pk primary key
145:             * @throws FxApplicationException on errors
146:             */
147:            public void addDeliveryAddress(FxPK pk)
148:                    throws FxApplicationException {
149:                FxContent customer = ce.load(pk);
150:                customer.setValue("/DeliveryAddress/Street", new FxString(
151:                        false, "Knightsbridge 84"));
152:                customer.setValue("/DeliveryAddress/ZIP", new FxString(false,
153:                        "4711"));
154:                ce.save(customer);
155:            }
156:
157:            /**
158:             * Change the delivery address property
159:             *
160:             * @param pk primary key
161:             * @throws FxApplicationException on errors
162:             */
163:            public void changeDeliveryAddress(FxPK pk)
164:                    throws FxApplicationException {
165:                FxContent customer = ce.load(pk);
166:                //variant1 - set a new value
167:                customer.setValue("/DeliveryAddress/Street", new FxString(
168:                        false, "Knightsbridge 85"));
169:                //variant2 - update existing value
170:                FxString street = (FxString) customer
171:                        .getValue("/DeliveryAddress/Street");
172:                street.setValue("Knightsbridge 85");
173:                ce.save(customer);
174:            }
175:
176:            /**
177:             * Create a piece of software or hardware
178:             *
179:             * @param type either the software or hardware type
180:             * @param name name of the product
181:             * @return primary key of the product
182:             * @throws FxApplicationException on errors
183:             */
184:            private FxPK createProduct(FxType type, String name)
185:                    throws FxApplicationException {
186:                FxContent product = ce.initialize(type.getId());
187:                product.setValue("/Name", new FxString(true, name));
188:                return ce.save(product);
189:            }
190:
191:            /**
192:             * Create a relation between a customer and products
193:             *
194:             * @return primary key of the customer
195:             * @throws FxApplicationException on errors
196:             */
197:            public FxPK relate() throws FxApplicationException {
198:                FxPK customer = createInstance();
199:                FxPK software = createProduct(softwareType, "[fleXive]");
200:                FxPK hardware = createProduct(hardwareType, "Fluxcompensator");
201:
202:                FxContent relation = ce.initialize(relationType.getId());
203:                relation.setRelatedSource(customer).setRelatedDestination(
204:                        software);
205:                ce.save(relation);
206:                relation = ce.initialize(relationType.getId());
207:                relation.setRelatedSource(customer).setRelatedDestination(
208:                        hardware);
209:                ce.save(relation);
210:                return customer;
211:            }
212:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.