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


001:        /*
002:         * Copyright (c) Mateusz Prokopowicz. All Rights Reserved.
003:         */
004:
005:        package com.technoetic.xplanner;
006:
007:        import java.util.List;
008:        import java.util.Properties;
009:        import java.util.Enumeration;
010:        import java.util.Set;
011:        import java.util.HashSet;
012:        import java.util.Collection;
013:        import java.util.Iterator;
014:        import java.util.Collections;
015:        import java.util.ArrayList;
016:
017:        import net.sf.hibernate.Hibernate;
018:        import net.sf.hibernate.HibernateException;
019:        import net.sf.hibernate.Session;
020:        import net.sf.hibernate.SessionFactory;
021:        import net.sf.hibernate.type.Type;
022:        import org.springframework.orm.hibernate.HibernateCallback;
023:        import org.springframework.orm.hibernate.HibernateTemplate;
024:
025:        import com.technoetic.xplanner.domain.Attribute;
026:        import com.technoetic.xplanner.domain.Iteration;
027:        import com.technoetic.xplanner.domain.Project;
028:        import com.technoetic.xplanner.domain.Task;
029:        import com.technoetic.xplanner.domain.UserStory;
030:
031:        /**
032:         * User: mprokopowicz
033:         * Date: Feb 6, 2006
034:         * Time: 12:59:52 PM
035:         */
036:        public class DomainSpecificProperties extends Properties {
037:            private SessionFactory sessionFactory;
038:            private Object object;
039:
040:            protected DomainSpecificProperties(Properties defaultProperties,
041:                    SessionFactory sessionFactory, Object domainObject) {
042:                super (defaultProperties);
043:                this .sessionFactory = sessionFactory;
044:                this .object = domainObject;
045:            }
046:
047:            public String getProperty(String key) {
048:                HibernateTemplate hibernateTemplate = new HibernateTemplate(
049:                        this .sessionFactory);
050:                final Integer attributeTargetId = getAttributeTargetId(object,
051:                        hibernateTemplate);
052:                if (attributeTargetId != null) {
053:                    HibernateCallback action = new GetAttributeHibernateCallback(
054:                            attributeTargetId, key);
055:                    Attribute attribute = (Attribute) hibernateTemplate
056:                            .execute(action);
057:                    if (attribute != null) {
058:                        return attribute.getValue();
059:                    }
060:                }
061:                return super .getProperty(key);
062:            }
063:
064:            private Integer getAttributeTargetId(Object object,
065:                    HibernateTemplate hibernateTemplate) {
066:                if (object instanceof  Project) {
067:                    Project project = (Project) object;
068:                    return new Integer(project.getId());
069:                }
070:                if (object instanceof  Iteration) {
071:                    Iteration iteration = (Iteration) object;
072:                    return new Integer(iteration.getProjectId());
073:                }
074:                Integer iterationId = null;
075:                if (object instanceof  UserStory) {
076:                    UserStory story = (UserStory) object;
077:                    iterationId = new Integer(story.getIterationId());
078:                }
079:                if (object instanceof  Task) {
080:                    Task task = (Task) object;
081:                    iterationId = new Integer(task.getStory().getIterationId());
082:                }
083:                if (iterationId != null) {
084:                    final Integer id = iterationId;
085:                    Iteration iteration = (Iteration) hibernateTemplate
086:                            .execute(new HibernateCallback() {
087:                                public Object doInHibernate(Session session)
088:                                        throws HibernateException {
089:                                    return session.load(Iteration.class, id);
090:                                }
091:                            });
092:                    return new Integer(iteration.getProjectId());
093:                }
094:                return null;
095:            }
096:
097:            public synchronized Enumeration keys() {
098:                Set keys = keySet();
099:                return Collections.enumeration(keys);
100:            }
101:
102:            public Set keySet() {
103:                Set keys = new HashSet(defaults.keySet());
104:                keys.addAll(super .keySet());
105:                return keys;
106:            }
107:
108:            public Collection values() {
109:                List values = new ArrayList(defaults.values());
110:                values.addAll(super .values());
111:                return values;
112:            }
113:
114:            private static class GetAttributeHibernateCallback implements 
115:                    HibernateCallback {
116:                private final Integer attributeTargetId;
117:                private final String key;
118:
119:                public GetAttributeHibernateCallback(Integer attributeTargetId,
120:                        String key) {
121:                    this .attributeTargetId = attributeTargetId;
122:                    this .key = key;
123:                }
124:
125:                public Object doInHibernate(Session session)
126:                        throws HibernateException {
127:                    Attribute attribute = null;
128:
129:                    List attributeList = session
130:                            .find(
131:                                    "select attribute from Attribute attribute where attribute.targetId = ? and attribute.name= ? ",
132:                                    new Object[] { attributeTargetId, key },
133:                                    new Type[] { Hibernate.INTEGER,
134:                                            Hibernate.STRING });
135:                    if (attributeList.size() > 0) {
136:                        attribute = (Attribute) attributeList.get(0);
137:                    }
138:                    return attribute;
139:                }
140:            }
141:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.