You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by pp...@apache.org on 2010/08/25 21:14:32 UTC
svn commit: r989310 - in
/openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/tools:
MigrationTool.java action/Actions.java
Author: ppoddar
Date: Wed Aug 25 19:14:32 2010
New Revision: 989310
URL: http://svn.apache.org/viewvc?rev=989310&view=rev
Log:
Add warning for ignored mapping
Modified:
openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/tools/MigrationTool.java
openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/tools/action/Actions.java
Modified: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/tools/MigrationTool.java
URL: http://svn.apache.org/viewvc/openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/tools/MigrationTool.java?rev=989310&r1=989309&r2=989310&view=diff
==============================================================================
--- openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/tools/MigrationTool.java (original)
+++ openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/tools/MigrationTool.java Wed Aug 25 19:14:32 2010
@@ -82,7 +82,7 @@ import org.w3c.dom.NodeList;
* becoming <code>optional="false"</code>, more complex transformations can occur,
* such as <br>
* <LI>some attributes can become elements (e.g. <code><column></code>)
- * <LI>some elements can become attributes (e.g. <code><cache></code>
+ * <LI>some elements can become attributes (e.g. <code><cache></code>)
* <LI>some elements can split into two elements that are added at different hierarchy in
* the XML document (e.g. <code><complex-id></code>
* <LI>new elements that have no counterpart in Hibernate may be inserted
@@ -306,16 +306,21 @@ public class MigrationTool {
_logger.info("Processing source [" + source.getNodeName() + "] with " + actions.size() + " actions");
List<String> consumedAttrs = new ArrayList<String>();
List<String> consumedElements = new ArrayList<String>();
+
// first action must create a target element
Actions action = actions.get(0);
- Element newElement = (Element)action.run(target, source, current, consumedAttrs, consumedElements);
+ Element newElement = (Element)action.run(target, source, current, consumedAttrs, consumedElements, _logger);
+ if (newElement == null) {
+ throw new RuntimeException("The first action " + action + " returned a null element." +
+ "But the root element can not be null");
+ }
Element root = newElement;
for (int i = 1; i < actions.size(); i++) {
action = actions.get(i);
_logger.info("Processing source [" + source.getNodeName() + "] "
+ i + "-th Action " + action.getClass().getSimpleName());
- Node newNode = action.run(target, source, root, consumedAttrs, consumedElements);
+ Node newNode = action.run(target, source, root, consumedAttrs, consumedElements, _logger);
if (newNode != null) {
switch (action.getOrder()) {
@@ -332,11 +337,11 @@ public class MigrationTool {
root.appendChild(newNode);
break;
case IGNORE_ATTR:
- break;
+ case IGNORE_NODE:
case RENAME_NODE:
break;
- default:
- throw new RuntimeException("Result of " + action + " not handled");
+ default:
+ throw new RuntimeException("Result of " + action + " not handled");
}
}
}
Modified: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/tools/action/Actions.java
URL: http://svn.apache.org/viewvc/openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/tools/action/Actions.java?rev=989310&r1=989309&r2=989310&view=diff
==============================================================================
--- openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/tools/action/Actions.java (original)
+++ openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/tools/action/Actions.java Wed Aug 25 19:14:32 2010
@@ -24,6 +24,7 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.logging.Logger;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
@@ -52,7 +53,7 @@ import org.w3c.dom.NodeList;
* @author Pinaki Poddar
*
*/
-public interface Actions {//extends Comparable<Actions> {
+public interface Actions {
/**
* Get the enumeration code of this action.
* Actions are orderable based on the ordinal values of this enumeration.
@@ -66,18 +67,23 @@ public interface Actions {//extends Comp
* @param source the element in the source document to be processed.
* @param current the target element from the top of the stack. This is the
* element most likely to add the result of this method.
+ * @param consumedAttrs a non-null list. The current action must add the name of the
+ * attributes processed by this run.
+ * @param consumedElements a non-null list. The current action must add the name of the
+ * elements processed by this run.
+ * @param logger TODO
* @return the output of this action. Null value is permissible to signal that
* this action have skipped the given source.
*/
public Node run(Document targetDoc, Element source, Element current,
- Collection<String> consumedAttrs, Collection<String> consumedElements);
+ Collection<String> consumedAttrs, Collection<String> consumedElements, Logger logger);
/**
* An enumeration of different allowed actions.
* <br>
* <B>Important</B>: The string value of each enumeration must match the XML node
- * name used for the <A HREF="../../../../../../resources/META-INF/actionrules.xml">
+ * name used for the <A HREF="../../../../../../resources/META-INF/migration-actions.xml">
* defined rules</A>.
* <br>
* <B>Important</B>: The enumeration order is significant. This order will determine
@@ -204,6 +210,10 @@ public interface Actions {//extends Comp
return (Element)nodes.item(0);
}
+ public String toString() {
+ return "Action:[" + original.getNodeName() + "]";
+ }
+
}
/**
@@ -213,35 +223,36 @@ public interface Actions {//extends Comp
*
*/
public static class RenameNode extends Abstract {
- private final String sourcetName;
+ private final String sourceName;
private final String targetName;
public RenameNode(Element node) {
super(Code.RENAME_NODE, node);
targetName = getAttribute("to", node.getParentNode().getNodeName());
- sourcetName = getAttribute("from", targetName);
+ sourceName = getAttribute("from", targetName);
}
/**
* Creates an element without any attribute or sub-element.
*/
public Element run(Document targetDoc, Element source, Element current,
- Collection<String> consumedAttrs, Collection<String> consumedElements) {
- consumedElements.add(sourcetName);
+ Collection<String> consumedAttrs, Collection<String> consumedElements, Logger logger) {
+ consumedElements.add(sourceName);
Element newElement = targetDoc.createElement(targetName);
+ logger.info(this + " renamed " + sourceName + " to " + targetName);
return newElement;
}
}
public static class RenameChildNode extends Abstract {
- private final String sourcetName;
+ private final String sourceName;
private final String targetName;
private List<String> _ignores = new ArrayList<String>();
private Map<String, String> _valueMap = new HashMap<String, String>();
public RenameChildNode(Element s) {
super(Code.RENAME_CHILD_NODE, s);
- sourcetName = getAttribute("from");
+ sourceName = getAttribute("from");
targetName = getAttribute("to", "from");
NodeList values = s.getElementsByTagName("ignore-attr");
@@ -253,18 +264,21 @@ public interface Actions {//extends Comp
}
public Node run(Document targetDoc, Element source, Element current,
- Collection<String> consumedAttrs, Collection<String> consumedElements) {
- Element sourceNode = getElementByName(source, sourcetName, false);
+ Collection<String> consumedAttrs, Collection<String> consumedElements, Logger logger) {
+ Element sourceNode = getElementByName(source, sourceName, false);
if (sourceNode == null)
return null;
- consumedElements.add(sourcetName);
+ consumedElements.add(sourceName);
Element newNode = targetDoc.createElement(targetName);
+ logger.info("renamed " + sourceName + " to " + targetName);
NamedNodeMap attrs = sourceNode.getAttributes();
int M = attrs.getLength();
for (int i = 0; i< M ; i++) {
Attr sourceAttr = (Attr)attrs.item(i);
if (!_ignores.contains(sourceAttr.getNodeName())) {
newNode.setAttribute(sourceAttr.getNodeName(), sourceAttr.getValue());
+ } else {
+ logger.warning("ignored attribute " + sourceAttr + " in " + sourceName);
}
}
return newNode;
@@ -290,7 +304,7 @@ public interface Actions {//extends Comp
}
public Attr run(Document targetDoc, Element source, Element current,
- Collection<String> consumedAttrs, Collection<String> consumedElements) {
+ Collection<String> consumedAttrs, Collection<String> consumedElements, Logger logger) {
if (source.hasAttribute(sourceName)) {
consumedAttrs.add(sourceName);
Attr newAttr = targetDoc.createAttribute(targetName);
@@ -314,7 +328,7 @@ public interface Actions {//extends Comp
}
public Element run(Document targetDoc, Element source, Element current,
- Collection<String> consumedAttrs, Collection<String> consumedElements) {
+ Collection<String> consumedAttrs, Collection<String> consumedElements, Logger logger) {
Element dummy = targetDoc.createElement(dummyName);
return dummy;
}
@@ -355,7 +369,7 @@ public interface Actions {//extends Comp
}
public Element run(Document targetDoc, Element source, Element current,
- Collection<String> consumedAttrs, Collection<String> consumedElements) {
+ Collection<String> consumedAttrs, Collection<String> consumedElements, Logger logger) {
if (!source.hasAttribute(sourceName))
return null;
consumedAttrs.add(sourceName);
@@ -381,25 +395,33 @@ public interface Actions {//extends Comp
public static class IgnoreAttr extends Abstract {
+ boolean silent = false;
public IgnoreAttr(Element e) {
super(Code.IGNORE_ATTR, e);
+ silent = "false".equalsIgnoreCase(e.getAttribute("warn"));
}
public Node run(Document targetDoc, Element source, Element current,
- Collection<String> consumedAttrs, Collection<String> consumedElements) {
- consumedAttrs.add(original.getAttribute("name"));
+ Collection<String> consumedAttrs, Collection<String> consumedElements, Logger logger) {
+ String attr = original.getAttribute("name");
+ if (!silent) logger.warning("ignored " + source.getNodeName() + "." + attr);
+ consumedAttrs.add(attr);
return null;
}
}
public static class IgnoreNode extends Abstract {
+ boolean silent = false;
public IgnoreNode(Element e) {
super(Code.IGNORE_NODE, e);
+ silent = "false".equalsIgnoreCase(e.getAttribute("warn"));
}
public Node run(Document targetDoc, Element source, Element current,
- Collection<String> consumedAttrs, Collection<String> consumedElements) {
- consumedElements.add(original.getAttribute("name"));
+ Collection<String> consumedAttrs, Collection<String> consumedElements, Logger logger) {
+ String node = original.getAttribute("name");
+ if (!silent) logger.warning("ignored " + source.getNodeName() + "/" + node);
+ consumedElements.add(node);
return null;
}
}
@@ -423,7 +445,7 @@ public interface Actions {//extends Comp
}
public Node run(Document targetDoc, Element source, Element current,
- Collection<String> consumedAttrs, Collection<String> consumedElements) {
+ Collection<String> consumedAttrs, Collection<String> consumedElements, Logger logger) {
Element forParent = targetDoc.createElement(targetName);
Element sourceChild = getElementByName(source, sourceName, false);
if (sourceChild == null)
@@ -447,7 +469,7 @@ public interface Actions {//extends Comp
}
public Node run(Document targetDoc, Element source, Element current,
- Collection<String> consumedAttrs, Collection<String> consumedElements) {
+ Collection<String> consumedAttrs, Collection<String> consumedElements, Logger logger) {
consumedAttrs.add("embed-xml");
consumedAttrs.add("mutable");
consumedAttrs.add("outer-join");