Source Code Cross Referenced for RegistryPublish.java in  » Portal » Open-Portal » com » sun » portal » wsrp » producer » admin » mbeans » 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 » Open Portal » com.sun.portal.wsrp.producer.admin.mbeans 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * RegistryPublish.java
003:         *
004:         * Copyright 2005 Sun Microsystems, Inc. All
005:         * rights reserved. Use of this product is subject
006:         * to license terms. Federal Acquisitions:
007:         * Commercial Software -- Government Users
008:         * Subject to Standard License Terms and
009:         * Conditions.
010:         *
011:         * Sun, Sun Microsystems, the Sun logo, and Sun ONE
012:         * are trademarks or registered trademarks of Sun Microsystems,
013:         * Inc. in the United States and other countries.
014:         */
015:
016:        package com.sun.portal.wsrp.producer.admin.mbeans;
017:
018:        import java.util.List;
019:        import java.util.Set;
020:        import java.util.Properties;
021:        import java.util.ArrayList;
022:        import java.util.Iterator;
023:        import java.util.Collections;
024:        import java.util.Collection;
025:        import java.util.logging.Level;
026:        import java.util.logging.Logger;
027:        import java.io.FileNotFoundException;
028:        import java.io.IOException;
029:
030:        import com.sun.portal.admin.common.context.PortalDomainContext;
031:        import com.sun.portal.admin.common.context.PSConfigContext;
032:        import com.sun.portal.admin.common.PSConfigConstants;
033:        import com.sun.portal.admin.server.mbeans.PSResource;
034:        import com.sun.portal.admin.common.PSMBeanException;
035:        import com.sun.portal.admin.server.AdminServerUtil;
036:        import com.sun.portal.log.common.PortalLogger;
037:        import com.sun.portal.util.ResourceLoader;
038:
039:        import com.sun.portal.wsrp.WSRPException;
040:        import com.sun.portal.wsrp.common.registry.RegistryConfiguration;
041:        import com.sun.portal.wsrp.common.registry.WSRPOrganization;
042:        import com.sun.portal.wsrp.common.registry.WSRPPortlet;
043:        import com.sun.portal.wsrp.common.registry.WSRPProducer;
044:        import com.sun.portal.wsrp.common.registry.RegistryConstants;
045:        import com.sun.portal.wsrp.common.registry.RegistryManagerFactory;
046:        import com.sun.portal.wsrp.common.registry.RegistryManager;
047:        import com.sun.portal.wsrp.common.registry.RegistryQueryManager;
048:        import com.sun.portal.wsrp.common.registry.RegistryLifeCycleManager;
049:        import com.sun.portal.wsrp.common.registry.RegistryObjectManager;
050:        import com.sun.portal.wsrp.common.registry.ebxml.JESRegistryConstants;
051:
052:        import com.sun.portal.wsrp.producer.Producer;
053:        import com.sun.portal.wsrp.producer.impl.ProducerImpl;
054:        import com.sun.portal.wsrp.producer.ProducerException;
055:        import com.sun.portal.wsrp.producer.servicedescription.ServiceDescriptionManager;
056:        import com.sun.portal.wsrp.common.stubs.ServiceDescription;
057:        import com.sun.portal.wsrp.common.stubs.PortletDescription;
058:        import com.sun.portal.wsrp.common.stubs.OperationFailedFault;
059:        import com.sun.portal.wsrp.common.stubs.LocalizedString;
060:        import com.sun.portal.wsrp.common.stubs.MarkupType;
061:
062:        import com.iplanet.sso.SSOToken;
063:        import com.iplanet.sso.SSOTokenManager;
064:        import com.iplanet.sso.SSOException;
065:
066:        import com.sun.ssoadapter.SSOAdapter;
067:        import com.sun.ssoadapter.SSOAdapterFactory;
068:        import com.sun.ssoadapter.SSOAdapterSession;
069:        import com.sun.ssoadapter.SSOAdapterException;
070:
071:        public class RegistryPublish extends PSResource implements 
072:                RegistryPublishMBean {
073:
074:            private String portalId = null;
075:            private String domainId = null;
076:
077:            private static Logger logger = PortalLogger
078:                    .getLogger(RegistryPublish.class);
079:
080:            public void init(PSConfigContext cc, PortalDomainContext pdc,
081:                    List path) {
082:                super .init(cc, pdc, path);
083:                domainId = getDomainID();
084:                portalId = (String) path.get(1);
085:            }
086:
087:            public void publishProducer(Properties producer)
088:                    throws PSMBeanException {
089:                publishProducer(null, producer, null);
090:            }
091:
092:            public void publishPortlets(Properties org, Properties producer,
093:                    List portlets) throws PSMBeanException {
094:                setClassLoader();
095:                try {
096:                    RegistryManager rm = getRegistryManager();
097:                    RegistryLifeCycleManager rlm = rm.getRegistryCycleManager();
098:                    RegistryObjectManager rom = rm.getRegistryObjectManager();
099:                    WSRPOrganization wsrporg = null;
100:                    List wsrpportlets = null;
101:
102:                    if (org != null) {
103:                        wsrporg = rom.getWSRPOrganization(org);
104:                    }
105:
106:                    if (portlets != null) {
107:                        String producerId = producer.get("producer.id")
108:                                .toString();
109:                        wsrpportlets = getWSRPPortlets(rom, producerId,
110:                                portlets);
111:                    }
112:
113:                    WSRPProducer wsrpproducer = rom
114:                            .getWSRPProducer(getProducerProperties(producer));
115:
116:                    mergeObjects(wsrporg, wsrpproducer, wsrpportlets);
117:                    rlm.publish(wsrporg, wsrpproducer, wsrpportlets);
118:
119:                } catch (WSRPException we) {
120:                    logger.log(Level.SEVERE, "PSWS_CSPWPAB0027", we);
121:                    throw new PSMBeanException("error-key" + we.getMessage());
122:                } catch (Throwable t) {
123:                    logger.log(Level.SEVERE, "PSWS_CSPWPAB0027", t);
124:                    throw new PSMBeanException("error-key", t.getMessage());
125:                }
126:
127:            }
128:
129:            public void publishPortlets(Properties producer, List portlets)
130:                    throws PSMBeanException {
131:                publishPortlets(null, producer, portlets);
132:
133:            }
134:
135:            public void publishProducer(Properties org, Properties producer)
136:                    throws PSMBeanException {
137:                publishProducer(org, producer, null);
138:            }
139:
140:            public void publishProducer(Properties org, Properties producer,
141:                    List portlets) throws PSMBeanException {
142:                setClassLoader();
143:                try {
144:                    RegistryManager rm = getRegistryManager();
145:                    RegistryLifeCycleManager rlm = rm.getRegistryCycleManager();
146:                    RegistryObjectManager rom = rm.getRegistryObjectManager();
147:                    WSRPOrganization wsrporg = null;
148:                    WSRPProducer wsrpproducer = null;
149:                    List wsrpportlets = null;
150:
151:                    if (org != null) {
152:                        wsrporg = rom.getWSRPOrganization(org);
153:                    }
154:                    if (producer != null) {
155:                        wsrpproducer = rom
156:                                .getWSRPProducer(getProducerProperties(producer));
157:                    }
158:
159:                    if (portlets != null) {
160:                        String producerId = producer.get(
161:                                RegistryConstants.PRODUCER_ID).toString();
162:                        wsrpportlets = getWSRPPortlets(rom, producerId,
163:                                portlets);
164:                    }
165:                    mergeObjects(wsrporg, wsrpproducer, wsrpportlets);
166:                    rlm.publish(wsrporg, wsrpproducer, wsrpportlets);
167:
168:                } catch (WSRPException we) {
169:                    logger.log(Level.SEVERE, "PSWS_CSPWPAB0028", we);
170:                    throw new PSMBeanException("error-key", we.getMessage());
171:                } catch (Throwable t) {
172:                    logger.log(Level.SEVERE, "PSWS_CSPWPAB0028", t);
173:                    throw new PSMBeanException("error-key", t.getMessage());
174:                }
175:            }
176:
177:            private RegistryManager getRegistryManager() throws Exception {
178:                RegistryManagerFactory rf = RegistryManagerFactory
179:                        .getInstance();
180:                Properties resource = getRegistryResource();
181:                RegistryConfiguration config = new RegistryConfiguration(
182:                        resource);
183:                return rf.getRegistryManager(RegistryConstants.TYPE_EBXML,
184:                        config);
185:            }
186:
187:            private void mergeObjects(WSRPOrganization org,
188:                    WSRPProducer producer, List wsrpportlets)
189:                    throws WSRPException {
190:                if (org != null) {
191:                    if (producer != null) {
192:                        org.addProducer(producer);
193:                    }
194:                    if (wsrpportlets != null && wsrpportlets.size() > 0) {
195:                        Iterator it = wsrpportlets.iterator();
196:                        while (it.hasNext()) {
197:                            org.addPortlet((WSRPPortlet) it.next());
198:                        }
199:                    }
200:                }
201:            }
202:
203:            //TODO you are calling GetService Description in a loop check for perf issues
204:            private List getWSRPPortlets(RegistryObjectManager rom,
205:                    String producerId, List portlets) throws WSRPException,
206:                    PSMBeanException {
207:                List wsrpPortlets = new ArrayList();
208:                if (!publishAllPortlets(portlets)) {
209:                    Iterator it = portlets.iterator();
210:                    WSRPPortlet portlet = null;
211:                    while (it.hasNext()) {
212:                        portlet = fetchPortlet(rom, producerId, it.next()
213:                                .toString());
214:                        wsrpPortlets.add(portlet);
215:                    }
216:                    return wsrpPortlets;
217:                } else {
218:                    wsrpPortlets = fetchAllPortlets(rom, producerId);
219:                    return wsrpPortlets;
220:                }
221:            }
222:
223:            private List fetchAllPortlets(RegistryObjectManager rom,
224:                    String producerId) throws WSRPException, PSMBeanException {
225:                Producer producer = getProducer(producerId);
226:                List wsrpPortlets = new ArrayList();
227:
228:                try {
229:                    ServiceDescriptionManager sdm = producer
230:                            .getServiceDescriptionManager();
231:                    //Set allPortlets = producer.getPortletChannelNames();
232:                    ServiceDescription sd = sdm.getServiceDescription(null);
233:                    PortletDescription publishedPortlets[] = sd
234:                            .getOfferedPortlets();
235:                    PortletDescription pdesc = null;
236:                    WSRPPortlet portlet = null;
237:
238:                    for (int i = 0; i < publishedPortlets.length; i++) {
239:                        pdesc = publishedPortlets[i];
240:                        Collection markupTypes = getCollection(pdesc
241:                                .getMarkupTypes());
242:
243:                        //TODO: Publish multiple URLS
244:                        String wsdlURL = ProducerAttributeHelper.getWSDLURL(
245:                                producer, domainId, portalId);
246:
247:                        Properties props = new Properties();
248:                        props.put(RegistryConstants.PORTLET_HANDLE, pdesc
249:                                .getPortletHandle());
250:                        //Sometime service description has displayName as null, Hence returning
251:                        // handle as the name and description
252:
253:                        String portletname = pdesc.getPortletHandle();
254:                        LocalizedString localizedString = pdesc
255:                                .getDisplayName();
256:                        if (localizedString != null) {
257:                            portletname = localizedString.getValue();
258:                        }
259:                        props.put(RegistryConstants.PORTLET_NAME, portletname);
260:
261:                        String portletDesc = pdesc.getPortletHandle();
262:                        localizedString = pdesc.getDescription();
263:                        if (localizedString != null) {
264:                            portletDesc = localizedString.getValue();
265:                        }
266:
267:                        props.put(RegistryConstants.PORTLET_DESC, portletDesc);
268:                        props.put(RegistryConstants.PORTLET_MARKUPTYPE,
269:                                markupTypes);
270:                        props.put(RegistryConstants.PORTLET_PRODUCER_URL,
271:                                wsdlURL);
272:
273:                        portlet = rom.getWSRPPortlet(props);
274:                        wsrpPortlets.add(portlet);
275:                    }
276:                    return wsrpPortlets;
277:                } catch (ProducerException pe) {
278:                    logger.log(Level.SEVERE, "PSWS_CSPWPAB0029", pe);
279:                    throw new WSRPException("Can't get portlet description. "
280:                            + pe.getMessage());
281:                } catch (OperationFailedFault off) {
282:                    logger.log(Level.SEVERE, "PSWS_CSPWPAB0029", off);
283:                    throw new WSRPException("Can't get portlet description. "
284:                            + off.getMessage());
285:                }
286:            }
287:
288:            private WSRPPortlet fetchPortlet(RegistryObjectManager rom,
289:                    String producerId, String portlet) throws WSRPException,
290:                    PSMBeanException {
291:                Producer producer = getProducer(producerId);
292:                try {
293:                    ServiceDescriptionManager sdm = producer
294:                            .getServiceDescriptionManager();
295:                    //Set allPortlets = producer.getPortletChannelNames();
296:                    ServiceDescription sd = sdm.getServiceDescription(null);
297:                    PortletDescription publishedPortlets[] = sd
298:                            .getOfferedPortlets();
299:                    PortletDescription pdesc = getPortletDescription(
300:                            publishedPortlets, portlet);
301:                    if (pdesc == null) {
302:                        logger.log(Level.SEVERE, "PSWS_CSPWPAB0030", portlet);
303:                        throw new WSRPException(
304:                                "Portlet not in published portlet list: "
305:                                        + portlet);
306:                    }
307:
308:                    Collection markupTypes = getCollection(pdesc
309:                            .getMarkupTypes());
310:
311:                    //TODO: Publish multiple URLS
312:                    String wsdlURL = ProducerAttributeHelper.getWSDLURL(
313:                            producer, domainId, portalId);
314:
315:                    Properties props = new Properties();
316:                    props.put(RegistryConstants.PORTLET_HANDLE, pdesc
317:                            .getPortletHandle());
318:                    //Sometime service description has displayName as null, Hence returning
319:                    // handle as the name and description
320:
321:                    String portletname = pdesc.getPortletHandle();
322:                    LocalizedString localizedString = pdesc.getDisplayName();
323:                    if (localizedString != null) {
324:                        portletname = localizedString.getValue();
325:                    }
326:                    props.put(RegistryConstants.PORTLET_NAME, portletname);
327:
328:                    String portletDesc = pdesc.getPortletHandle();
329:                    localizedString = pdesc.getDescription();
330:                    if (localizedString != null) {
331:                        portletDesc = localizedString.getValue();
332:                    }
333:
334:                    props.put(RegistryConstants.PORTLET_DESC, portletDesc);
335:                    props
336:                            .put(RegistryConstants.PORTLET_MARKUPTYPE,
337:                                    markupTypes);
338:                    props.put(RegistryConstants.PORTLET_PRODUCER_URL, wsdlURL);
339:
340:                    return rom.getWSRPPortlet(props);
341:                } catch (ProducerException pe) {
342:                    logger.log(Level.SEVERE, "PSWS_CSPWPAB0029", pe);
343:                    throw new WSRPException("Can't get portlet description. "
344:                            + pe.getMessage());
345:                } catch (OperationFailedFault off) {
346:                    logger.log(Level.SEVERE, "PSWS_CSPWPAB0029", off);
347:                    throw new WSRPException("Can't get portlet description. "
348:                            + off.getMessage());
349:                }
350:            }
351:
352:            private PortletDescription getPortletDescription(
353:                    PortletDescription offeredPortlets[], String portlet) {
354:                PortletDescription pdesc = null;
355:                for (int i = 0; i < offeredPortlets.length; i++) {
356:                    pdesc = offeredPortlets[i];
357:                    if (pdesc.getPortletHandle().equals(portlet)) {
358:                        return pdesc;
359:                    }
360:                }
361:                return null;
362:            }
363:
364:            private Properties getProducerProperties(Properties cliOptions)
365:                    throws WSRPException, PSMBeanException {
366:                try {
367:                    Producer producer = getProducer(cliOptions.getProperty(
368:                            "producer.id").toString());
369:                    String wsdlURL = ProducerAttributeHelper.getWSDLURL(
370:                            producer, domainId, portalId);
371:                    cliOptions.put(RegistryConstants.PRODUCER_URL, Collections
372:                            .singletonList(wsdlURL));
373:                    cliOptions.put(RegistryConstants.PRODUCER_REQUIRES_REG,
374:                            Boolean.toString(producer.requiresRegistration()));
375:                    ServiceDescriptionManager sdm = producer
376:                            .getServiceDescriptionManager();
377:                    ServiceDescription sd = sdm.getServiceDescription(null);
378:                    String requiresInitCookie = sd.getRequiresInitCookie()
379:                            .getValue();
380:                    cliOptions.put(
381:                            RegistryConstants.PRODUCER_REQUIRES_INIT_COOKIE,
382:                            requiresInitCookie);
383:                    return cliOptions;
384:                } catch (ProducerException pe) {
385:                    logger.log(Level.SEVERE, "PSWS_CSPWPAB0031", pe);
386:                    throw new WSRPException("Can't get producer description. "
387:                            + pe.getMessage());
388:                } catch (OperationFailedFault off) {
389:                    logger.log(Level.SEVERE, "PSWS_CSPWPAB0031", off);
390:                    throw new WSRPException("Can't get producer description. "
391:                            + off.getMessage());
392:                }
393:            }
394:
395:            private Producer getProducer(String producerID)
396:                    throws WSRPException {
397:                try {
398:                    SSOToken ssoToken = AdminServerUtil.getSSOToken();
399:                    return new ProducerImpl(ssoToken, producerID, portalId);
400:                } catch (ProducerException e) {
401:                    logger.log(Level.SEVERE, "PSWS_CSPWPAB0032", e);
402:                    throw new WSRPException("Can't get producer. "
403:                            + e.getMessage(), e);
404:                }
405:            }
406:
407:            private Collection getCollection(MarkupType type[]) {
408:                List result = new ArrayList();
409:                for (int i = 0; i < type.length; i++) {
410:                    result.add(type[i].getMimeType());
411:                }
412:                return result;
413:            }
414:
415:            private Properties getRegistryProperties() throws WSRPException {
416:                ResourceLoader resourceLoader = null;
417:                Properties properties = null;
418:                if (portalId == null) {
419:                    resourceLoader = ResourceLoader.getInstance(System
420:                            .getProperties());
421:                } else {
422:                    resourceLoader = ResourceLoader.getInstance(portalId);
423:                }
424:                try {
425:                    properties = resourceLoader
426:                            .getProperties(RegistryConstants.JES_REGISTRY_PROPERTY);
427:
428:                } catch (FileNotFoundException fnfe) {
429:                    throw new WSRPException("Registry Config not found: ", fnfe);
430:                } catch (IOException ioe) {
431:                    throw new WSRPException(
432:                            "Cannot load registry config file: ", ioe);
433:                }
434:                return properties;
435:            }
436:
437:            private Properties getRegistryResource() throws WSRPException {
438:                try {
439:                    Properties prop = getRegistryProperties();
440:                    SSOToken token = AdminServerUtil.getSSOToken();
441:                    SSOAdapterSession session = new SSOAdapterSession(token);
442:                    SSOAdapterFactory ssoFact = SSOAdapterFactory.getInstance();
443:                    SSOAdapter adapter = ssoFact.getSSOAdapter(
444:                            RegistryConstants.SSO_ADAPTER_CONFIG, session);
445:                    prop.putAll(adapter.getProperties());
446:                    return prop;
447:                } catch (SSOAdapterException e) {
448:                    logger.log(Level.SEVERE, "PSWS_CSPWPAB0033", e);
449:                    throw new WSRPException(
450:                            "Cannot load registry config file: ", e);
451:                }
452:            }
453:
454:            private boolean publishAllPortlets(List portlets) {
455:                int allPortlets = portlets
456:                        .indexOf(RegistryConstants.PUBLISH_ALL_PORTLETS);
457:                if (allPortlets == -1) {
458:                    return false;
459:                }
460:                return true;
461:            }
462:
463:            /*
464:             * Workaround for CACAO bug 6213676
465:             */
466:            private void setClassLoader() {
467:                ClassLoader cl = this.getClass().getClassLoader();
468:                Thread.currentThread().setContextClassLoader(cl);
469:            }
470:
471:        }
w__w_w_._ja_v___a2___s__.c_o__m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.