You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by bi...@apache.org on 2008/11/16 03:27:25 UTC
svn commit: r717963 - in
/webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH: maint/
maint/DoMerges.java
src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java
src/main/java/org/apache/ws/commons/schema/utils/NodeNamespaceContext.java
Author: bimargulies
Date: Sat Nov 15 18:27:24 2008
New Revision: 717963
URL: http://svn.apache.org/viewvc?rev=717963&view=rev
Log:
WSCOMMONS-358 and WSCOMMONS-361.
Added:
webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/maint/
webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/maint/DoMerges.java (with props)
Modified:
webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java
webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/utils/NodeNamespaceContext.java
Added: webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/maint/DoMerges.java
URL: http://svn.apache.org/viewvc/webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/maint/DoMerges.java?rev=717963&view=auto
==============================================================================
--- webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/maint/DoMerges.java (added)
+++ webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/maint/DoMerges.java Sat Nov 15 18:27:24 2008
@@ -0,0 +1,232 @@
+/*
+ * 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.
+ */
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.util.*;
+
+
+/* dkulp - Stupid little program I use to help merge changes from
+ trunk to the fixes branches. It requires the svnmerge.py be
+ available on the path. Grab the latest from:
+ http://svn.collab.net/repos/svn/trunk/contrib/client-side/svnmerge/
+ (of course, that then requries python installed and whatever else svnmerge.py
+ needs.) It also requires the command line version of svn.
+
+ Basically, svnmerge.py does all the work, but this little wrapper
+ thing will display the commit logs, prompt if you want to merge/block/ignore
+ each commit, prompt for commit (so you can resolve any conflicts first),
+ etc....
+
+ Yes - doing this in python itself (or perl or even bash itself or ruby or ...)
+ would probably be better. However, I'd then need to spend time
+ learning python/ruby/etc... that I just don't have time to do right now.
+ What is more productive: Taking 30 minutes to bang this out in Java or
+ spending a couple days learning another language that would allow me to
+ bang it out in 15 minutes?
+*/
+
+public class DoMerges {
+ public static boolean auto = false;
+
+ static void doCommit() throws Exception {
+ while (System.in.available() > 0) {
+ System.in.read();
+ }
+ char c = auto ? 'Y' : 0;
+ while (c != 'Y'
+ && c != 'N') {
+ System.out.print("Commit: [Y]es, or [N]o? ");
+ int i = System.in.read();
+ c = Character.toUpperCase((char)i);
+ }
+ if (c == 'N') {
+ return;
+ }
+ Process p = Runtime.getRuntime().exec(new String[] {"svn", "resolved", "."});
+ if (p.waitFor() != 0) {
+ Thread.sleep(10);
+ }
+ p = Runtime.getRuntime().exec(new String[] {"svn", "commit", "-F", "svnmerge-commit-message.txt"});
+ BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
+ String line = reader.readLine();
+ while (line != null) {
+ System.out.println(line);
+ line = reader.readLine();
+ }
+ if (p.waitFor() != 0) {
+ System.out.println("ERROR!");
+ reader = new BufferedReader(new InputStreamReader(p.getErrorStream()));
+ line = reader.readLine();
+ while (line != null) {
+ System.out.println(line);
+ line = reader.readLine();
+ }
+ System.exit(1);
+ }
+ }
+
+ public static void main (String args[]) throws Exception {
+ if (args.length > 0 && "-auto".equals(args[0])) {
+ auto = true;
+ }
+
+ System.out.println("Updating directory");
+
+ Process p = Runtime.getRuntime().exec(new String[] {"svn", "up", "-r", "head", "."});
+ BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
+ String line = reader.readLine();
+ while (line != null) {
+ System.out.println(line);
+ line = reader.readLine();
+ }
+ p.waitFor();
+
+
+ p = Runtime.getRuntime().exec(getCommandLine(new String[] {"svnmerge.py", "avail"}));
+
+ reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
+ line = reader.readLine();
+ List<String> verList = new ArrayList<String>();
+ while (line != null) {
+ String vers[] = line.split(",");
+ for (String s : vers) {
+ if (s.indexOf("-") != -1) {
+ String s1 = s.substring(0, s.indexOf("-"));
+ String s2 = s.substring(s.indexOf("-") + 1);
+ int i1 = Integer.parseInt(s1);
+ int i2 = Integer.parseInt(s2);
+ for (int x = i1; x <= i2; x++) {
+ verList.add(Integer.toString(x));
+ }
+ } else {
+ verList.add(s);
+ }
+ }
+ line = reader.readLine();
+ }
+ p.waitFor();
+ System.out.println("Merging versions (" + verList.size() + "): " + verList);
+
+
+
+
+ String root = null;
+
+ p = Runtime.getRuntime().exec(new String[] {"svn", "info"});
+ reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
+ line = reader.readLine();
+ while (line != null) {
+ if (line.startsWith("Repository Root: ")) {
+ root = line.substring("Repository Root: ".length()).trim();
+ }
+ line = reader.readLine();
+ }
+ System.out.println("Root: " + root);
+ p.waitFor();
+
+
+ int count = 1;
+ for (String ver : verList) {
+ System.out.println("Merging: " + ver + " (" + (count++) + "/" + verList.size() + ")");
+ p = Runtime.getRuntime().exec(new String[] {"svn", "log", "-r" , ver, root});
+ reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
+ line = reader.readLine();
+ while (line != null) {
+ System.out.println(line);
+ line = reader.readLine();
+ }
+ p.waitFor();
+
+ while (System.in.available() > 0) {
+ System.in.read();
+ }
+ char c = auto ? 'M' : 0;
+ while (c != 'M'
+ && c != 'B'
+ && c != 'I') {
+ System.out.print("[M]erge, [B]lock, or [I]gnore? ");
+ int i = System.in.read();
+ c = Character.toUpperCase((char)i);
+ }
+
+ switch (c) {
+ case 'M':
+ p = Runtime.getRuntime().exec(getCommandLine(new String[] {"svnmerge.py", "merge", "-r", ver}));
+ reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
+ line = reader.readLine();
+ while (line != null) {
+ System.out.println(line);
+ line = reader.readLine();
+ }
+ if (p.waitFor() != 0) {
+ System.out.println("ERROR!");
+ reader = new BufferedReader(new InputStreamReader(p.getErrorStream()));
+ line = reader.readLine();
+ while (line != null) {
+ System.out.println(line);
+ line = reader.readLine();
+ }
+ System.exit(1);
+ }
+
+ doCommit();
+ break;
+ case 'B':
+ p = Runtime.getRuntime().exec(getCommandLine(new String[] {"svnmerge.py", "block", "-r", ver}));
+ reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
+ line = reader.readLine();
+ while (line != null) {
+ System.out.println(line);
+ line = reader.readLine();
+ }
+ if (p.waitFor() != 0) {
+ System.out.println("ERROR!");
+ reader = new BufferedReader(new InputStreamReader(p.getErrorStream()));
+ line = reader.readLine();
+ while (line != null) {
+ System.out.println(line);
+ line = reader.readLine();
+ }
+ System.exit(1);
+ }
+ doCommit();
+ break;
+ case 'I':
+ System.out.println("Ignoring");
+ break;
+ }
+ }
+ }
+
+ private static String[] getCommandLine(String[] args) {
+ List<String> argLine = new ArrayList<String>();
+ if (isWindows()) {
+ argLine.add("cmd.exe");
+ argLine.add("/c");
+ }
+
+ argLine.addAll(Arrays.asList(args));
+ System.out.println("Running " + argLine + "...");
+ return argLine.toArray(new String[argLine.size()]);
+ }
+
+ private static boolean isWindows() {
+ return System.getProperty("os.name").toLowerCase().indexOf("windows") != -1;
+ }
+}
Propchange: webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/maint/DoMerges.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/maint/DoMerges.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java?rev=717963&r1=717962&r2=717963&view=diff
==============================================================================
--- webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java (original)
+++ webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java Sat Nov 15 18:27:24 2008
@@ -128,7 +128,7 @@
*/
XmlSchema handleXmlSchemaElement(Element schemaEl, String uri) {
// get all the attributes along with the namespace declns
- schema.setNamespaceContext(new NodeNamespaceContext(schemaEl));
+ schema.setNamespaceContext(NodeNamespaceContext.getNamespaceContext(schemaEl));
setNamespaceAttributes(schema, schemaEl);
XmlSchemaCollection.SchemaKey schemaKey = new XmlSchemaCollection.SchemaKey(
@@ -431,7 +431,7 @@
restrictionEl, XmlSchema.SCHEMA_NS, "simpleType");
if (restrictionEl.hasAttribute("base")) {
- NamespaceContext ctx = new NodeNamespaceContext(restrictionEl);
+ NamespaceContext ctx = NodeNamespaceContext.getNamespaceContext(restrictionEl);
restriction.baseTypeName = getRefQName(restrictionEl
.getAttribute("base"), ctx);
} else if (inlineSimpleType != null) {
@@ -558,7 +558,7 @@
}
private QName getRefQName(String pName, Node pNode) {
- return getRefQName(pName, new NodeNamespaceContext(pNode));
+ return getRefQName(pName, NodeNamespaceContext.getNamespaceContext(pNode));
}
private QName getRefQName(String pName, NamespaceContext pContext) {
@@ -1311,7 +1311,7 @@
// there is a possiblily of some namespace mapping
String prefix = value.substring(0, value.indexOf(":"));
if (ctx == null) {
- ctx = new NodeNamespaceContext(attrEl);
+ ctx = NodeNamespaceContext.getNamespaceContext(attrEl);
}
String namespace = ctx.getNamespaceURI(prefix);
if (!Constants.NULL_NS_URI.equals(namespace)) {
@@ -1956,12 +1956,10 @@
}
//process elements
- NodeList allChildren = parentElement.getChildNodes();
- for (int i = 0; i < allChildren.getLength(); i++) {
- if (allChildren.item(i).getNodeType() == Node.ELEMENT_NODE) {
-
- Element extElement = (Element) allChildren.item(i);
-
+ Node child = parentElement.getFirstChild();
+ while (child != null) {
+ if (child.getNodeType() == Node.ELEMENT_NODE) {
+ Element extElement = (Element) child;
String namespaceURI = extElement.getNamespaceURI();
String name = extElement.getLocalName();
@@ -1973,9 +1971,9 @@
QName qName = new QName(namespaceURI, name);
extReg.deserializeExtension(schemaObject, qName,
extElement);
-
}
}
+ child = child.getNextSibling();
}
}
Modified: webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/utils/NodeNamespaceContext.java
URL: http://svn.apache.org/viewvc/webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/utils/NodeNamespaceContext.java?rev=717963&r1=717962&r2=717963&view=diff
==============================================================================
--- webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/utils/NodeNamespaceContext.java (original)
+++ webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/utils/NodeNamespaceContext.java Sat Nov 15 18:27:24 2008
@@ -20,42 +20,94 @@
package org.apache.ws.commons.schema.utils;
import org.apache.ws.commons.schema.constants.Constants;
+
+import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import javax.xml.namespace.NamespaceContext;
+
+import java.lang.reflect.Method;
import java.util.*;
/**
* Implementation of {@link NamespaceContext}, which is based on a DOM node.
*/
public class NodeNamespaceContext implements NamespacePrefixList {
+ private static final String NODE_NAMSPACE_CONTEXT = NamespacePrefixList.class.getName();
private static final Collection XML_NS_PREFIX_COLLECTION = Collections.singletonList(Constants.XML_NS_PREFIX);
private static final Collection XMLNS_ATTRIBUTE_COLLECTION = Collections.singletonList(Constants.XMLNS_ATTRIBUTE);
- private Node node;
- private Map declarations;
+
+ static Method getUserData;
+ static Method setUserData;
+ static {
+ try {
+ Class cls = Class.forName("org.w3c.dom.UserDataHandler", false, Node.class.getClassLoader());
+ getUserData = Node.class.getMethod("getUserData", new Class[]{String.class});
+ setUserData = Node.class.getMethod("setUserData", new Class[]{String.class, Object.class, cls});
+ } catch (Throwable e) {
+ getUserData = null;
+ setUserData = null;
+ }
+ }
+
+
+
+ private final Map declarations;
private String[] prefixes;
/**
* Creates a new instance with the given nodes context.
*/
- public NodeNamespaceContext(Node pNode) {
- node = pNode;
+ private NodeNamespaceContext(Map decls) {
+ declarations = decls;
}
-
- private Map getDeclarations() {
- if (declarations == null) {
- declarations = new HashMap();
- //FIXME: Do we really need to add this mapping? shows up in the serialized schema as xmlns=""
- //declarations.put(Constants.DEFAULT_NS_PREFIX, Constants.NULL_NS_URI);
- new PrefixCollector(){
- protected void declare(String pPrefix, String pNamespaceURI) {
- declarations.put(pPrefix, pNamespaceURI);
+
+ public static NodeNamespaceContext getNamespaceContext(Node pNode) {
+ if (getUserData != null) {
+ try {
+ NodeNamespaceContext ctx = (NodeNamespaceContext)getUserData.invoke(pNode, new Object[] {NODE_NAMSPACE_CONTEXT});
+ if (ctx == null) {
+ Map declarations = new HashMap();
+
+ Node parentNode = pNode.getParentNode();
+ if (parentNode != null) {
+ NodeNamespaceContext parent =
+ (NodeNamespaceContext)getUserData.invoke(parentNode, new Object[] {NODE_NAMSPACE_CONTEXT});
+ if (parent == null) {
+ parent = getNamespaceContext(parentNode);
+ }
+ declarations.putAll(parent.declarations);
+ }
+
+ NamedNodeMap map = pNode.getAttributes();
+ if (map != null) {
+ for (int i = 0; i < map.getLength(); i++) {
+ Node attr = map.item(i);
+ final String uri = attr.getNamespaceURI();
+ if (Constants.XMLNS_ATTRIBUTE_NS_URI.equals(uri)) {
+ String localName = attr.getLocalName();
+ String prefix = Constants.XMLNS_ATTRIBUTE.equals(localName) ? Constants.DEFAULT_NS_PREFIX : localName;
+ declarations.put(prefix, attr.getNodeValue());
+ }
+ }
+ }
+ ctx = new NodeNamespaceContext(declarations);
+ setUserData.invoke(pNode, new Object[] {NODE_NAMSPACE_CONTEXT, ctx, null});
}
- }.searchAllPrefixDeclarations(node);
- Collection keys = declarations.keySet();
- prefixes = (String[]) keys.toArray(new String[keys.size()]);
+ return ctx;
+ } catch (Throwable t) {
+ //ignore. DOM level 2 implementation would not have the getUserData stuff.
+ //Thus, fall back to the old, slower method.
+ }
}
- return declarations;
+
+ final Map declarations = new HashMap();
+ new PrefixCollector(){
+ protected void declare(String pPrefix, String pNamespaceURI) {
+ declarations.put(pPrefix, pNamespaceURI);
+ }
+ }.searchAllPrefixDeclarations(pNode);
+ return new NodeNamespaceContext(declarations);
}
public String getNamespaceURI(String pPrefix) {
@@ -68,7 +120,7 @@
if (Constants.XMLNS_ATTRIBUTE.equals(pPrefix)) {
return Constants.XMLNS_ATTRIBUTE_NS_URI;
}
- final String uri = (String) getDeclarations().get(pPrefix);
+ final String uri = (String) declarations.get(pPrefix);
return uri == null ? Constants.NULL_NS_URI : uri;
}
@@ -82,8 +134,7 @@
if (Constants.XMLNS_ATTRIBUTE_NS_URI.equals(pNamespaceURI)) {
return Constants.XMLNS_ATTRIBUTE;
}
- Map decl = getDeclarations();
- for (Iterator iter = decl.entrySet().iterator(); iter.hasNext(); ) {
+ for (Iterator iter = declarations.entrySet().iterator(); iter.hasNext(); ) {
Map.Entry entry = (Map.Entry) iter.next();
if (pNamespaceURI.equals(entry.getValue())) {
return (String) entry.getKey();
@@ -103,7 +154,7 @@
return XMLNS_ATTRIBUTE_COLLECTION.iterator();
}
final List list = new ArrayList();
- for (Iterator iter = getDeclarations().entrySet().iterator(); iter.hasNext(); ) {
+ for (Iterator iter = declarations.entrySet().iterator(); iter.hasNext(); ) {
Map.Entry entry = (Map.Entry) iter.next();
if (pNamespaceURI.equals(entry.getValue())) {
list.add(entry.getKey());
@@ -113,7 +164,10 @@
}
public String[] getDeclaredPrefixes() {
- getDeclarations(); // Make sure, that the prefixes array is valid
+ if (prefixes == null) {
+ Collection keys = declarations.keySet();
+ prefixes = (String[]) keys.toArray(new String[keys.size()]);
+ }
return prefixes;
}
}