Author: DartPeng
Date: 2009-01-20 02:34:31 -0500 (Tue, 20 Jan 2009)
New Revision: 13136
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/ui/AbstractJavaBeanBuilder.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/ui/JavaBeanSourceBuilder.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/ui/JavaBeanTargetBuilder.java
Log:
JBIDE-3593
Merge the javabean model load form the .graph file with other javabean model parse from
.smooks file
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/ui/AbstractJavaBeanBuilder.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/ui/AbstractJavaBeanBuilder.java 2009-01-20
07:09:55 UTC (rev 13135)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/ui/AbstractJavaBeanBuilder.java 2009-01-20
07:34:31 UTC (rev 13136)
@@ -3,11 +3,24 @@
*/
package org.jboss.tools.smooks.javabean.ui;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.jboss.tools.smooks.graphical.GraphInformations;
+import org.jboss.tools.smooks.graphical.Param;
+import org.jboss.tools.smooks.graphical.Params;
+import org.jboss.tools.smooks.javabean.model.JavaBeanList;
+import org.jboss.tools.smooks.javabean.model.JavaBeanModel;
+import org.jboss.tools.smooks.javabean.model.JavaBeanModelFactory;
+
/**
* @author Dart
- *
+ *
*/
public class AbstractJavaBeanBuilder {
+ public static final int SOURCE_DATA = 0;
+ public static final int TARGET_DATA = 1;
private ClassLoader classLoader = null;
public ClassLoader getClassLoader() {
@@ -17,5 +30,71 @@
public void setClassLoader(ClassLoader classLoader) {
this.classLoader = classLoader;
}
-
+
+ protected boolean hasSameNameBean(JavaBeanList list, JavaBeanModel model) {
+ List children = list.getChildren();
+ for (Iterator iterator = children.iterator(); iterator.hasNext();) {
+ JavaBeanModel object = (JavaBeanModel) iterator.next();
+ if (object.getBeanClass().getName().equals(
+ model.getBeanClass().getName())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public void mergeJavaBeans(JavaBeanList beanList, List javabeans) {
+ for (Iterator iterator = javabeans.iterator(); iterator.hasNext();) {
+ JavaBeanModel javaBean = (JavaBeanModel) iterator.next();
+ if (!hasSameNameBean(beanList, javaBean)) {
+ beanList.addJavaBean(javaBean);
+ }
+ }
+ }
+
+ public List getTheJavaBeanFromGraphFile(ClassLoader classLoader,
+ GraphInformations graphInfo, int dataMode) {
+ String array = getDataSourceClassArray(graphInfo, dataMode);
+ List list = new ArrayList();
+ String[] classes = array.split(";");
+ for (int i = 0; i < classes.length; i++) {
+ String className = classes[i];
+ if (className != null)
+ className.trim();
+ if (className.length() == 0)
+ continue;
+ try {
+ Class clazz = classLoader.loadClass(className);
+ JavaBeanModel javaBean = JavaBeanModelFactory
+ .getJavaBeanModelWithLazyLoad(clazz);
+ if (javaBean != null) {
+ list.add(javaBean);
+ }
+ } catch (Throwable t) {
+ continue;
+ }
+ }
+ return list;
+ }
+
+ private String getDataSourceClassArray(GraphInformations info, int dataMode) {
+ String key = "sourceDataPath"; //$NON-NLS-1$
+ if (dataMode == SOURCE_DATA) {
+ key = "sourceDataPath"; //$NON-NLS-1$
+ }
+ if (dataMode == TARGET_DATA) {
+ key = "targetDataPath"; //$NON-NLS-1$
+ }
+
+ Params params = info.getParams();
+ List paramList = params.getParam();
+ for (Iterator iterator = paramList.iterator(); iterator.hasNext();) {
+ Param param = (Param) iterator.next();
+ if (key.equals(param.getName())) {
+ return param.getValue();
+ }
+ }
+ return null;
+ }
+
}
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/ui/JavaBeanSourceBuilder.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/ui/JavaBeanSourceBuilder.java 2009-01-20
07:09:55 UTC (rev 13135)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/ui/JavaBeanSourceBuilder.java 2009-01-20
07:34:31 UTC (rev 13136)
@@ -35,8 +35,20 @@
public Object buildSourceInputObjects(GraphInformations graphInfo,
SmooksResourceListType listType, IFile sourceFile, Object viewer)
throws InvocationTargetException {
- return buildSourceInputObjects(graphInfo, listType, sourceFile, viewer,
- getClassLoader());
+ ClassLoader classLoader = getClassLoader();
+ if (classLoader == null) {
+ IProject project = sourceFile.getProject();
+ try {
+ classLoader = new ProjectClassLoader(JavaCore.create(project));
+ } catch (JavaModelException e) {
+ throw new InvocationTargetException(e);
+ }
+ }
+ JavaBeanList beanList = (JavaBeanList) buildSourceInputObjects(
+ graphInfo, listType, sourceFile, viewer, getClassLoader());
+ mergeJavaBeans(beanList, getTheJavaBeanFromGraphFile(classLoader,
+ graphInfo, SOURCE_DATA));
+ return beanList;
}
public Object buildSourceInputObjects(GraphInformations graphInfo,
@@ -87,7 +99,8 @@
}
}
if (viewer instanceof PropertyChangeListener) {
- beanList.addNodePropetyChangeListener((PropertyChangeListener) viewer);
+ beanList
+ .addNodePropetyChangeListener((PropertyChangeListener) viewer);
}
return beanList;
}
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/ui/JavaBeanTargetBuilder.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/ui/JavaBeanTargetBuilder.java 2009-01-20
07:09:55 UTC (rev 13135)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/ui/JavaBeanTargetBuilder.java 2009-01-20
07:34:31 UTC (rev 13136)
@@ -36,8 +36,19 @@
public Object buildTargetInputObjects(GraphInformations graphInfo,
SmooksResourceListType listType, IFile sourceFile, Object viewer)
throws InvocationTargetException {
- return buildTargetInputObjects(graphInfo, listType, sourceFile, viewer,
+ ClassLoader classLoader = getClassLoader();
+ if (classLoader == null) {
+ IProject project = sourceFile.getProject();
+ try {
+ classLoader = new ProjectClassLoader(JavaCore.create(project));
+ } catch (JavaModelException e) {
+ throw new InvocationTargetException(e);
+ }
+ }
+ JavaBeanList beanList = (JavaBeanList) buildTargetInputObjects(graphInfo, listType,
sourceFile, viewer,
getClassLoader());
+ mergeJavaBeans(beanList, getTheJavaBeanFromGraphFile(classLoader, graphInfo,
TARGET_DATA));
+ return beanList;
}
public Object buildTargetInputObjects(GraphInformations graphInfo,