Author: DartPeng
Date: 2008-09-24 02:54:26 -0400 (Wed, 24 Sep 2008)
New Revision: 10441
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.javabean/src/org/jboss/tools/smooks/javabean/analyzer/JavaBeanAnalyzer.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/analyzer/AbstractAnalyzer.java
trunk/smooks/plugins/org.jboss.tools.smooks.xml/src/org/jboss/tools/smooks/xml/ui/XMLStructuredDataContentProvider.java
trunk/smooks/plugins/org.jboss.tools.smooks.xml2java/src/org/jboss/tools/smooks/xml2java/analyzer/XML2JavaAnalyzer.java
Log:
finish the XML2JavaAnalyzer!!!
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.javabean/src/org/jboss/tools/smooks/javabean/analyzer/JavaBeanAnalyzer.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.javabean/src/org/jboss/tools/smooks/javabean/analyzer/JavaBeanAnalyzer.java 2008-09-23
23:39:16 UTC (rev 10440)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.javabean/src/org/jboss/tools/smooks/javabean/analyzer/JavaBeanAnalyzer.java 2008-09-24
06:54:26 UTC (rev 10441)
@@ -438,7 +438,7 @@
continue;
if (isReferenceSelector(selector)) {
ResourceConfigType rc = this
- .findResourceCinfigTypeWithSelector(selector,
+ .findResourceConfigTypeWithSelector(selector,
resourceList);
if (rc != null) {
String newSelector = rc.getSelector();
@@ -663,9 +663,9 @@
model.setError("don't exist");
}
- if (selector.startsWith("${") && selector.endsWith("}")) {
+ if (isReferenceSelector(selector)) {
selector = selector.substring(2, selector.length() - 1);
- ResourceConfigType resourceConfig = findResourceCinfigTypeWithSelector(
+ ResourceConfigType resourceConfig = findResourceConfigTypeWithSelector(
selector, listType);
if (resourceConfig != null) {
this.buildChildrenOfTargetInputModel(listType, model, false,
@@ -712,7 +712,7 @@
}
}
- protected ResourceConfigType findResourceCinfigTypeWithSelector(
+ protected ResourceConfigType findResourceConfigTypeWithSelector(
String selector, SmooksResourceListType listType) {
if (isReferenceSelector(selector)) {
selector = this.getBeanIdWithRawSelectorString(selector);
@@ -740,7 +740,7 @@
// memory out???
currentModel.getProperties();
selector = this.getBeanIdWithRawSelectorString(selector);
- ResourceConfigType resourceConfig = findResourceCinfigTypeWithSelector(
+ ResourceConfigType resourceConfig = findResourceConfigTypeWithSelector(
selector, listType);
if (resourceConfig != null) {
String referenceSelector = resourceConfig.getSelector();
@@ -825,7 +825,7 @@
* @param parentModel
* @return
*/
- protected JavaBeanModel findTheChildJavaBeanModel(String name,
+ public static JavaBeanModel findTheChildJavaBeanModel(String name,
JavaBeanModel parentModel) {
List list = parentModel.getProperties();
if (list == null)
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/analyzer/AbstractAnalyzer.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/analyzer/AbstractAnalyzer.java 2008-09-23
23:39:16 UTC (rev 10440)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/analyzer/AbstractAnalyzer.java 2008-09-24
06:54:26 UTC (rev 10441)
@@ -12,6 +12,7 @@
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
import org.eclipse.emf.common.command.BasicCommandStack;
@@ -38,8 +39,9 @@
protected List usedConnectionList = new ArrayList();
protected AdapterFactoryEditingDomain editingDomain;
protected ComposedAdapterFactory adapterFactory;
-
+ private HashMap<String, Object> userdResourceTypeMap;
public AbstractAnalyzer() {
+ userdResourceTypeMap = new HashMap<String, Object>();
adapterFactory = new ComposedAdapterFactory(
ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
@@ -68,6 +70,16 @@
usedConnectionList.clear();
}
+
+ protected void setSelectorIsUsed(String selector) {
+ userdResourceTypeMap.put(selector, new Object());
+ }
+
+
+ protected boolean isSelectorIsUsed(String resourceType) {
+ return (userdResourceTypeMap.get(resourceType) != null);
+ }
+
protected void addResourceConfigType(SmooksResourceListType resourceList,
ResourceConfigType resourceConfig) {
Command addResourceConfigCommand = AddCommand.create(
@@ -88,7 +100,50 @@
resourceConfigType.getParam().add(paramType);
return paramType;
}
+
+
+ protected String getBeanIDFromParam(ResourceConfigType config) {
+ List list = config.getParam();
+ for (Iterator iterator = list.iterator(); iterator.hasNext();) {
+ ParamType p = (ParamType) iterator.next();
+ if ("beanId".equals(p.getName())) {
+ return SmooksModelUtils.getAnyTypeText(p);
+ }
+ }
+ return null;
+ }
+
+ protected String getBeanIdWithRawSelectorString(String selector) {
+ selector = selector.substring(2, selector.length() - 1);
+ return selector;
+ }
+
+ protected boolean isReferenceSelector(String selector) {
+ return (selector.startsWith("${") &&
selector.endsWith("}"));
+ }
+
+
+ protected ResourceConfigType findResourceConfigTypeWithSelector(
+ String selector, SmooksResourceListType listType) {
+ if (isReferenceSelector(selector)) {
+ selector = this.getBeanIdWithRawSelectorString(selector);
+ }
+ List rl = listType.getAbstractResourceConfig();
+ ResourceConfigType resourceConfig = null;
+ for (Iterator iterator = rl.iterator(); iterator.hasNext();) {
+ ResourceConfigType rct = (ResourceConfigType) iterator.next();
+ if (this.isSelectorIsUsed(rct.getSelector()))
+ continue;
+ String beanId = getBeanIDFromParam(rct);
+ if (selector.equals(beanId)) {
+ resourceConfig = rct;
+ break;
+ }
+ }
+ return resourceConfig;
+ }
+
/**
* @return the editingDomain
*/
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.xml/src/org/jboss/tools/smooks/xml/ui/XMLStructuredDataContentProvider.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.xml/src/org/jboss/tools/smooks/xml/ui/XMLStructuredDataContentProvider.java 2008-09-23
23:39:16 UTC (rev 10440)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.xml/src/org/jboss/tools/smooks/xml/ui/XMLStructuredDataContentProvider.java 2008-09-24
06:54:26 UTC (rev 10441)
@@ -15,6 +15,7 @@
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
+import org.jboss.tools.smooks.xml.model.AbstractXMLObject;
import org.jboss.tools.smooks.xml.model.DocumentObject;
import org.jboss.tools.smooks.xml.model.TagObject;
@@ -50,7 +51,9 @@
* @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object )
*/
public Object getParent(Object arg0) {
- // if(arg0 instanceof)
+ if(arg0 instanceof AbstractXMLObject){
+ return ((AbstractXMLObject)arg0).getParent();
+ }
return null;
}
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.xml2java/src/org/jboss/tools/smooks/xml2java/analyzer/XML2JavaAnalyzer.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.xml2java/src/org/jboss/tools/smooks/xml2java/analyzer/XML2JavaAnalyzer.java 2008-09-23
23:39:16 UTC (rev 10440)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.xml2java/src/org/jboss/tools/smooks/xml2java/analyzer/XML2JavaAnalyzer.java 2008-09-24
06:54:26 UTC (rev 10441)
@@ -10,6 +10,7 @@
******************************************************************************/
package org.jboss.tools.smooks.xml2java.analyzer;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -20,6 +21,7 @@
import org.jboss.tools.smooks.analyzer.MappingModel;
import org.jboss.tools.smooks.analyzer.MappingResourceConfigList;
import org.jboss.tools.smooks.analyzer.SmooksAnalyzerException;
+import org.jboss.tools.smooks.javabean.analyzer.JavaBeanAnalyzer;
import org.jboss.tools.smooks.javabean.model.JavaBeanModel;
import org.jboss.tools.smooks.model.ParamType;
import org.jboss.tools.smooks.model.ResourceConfigType;
@@ -208,25 +210,22 @@
|| !(targetObject instanceof JavaBeanModel)) {
return MappingResourceConfigList.createEmptyList();
}
-
AbstractXMLObject sourceRoot = (AbstractXMLObject) sourceObject;
JavaBeanModel sourceTarget = (JavaBeanModel) targetObject;
ResourceConfigType rootResourceConfig = findFirstMappingResourceConfig(listType);
- String selector = rootResourceConfig.getSelector();
- AbstractXMLObject source = findXMLObjectBySelector(selector, sourceRoot);
+ String xmlName = rootResourceConfig.getSelector();
+ AbstractXMLObject source = findXMLObjectByName(xmlName, sourceRoot);
if (source == null)
return MappingResourceConfigList.createEmptyList();
MappingResourceConfigList rcl = new MappingResourceConfigList();
- MappingModel mapping = new MappingModel(source, sourceTarget);
- rcl.getMappingModelList().add(mapping);
- rcl.addResourceConfig(rootResourceConfig);
-
- return null;
+ this.createMappingResourceConfigList(rcl, listType, rootResourceConfig,
+ source, sourceTarget);
+ return rcl;
}
- private AbstractXMLObject findXMLObjectBySelector(String selector,
+ public static AbstractXMLObject findXMLObjectByName(String selector,
AbstractXMLObject root) {
if (selector == null)
return null;
@@ -244,7 +243,7 @@
for (Iterator iterator = tags.iterator(); iterator.hasNext();) {
AbstractXMLObject tagChild = (AbstractXMLObject) iterator
.next();
- AbstractXMLObject result = findXMLObjectBySelector(selector,
+ AbstractXMLObject result = findXMLObjectByName(selector,
tagChild);
if (result != null)
return result;
@@ -257,12 +256,18 @@
protected void createMappingResourceConfigList(
MappingResourceConfigList configList, SmooksResourceListType list,
ResourceConfigType config, AbstractXMLObject sourceRoot,
- JavaBeanModel targetRoot) {
+ JavaBeanModel targetJavaBean) {
String selector = config.getSelector();
String beanID = SmooksModelUtils.getParmaText(
SmooksModelConstants.BEAN_ID, config);
String beanClass = SmooksModelUtils.getParmaText(
SmooksModelConstants.BEAN_CLASS, config);
+
+ MappingModel mapping = new MappingModel(sourceRoot, targetJavaBean);
+ configList.getMappingModelList().add(mapping);
+ configList.addResourceConfig(config);
+ this.setSelectorIsUsed(config.getSelector());
+
List<ParamType> paramList = config.getParam();
ParamType bindingParam = null;
for (Iterator iterator = paramList.iterator(); iterator.hasNext();) {
@@ -280,20 +285,91 @@
if (bindings != null) {
for (Iterator iterator = bindings.iterator(); iterator
.hasNext();) {
+ AnyType binding = (AnyType) iterator.next();
String property = SmooksModelUtils
- .getAttributeValueFromAnyType((AnyType) iterator
- .next(),
+ .getAttributeValueFromAnyType(binding,
SmooksModelUtils.ATTRIBUTE_PROPERTY);
String selectorStr = SmooksModelUtils
- .getAttributeValueFromAnyType((AnyType) iterator
- .next(),
+ .getAttributeValueFromAnyType(binding,
SmooksModelUtils.ATTRIBUTE_SELECTOR);
+ JavaBeanModel childBean = JavaBeanAnalyzer
+ .findTheChildJavaBeanModel(property, targetJavaBean);
+ processXMLSelector(configList, config, sourceRoot,
+ childBean, list, selectorStr);
}
}
}
- AbstractXMLObject source = findXMLObjectBySelector(selector, sourceRoot);
}
+ protected void processXMLSelector(MappingResourceConfigList configList,
+ ResourceConfigType resourceConfig, AbstractXMLObject root,
+ JavaBeanModel targetBean, SmooksResourceListType listType,
+ String selector) {
+ if (isReferenceSelector(selector)) {
+ ResourceConfigType resourceConfig1 = this
+ .findResourceConfigTypeWithSelector(selector, listType);
+ String newSelector = resourceConfig1.getSelector();
+ if (newSelector == null)
+ return;
+ AbstractXMLObject newRoot = findXMLObjectByName(newSelector, root);
+ createMappingResourceConfigList(configList, listType,
+ resourceConfig1, newRoot, targetBean);
+ } else {
+ AbstractXMLObject source = findXMLObjectWithSelectorString(
+ selector, root);
+ if (source != null) {
+ MappingModel mapping = new MappingModel(source, targetBean);
+ configList.getMappingModelList().add(mapping);
+ configList.addResourceConfig(resourceConfig);
+ this.setSelectorIsUsed(selector);
+ }
+ }
+ }
+
+ public static AbstractXMLObject findXMLObjectWithSelectorString(
+ String selector, AbstractXMLObject parent) {
+ if (selector == null)
+ return null;
+ selector = selector.trim();
+ String[] names = selector.split(" ");
+ if (names == null)
+ return null;
+ AbstractXMLObject current = parent;
+ for (int i = 0; i < names.length; i++) {
+ String name = names[i].trim();
+ if (current instanceof TagObject && isXMLAttributeObject(name)) {
+ List properties = ((TagObject) current).getProperties();
+ for (Iterator iterator = properties.iterator(); iterator
+ .hasNext();) {
+ TagPropertyObject property = (TagPropertyObject) iterator
+ .next();
+ if (name.equals(property.getName())) {
+ current = property;
+ }
+ }
+ } else {
+ List list = parent.getChildren();
+ for (Iterator iterator = list.iterator(); iterator.hasNext();) {
+ AbstractXMLObject child = (AbstractXMLObject) iterator
+ .next();
+ if (name.equals(child.getName())) {
+ current = child;
+ break;
+ }
+ }
+ }
+ }
+ if (current == parent)
+ return null;
+ return current;
+ }
+
+ public static boolean isXMLAttributeObject(String name) {
+ if (name != null && name.startsWith("@"))
+ return true;
+ return false;
+ }
+
private ResourceConfigType findFirstMappingResourceConfig(
SmooksResourceListType listType) {
List list = listType.getAbstractResourceConfig();