Source Code Cross Referenced for Continuer.java in  » Project-Management » XPlanner-0.7b7 » com » technoetic » xplanner » actions » 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 » Project Management » XPlanner 0.7b7 » com.technoetic.xplanner.actions 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Created by IntelliJ IDEA.
003:         * User: Jacques
004:         * Date: May 28, 2005
005:         * Time: 8:52:29 PM
006:         */
007:        package com.technoetic.xplanner.actions;
008:
009:        import java.text.MessageFormat;
010:        import java.util.Date;
011:        import java.util.Iterator;
012:
013:        import net.sf.hibernate.HibernateException;
014:        import net.sf.hibernate.Query;
015:        import net.sf.hibernate.Session;
016:        import org.apache.commons.beanutils.BeanUtils;
017:        import org.apache.log4j.Logger;
018:        import org.apache.struts.util.MessageResources;
019:
020:        import com.technoetic.xplanner.db.hibernate.ThreadSession;
021:        import com.technoetic.xplanner.domain.*;
022:        import com.technoetic.xplanner.history.Historian;
023:        import com.technoetic.xplanner.history.HistoricalEvent;
024:        import com.technoetic.xplanner.util.LogUtil;
025:
026:        public abstract class Continuer {
027:            protected static final Logger LOG = LogUtil.getLogger();
028:
029:            public static final String CONTINUE_ACTION = "Continue";
030:            public static final String MOVE_ACTION = "Move";
031:            protected MessageFormat toText;
032:            protected MessageFormat fromText;
033:            protected MessageFormat fromParentText;
034:            protected MessageFormat toParentText;
035:
036:            protected DomainObjectWikiLinkFormatter linkFormatter;
037:            protected int currentUserId;
038:            private Session hibernateSession;
039:            protected Date when = new Date();
040:            protected Historian historian;
041:            public static final String CONTINUED_FROM_DESCRIPTION_KEY = "continue.description.from";
042:            public static final String CONTINUED_AS_DESCRIPTION_KEY = "continue.description.to";
043:            public static final String CONTINUE_DESCRIPTION_TO_PARENT_KEY = "continue.description.from_parent";
044:            public static final String CONTINUE_DESCRIPTION_FROM_PARENT_KEY = "continue.description.to_parent";
045:            protected DomainMetaDataRepository metaDataRepository;
046:
047:            protected Continuer() {
048:            }
049:
050:            public Continuer(Session session, int currentUserId,
051:                    MessageResources messageResources) {
052:                init(session, messageResources, currentUserId);
053:            }
054:
055:            public final void init(Session session,
056:                    MessageResources messageResources, int currentUserId) {
057:                setHibernateSession(session);
058:                setLinkFormatter(new DomainObjectWikiLinkFormatter());
059:                setMessageResources(messageResources);
060:                setCurrentUserId(currentUserId);
061:            }
062:
063:            public void setMessageResources(MessageResources messageResources) {
064:                toText = new MessageFormat(messageResources
065:                        .getMessage(CONTINUED_FROM_DESCRIPTION_KEY));
066:                fromText = new MessageFormat(messageResources
067:                        .getMessage(CONTINUED_AS_DESCRIPTION_KEY));
068:                fromParentText = new MessageFormat(messageResources
069:                        .getMessage(CONTINUE_DESCRIPTION_FROM_PARENT_KEY));
070:                toParentText = new MessageFormat(messageResources
071:                        .getMessage(CONTINUE_DESCRIPTION_TO_PARENT_KEY));
072:            }
073:
074:            public DomainObject continueObject(DomainObject fromObject,
075:                    DomainObject fromParent, DomainObject toParent)
076:                    throws HibernateException {
077:
078:                LOG.debug("hibernateSession used=" + getHibernateSession());
079:                DomainObject toObject = createContinuingObject(fromObject,
080:                        toParent);
081:
082:                doContinueObject(fromObject, toParent, toObject);
083:
084:                //      FIXME The original iteration should not have container events of created action when continue a story in target targetIteration
085:
086:                updateDescriptionAndHistory(fromObject, fromParent, toObject,
087:                        toParent);
088:
089:                continueNotes((NoteAttachable) fromObject,
090:                        (NoteAttachable) toObject);
091:
092:                getHibernateSession().update(fromObject);
093:                getHibernateSession().update(toParent);
094:                getHibernateSession().update(fromParent);
095:
096:                return toObject;
097:
098:            }
099:
100:            public void setMetaDataRepository(
101:                    DomainMetaDataRepository metaDataRepository) {
102:                this .metaDataRepository = metaDataRepository;
103:            }
104:
105:            private DomainObject createContinuingObject(
106:                    DomainObject fromObject, DomainObject toParent)
107:                    throws HibernateException {
108:                DomainObject toObject = cloneObject(fromObject);
109:                getHibernateSession().save(toObject);
110:                metaDataRepository.setParent(toObject, toParent);
111:                return toObject;
112:            }
113:
114:            private void updateDescriptionAndHistory(DomainObject fromObject,
115:                    DomainObject fromParent, DomainObject toObject,
116:                    DomainObject toParent) {
117:                Object[] parentDescriptionParams = new Object[] {
118:                        linkFormatter.format(fromObject),
119:                        linkFormatter.format(fromParent),
120:                        linkFormatter.format(toObject),
121:                        linkFormatter.format(toParent) };
122:                updateDescription((Describable) toObject, fromText,
123:                        parentDescriptionParams);
124:                updateDescription((Describable) fromObject, toText,
125:                        parentDescriptionParams);
126:
127:                addHistoryEvent(HistoricalEvent.CONTINUED, fromObject, toText
128:                        .format(parentDescriptionParams));
129:                addHistoryEvent(HistoricalEvent.CONTINUED, toObject, fromText
130:                        .format(parentDescriptionParams));
131:                addHistoryEvent(HistoricalEvent.CONTINUED, fromParent,
132:                        toParentText.format(parentDescriptionParams));
133:                addHistoryEvent(HistoricalEvent.CONTINUED, toParent,
134:                        fromParentText.format(parentDescriptionParams));
135:            }
136:
137:            private DomainObject cloneObject(DomainObject fromObject) {
138:                try {
139:                    DomainObject toObject = createInstance(fromObject);
140:                    BeanUtils.copyProperties(toObject, fromObject);
141:                    toObject.setId(0);
142:                    return toObject;
143:
144:                } catch (Exception e) {
145:                    LOG.error(e);
146:                }
147:                return null;
148:            }
149:
150:            protected DomainObject createInstance(DomainObject fromObject)
151:                    throws InstantiationException, IllegalAccessException {
152:                return (DomainObject) fromObject.getClass().newInstance();
153:            }
154:
155:            protected abstract void doContinueObject(DomainObject fromObject,
156:                    DomainObject toParent, DomainObject toObject)
157:                    throws HibernateException;
158:
159:            protected void addHistoryEvent(String type, DomainObject target,
160:                    String description) {
161:                historian = new Historian(getHibernateSession(), currentUserId);
162:                historian.saveEvent(target, type, description, when);
163:            }
164:
165:            private void updateDescription(Describable describable,
166:                    MessageFormat direction, Object[] params) {
167:                describable.setDescription(direction.format(params) + "\n\n"
168:                        + describable.getDescription());
169:            }
170:
171:            public void continueNotes(NoteAttachable fromObject,
172:                    NoteAttachable toObject) throws HibernateException {
173:                Query query = getHibernateSession().getNamedQuery(
174:                        Note.class.getName() + Note.ATTACHED_NOTES_QUERY);
175:                query.setString("attachedToId", String.valueOf(fromObject
176:                        .getId()));
177:                Iterator iterator = query.iterate();
178:                while (iterator.hasNext()) {
179:                    Note note = (Note) iterator.next();
180:                    Note newNote = (Note) cloneObject(note);
181:                    newNote.setAttachedToId(toObject.getId());
182:                    newNote.setId(0);
183:                    getHibernateSession().save(newNote);
184:                }
185:            }
186:
187:            public Session getHibernateSession() {
188:                if (hibernateSession != ThreadSession.get()) {
189:                    LOG.error("hibernateSession mismatch " + hibernateSession
190:                            + " and " + ThreadSession.get());
191:                }
192:                return hibernateSession;
193:            }
194:
195:            public void setHibernateSession(Session hibernateSession) {
196:                this .hibernateSession = hibernateSession;
197:            }
198:
199:            public void setCurrentUserId(int currentUserId) {
200:                this .currentUserId = currentUserId;
201:            }
202:
203:            public void setLinkFormatter(
204:                    DomainObjectWikiLinkFormatter linkFormatter) {
205:                this.linkFormatter = linkFormatter;
206:            }
207:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.