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


001:        /**
002:         * $Id: ConsumerObjectFactory.java,v 1.2 2005/04/18 12:24:04 pa157442 Exp $
003:         * Copyright 2003 Sun Microsystems, Inc. All
004:         * rights reserved. Use of this product is subject
005:         * to license terms. Federal Acquisitions:
006:         * Commercial Software -- Government Users
007:         * Subject to Standard License Terms and
008:         * Conditions.
009:         *
010:         * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011:         * are trademarks or registered trademarks of Sun Microsystems,
012:         * Inc. in the United States and other countries.
013:         */package com.sun.portal.wsrp.consumer.producermanager;
014:
015:        import java.util.List;
016:        import java.util.ArrayList;
017:        import java.util.Iterator;
018:        import java.util.Map;
019:        import java.util.HashMap;
020:
021:        import java.io.StringReader;
022:        import java.io.StringWriter;
023:        import java.io.ByteArrayInputStream;
024:        import java.io.ByteArrayOutputStream;
025:        import java.io.InputStream;
026:        import java.io.UnsupportedEncodingException;
027:
028:        import javax.xml.bind.JAXBContext;
029:        import javax.xml.bind.JAXBException;
030:        import javax.xml.bind.Marshaller;
031:        import javax.xml.bind.Unmarshaller;
032:        import javax.xml.transform.stream.StreamSource;
033:
034:        import com.sun.portal.wsrp.common.jaxb.consumer.ObjectFactory;
035:        import com.sun.portal.wsrp.common.jaxb.consumer.MultiValueMap;
036:        import com.sun.portal.wsrp.common.jaxb.consumer.MultiValuePairType;
037:
038:        import com.sun.portal.wsrp.consumer.common.WSRPConsumerException;
039:
040:        /**
041:         * utility class for marshalling and unmarshalling jaxb objects.  
042:         */
043:        public class ConsumerObjectFactory {
044:
045:            //
046:            // static instance
047:            //
048:            protected static ConsumerObjectFactory factory = null;
049:            //
050:            // jaxb context
051:            //
052:            private JAXBContext jc = null;
053:            private ObjectFactory jfactory = null;
054:
055:            public static ConsumerObjectFactory getInstance()
056:                    throws WSRPConsumerException {
057:
058:                //
059:                // perform double-checked locking
060:                //
061:                if (factory == null) {
062:                    synchronized (ConsumerObjectFactory.class) {
063:                        if (factory == null) {
064:                            factory = new ConsumerObjectFactory();
065:                        }
066:                    }
067:                }
068:                return factory;
069:            }
070:
071:            private ConsumerObjectFactory() throws WSRPConsumerException {
072:                init();
073:            }
074:
075:            public void init() throws WSRPConsumerException {
076:                //
077:                // initialize jaxb
078:                //
079:                try {
080:                    jc = JAXBContext.newInstance(
081:                            "com.sun.portal.wsrp.common.jaxb.consumer", this 
082:                                    .getClass().getClassLoader());
083:                    jfactory = new ObjectFactory();
084:                } catch (JAXBException jbe) {
085:                    throw new WSRPConsumerException(
086:                            "ConsumerObjectFactory.init(): failed to initialize JAXB components.",
087:                            jbe);
088:                }
089:            }
090:
091:            public ObjectFactory getObjectFactory() {
092:                return jfactory;
093:            }
094:
095:            public Map getMap(String mvXML) throws WSRPConsumerException {
096:                MultiValueMap mvMap = getMultiValueMap(mvXML);
097:                return getMap(mvMap);
098:            }
099:
100:            public String getMultiValueMapXML(Map map)
101:                    throws WSRPConsumerException {
102:
103:                return getMultiValueMapXML(map, false);
104:            }
105:
106:            public String getMultiValueMapXML(Map map, boolean isFormatted)
107:                    throws WSRPConsumerException {
108:
109:                MultiValueMap mvMap = getMultiValueMap(map);
110:                String xml = null;
111:                if (mvMap != null) {
112:                    StringWriter writer = new StringWriter();
113:                    try {
114:                        Marshaller marshaller = jc.createMarshaller();
115:                        if (isFormatted) {
116:                            marshaller.setProperty(
117:                                    Marshaller.JAXB_FORMATTED_OUTPUT,
118:                                    Boolean.TRUE);
119:                        }
120:                        marshaller.marshal(mvMap, writer);
121:                    } catch (JAXBException jbe) {
122:                        throw new WSRPConsumerException(
123:                                "ConsumerObjectFactory.getMultiValueMapXML(): failed to marshall MultiValueMap mvMap="
124:                                        + mvMap, jbe);
125:                    }
126:                    xml = writer.toString();
127:                }
128:
129:                return xml;
130:            }
131:
132:            public MultiValueMap getMultiValueMap(String mvXML)
133:                    throws WSRPConsumerException {
134:
135:                MultiValueMap mvMap = null;
136:                if (mvXML != null && mvXML.length() > 0) {
137:                    try {
138:                        Unmarshaller unmarshaller = jc.createUnmarshaller();
139:                        mvMap = (MultiValueMap) unmarshaller
140:                                .unmarshal(new StreamSource(new StringReader(
141:                                        mvXML)));
142:                    } catch (JAXBException jbe) {
143:                        throw new WSRPConsumerException(
144:                                "ConsumerObjectFactory.getMultiValueMap(): failed to unmarshall multiValueMap data.  xml="
145:                                        + mvXML, jbe);
146:                    }
147:                }
148:
149:                return mvMap;
150:            }
151:
152:            public Map getMap(MultiValueMap mvMap) throws WSRPConsumerException {
153:
154:                Map map = null;
155:                if (mvMap != null) {
156:                    List values = mvMap.getValues();
157:                    if (values != null && values.size() > 0) {
158:                        map = new HashMap();
159:                        for (Iterator i = values.iterator(); i.hasNext();) {
160:                            MultiValuePairType pair = (MultiValuePairType) i
161:                                    .next();
162:                            map.put(pair.getKey(), pair.getValues());
163:                        }
164:                    }
165:                }
166:
167:                return map;
168:            }
169:
170:            public MultiValueMap getMultiValueMap(Map map)
171:                    throws WSRPConsumerException {
172:
173:                MultiValueMap mvMap = null;
174:                if (map != null && map.size() > 0) {
175:                    try {
176:                        mvMap = jfactory.createMultiValueMap();
177:                    } catch (JAXBException jbe) {
178:                        throw new WSRPConsumerException(
179:                                "ConsumerObjectFactory.getMultiValueMap(): failed to create JAXB object.",
180:                                jbe);
181:                    }
182:
183:                    List values = new ArrayList();
184:                    for (Iterator i = map.keySet().iterator(); i.hasNext();) {
185:                        String key = (String) i.next();
186:                        MultiValuePairType pair = null;
187:                        try {
188:                            pair = jfactory.createMultiValuePairType();
189:                        } catch (JAXBException jbe) {
190:                            throw new WSRPConsumerException(
191:                                    "ConsumerObjectFactory.getMultiValueMap(): failed to create JAXB object.",
192:                                    jbe);
193:                        }
194:                        pair.setKey(key);
195:                        pair.getValues().addAll((List) map.get(key));
196:                        values.add(pair);
197:                    }
198:                    mvMap.getValues().addAll(values);
199:                }
200:
201:                return mvMap;
202:            }
203:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.