Author: DartPeng
Date: 2008-09-01 06:07:50 -0400 (Mon, 01 Sep 2008)
New Revision: 9975
Added:
workspace/dart/plugins/trunk/org.jboss.tools.smooks.javabean/src_test/Header.java
workspace/dart/plugins/trunk/org.jboss.tools.smooks.javabean/src_test/Order.java
workspace/dart/plugins/trunk/org.jboss.tools.smooks.javabean/src_test/test/
workspace/dart/plugins/trunk/org.jboss.tools.smooks.javabean/src_test/test/SmooksAnalyzerTester.java
workspace/dart/plugins/trunk/org.jboss.tools.smooks.javabean/src_test/test/Test.xml
Modified:
workspace/dart/plugins/trunk/org.jboss.tools.smooks.javabean/META-INF/MANIFEST.MF
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/model/JavaBeanModel.java
Log:
add some code for testing the JavaBeanAnalyzer
Modified:
workspace/dart/plugins/trunk/org.jboss.tools.smooks.javabean/META-INF/MANIFEST.MF
===================================================================
---
workspace/dart/plugins/trunk/org.jboss.tools.smooks.javabean/META-INF/MANIFEST.MF 2008-09-01
09:55:07 UTC (rev 9974)
+++
workspace/dart/plugins/trunk/org.jboss.tools.smooks.javabean/META-INF/MANIFEST.MF 2008-09-01
10:07:50 UTC (rev 9975)
@@ -17,7 +17,8 @@
org.jboss.tools.smooks.model,
org.jboss.tools.smooks.model.edit,
org.eclipse.ui.ide,
- org.jboss.tools.smooks.graphicalInfo
+ org.jboss.tools.smooks.graphicalInfo,
+ org.junit
Eclipse-LazyStart: true
Bundle-ClassPath: libs/commons-beanutils-1.8.0-BETA.jar,
libs/commons-beanutils-1.8.0-BETA-javadoc.jar,
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-01
09:55:07 UTC (rev 9974)
+++
workspace/dart/plugins/trunk/org.jboss.tools.smooks.javabean/src/org/jboss/tools/smooks/javabean/analyzer/JavaBeanAnalyzer.java 2008-09-01
10:07:50 UTC (rev 9975)
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Red Hat, Inc.
+ * Copyright (c) 2008 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
@@ -343,8 +343,8 @@
}
public Object buildSourceInputObjects(GraphInformations graphInfo,
- SmooksResourceListType listType, IFile sourceFile)
- throws InvocationTargetException {
+ SmooksResourceListType listType, IFile sourceFile,
+ ClassLoader classLoader) throws InvocationTargetException {
List resourceConfigList = listType.getAbstractResourceConfig();
String rootClassName = null;
ResourceConfigType current = null;
@@ -367,14 +367,17 @@
if (rootClassName == null)
return null;
- IProject project = sourceFile.getProject();
+
boolean isWarning = false;
boolean isError = false;
Class clazz = null;
try {
- ProjectClassLoader loader = new ProjectClassLoader(JavaCore
- .create(project));
- clazz = loader.loadClass(rootClassName);
+ if (classLoader == null) {
+ IProject project = sourceFile.getProject();
+ classLoader = new ProjectClassLoader(JavaCore.create(project));
+ }
+
+ clazz = classLoader.loadClass(rootClassName);
} catch (Exception e) {
// ignore
}
@@ -394,6 +397,13 @@
return null;
}
+ public Object buildSourceInputObjects(GraphInformations graphInfo,
+ SmooksResourceListType listType, IFile sourceFile)
+ throws InvocationTargetException {
+ return this.buildSourceInputObjects(graphInfo, listType, sourceFile,
+ null);
+ }
+
protected void buildSourceInputProperties(SmooksResourceListType listType,
JavaBeanModel beanModel, boolean rootIsWarning,
boolean rootIsError, ResourceConfigType currentResourceConfigType) {
@@ -412,6 +422,9 @@
String selector = (String) binding
.getAnyAttribute()
.get(SmooksModelUtils.ATTRIBUTE_SELECTOR, false);
+ setSelectorIsUsed(currentResourceConfigType
+ .getSelector());
+ analyzeBindingSelector(selector, beanModel, listType);
}
}
}
@@ -426,26 +439,31 @@
currentModel.setProperties(null);
currentModel.getProperties();
selector = selector.substring(2, selector.length() - 1);
- JavaBeanModel model = findTheChildJavaBeanModel(selector,
- currentModel);
- // something wrong
- if (model == null) {
- JavaBeanModel errorModel = new JavaBeanModel(null, selector);
- currentModel.addProperty(errorModel);
- errorModel.setError("don't exist");
- List rl = listType.getAbstractResourceConfig();
- 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)) {
- buildSourceInputProperties(listType, errorModel, false,
- true, rct);
- }
+ 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);
+ System.out.println(beanId);
+ if (selector.equals(beanId)) {
+ resourceConfig = rct;
+ break;
}
}
+ if (resourceConfig != null) {
+ JavaBeanModel model = findTheChildJavaBeanModelFromBeanId(
+ resourceConfig.getSelector(), currentModel);
+ // something wrong
+ if (model == null) {
+ model = new JavaBeanModel(null, selector);
+ currentModel.addProperty(model);
+ model.setError("don't exist");
+ }
+ buildSourceInputProperties(listType, model, false, true,
+ resourceConfig);
+ }
}
}
@@ -457,17 +475,26 @@
Object obj = p.getMixed().get(
XMLTypePackage.Literals.XML_TYPE_DOCUMENT_ROOT__TEXT,
true);
- if (obj != null)
- return obj.toString().trim();
+ if (obj != null && obj instanceof List)
+ return ((List) obj).get(0).toString().trim();
}
}
return null;
}
- protected JavaBeanModel findTheChildJavaBeanModel(String name,
+ protected JavaBeanModel findTheChildJavaBeanModelFromBeanId(String name,
JavaBeanModel parentModel) {
List list = parentModel.getProperties();
+ if (parentModel.isList() || parentModel.isMany()) {
+ if (list.size() >= 1) {
+ JavaBeanModel m = (JavaBeanModel) list.get(0);
+ if (m.getBeanClass().getName().equals(name)) {
+ return m;
+ }
+ }
+ }
+
for (Iterator iterator = list.iterator(); iterator.hasNext();) {
JavaBeanModel child = (JavaBeanModel) iterator.next();
if (name.equals(child.getName())) {
Modified:
workspace/dart/plugins/trunk/org.jboss.tools.smooks.javabean/src/org/jboss/tools/smooks/javabean/model/JavaBeanModel.java
===================================================================
---
workspace/dart/plugins/trunk/org.jboss.tools.smooks.javabean/src/org/jboss/tools/smooks/javabean/model/JavaBeanModel.java 2008-09-01
09:55:07 UTC (rev 9974)
+++
workspace/dart/plugins/trunk/org.jboss.tools.smooks.javabean/src/org/jboss/tools/smooks/javabean/model/JavaBeanModel.java 2008-09-01
10:07:50 UTC (rev 9975)
@@ -105,6 +105,21 @@
private boolean lazyLoadProperties = true;
public boolean isList() {
+ if (Collection.class.isAssignableFrom(beanClass)) {
+ if (this.propertyDescriptor != null) {
+ Method rmethod = propertyDescriptor.getReadMethod();
+ if (rmethod != null) {
+ Type returnType = rmethod.getGenericReturnType();
+ if (returnType instanceof ParameterizedType) {
+ Type gtype = ((ParameterizedType) returnType)
+ .getActualTypeArguments()[0];
+ Class beanType = (Class) gtype;
+ componentClass = beanType;
+ }
+ }
+ }
+ setList(true);
+ }
return isList;
}
@@ -201,6 +216,11 @@
}
public boolean isMany() {
+ if (beanClass.isArray()) {
+ Class beanType = beanClass.getComponentType();
+ setMany(true);
+ componentClass = beanType;
+ }
return many;
}
Added: workspace/dart/plugins/trunk/org.jboss.tools.smooks.javabean/src_test/Header.java
===================================================================
--- workspace/dart/plugins/trunk/org.jboss.tools.smooks.javabean/src_test/Header.java
(rev 0)
+++
workspace/dart/plugins/trunk/org.jboss.tools.smooks.javabean/src_test/Header.java 2008-09-01
10:07:50 UTC (rev 9975)
@@ -0,0 +1,17 @@
+
+ public class Header {
+ private Integer age;
+ private String name;
+ public Integer getAge() {
+ return age;
+ }
+ public void setAge(Integer age) {
+ this.age = age;
+ }
+ public String getName() {
+ return name;
+ }
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Property changes on:
workspace/dart/plugins/trunk/org.jboss.tools.smooks.javabean/src_test/Header.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: workspace/dart/plugins/trunk/org.jboss.tools.smooks.javabean/src_test/Order.java
===================================================================
--- workspace/dart/plugins/trunk/org.jboss.tools.smooks.javabean/src_test/Order.java
(rev 0)
+++
workspace/dart/plugins/trunk/org.jboss.tools.smooks.javabean/src_test/Order.java 2008-09-01
10:07:50 UTC (rev 9975)
@@ -0,0 +1,26 @@
+
+public class Order {
+ private String name;
+ private int height;
+ private Header header;
+ public Header getHeader() {
+ return header;
+ }
+ public void setHeader(Header header) {
+ this.header = header;
+ }
+ public String getName() {
+ return name;
+ }
+ public void setName(String name) {
+ this.name = name;
+ }
+ public int getHeight() {
+ return height;
+ }
+ public void setHeight(int height) {
+ this.height = height;
+ }
+
+
+}
Property changes on:
workspace/dart/plugins/trunk/org.jboss.tools.smooks.javabean/src_test/Order.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
workspace/dart/plugins/trunk/org.jboss.tools.smooks.javabean/src_test/test/SmooksAnalyzerTester.java
===================================================================
---
workspace/dart/plugins/trunk/org.jboss.tools.smooks.javabean/src_test/test/SmooksAnalyzerTester.java
(rev 0)
+++
workspace/dart/plugins/trunk/org.jboss.tools.smooks.javabean/src_test/test/SmooksAnalyzerTester.java 2008-09-01
10:07:50 UTC (rev 9975)
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package test;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Collections;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EPackage.Registry;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.xmi.impl.XMLResourceFactoryImpl;
+import org.jboss.tools.smooks.graphical.GraphInformations;
+import org.jboss.tools.smooks.graphical.GraphicalPackage;
+import org.jboss.tools.smooks.javabean.analyzer.JavaBeanAnalyzer;
+import org.milyn.xsd.smooks.DocumentRoot;
+import org.milyn.xsd.smooks.SmooksPackage;
+import org.milyn.xsd.smooks.SmooksResourceListType;
+import org.milyn.xsd.smooks.util.SmooksResourceFactoryImpl;
+
+/**
+ * @author Dart Peng Date : 2008-9-1
+ */
+public class SmooksAnalyzerTester extends TestCase {
+ public void testParse() {
+ Registry.INSTANCE.put(GraphicalPackage.eNS_URI,
+ GraphicalPackage.eINSTANCE);
+ Registry.INSTANCE.put(SmooksPackage.eNS_URI, SmooksPackage.eINSTANCE);
+ try {
+ String path = "C:\\Users\\Dart\\Documents\\SmooksTest\\Test.smooks";
+ String path1 = "C:\\Users\\Dart\\Documents\\SmooksTest\\Test.smooks.graph";
+ Resource resource = new SmooksResourceFactoryImpl()
+ .createResource(URI.createFileURI(path));
+ Resource gr = new XMLResourceFactoryImpl()
+ .createResource(URI.createFileURI(path1));
+ gr.load(Collections.EMPTY_MAP);
+ GraphInformations graph = (GraphInformations) gr.getContents().get(0);;
+
+ resource.load(Collections.EMPTY_MAP);
+ JavaBeanAnalyzer sourceModelAnalyzer = new JavaBeanAnalyzer();
+
+ SmooksResourceListType listType = ((DocumentRoot) resource
+ .getContents().get(0)).getSmooksResourceList();
+ Object obj = sourceModelAnalyzer
+ .buildSourceInputObjects(graph, listType, null,
+ SmooksAnalyzerTester.class.getClassLoader());
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (InvocationTargetException e) {
+ e.printStackTrace();
+ }
+ }
+}
Property changes on:
workspace/dart/plugins/trunk/org.jboss.tools.smooks.javabean/src_test/test/SmooksAnalyzerTester.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
workspace/dart/plugins/trunk/org.jboss.tools.smooks.javabean/src_test/test/Test.xml
===================================================================
--- workspace/dart/plugins/trunk/org.jboss.tools.smooks.javabean/src_test/test/Test.xml
(rev 0)
+++
workspace/dart/plugins/trunk/org.jboss.tools.smooks.javabean/src_test/test/Test.xml 2008-09-01
10:07:50 UTC (rev 9975)
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="ASCII"?>
+<smooks-resource-list
xmlns="http://www.milyn.org/xsd/smooks-1.0.xsd">
+ <resource-config selector="srcmodel.Order">
+ <resource>org.milyn.javabean.BeanPopulator</resource>
+ <param name="beanId">LineOrder</param>
+ <param name="beanClass">targetmodel.LineOrder</param>
+ <param name="bindings">
+ <binding property="customerId"
+ selector="header customerNumber" />
+ <binding property="customerName"
+ selector="header customerName" />
+ <binding property="lineItems" selector="${lineItems}" />
+ </param>
+ </resource-config>
+ <resource-config selector="orderItems">
+ <resource>org.milyn.javabean.BeanPopulator</resource>
+ <param name="beanId">lineItems</param>
+ <param name="beanClass">targetmodel.LineItem[]</param>
+ <param name="bindings">
+ <binding property="LineItem" selector="${LineItem}" />
+ </param>
+ </resource-config>
+ <resource-config selector="srcmodel.OrderItem">
+ <resource>org.milyn.javabean.BeanPopulator</resource>
+ <param name="beanId">LineItem</param>
+ <param name="beanClass">targetmodel.LineItem</param>
+ <param name="bindings">
+ <binding property="productCode"
+ selector="srcmodel.OrderItem productId" />
+ <binding property="unitPrice"
+ selector="srcmodel.OrderItem price" />
+ <binding property="unitQuantity"
+ selector="srcmodel.OrderItem quantity" />
+ </param>
+ </resource-config>
+</smooks-resource-list>
\ No newline at end of file
Property changes on:
workspace/dart/plugins/trunk/org.jboss.tools.smooks.javabean/src_test/test/Test.xml
___________________________________________________________________
Name: svn:mime-type
+ text/plain