Author: DartPeng
Date: 2008-09-02 05:42:09 -0400 (Tue, 02 Sep 2008)
New Revision: 10021
Modified:
workspace/dart/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/editors/SmooksGraphicalFormPage.java
workspace/dart/plugins/trunk/org.jboss.tools.smooks.javabean/src/org/jboss/tools/smooks/javabean/analyzer/JavaBeanAnalyzer.java
workspace/dart/plugins/trunk/org.jboss.tools.smooks.model/src/org/milyn/xsd/smooks/util/SmooksModelUtils.java
Log:
add some code for parse input target object model via smooks file
Modified:
workspace/dart/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/editors/SmooksGraphicalFormPage.java
===================================================================
---
workspace/dart/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/editors/SmooksGraphicalFormPage.java 2008-09-02
09:11:03 UTC (rev 10020)
+++
workspace/dart/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/editors/SmooksGraphicalFormPage.java 2008-09-02
09:42:09 UTC (rev 10021)
@@ -303,9 +303,9 @@
section1.setLayoutData(sgd1);
toolkit.paintBordersFor(rootMainControl);
-
+
form.pack();
-
+
this.hookGraphicalViewer();
this.initGraphicalViewer();
if (initSourceTreeViewerProviders()) {
@@ -623,12 +623,19 @@
resource.load(Collections.EMPTY_MAP);
IAnalyzer sourceModelAnalyzer = AnalyzerFactory.getInstance()
.getSmooksModelAnalyzer(sourceDataTypeID);
-
+ IAnalyzer targetModelAnalyzer = AnalyzerFactory.getInstance()
+ .getSmooksModelAnalyzer(targetDataTypeID);
SmooksResourceListType listType = ((DocumentRoot) resource
.getContents().get(0)).getSmooksResourceList();
+
sourceTreeViewerInputModel = sourceModelAnalyzer
.buildSourceInputObjects(graph, listType,
((IFileEditorInput) input).getFile());
+
+ targetTreeViewerInputModel = targetModelAnalyzer
+ .buildTargetInputObjects(graph, listType,
+ ((IFileEditorInput) input).getFile());
+
} catch (IOException e) {
e.printStackTrace();
} catch (CoreException e) {
Modified:
workspace/dart/plugins/trunk/org.jboss.tools.smooks.javabean/src/org/jboss/tools/smooks/javabean/analyzer/JavaBeanAnalyzer.java
===================================================================
---
workspace/dart/plugins/trunk/org.jboss.tools.smooks.javabean/src/org/jboss/tools/smooks/javabean/analyzer/JavaBeanAnalyzer.java 2008-09-02
09:11:03 UTC (rev 10020)
+++
workspace/dart/plugins/trunk/org.jboss.tools.smooks.javabean/src/org/jboss/tools/smooks/javabean/analyzer/JavaBeanAnalyzer.java 2008-09-02
09:42:09 UTC (rev 10021)
@@ -22,6 +22,7 @@
import org.eclipse.emf.common.command.BasicCommandStack;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.command.CommandStack;
+import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.util.ExtendedMetaData;
import org.eclipse.emf.ecore.xml.type.AnyType;
@@ -408,31 +409,150 @@
null);
}
+ public Object buildTargetInputObjects(GraphInformations graphInfo,
+ SmooksResourceListType listType, IFile sourceFile)
+ throws InvocationTargetException {
+ return this.buildTargetInputObjects(graphInfo, listType, sourceFile,
+ null);
+ }
+
+ public Object buildTargetInputObjects(GraphInformations graphInfo,
+ SmooksResourceListType listType, IFile sourceFile,
+ ClassLoader loader) throws InvocationTargetException {
+ if (loader == null) {
+ try {
+ loader = new ProjectClassLoader(JavaCore.create(sourceFile
+ .getProject()));
+ } catch (JavaModelException e) {
+ // ignore
+ }
+ }
+ List resourceConfigList = listType.getAbstractResourceConfig();
+ String rootClassName = null;
+ ResourceConfigType current = null;
+ for (Iterator iterator = resourceConfigList.iterator(); iterator
+ .hasNext();) {
+ AbstractResourceConfig ar = (AbstractResourceConfig) iterator
+ .next();
+ if (ar instanceof ResourceConfigType) {
+ ResourceConfigType rc = (ResourceConfigType) ar;
+ ResourceType resourceType = rc.getResource();
+ String resource = resourceType.getValue();
+ if (BEANPOPULATOR.equals(resource)) {
+ // create root beanmodel
+ current = rc;
+ break;
+ }
+ }
+ }
+ Class rootClass = null;
+ rootClassName = SmooksModelUtils.getParmaText("beanClass", current);
+ if (rootClassName != null && loader != null) {
+ try {
+ rootClass = loader.loadClass(rootClassName);
+ } catch (ClassNotFoundException e) {
+ // ignore
+ }
+ }
+ boolean rootIsError = false;
+ JavaBeanModel rootModel = null;
+ if (rootClass != null) {
+ rootModel = JavaBeanModelFactory
+ .getJavaBeanModelWithLazyLoad(rootClass);
+ rootIsError = true;
+ } else {
+ rootModel = new JavaBeanModel(null, rootClassName);
+ }
+ setSelectorIsUsed(rootClassName);
+ buildChildrenOfTargetInputModel(listType, rootModel, false,
+ rootIsError, current, loader);
+ return rootModel;
+ }
+
+ protected void buildChildrenOfTargetInputModel(
+ SmooksResourceListType listType, JavaBeanModel beanModel,
+ boolean rootIsWarning, boolean rootIsError,
+ ResourceConfigType currentResourceConfigType,
+ ClassLoader classLoader) {
+ if (currentResourceConfigType != null) {
+ List bindingList = getBindingListFromResourceConfigType(currentResourceConfigType);
+ for (Iterator iterator = bindingList.iterator(); iterator.hasNext();) {
+ AnyType binding = (AnyType) iterator.next();
+ String property = SmooksModelUtils
+ .getAttributeValueFromAnyType(binding,
+ SmooksModelUtils.ATTRIBUTE_PROPERTY);
+ String selector = SmooksModelUtils
+ .getAttributeValueFromAnyType(binding,
+ SmooksModelUtils.ATTRIBUTE_SELECTOR);
+ // if(property == null){
+ // continue;
+ // }
+ processBindingPropertyFromTargetModel(listType, property,
+ selector, beanModel,classLoader);
+ }
+ }
+
+ }
+
+ protected void processBindingPropertyFromTargetModel(
+ SmooksResourceListType listType, String property, String selector,
+ JavaBeanModel parentModel,ClassLoader classLoader) {
+ parentModel.getProperties();
+ JavaBeanModel model = this.findTheChildJavaBeanModel(property, parentModel);
+ if(model == null){
+ model = new JavaBeanModel(null,property);
+ parentModel.addProperty(model);
+ model.setError("don't exist");
+ }
+
+ if(selector.startsWith("${") && selector.endsWith("}")){
+ selector = selector.substring(2, selector.length() - 1);
+ List rList = listType.getAbstractResourceConfig();
+ for (Iterator iterator = rList.iterator(); iterator.hasNext();) {
+ ResourceConfigType configType = (ResourceConfigType) iterator.next();
+ if(isSelectorIsUsed(configType.getSelector())){
+ continue;
+ }
+ String beanId = this.getBeanIDFromParam(configType);
+ if(selector.equals(beanId)){
+ this.buildChildrenOfTargetInputModel(listType, model, false, false, configType,
classLoader);
+ }
+ }
+ }
+ }
+
+ protected List getBindingListFromResourceConfigType(
+ ResourceConfigType resourceConfig) {
+ List paramList = resourceConfig.getParam();
+ for (Iterator iterator = paramList.iterator(); iterator.hasNext();) {
+ ParamType param = (ParamType) iterator.next();
+ if ("bindings".equals(param.getName())) {
+ if (param.eContents().isEmpty())
+ continue;
+ List bindingList = (List) param.getMixed().get(
+ SmooksModelUtils.ELEMENT_BINDING, false);
+ return bindingList;
+ }
+ }
+ return null;
+ }
+
protected void buildSourceInputProperties(SmooksResourceListType listType,
JavaBeanModel beanModel, boolean rootIsWarning,
boolean rootIsError, ResourceConfigType currentResourceConfigType,
ClassLoader classLoader) {
if (currentResourceConfigType != null) {
- List paramList = currentResourceConfigType.getParam();
- for (Iterator iterator = paramList.iterator(); iterator.hasNext();) {
- ParamType param = (ParamType) iterator.next();
- if ("bindings".equals(param.getName())) {
- if (param.eContents().isEmpty())
- continue;
- List bindingList = (List) param.getMixed().get(
- SmooksModelUtils.ELEMENT_BINDING, false);
- for (Iterator iterator2 = bindingList.iterator(); iterator2
- .hasNext();) {
- AnyType binding = (AnyType) iterator2.next();
- String selector = (String) binding
- .getAnyAttribute()
- .get(SmooksModelUtils.ATTRIBUTE_SELECTOR, false);
- setSelectorIsUsed(currentResourceConfigType
- .getSelector());
- analyzeBindingSelector(selector, beanModel, listType,
- classLoader);
- }
- }
+ List bindingList = this
+ .getBindingListFromResourceConfigType(currentResourceConfigType);
+ for (Iterator iterator2 = bindingList.iterator(); iterator2
+ .hasNext();) {
+ AnyType binding = (AnyType) iterator2.next();
+ String selector = SmooksModelUtils
+ .getAttributeValueFromAnyType(binding,
+ SmooksModelUtils.ATTRIBUTE_SELECTOR);
+ setSelectorIsUsed(currentResourceConfigType.getSelector());
+ analyzeBindingSelector(selector, beanModel, listType,
+ classLoader);
}
}
}
@@ -519,11 +639,7 @@
for (Iterator iterator = list.iterator(); iterator.hasNext();) {
ParamType p = (ParamType) iterator.next();
if ("beanId".equals(p.getName())) {
- Object obj = p.getMixed().get(
- XMLTypePackage.Literals.XML_TYPE_DOCUMENT_ROOT__TEXT,
- true);
- if (obj != null && obj instanceof List)
- return ((List) obj).get(0).toString().trim();
+ return SmooksModelUtils.getAnyTypeText(p);
}
}
Modified:
workspace/dart/plugins/trunk/org.jboss.tools.smooks.model/src/org/milyn/xsd/smooks/util/SmooksModelUtils.java
===================================================================
---
workspace/dart/plugins/trunk/org.jboss.tools.smooks.model/src/org/milyn/xsd/smooks/util/SmooksModelUtils.java 2008-09-02
09:11:03 UTC (rev 10020)
+++
workspace/dart/plugins/trunk/org.jboss.tools.smooks.model/src/org/milyn/xsd/smooks/util/SmooksModelUtils.java 2008-09-02
09:42:09 UTC (rev 10021)
@@ -10,12 +10,16 @@
******************************************************************************/
package org.milyn.xsd.smooks.util;
+import java.util.Iterator;
+import java.util.List;
+
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.util.ExtendedMetaData;
import org.eclipse.emf.ecore.xml.type.AnyType;
import org.eclipse.emf.ecore.xml.type.XMLTypePackage;
import org.milyn.xsd.smooks.ParamType;
+import org.milyn.xsd.smooks.ResourceConfigType;
import org.milyn.xsd.smooks.SmooksPackage;
/**
@@ -35,7 +39,8 @@
.demandFeature(null, "type", false);
public static EStructuralFeature ELEMENT_BINDING = ExtendedMetaData.INSTANCE
- .demandFeature("http://www.milyn.org/xsd/smooks-1.0.xsd",
"binding", true);
+ .demandFeature("http://www.milyn.org/xsd/smooks-1.0.xsd",
+ "binding", true);
public static void addBindingTypeToParamType(ParamType param,
String property, String selector, String type, String uri) {
@@ -43,6 +48,36 @@
param.getMixed().add(ELEMENT_BINDING, binding);
}
+ public static String getParmaText(String paramName,
+ ResourceConfigType resourceConfigType) {
+ List plist = resourceConfigType.getParam();
+ for (Iterator iterator = plist.iterator(); iterator.hasNext();) {
+ ParamType p = (ParamType) iterator.next();
+ if (paramName.equals(p.getName())) {
+ return getAnyTypeText(p);
+ }
+ }
+ return null;
+ }
+
+ public static String getAttributeValueFromAnyType(AnyType anyType,EStructuralFeature
attribute) {
+ String value = (String) anyType.getAnyAttribute().get(attribute, false);
+ return value;
+ }
+
+ public static String getAnyTypeText(AnyType anyType){
+ Object value = anyType.getMixed().get(
+ XMLTypePackage.Literals.XML_TYPE_DOCUMENT_ROOT__TEXT,
+ true);
+ if (value != null) {
+ if (value instanceof List) {
+ return ((List) value).get(0).toString().trim();
+ }
+ return value.toString();
+ }
+ return null;
+ }
+
public static AnyType createBindingType(String property, String selector,
String type, String uri) {
if (uri == null) {