You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by mc...@apache.org on 2008/08/13 21:24:13 UTC
svn commit: r685643 - in /geronimo/devtools/eclipse-plugin/trunk: ./
plugins/org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/jaxb/
plugins/org.apache.geronimo.st.core/src/test/java/org/apache/geronimo/st/core/internal/
Author: mcconne
Date: Wed Aug 13 12:24:11 2008
New Revision: 685643
URL: http://svn.apache.org/viewvc?rev=685643&view=rev
Log:
GERONIMODEVTOOLS-468 Support Java 5 and 6 for both build-time and runtime
Added:
geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/jaxb/NamespacePrefix.java (with props)
Removed:
geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/jaxb/NamespacePrefixMapperImpl.java
geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/jaxb/NamespacePrefixMapperImpl6.java
Modified:
geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/jaxb/JAXBUtils.java
geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/test/java/org/apache/geronimo/st/core/internal/DependencyHelperTest.java
geronimo/devtools/eclipse-plugin/trunk/pom.xml
Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/jaxb/JAXBUtils.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/jaxb/JAXBUtils.java?rev=685643&r1=685642&r2=685643&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/jaxb/JAXBUtils.java (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/jaxb/JAXBUtils.java Wed Aug 13 12:24:11 2008
@@ -18,6 +18,8 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.io.OutputStreamWriter;
+import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@@ -26,10 +28,20 @@
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Result;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.sax.SAXSource;
+import javax.xml.transform.stream.StreamResult;
import org.apache.geronimo.st.core.Activator;
import org.apache.geronimo.st.core.internal.Trace;
@@ -37,6 +49,7 @@
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.runtime.CoreException;
+import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
@@ -47,7 +60,7 @@
// JAXBContext instantiation is costly - must be done only once!
private static final JAXBContext jaxbContext = newJAXBContext();
- private static final MarshallerListener marshellerListener = new MarshallerListener();
+ private static final MarshallerListener marshallerListener = new MarshallerListener();
private static JAXBContext newJAXBContext() {
try {
return JAXBContext.newInstance(
@@ -69,18 +82,32 @@
public static void marshalDeploymentPlan(JAXBElement jaxbElement, IFile file) {
try {
Marshaller marshaller = jaxbContext.createMarshaller();
- marshaller.setListener(marshellerListener);
- marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
- marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
- Trace.tracePoint("JAXBUtils", "JAXBUtils.marshalDeploymentPlan()", System.getProperty("java.runtime.version"));
- if ( System.getProperty("java.runtime.version").startsWith("1.6") ) {
- marshaller.setProperty("com.sun.xml.internal.bind.namespacePrefixMapper", new NamespacePrefixMapperImpl6());
- }
- else {
- marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", new NamespacePrefixMapperImpl());
+ marshaller.setListener(marshallerListener);
+
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(true);
+ DocumentBuilder db = dbf.newDocumentBuilder();
+ Document doc = db.newDocument();
+
+ marshaller.marshal(jaxbElement, doc);
+
+ TransformerFactory xf = TransformerFactory.newInstance();
+ try {
+ xf.setAttribute("indent-number", new Integer(4));
+ } catch (IllegalArgumentException iae) {
+ //ignore this. http://forums.sun.com/thread.jspa?threadID=562510&messageID=2841867
}
+ Transformer xformer = xf.newTransformer();
+ xformer.setOutputProperty(OutputKeys.METHOD, "xml");
+ xformer.setOutputProperty(OutputKeys.INDENT, "yes");
+ xformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
+ xformer.setOutputProperty("{http://xml.apache.org/xalan}indent-amount", "4");
+
ByteArrayOutputStream outBuffer = new ByteArrayOutputStream();
- marshaller.marshal(jaxbElement, outBuffer);
+ Result out = new StreamResult(new OutputStreamWriter(outBuffer,"UTF-8"));
+ NamespacePrefix.processPrefix( doc );
+
+ xformer.transform(new DOMSource(doc), out);
ByteArrayInputStream inBuffer = new ByteArrayInputStream(outBuffer.toByteArray());
if(file.exists()) {
file.setContents(inBuffer, true, false, null);
@@ -94,7 +121,19 @@
} catch (CoreException coreException) {
Trace.tracePoint("CoreException", "JAXBUtils.marshalDeploymentPlan()", file.getFullPath());
coreException.printStackTrace();
- }
+ } catch (ParserConfigurationException e) {
+ Trace.tracePoint("ParserConfigurationException", "JAXBUtils.marshalDeploymentPlan()", file.getFullPath());
+ e.printStackTrace();
+ } catch (TransformerConfigurationException e) {
+ Trace.tracePoint("TransformerConfigurationException", "JAXBUtils.marshalDeploymentPlan()", file.getFullPath());
+ e.printStackTrace();
+ } catch (UnsupportedEncodingException e) {
+ Trace.tracePoint("UnsupportedEncodingException", "JAXBUtils.marshalDeploymentPlan()", file.getFullPath());
+ e.printStackTrace();
+ } catch (TransformerException e) {
+ Trace.tracePoint("TransformerException", "JAXBUtils.marshalDeploymentPlan()", file.getFullPath());
+ e.printStackTrace();
+ }
}
public static JAXBElement unmarshalFilterDeploymentPlan(IFile file) {
Added: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/jaxb/NamespacePrefix.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/jaxb/NamespacePrefix.java?rev=685643&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/jaxb/NamespacePrefix.java (added)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/jaxb/NamespacePrefix.java Wed Aug 13 12:24:11 2008
@@ -0,0 +1,95 @@
+/**
+ * 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.
+ */
+
+package org.apache.geronimo.st.core.jaxb;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class NamespacePrefix {
+
+ private static Map<String, String> prefixMap = new HashMap<String, String>();
+
+ static {
+ prefixMap.put("http://geronimo.apache.org/xml/ns/deployment-1.2", "dep");
+ prefixMap.put("http://geronimo.apache.org/xml/ns/j2ee/application-2.0", "app");
+ prefixMap.put("http://geronimo.apache.org/xml/ns/j2ee/application-client-2.0", "client");
+ prefixMap.put("http://geronimo.apache.org/xml/ns/j2ee/connector-1.2", "conn");
+ prefixMap.put("http://openejb.apache.org/xml/ns/openejb-jar-2.2", "ejb");
+ prefixMap.put("http://java.sun.com/xml/ns/persistence", "pers");
+ prefixMap.put("http://openejb.apache.org/xml/ns/pkgen-2.1", "pkgen");
+ prefixMap.put("http://geronimo.apache.org/xml/ns/naming-1.2", "name");
+ prefixMap.put("http://geronimo.apache.org/xml/ns/security-2.0", "sec");
+ prefixMap.put("http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1", "web");
+ }
+
+ public static void processPrefix( Node parent ) {
+ NodeList nl = parent.getChildNodes();
+
+ if ( parent instanceof Element ) {
+ updatePrefix( (Element)parent );
+ }
+
+ for ( int i = 0; i <= nl.getLength(); i ++ ) {
+ Node node = nl.item(i);
+ if ( node instanceof Element ) {
+ processPrefix( node );
+ }
+ }
+
+ }
+
+ private static void updatePrefix( Element element ) {
+ NamedNodeMap mnm = element.getAttributes();
+
+ ArrayList<Attr> attributes = new ArrayList<Attr>();
+ for ( int j = 0; j <= mnm.getLength(); j ++ ) {
+ Attr attr = (Attr)mnm.item(j);
+ if ( attr != null && attr.getOwnerElement() != null && getPrefix( attr.getNodeValue() ) != null ) {
+ attributes.add((Attr)attr.cloneNode(false));
+ }
+ }
+ for ( int j = 0; j < attributes.size(); j ++ ) {
+ Attr tempAttr = attributes.get(j);
+ Attr attr = element.getAttributeNode(tempAttr.getName());
+ Element owner = (Element)attr.getOwnerElement();
+ owner.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:" + getPrefix( attr.getNodeValue() ), attr.getNodeValue());
+ owner.removeAttributeNode(attr);
+ }
+ String prefix = getPrefix( element.getNamespaceURI() );
+ if ( prefix != null ) {
+ element.setPrefix( prefix );
+ }
+ }
+
+ private static String getPrefix(String namespaceURI) {
+ if (prefixMap.containsKey(namespaceURI))
+ return prefixMap.get(namespaceURI);
+ return null;
+ }
+
+}
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/jaxb/NamespacePrefix.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/jaxb/NamespacePrefix.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/jaxb/NamespacePrefix.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/test/java/org/apache/geronimo/st/core/internal/DependencyHelperTest.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/test/java/org/apache/geronimo/st/core/internal/DependencyHelperTest.java?rev=685643&r1=685642&r2=685643&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/test/java/org/apache/geronimo/st/core/internal/DependencyHelperTest.java (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/test/java/org/apache/geronimo/st/core/internal/DependencyHelperTest.java Wed Aug 13 12:24:11 2008
@@ -22,18 +22,15 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
-import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import junit.framework.TestCase;
-import org.apache.geronimo.st.core.jaxb.NamespacePrefixMapperImpl;
import org.xml.sax.InputSource;
/**
@@ -90,15 +87,10 @@
//
public void setUp() throws Exception {
-
//
- // Create unmarshaller and marshaller
+ // Create unmarshaller
//
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
- Marshaller marshaller = jaxbContext.createMarshaller();
- marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
- marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
- marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", new NamespacePrefixMapperImpl());
//
// Read XML files
Modified: geronimo/devtools/eclipse-plugin/trunk/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/pom.xml?rev=685643&r1=685642&r2=685643&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/pom.xml (original)
+++ geronimo/devtools/eclipse-plugin/trunk/pom.xml Wed Aug 13 12:24:11 2008
@@ -288,23 +288,6 @@
<configuration>
<source>1.5</source>
<target>1.5</target>
- <!--
- |
- | If using a JDK 1.6 this entry will point to the rt.jar without any changes.
- | For example:
- |
- | <bootclasspath>${java.home}/lib/rt.jar</bootclasspath>
- |
- | If using a JDK 1.5 this entry must be modified to point to a 1.6 rt.jar
- | on your system, which means it must be either manually downloaded or
- | installed. For example:
- |
- | <bootclasspath>C:/Program Files/Java/jre1.6.0_07/lib/rt.jar</bootclasspath>
- |
- -->
- <compilerArguments>
- <bootclasspath>${java.home}/lib/rt.jar</bootclasspath>
- </compilerArguments>
</configuration>
</plugin>
<plugin>
Re: svn commit: r685643 - in /geronimo/devtools/eclipse-plugin/trunk:
./ plugins/org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/jaxb/
plugins/org.apache.geronimo.st.core/src/test/java/org/apache/geronimo/st/core/internal/
Posted by Tim McConnell <ti...@gmail.com>.
Oh my fault. Will remember next time though....
Kevan Miller wrote:
>
> On Aug 13, 2008, at 3:24 PM, mcconne@apache.org
> <ma...@apache.org> wrote:
>
>> Author: mcconne
>> Date: Wed Aug 13 12:24:11 2008
>> New Revision: 685643
>>
>> URL: http://svn.apache.org/viewvc?rev=685643&view=rev
>> <http://svn.apache.org/viewvc?rev=685643&view=rev>
>> Log:
>> GERONIMODEVTOOLS-468 Support Java 5 and 6 for both build-time and runtime
>
> Tim,
> Friendly reminder -- please include the contributor's name in your
> commit message when applying a patch.
>
> --kevan
>
--
Thanks,
Tim McConnell
Re: svn commit: r685643 - in /geronimo/devtools/eclipse-plugin/trunk: ./ plugins/org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/jaxb/ plugins/org.apache.geronimo.st.core/src/test/java/org/apache/geronimo/st/core/internal/
Posted by Kevan Miller <ke...@gmail.com>.
On Aug 13, 2008, at 3:24 PM, mcconne@apache.org wrote:
> Author: mcconne
> Date: Wed Aug 13 12:24:11 2008
> New Revision: 685643
>
> URL: http://svn.apache.org/viewvc?rev=685643&view=rev
> Log:
> GERONIMODEVTOOLS-468 Support Java 5 and 6 for both build-time and
> runtime
Tim,
Friendly reminder -- please include the contributor's name in your
commit message when applying a patch.
--kevan