Source Code Cross Referenced for AssociatedEntityMapping.java in  » Content-Management-System » daisy » org » outerj » daisy » sync » mapping » 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 » Content Management System » daisy » org.outerj.daisy.sync.mapping 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.outerj.daisy.sync.mapping;
002:
003:        import java.util.ArrayList;
004:        import java.util.List;
005:        import java.util.logging.Level;
006:
007:        import org.outerj.daisy.sync.Attribute;
008:        import org.outerj.daisy.sync.AttributeImpl;
009:        import org.outerj.daisy.sync.Entity;
010:        import org.outerj.daisy.sync.VariantHelper;
011:        import org.outerj.daisy.sync.dao.ExternalEntityDao;
012:        import org.outerj.daisy.sync.dao.SyncEntityDao;
013:        import org.outerj.daisy.sync.mapping.EntityMapping.MappedAttribute;
014:
015:        public class AssociatedEntityMapping extends AbstractAssociatedMapping {
016:            private String entityName;
017:
018:            private String joinKey;
019:
020:            private String joinParentKey;
021:
022:            private List<AssociatedMapping> childMappings = new ArrayList<AssociatedMapping>();
023:
024:            private AttributeMapping targetAttribute;
025:
026:            public AssociatedEntityMapping(String entityName, String joinKey,
027:                    String joinParentKey, ExternalEntityDao externalEntityDao,
028:                    SyncEntityDao syncEntityDao,
029:                    MappingConfiguration configuration) {
030:                super (externalEntityDao, syncEntityDao, configuration);
031:                this .entityName = entityName;
032:                this .joinKey = joinKey;
033:                this .joinParentKey = joinParentKey;
034:            }
035:
036:            public void applyMapping(Entity originalEntity)
037:                    throws MappingException {
038:                applyMapping(originalEntity, originalEntity);
039:            }
040:
041:            // joinParentKey here then this object should make use of the associatedEntity to fetch the key 
042:            public void applyMapping(Entity originalEntity,
043:                    Entity associatedEntity) throws MappingException {
044:                List<Entity> associatedEntities = null;
045:                if (joinKey != null) {
046:                    long extId = associatedEntity.getExternalId();
047:                    associatedEntities = externalEntityDao
048:                            .getAssociatedEntities(extId, entityName, joinKey);
049:                } else if (joinParentKey != null) {
050:                    Attribute associatedAttr = associatedEntity
051:                            .getAttributeByExternalName(joinParentKey);
052:                    associatedEntities = new ArrayList<Entity>();
053:                    if (associatedAttr != null) {
054:                        for (String joinValue : associatedAttr.getValues()) {
055:                            List<Entity> entities = externalEntityDao
056:                                    .getEntity(entityName, Long
057:                                            .parseLong(joinValue));
058:                            if (entities != null)
059:                                associatedEntities.addAll(entities);
060:                        }
061:                    }
062:                }
063:
064:                for (Entity entity : associatedEntities) {
065:                    if (this .childMappings.size() > 0) {
066:                        for (AssociatedMapping childMapping : this .childMappings)
067:                            childMapping.applyMapping(originalEntity, entity);
068:                    } else {
069:                        // if this mapping doesn't have any children get the daisy id
070:                        // and store it in the attribute
071:                        // TODO check if entity exists first
072:                        try {
073:                            String internalEntityName = entity
074:                                    .getInternalName();
075:                            if (internalEntityName == null)
076:                                internalEntityName = configuration
077:                                        .getEntityMappingByEntityName(
078:                                                entity.getName())
079:                                        .getDaisyDocumentTypeName();
080:
081:                            Entity sourceEntity = syncEntityDao.getEntity(
082:                                    internalEntityName, entity.getExternalId(),
083:                                    originalEntity.getLanguage());
084:
085:                            Attribute attribute = originalEntity
086:                                    .getAttributeByExternalName(targetAttribute
087:                                            .getName());
088:                            if (attribute == null) {
089:                                // if it's not found then it must be created
090:                                attribute = new AttributeImpl(targetAttribute
091:                                        .getName(), null, targetAttribute
092:                                        .getDaisyName(), targetAttribute
093:                                        .getType());
094:                                originalEntity.addAttribute(attribute);
095:                            }
096:
097:                            if (sourceEntity != null)
098:                                attribute.addValue(VariantHelper
099:                                        .variantKeyToString(sourceEntity
100:                                                .getDaisyVariantKey()));
101:                            else
102:                                logger
103:                                        .logp(
104:                                                Level.WARNING,
105:                                                this .getClass().getName(),
106:                                                "applyMapping",
107:                                                "Could not map associated entity ({0} - {1}) since the source entity could not be found",
108:                                                new Object[] {
109:                                                        entity.getName(),
110:                                                        entity.getExternalId() });
111:                            if (attribute instanceof  MappedAttribute)
112:                                ((MappedAttribute) attribute).setMapped(true);
113:                        } catch (Exception e) {
114:                            logger.logp(Level.SEVERE,
115:                                    this .getClass().getName(), "applyMapping",
116:                                    "Error setting associated mapping for entity ("
117:                                            + entity.getName() + " - "
118:                                            + entity.getExternalId() + ")", e);
119:                        }
120:                    }
121:                }
122:
123:            }
124:
125:            public AttributeMapping getTargetAttribute() {
126:                return targetAttribute;
127:            }
128:
129:            public void setTargetAttribute(AttributeMapping attributeMapping) {
130:                this .targetAttribute = attributeMapping;
131:                for (AssociatedMapping childMapping : this .childMappings)
132:                    childMapping.setTargetAttribute(attributeMapping);
133:            }
134:
135:            public List<AssociatedMapping> getChildMappings() {
136:                return childMappings;
137:            }
138:
139:            public void setChildMappings(List<AssociatedMapping> childMappings) {
140:                this .childMappings = childMappings;
141:                if (targetAttribute != null) {
142:                    for (AssociatedMapping childMapping : this .childMappings)
143:                        childMapping.setTargetAttribute(targetAttribute);
144:                }
145:            }
146:
147:            public void addChildMapping(AssociatedMapping mapping) {
148:                this .childMappings.add(mapping);
149:                if (this .targetAttribute != null) {
150:                    mapping.setTargetAttribute(this .targetAttribute);
151:                }
152:            }
153:
154:            public String getJoinKey() {
155:                return joinKey;
156:            }
157:
158:            public String getJoinParentKey() {
159:                return joinParentKey;
160:            }
161:
162:            public String getEntityName() {
163:                return entityName;
164:            }
165:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.