You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ch...@apache.org on 2010/07/31 12:50:39 UTC
svn commit: r981034 - in /activemq/activemq-apollo/trunk/apollo-dto/src/main:
java/org/apache/activemq/apollo/dto/ resources/META-INF/
resources/META-INF/services/
resources/META-INF/services/org.apache.activemq.apollo/
Author: chirino
Date: Sat Jul 31 10:50:38 2010
New Revision: 981034
URL: http://svn.apache.org/viewvc?rev=981034&view=rev
Log:
Support parsing XML dto's defined in extension modules.
Added:
activemq/activemq-apollo/trunk/apollo-dto/src/main/resources/META-INF/
activemq/activemq-apollo/trunk/apollo-dto/src/main/resources/META-INF/services/
activemq/activemq-apollo/trunk/apollo-dto/src/main/resources/META-INF/services/org.apache.activemq.apollo/
activemq/activemq-apollo/trunk/apollo-dto/src/main/resources/META-INF/services/org.apache.activemq.apollo/xml-packages.index
Modified:
activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/XmlCodec.java
Modified: activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/XmlCodec.java
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/XmlCodec.java?rev=981034&r1=981033&r2=981034&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/XmlCodec.java (original)
+++ activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/XmlCodec.java Sat Jul 31 10:50:38 2010
@@ -26,6 +26,8 @@ import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.util.StreamReaderDelegate;
import java.io.*;
import java.net.URL;
+import java.util.Enumeration;
+import java.util.HashSet;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -76,12 +78,61 @@ public class XmlCodec {
static {
try {
- context = JAXBContext.newInstance("org.apache.activemq.apollo.dto");
+ String path = "META-INF/services/org.apache.activemq.apollo/xml-packages.index";
+ ClassLoader[] loaders = new ClassLoader[]{Thread.currentThread().getContextClassLoader()};
+
+ HashSet<String> names = new HashSet<String>();
+ for (ClassLoader loader : loaders) {
+ try {
+ Enumeration<URL> resources = loader.getResources(path);
+
+ while (resources.hasMoreElements()) {
+ URL url = resources.nextElement();
+ Properties p = loadProperties(url.openStream());
+ Enumeration<Object> keys = p.keys();
+ while (keys.hasMoreElements()) {
+ names.add((String) keys.nextElement());
+ }
+ }
+
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ String packages = "";
+ for ( String p : names) {
+ if( p.length() !=0 ) {
+ p += ":";
+ }
+ packages += p;
+ }
+ context = JAXBContext.newInstance(packages);
+
} catch (JAXBException e) {
throw new RuntimeException(e);
}
}
+ static private Properties loadProperties(InputStream is) {
+ if (is == null) {
+ return null;
+ }
+ try {
+ Properties p = new Properties();
+ p.load(is);
+ return p;
+ } catch (Exception e) {
+ return null;
+ } finally {
+ try {
+ is.close();
+ } catch (Throwable e) {
+ }
+ }
+ }
+
+
static public BrokerDTO unmarshalBrokerDTO(URL url) throws IOException, XMLStreamException, JAXBException {
return unmarshalBrokerDTO(url, null);
}
Added: activemq/activemq-apollo/trunk/apollo-dto/src/main/resources/META-INF/services/org.apache.activemq.apollo/xml-packages.index
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-dto/src/main/resources/META-INF/services/org.apache.activemq.apollo/xml-packages.index?rev=981034&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-dto/src/main/resources/META-INF/services/org.apache.activemq.apollo/xml-packages.index (added)
+++ activemq/activemq-apollo/trunk/apollo-dto/src/main/resources/META-INF/services/org.apache.activemq.apollo/xml-packages.index Sat Jul 31 10:50:38 2010
@@ -0,0 +1,17 @@
+## ---------------------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one or more
+## contributor license agreements. See the NOTICE file distributed with
+## this work for additional information regarding copyright ownership.
+## The ASF licenses this file to You under the Apache License, Version 2.0
+## (the "License"); you may not use this file except in compliance with
+## the License. You may obtain a copy of the License at
+##
+## http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+## ---------------------------------------------------------------------------
+org.apache.activemq.apollo.dto
\ No newline at end of file