Source Code Cross Referenced for MigrationUtils.java in  » Portal » jboss-portal-2.6.4 » org » jboss » portal » migration » 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 » Portal » jboss portal 2.6.4 » org.jboss.portal.migration 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /******************************************************************************
002:         * JBoss, a division of Red Hat                                               *
003:         * Copyright 2006, Red Hat Middleware, LLC, and individual                    *
004:         * contributors as indicated by the @authors tag. See the                     *
005:         * copyright.txt in the distribution for a full listing of                    *
006:         * individual contributors.                                                   *
007:         *                                                                            *
008:         * This is free software; you can redistribute it and/or modify it            *
009:         * under the terms of the GNU Lesser General Public License as                *
010:         * published by the Free Software Foundation; either version 2.1 of           *
011:         * the License, or (at your option) any later version.                        *
012:         *                                                                            *
013:         * This software is distributed in the hope that it will be useful,           *
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU           *
016:         * Lesser General Public License for more details.                            *
017:         *                                                                            *
018:         * You should have received a copy of the GNU Lesser General Public           *
019:         * License along with this software; if not, write to the Free                *
020:         * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA         *
021:         * 02110-1301 USA, or see the FSF site: http://www.fsf.org.                   *
022:         ******************************************************************************/package org.jboss.portal.migration;
023:
024:        import org.jboss.portal.migration.model20.impl.role.Role20Impl;
025:        import org.jboss.portal.migration.model20.impl.user.User20Impl;
026:        import org.jboss.portal.migration.model20.impl.user.UserPref20;
027:        import org.jboss.portal.migration.model20.impl.user.UserPrefSet20;
028:        import org.jboss.portal.migration.model22.impl.instance.Instance22Impl;
029:        import org.jboss.portal.migration.model22.impl.instance.InstancePreference22Impl;
030:        import org.jboss.portal.migration.model22.impl.portal.Context22Impl;
031:        import org.jboss.portal.migration.model22.impl.portal.ObjectNode22;
032:        import org.jboss.portal.migration.model22.impl.portal.Page22Impl;
033:        import org.jboss.portal.migration.model22.impl.portal.Portal22Impl;
034:        import org.jboss.portal.migration.model22.impl.portal.PortalObject22Impl;
035:        import org.jboss.portal.migration.model22.impl.portal.Window22Impl;
036:        import org.jboss.portal.migration.model22.impl.role.Role22Impl;
037:        import org.jboss.portal.migration.model22.impl.security.HbmSecurityConstraint;
038:        import org.jboss.portal.migration.model22.impl.user.User22Impl;
039:        import org.jboss.portal.migration.model22.impl.user.UserPreference22Impl;
040:        import org.jboss.portal.migration.model22.impl.user.UserPreferences22Impl;
041:        import org.jboss.portal.migration.model24.identity.Role24Impl;
042:        import org.jboss.portal.migration.model24.identity.User24Impl;
043:        import org.jboss.portal.migration.model24.instance.Instance24Impl;
044:        import org.jboss.portal.migration.model24.instance.InstanceSecurityBinding;
045:        import org.jboss.portal.migration.model24.portal.Context24Impl;
046:        import org.jboss.portal.migration.model24.portal.ObjectNode24;
047:        import org.jboss.portal.migration.model24.portal.ObjectNodeSecurityConstraint;
048:        import org.jboss.portal.migration.model24.portal.Page24Impl;
049:        import org.jboss.portal.migration.model24.portal.Portal24Impl;
050:        import org.jboss.portal.migration.model24.portal.PortalObject24Impl;
051:        import org.jboss.portal.migration.model24.portal.Window24Impl;
052:        import org.jboss.portal.migration.model24.portlet.PersistentStateEntry24;
053:
054:        import java.util.HashMap;
055:        import java.util.HashSet;
056:        import java.util.Iterator;
057:        import java.util.Map;
058:        import java.util.Set;
059:
060:        /**
061:         * Helper class for doing operations need for migration
062:         *
063:         * @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw Dawidowicz</a>
064:         * @version $Revision: 8784 $
065:         */
066:        public class MigrationUtils {
067:            /**
068:             * Creating new User22Impl object copying content fom User20Impl. Not copying id and maps of objects like roles,
069:             * prefSets
070:             *
071:             * @param user20Impl
072:             * @return user22Impl
073:             */
074:            public static User22Impl cloneUserTo22(User20Impl user20Impl) {
075:                User22Impl user22Impl = new User22Impl();
076:
077:                //casting id field
078:                user22Impl.key = new Long(user20Impl.getID().longValue());
079:
080:                user22Impl.userName = user20Impl.userName;
081:
082:                user22Impl.givenName = user20Impl.givenName;
083:                user22Impl.familyName = user20Impl.familyName;
084:                user22Impl.password = user20Impl.password;
085:                user22Impl.realEmail = user20Impl.realEmail;
086:                user22Impl.fakeEmail = user20Impl.fakeEmail;
087:                user22Impl.registrationDate = user20Impl.registrationDate;
088:                user22Impl.viewRealEmail = user20Impl.viewRealEmail;
089:                user22Impl.enabled = user20Impl.enabled;
090:                user22Impl.dynamic = new HashMap();
091:                user22Impl.dynamic.putAll(user20Impl.dynamic);
092:
093:                return user22Impl;
094:            }
095:
096:            /**
097:             * Creating new User24Impl object copying content fom User22Impl. Not copying id and maps of objects like roles,
098:             * prefSets
099:             *
100:             * @param user22Impl
101:             * @return user24Impl
102:             */
103:            public static User24Impl cloneUserTo24(User22Impl user22Impl) {
104:                User24Impl user24Impl = new User24Impl();
105:
106:                //casting id field
107:                user24Impl.key = new Long(user22Impl.getKey().longValue());
108:
109:                user24Impl.userName = user22Impl.userName;
110:
111:                user24Impl.givenName = user22Impl.givenName;
112:                user24Impl.familyName = user22Impl.familyName;
113:                user24Impl.password = user22Impl.password;
114:                user24Impl.realEmail = user22Impl.realEmail;
115:                user24Impl.fakeEmail = user22Impl.fakeEmail;
116:                user24Impl.registrationDate = user22Impl.registrationDate;
117:                user24Impl.viewRealEmail = user22Impl.viewRealEmail;
118:                user24Impl.enabled = user22Impl.enabled;
119:                user24Impl.dynamic = new HashMap();
120:                user24Impl.dynamic.putAll(user22Impl.dynamic);
121:
122:                return user24Impl;
123:            }
124:
125:            /**
126:             * Creating new Role22Impl object copying content from Role20Impl. Not copying users set.
127:             *
128:             * @param role20Impl
129:             * @return Role22Impl
130:             */
131:            public static Role22Impl cloneRoleTo22(Role20Impl role20Impl) {
132:                Role22Impl role22Impl = new Role22Impl();
133:
134:                //casting id field 
135:                role22Impl.key = new Long(role20Impl.id.longValue());
136:
137:                role22Impl.name = role20Impl.name;
138:                role22Impl.displayName = role20Impl.displayName;
139:
140:                //
141:                return role22Impl;
142:            }
143:
144:            /**
145:             * Creating new Role22Impl object copying content from Role20Impl. Not copying users set.
146:             *
147:             * @param role22Impl
148:             * @return Role24Impl
149:             */
150:            public static Role24Impl cloneRoleTo24(Role22Impl role22Impl) {
151:                Role24Impl role24Impl = new Role24Impl();
152:
153:                //casting id field
154:                role24Impl.key = new Long(role22Impl.key.longValue());
155:
156:                role24Impl.name = role22Impl.name;
157:                role24Impl.displayName = role22Impl.displayName;
158:
159:                //
160:                return role24Impl;
161:            }
162:
163:            public static void parseUserPrefSet20To22(
164:                    UserPrefSet20 userPrefSet20, Map prefMap, String name,
165:                    boolean concatenate) {
166:
167:                //If there are no children in set this is the last node (PortletInstance)
168:                if (userPrefSet20.getChildren().size() == 0) {
169:                    //new 22 preferences
170:                    UserPreferences22Impl preferences22Impl = new UserPreferences22Impl();
171:
172:                    //Extract map of prefs one by one
173:                    Map user20Prefs = userPrefSet20.getContent();
174:                    if (user20Prefs != null && (user20Prefs.size() != 0)) {
175:                        preferences22Impl.setContent(new HashMap());
176:
177:                        for (Iterator i = user20Prefs.keySet().iterator(); i
178:                                .hasNext();) {
179:                            String key = (String) i.next();
180:                            UserPref20 userPref20 = (UserPref20) user20Prefs
181:                                    .get(key);
182:
183:                            UserPreference22Impl pref = new UserPreference22Impl();
184:                            pref.name = userPref20.name;
185:                            pref.type = userPref20.type;
186:                            //pref.strings = userPref20.strings;
187:
188:                            //rewrite strings table
189:                            pref.strings = new String[userPref20.strings.length];
190:                            for (int tab_i = 0; tab_i < userPref20.strings.length; tab_i++) {
191:                                pref.strings[tab_i] = userPref20.strings[tab_i];
192:                            }
193:
194:                            //add new 22 pref into preferences
195:                            preferences22Impl.getContent().put(key, pref);
196:                        }
197:                    }
198:
199:                    //id will be concatenation of all names in whole tree path
200:
201:                    if (concatenate) {
202:                        preferences22Impl.setId(name + "_"
203:                                + userPrefSet20.getName());
204:                    } else {
205:                        preferences22Impl.setId(userPrefSet20.getName());
206:                    }
207:
208:                    prefMap.put(preferences22Impl.getId(), preferences22Impl);
209:                    return;
210:                }
211:
212:                if (name == null && (concatenate)) {
213:                    name = userPrefSet20.getName();
214:                } else if (concatenate) {
215:                    name += "_" + userPrefSet20.getName();
216:                }
217:                //recurently parse every child
218:                for (Iterator i = userPrefSet20.getChildren().iterator(); i
219:                        .hasNext();) {
220:                    UserPrefSet20 childPrefSet20 = (UserPrefSet20) i.next();
221:                    parseUserPrefSet20To22(childPrefSet20, prefMap, name,
222:                            concatenate);
223:                }
224:                //return;
225:            }
226:
227:            /**
228:             * Creates new Window24Impl and copys data from provided Window22Impl object. Does not copy ObjectNode reference
229:             *
230:             * @param window22
231:             * @return
232:             */
233:            public static Window24Impl cloneWindow22ImplTo24(
234:                    Window22Impl window22) {
235:
236:                Window24Impl window24 = new Window24Impl();
237:                window24.setInstanceRef(window22.getInstanceRef());
238:
239:                Map declaredProperties = new HashMap();
240:                declaredProperties.putAll(window22.getDeclaredProperties());
241:                window24.setDeclaredProperties(declaredProperties);
242:                window24.setListener(window22.getListener());
243:
244:                return window24;
245:            }
246:
247:            /**
248:             * Creates new Page24Impl and copys data from provided Page22Impl object. Does not copy ObjectNode reference
249:             *
250:             * @param page22
251:             * @return
252:             */
253:            public static Page24Impl clonePage22ImplTo24(Page22Impl page22) {
254:                Page24Impl page24 = new Page24Impl();
255:
256:                Map declaredProperties = new HashMap();
257:                declaredProperties.putAll(page22.getDeclaredProperties());
258:                page24.setDeclaredProperties(declaredProperties);
259:                page24.setListener(page22.getListener());
260:
261:                return page24;
262:            }
263:
264:            /**
265:             * Creates new Context24Impl and copys data from provided Context22Impl object. Does not copy ObjectNode reference
266:             *
267:             * @param context22
268:             * @return
269:             */
270:            public static Context24Impl cloneContext22ImplTo24(
271:                    Context22Impl context22) {
272:                Context24Impl context24 = new Context24Impl();
273:
274:                Map declaredProperties = new HashMap();
275:                declaredProperties.putAll(context22.getDeclaredProperties());
276:                context24.setDeclaredProperties(declaredProperties);
277:                context24.setListener(context22.getListener());
278:
279:                return context24;
280:            }
281:
282:            /**
283:             * Creates new Portal24Impl and copys data from provided Portal22Impl object. Does not copy ObjectNode reference
284:             *
285:             * @param portal22
286:             * @return
287:             */
288:            public static Portal24Impl clonePortal22ImplTo24(
289:                    Portal22Impl portal22) {
290:                Portal24Impl portal24 = new Portal24Impl();
291:
292:                Map declaredProperties = new HashMap();
293:                declaredProperties.putAll(portal22.getDeclaredProperties());
294:                portal24.setDeclaredProperties(declaredProperties);
295:                portal24.setListener(portal22.getListener());
296:
297:                Set modes = portal22.getModes();
298:                Set newModes = new HashSet();
299:                for (Iterator i = modes.iterator(); i.hasNext();) {
300:                    Object o = i.next();
301:                    newModes.add(o.toString());
302:                }
303:                portal24.setModes(newModes);
304:
305:                Set states = portal22.getWindowStates();
306:                Set newStates = new HashSet();
307:                for (Iterator i = states.iterator(); i.hasNext();) {
308:                    Object o = i.next();
309:                    newStates.add(o.toString());
310:                }
311:                portal24.setWindowStates(newStates);
312:
313:                return portal24;
314:
315:            }
316:
317:            /**
318:             * Clones ObjectNode22 to newly created ObjectNode24. Does not copy object, children and parent properties
319:             *
320:             * @param node22
321:             * @return
322:             */
323:            public static ObjectNode24 cloneObjectNode22To24(ObjectNode22 node22) {
324:                ObjectNode24 node24 = new ObjectNode24();
325:
326:                node24.setName(node22.getName());
327:                node24.setPath(node22.getPath());
328:
329:                return node24;
330:
331:            }
332:
333:            /**
334:             * Method migrates PortalObject associated with ObjectNode
335:             *
336:             * @throws Exception
337:             */
338:            public static PortalObject24Impl clonePortalObject(
339:                    PortalObject22Impl object22) throws Exception {
340:                if (object22 == null) {
341:                    return null;
342:                } else if (object22 instanceof  Context22Impl) {
343:                    return MigrationUtils
344:                            .cloneContext22ImplTo24((Context22Impl) object22);
345:                } else if (object22 instanceof  Portal22Impl) {
346:                    return MigrationUtils
347:                            .clonePortal22ImplTo24((Portal22Impl) object22);
348:                } else if (object22 instanceof  Page22Impl) {
349:                    return MigrationUtils
350:                            .clonePage22ImplTo24((Page22Impl) object22);
351:                } else if (object22 instanceof  Window22Impl) {
352:                    return MigrationUtils
353:                            .cloneWindow22ImplTo24((Window22Impl) object22);
354:                }
355:
356:                return null;
357:            }
358:
359:            /** Clone Instance22Impl to Instance24Impl. Does not copy preferences Map */
360:            public static Instance24Impl cloneInstance22ImplTo24(
361:                    Instance22Impl instance22) {
362:                Instance24Impl instance24 = new Instance24Impl();
363:
364:                instance24.setInstanceId(instance22.getInstanceId());
365:                instance24.setPortletRef("local."
366:                        + instance22.getComponentRef());
367:
368:                return instance24;
369:            }
370:
371:            /**
372:             * convert InstancePreference22Impl into PersistentStateEntry24
373:             *
374:             * @param pref22
375:             * @return
376:             */
377:            public static PersistentStateEntry24 cloneInstancePrefToPortletState(
378:                    InstancePreference22Impl pref22) {
379:                PersistentStateEntry24 entry24 = new PersistentStateEntry24();
380:                entry24.setName(pref22.getName());
381:                entry24.setType(pref22.getType());
382:                entry24.setStrings(pref22.getStrings());
383:
384:                return entry24;
385:            }
386:
387:            /**
388:             * convert UserPreference22Impl into PersistentStateEntry24
389:             *
390:             * @param pref22
391:             * @return
392:             */
393:            public static PersistentStateEntry24 cloneUserPrefToPortletState(
394:                    UserPreference22Impl pref22) {
395:                PersistentStateEntry24 entry24 = new PersistentStateEntry24();
396:                entry24.setName(pref22.getName());
397:                entry24.setType(pref22.getType());
398:                entry24.setStrings(pref22.getStrings());
399:
400:                return entry24;
401:            }
402:
403:            /**
404:             * converts HbmSecurityConstratint into ObjectNodeSecurityConstraint. Does not converts ObjectNode reference
405:             *
406:             * @param hsc
407:             * @return
408:             */
409:            public static ObjectNodeSecurityConstraint cloneConstraintToObjectNodeConstraint(
410:                    HbmSecurityConstraint hsc) {
411:                ObjectNodeSecurityConstraint constraint = new ObjectNodeSecurityConstraint();
412:
413:                constraint.setRole(hsc.getRole());
414:                String[] actions = hsc.getActions().split(", ");
415:                Set actionSet = new HashSet();
416:                for (int i = 0; i < actions.length; i++) {
417:                    actionSet.add(actions[i]);
418:                }
419:                constraint.setActions(actionSet);
420:                return constraint;
421:            }
422:
423:            /**
424:             * converts HbmSecurityBinding into InstanceSecurityBinding. Does not converts ObjectNode reference
425:             *
426:             * @param hsc
427:             * @return
428:             */
429:            public static InstanceSecurityBinding cloneConstraintToInstanceConstraint(
430:                    HbmSecurityConstraint hsc) {
431:                InstanceSecurityBinding constraint = new InstanceSecurityBinding();
432:
433:                constraint.setRole(hsc.getRole());
434:                String[] actions = hsc.getActions().split(", ");
435:                Set actionSet = new HashSet();
436:                for (int i = 0; i < actions.length; i++) {
437:                    actionSet.add(actions[i]);
438:                }
439:                constraint.setActions(actionSet);
440:                return constraint;
441:            }
442:
443:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.