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


001:        /******************************************************************************
002:         * JBoss, a division of Red Hat                                               *
003:         * Copyright 2007, 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.wsrp.producer.config.impl;
023:
024:        import org.jboss.mx.util.MBeanServerLocator;
025:        import org.jboss.mx.util.ObjectNameFactory;
026:        import org.jboss.portal.common.net.URLTools;
027:        import org.jboss.portal.jems.as.system.AbstractJBossService;
028:        import org.jboss.portal.wsrp.producer.config.ProducerConfiguration;
029:        import org.jboss.portal.wsrp.producer.config.ProducerConfigurationFactory;
030:        import org.jboss.portal.wsrp.producer.config.ProducerConfigurationProvider;
031:        import org.jboss.portal.wsrp.producer.config.ProducerConfigurationService;
032:        import org.jboss.xb.binding.JBossXBException;
033:        import org.jboss.xb.binding.ObjectModelFactory;
034:        import org.jboss.xb.binding.ObjectModelProvider;
035:        import org.jboss.xb.binding.Unmarshaller;
036:        import org.jboss.xb.binding.UnmarshallerFactory;
037:        import org.jboss.xb.binding.XercesXsMarshaller;
038:        import org.jboss.xb.binding.sunday.unmarshalling.DefaultSchemaResolver;
039:
040:        import javax.management.MBeanServer;
041:        import javax.management.ObjectName;
042:        import java.io.BufferedWriter;
043:        import java.io.File;
044:        import java.io.FileWriter;
045:        import java.io.IOException;
046:        import java.io.InputStream;
047:        import java.io.InputStreamReader;
048:        import java.io.Reader;
049:        import java.io.StringWriter;
050:        import java.io.Writer;
051:        import java.net.URL;
052:        import java.util.Enumeration;
053:
054:        /**
055:         * @author <a href="mailto:chris.laprun@jboss.com">Chris Laprun</a>
056:         * @version $Revision: 9461 $
057:         * @since 2.6
058:         */
059:        public class ProducerConfigurationServiceImpl extends
060:                AbstractJBossService implements  ProducerConfigurationService {
061:            private String configLocation;
062:            private ProducerConfiguration configuration;
063:
064:            private File config;
065:
066:            private static DefaultSchemaResolver RESOLVER;
067:
068:            static {
069:                RESOLVER = new DefaultSchemaResolver();
070:                RESOLVER.setCacheResolvedSchemas(true);
071:                RESOLVER.addSchemaLocation(
072:                        "http://www.w3.org/XML/1998/namespace", "xsd/xml.xsd");
073:                RESOLVER.addSchemaLocation(
074:                        "urn:jboss:portal:wsrp:producer:v2_6",
075:                        "xsd/jboss-wsrp-producer_2_6.xsd");
076:            }
077:
078:            public String getConfigLocation() {
079:                return configLocation;
080:            }
081:
082:            public void setConfigLocation(String configLocation) {
083:                this .configLocation = configLocation;
084:            }
085:
086:            public ProducerConfiguration getConfiguration() {
087:                return configuration;
088:            }
089:
090:            protected void startService() throws Exception {
091:                MBeanServer server = MBeanServerLocator.locateJBoss();
092:                ObjectName oname = ObjectNameFactory
093:                        .create("jboss.system:type=ServerConfig");
094:                File dataDir;
095:                try {
096:                    dataDir = (File) server
097:                            .getAttribute(oname, "ServerDataDir");
098:                } catch (Exception e) {
099:                    throw new RuntimeException(
100:                            "Couldn't locate server data dir!", e);
101:                }
102:                config = new File(dataDir, "portal/wsrp-producer-config.xml");
103:
104:                reloadConfiguration();
105:            }
106:
107:            public void reloadConfiguration() throws Exception {
108:                URL configURL = getConfigLocationURL();
109:
110:                try {
111:                    loadConfigurationAt(configURL);
112:                } catch (Exception e) {
113:                    if (config.exists()) {
114:                        log
115:                                .debug("Configuration saved at "
116:                                        + config.getCanonicalPath()
117:                                        + " is not loading properly. Falling back to default configuration.");
118:                        config.delete(); // delete improper config so that we retrieve the default configuration
119:                        loadConfigurationAt(getConfigLocationURL());
120:                    }
121:                }
122:            }
123:
124:            private void loadConfigurationAt(URL configURL)
125:                    throws JBossXBException, IOException {
126:                log.debug("About to parse producer configuration " + configURL);
127:                Unmarshaller unmarshaller = UnmarshallerFactory.newInstance()
128:                        .newUnmarshaller();
129:                ObjectModelFactory factory = new ProducerConfigurationFactory();
130:                configuration = (ProducerConfiguration) unmarshaller.unmarshal(
131:                        configURL.openStream(), factory, null);
132:            }
133:
134:            private URL getConfigLocationURL() throws Exception {
135:                if (!config.exists()) {
136:                    // Setup URLs
137:                    if (configLocation == null) {
138:                        throw new Exception("The config location is null");
139:                    }
140:
141:                    // make sure we pick the furthest down the path in case there's several similarly named resources in the path
142:                    Enumeration resources = Thread.currentThread()
143:                            .getContextClassLoader().getResources(
144:                                    configLocation);
145:                    URL configURL = null;
146:                    while (resources.hasMoreElements()) {
147:                        configURL = (URL) resources.nextElement();
148:                    }
149:
150:                    if (configURL == null) {
151:                        throw new Exception("The config " + configLocation
152:                                + " does not exist");
153:                    }
154:                    if (!URLTools.exists(configURL)) {
155:                        throw new Exception("The config " + configURL
156:                                + " does not exist");
157:                    }
158:                    return configURL;
159:                } else {
160:                    return config.toURL();
161:                }
162:            }
163:
164:            public void saveConfiguration() throws Exception {
165:                // get the output writer to write the XML content
166:                StringWriter xmlOutput = new StringWriter();
167:
168:                // get the XML Schema source
169:                InputStream is = Thread.currentThread().getContextClassLoader()
170:                        .getResourceAsStream("xsd/jboss-wsrp-producer_2_6.xsd");
171:
172:                Reader xsReader = new InputStreamReader(is);
173:
174:                // create an instance of XML Schema marshaller
175:                XercesXsMarshaller marshaller = new XercesXsMarshaller();
176:
177:                marshaller.setSchemaResolver(RESOLVER);
178:
179:                // we need to specify what elements are top most (roots) providing namespace URI, prefix and local name
180:                marshaller.addRootElement(
181:                        "urn:jboss:portal:wsrp:producer:v2_6", "",
182:                        "producer-configuration");
183:
184:                // declare default namespace
185:                marshaller.declareNamespace("wpc",
186:                        "urn:jboss:portal:wsrp:producer:v2_6");
187:
188:                // add schema location by declaring xsi namespace and adding xsi:schemaLocation attribute
189:                marshaller.declareNamespace("xsi",
190:                        "http://www.w3.org/2001/XMLSchema-instance");
191:                marshaller
192:                        .addAttribute(
193:                                "xsi",
194:                                "schemaLocation",
195:                                "string",
196:                                "urn:jboss:portal:wsrp:producer:v2_6 http://www.jboss.org/portal/xsd/jboss-wsrp-producer_2_6.xsd");
197:
198:                // create an instance of Object Model Provider
199:                ObjectModelProvider provider = new ProducerConfigurationProvider();
200:
201:                marshaller.setProperty(
202:                        "org.jboss.xml.binding.marshalling.indent", "true");
203:                marshaller
204:                        .marshal(xsReader, provider, configuration, xmlOutput);
205:
206:                // close XML Schema reader
207:                xsReader.close();
208:
209:                config.createNewFile();
210:                Writer configFile = new BufferedWriter(new FileWriter(config));
211:                configFile.write(xmlOutput.toString());
212:                configFile.flush();
213:                configFile.close();
214:            }
215:        }
ww_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.