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


001:        /**
002:         * Copyright 2003 Sun Microsystems, Inc. All
003:         * rights reserved. Use of this product is subject
004:         * to license terms. Federal Acquisitions:
005:         * Commercial Software -- Government Users
006:         * Subject to Standard License Terms and
007:         * Conditions.
008:         *
009:         * Sun, Sun Microsystems, the Sun logo, and Sun ONE
010:         * are trademarks or registered trademarks of Sun Microsystems,
011:         * Inc. in the United States and other countries.
012:         */package com.sun.portal.wsrp.consumer.cli;
013:
014:        import java.util.Map;
015:        import java.util.HashMap;
016:        import java.util.Set;
017:        import java.util.Iterator;
018:        import java.util.logging.Level;
019:        import java.util.logging.Logger;
020:
021:        import java.io.StringReader;
022:
023:        import org.xml.sax.SAXParseException;
024:
025:        import com.iplanet.am.util.Debug;
026:
027:        import com.sun.portal.desktop.encode.Encoder;
028:
029:        import com.sun.portal.desktop.dp.DPRoot;
030:        import com.sun.portal.desktop.dp.DPChannel;
031:        import com.sun.portal.desktop.dp.DPError;
032:        import com.sun.portal.desktop.dp.xml.XMLDPFactory;
033:        import com.sun.portal.desktop.dp.xml.XMLDPRoot;
034:
035:        import com.sun.portal.desktop.context.DSAMEAdminDPContext;
036:
037:        import com.sun.portal.wsrp.common.stubs.PortletDescription;
038:
039:        import com.sun.portal.wsrp.consumer.common.WSRPProviderConstants;
040:        import com.sun.portal.wsrp.consumer.common.WSRPConsumerException;
041:
042:        import com.sun.portal.wsrp.consumer.producermanager.ProducerEntityManager;
043:        import com.sun.portal.wsrp.consumer.producermanager.ProducerEntity;
044:        import com.sun.portal.log.common.PortalLogger;
045:
046:        class PEADeploy implements  WSRPProviderConstants {
047:
048:            StringBuffer chnames = new StringBuffer();
049:            private static Logger logger = PortalLogger
050:                    .getLogger(PEADeploy.class);
051:
052:            public String process(ProducerEntityManager pem,
053:                    DSAMEAdminDPContext dadc, String dn, String pid,
054:                    String rid, String chname, boolean cont, boolean verbose,
055:                    boolean dryrun, Debug debug) throws PEAException {
056:
057:                //
058:                // sanity check: rid depends on pid
059:                //               chname depends on rid
060:                //
061:                if (pid == null && rid != null) {
062:                    throw new PEAException("errorNoPIDWithRID");
063:                }
064:                if (rid == null && chname != null) {
065:                    throw new PEAException("errorNoRIDWithCh");
066:                }
067:
068:                if (verbose) {
069:                    if (rid != null) {
070:
071:                        if (logger.isLoggable(Level.FINEST)) {
072:                            Object[] tokens = { dn, pid, rid };
073:                            logger
074:                                    .log(Level.FINEST, "PSWS_CSPWCCL0007",
075:                                            tokens);
076:                        }
077:                    } else {
078:                        if (logger.isLoggable(Level.FINEST)) {
079:                            Object[] tokens = { dn };
080:                            logger
081:                                    .log(Level.FINEST, "PSWS_CSPWCCL0008",
082:                                            tokens);
083:                        }
084:                    }
085:                }
086:
087:                //
088:                // get dp document
089:                //
090:                if (logger.isLoggable(Level.FINE)) {
091:                    Object[] tokens = { dn };
092:                    logger.log(Level.FINE, "PSWS_CSPWCCL0009", tokens);
093:                }
094:
095:                String doc = null;
096:                try {
097:                    doc = dadc.getDPDocumentByDN(dn);
098:                } catch (Throwable ex) {
099:                    Object[] tokens = { dn };
100:                    throw new PEAException("errorRetrieveDP", ex, tokens);
101:                }
102:
103:                //
104:                // build merged dproot
105:                //
106:                DPRoot dpr = null;
107:                XMLDPFactory dpf = XMLDPFactory.getInstance();
108:                try {
109:                    if (doc != null && doc.length() > 0) {
110:                        dpr = dpf.createRoot(dadc, doc);
111:                    } else {
112:                        //
113:                        // empty dp doc created
114:                        //
115:                        dpr = dpf.createRoot(dadc);
116:                    }
117:                    //
118:                    // add mergers
119:                    //
120:                    Set names = dadc.getDPDocumentNames(dn);
121:                    dpr = dpf.addMergers(dadc, dpr, names, new HashMap());
122:                } catch (Throwable ex) {
123:                    Object[] tokens = { dn };
124:                    throw new PEAException("errorCreateDPRoot", ex, tokens);
125:                }
126:
127:                //
128:                // deploy wsrp portlet channel(s)
129:                //
130:                // 1. when pid and rid are specified, deploy only that portlet.
131:                // 2. when pid alone is specified, deploy all portlets offered by
132:                //    the producer
133:                // 3. when neither is specified, deploy all portlets offered by
134:                //    all producers that are currently found under the consumer
135:                //
136:                if (pid != null) {
137:                    ProducerEntity pe = null;
138:                    try {
139:                        pe = pem.getProducerEntity(pid);
140:                    } catch (WSRPConsumerException wce) {
141:                        Object[] tokens = { dn, pid };
142:                        throw new PEAException("errorGetPE", wce, tokens);
143:                    }
144:                    if (rid != null) {
145:                        //
146:                        // make sure rid is a valid one
147:                        //
148:                        PortletDescription[] pds = pe.getServiceDescription()
149:                                .getOfferedPortlets();
150:                        boolean found = false;
151:                        int i = 0;
152:                        for (; i < pds.length; i++) {
153:                            if (pds[i].getPortletHandle().equals(rid)) {
154:                                found = true;
155:                                break;
156:                            }
157:                        }
158:                        if (!found) {
159:                            Object[] tokens = { dn, pid, rid };
160:                            throw new PEAException("errorInvalidRID", tokens);
161:                        }
162:                        deployPortlet(dpr, dadc, dn, pds[i], pe, rid, chname,
163:                                verbose);
164:                    } else {
165:                        deployAllPortlets(dpr, dadc, dn, pe, cont, verbose,
166:                                debug);
167:                    }
168:                } else {
169:                    Set pidSet = null;
170:                    try {
171:                        pidSet = pem.getProducerEntityIds();
172:                    } catch (WSRPConsumerException wce) {
173:                        Object[] tokens = { dn };
174:                        throw new PEAException("errorGetPEs", wce, tokens);
175:                    }
176:                    if (pidSet.size() > 0) {
177:                        for (Iterator i = pidSet.iterator(); i.hasNext();) {
178:                            ProducerEntity pe = null;
179:                            try {
180:                                pe = pem.getProducerEntity((String) i.next());
181:                            } catch (WSRPConsumerException wce) {
182:                                Object[] tokens = { dn, pid };
183:                                throw new PEAException("errorGetPE", wce,
184:                                        tokens);
185:                            }
186:                            deployAllPortlets(dpr, dadc, dn, pe, cont, verbose,
187:                                    debug);
188:                        }
189:                    }
190:                }
191:
192:                //
193:                // write out dp doc
194:                //
195:                writeDP(dpr, dadc, dn, verbose, dryrun);
196:
197:                //
198:                // return channel name list
199:                //
200:                return chnames.toString();
201:            }
202:
203:            protected void deployAllPortlets(DPRoot dpr,
204:                    DSAMEAdminDPContext dadc, String dn, ProducerEntity pe,
205:                    boolean cont, boolean verbose, Debug debug)
206:                    throws PEAException {
207:
208:                String pid = pe.getId();
209:                PortletDescription[] pds = pe.getServiceDescription()
210:                        .getOfferedPortlets();
211:
212:                for (int i = 0; i < pds.length; i++) {
213:                    String rid = pds[i].getPortletHandle();
214:                    if (cont) {
215:                        //
216:                        // catch any throwable if continous mode is on
217:                        //
218:                        try {
219:                            deployPortlet(dpr, dadc, dn, pds[i], pe, rid, null,
220:                                    verbose);
221:                        } catch (Throwable th) {
222:                            if (logger.isLoggable(Level.SEVERE)) {
223:                                Object[] tokens = { dn, pid, rid };
224:                                logger.log(Level.SEVERE, "PSWS_CSPWCCL0010",
225:                                        tokens);
226:                                logger
227:                                        .log(Level.SEVERE, "PSWS_CSPWCCL0011",
228:                                                th);
229:                            }
230:                        }
231:                    } else {
232:                        deployPortlet(dpr, dadc, dn, pds[i], pe, rid, null,
233:                                verbose);
234:                    }
235:                }
236:            }
237:
238:            public DPRoot deployPortlet(DPRoot dpr, DSAMEAdminDPContext dadc,
239:                    String dn, PortletDescription pd, ProducerEntity pe,
240:                    String rid, String chname, boolean verbose)
241:                    throws PEAException {
242:
243:                String pid = pe.getId();
244:
245:                if (pd.getUsesMethodGet().booleanValue()) {
246:                    Object[] tokens = { dn, pid, rid };
247:                    throw new PEAException("errorMethodGetOn", tokens);
248:                }
249:
250:                if (logger.isLoggable(Level.FINEST)) {
251:                    Object[] tokens = { dn, pid, rid };
252:                    logger.log(Level.FINEST, "PSWS_CSPWCCL0012", tokens);
253:                }
254:
255:                //
256:                // in case channel name is unspecified, create an unique name
257:                //
258:                if (chname == null) {
259:                    String pname = pe.getName();
260:                    //
261:                    // escape offending characters
262:                    //
263:                    String pnameEsc = Encoder.FORMNAME_ENCODER.encode(pname);
264:                    String ridEsc = Encoder.FORMNAME_ENCODER.encode(rid);
265:                    chname = pnameEsc + "_" + ridEsc;
266:                }
267:
268:                if (logger.isLoggable(Level.FINEST)) {
269:                    Object[] tokens = { dn, chname };
270:                    logger.log(Level.FINEST, "PSWS_CSPWCCL0013", tokens);
271:                }
272:
273:                boolean dupFound = false;
274:                XMLDPRoot xdpr = (XMLDPRoot) dpr;
275:                try {
276:                    dupFound = (xdpr.getChannelFromThis(chname) != null);
277:                    if (!dupFound) {
278:                        dupFound = (xdpr.getProviderFromThis(chname) != null);
279:                    }
280:                } catch (Throwable ex) {
281:                    Object[] tokens = { dn, chname };
282:                    throw new PEAException("errorCheckDup", ex, tokens);
283:                }
284:
285:                if (dupFound) {
286:                    Object[] tokens = { dn, chname };
287:                    throw new PEAException("errorDupFound", tokens);
288:                }
289:
290:                DPChannel ch = null;
291:                try {
292:                    XMLDPFactory dpf = XMLDPFactory.getInstance();
293:                    ch = dpf.createChannel(dadc, dpr, xdpr.getDocument(),
294:                            chname, WSRP_PROVIDER);
295:                    ch = dpr.addChannel(ch);
296:                    ch.getProperties().setString(CONSUMER_ID, dn);
297:                    ch.getProperties().setString(PRODUCER_ENTITY_ID, pid);
298:                    ch.getProperties().setString(PORTLET_ID, rid);
299:                    //
300:                    // TBD: portletHandle == rid ?
301:                    //
302:                    ch.getProperties().setString(PORTLET_HANDLE, rid);
303:                } catch (Throwable ex) {
304:                    Object[] tokens = { dn, chname };
305:                    throw new PEAException("errorAddCh", ex, tokens);
306:                }
307:
308:                //
309:                // record channel name
310:                //
311:                if (ch != null) {
312:                    chnames.append(ch.getName()).append("\n");
313:                }
314:
315:                return dpr;
316:            }
317:
318:            protected void writeDP(DPRoot dpr, DSAMEAdminDPContext dadc,
319:                    String dn, boolean verbose, boolean dryrun)
320:                    throws PEAException {
321:
322:                //
323:                // check for invalid XML
324:                //
325:                String dpDoc = null;
326:                try {
327:                    //
328:                    // set dirty to false before writing out.
329:                    // not doing this will cause "dirty=true" attribute to
330:                    // be added which will then cause validation error.
331:                    //
332:                    if (dpr.isDirty()) {
333:                        dpr.setDirty(false);
334:                    }
335:                    dpDoc = dpr.toString();
336:                    XMLDPFactory dpf = XMLDPFactory.getInstance();
337:                    dpf.createRoot(dadc, dpDoc);
338:                } catch (DPError de) {
339:                    Throwable wrapped = de.getCause();
340:                    if (wrapped != null && wrapped instanceof  SAXParseException) {
341:                        SAXParseException spe = (SAXParseException) wrapped;
342:                        int linenum = spe.getLineNumber();
343:                        Object[] tokens = { PEAUtil.getLines(new StringReader(
344:                                dpDoc), linenum) };
345:                        throw new PEAException("errorInvalidXMLText", de,
346:                                tokens);
347:                    }
348:                } catch (Throwable ex) {
349:                    throw new PEAException("errorInvalidXML", ex);
350:                }
351:
352:                //
353:                // write out changes only if dryrun is off
354:                //
355:                if (!dryrun) {
356:                    if (logger.isLoggable(Level.FINEST)) {
357:                        Object[] tokens = { dn };
358:                        logger.log(Level.FINEST, "", tokens);
359:                    }
360:
361:                    try {
362:                        StringBuffer sb = new StringBuffer(256);
363:                        dpr.toXML(sb, 0);
364:                        dadc.storeDPDocumentByDN(dn, sb.toString());
365:                    } catch (Throwable ex) {
366:                        Object[] tokens = { dn };
367:                        throw new PEAException("ErrorStoreDP", ex);
368:                    }
369:                }
370:            }
371:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.