Author: DartPeng
Date: 2008-09-02 02:56:25 -0400 (Tue, 02 Sep 2008)
New Revision: 10009
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/model/BeanlabelProvider.java
workspace/dart/plugins/trunk/org.jboss.tools.smooks.javabean/src/org/jboss/tools/smooks/javabean/model/JavaBeanModel.java
Log:
add some new functions:
1.lazy load javabean properties (javabean children)
2.can analyze the Smooks config file to find whitch property donest exist
3.show error image with LabelProvider
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
06:26:03 UTC (rev 10008)
+++
workspace/dart/plugins/trunk/org.jboss.tools.smooks.javabean/src/org/jboss/tools/smooks/javabean/analyzer/JavaBeanAnalyzer.java 2008-09-02
06:56:25 UTC (rev 10009)
@@ -67,6 +67,8 @@
public static final Object PRO_PROJECT_NAME = "__pro_project_name_";
+ public static final String SPACE_STRING = " ";
+
private List usedConnectionList = new ArrayList();
private ComposedAdapterFactory adapterFactory;
@@ -387,14 +389,16 @@
} else {
model = new JavaBeanModel(null, rootClassName);
model.setRootClassModel(true);
- model.setError(true);
+ model.setError("Can't find the class : " + rootClassName);
+ model.setProperties(new ArrayList());
isError = true;
}
if (model != null) {
this.setSelectorIsUsed(rootClassName);
- buildSourceInputProperties(listType, model, false, isError, current);
+ buildSourceInputProperties(listType, model, false, isError,
+ current, classLoader);
}
- return null;
+ return model;
}
public Object buildSourceInputObjects(GraphInformations graphInfo,
@@ -406,7 +410,8 @@
protected void buildSourceInputProperties(SmooksResourceListType listType,
JavaBeanModel beanModel, boolean rootIsWarning,
- boolean rootIsError, ResourceConfigType currentResourceConfigType) {
+ boolean rootIsError, ResourceConfigType currentResourceConfigType,
+ ClassLoader classLoader) {
if (currentResourceConfigType != null) {
List paramList = currentResourceConfigType.getParam();
for (Iterator iterator = paramList.iterator(); iterator.hasNext();) {
@@ -424,7 +429,8 @@
.get(SmooksModelUtils.ATTRIBUTE_SELECTOR, false);
setSelectorIsUsed(currentResourceConfigType
.getSelector());
- analyzeBindingSelector(selector, beanModel, listType);
+ analyzeBindingSelector(selector, beanModel, listType,
+ classLoader);
}
}
}
@@ -432,11 +438,11 @@
}
protected void analyzeBindingSelector(String selector,
- JavaBeanModel currentModel, SmooksResourceListType listType) {
+ JavaBeanModel currentModel, SmooksResourceListType listType,
+ ClassLoader classLoader) {
if (selector.startsWith("${") && selector.endsWith("}")) {
// should get the bean properties
// memory out???
- currentModel.setProperties(null);
currentModel.getProperties();
selector = selector.substring(2, selector.length() - 1);
List rl = listType.getAbstractResourceConfig();
@@ -446,24 +452,65 @@
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);
+ String referenceSelector = resourceConfig.getSelector();
+ JavaBeanModel model = findTheChildJavaBeanModel(
+ referenceSelector, currentModel);
+ // try to test the selector is can be loaded by classloader??
+ Class clazz = null;
+ try {
+ if (classLoader != null) {
+ clazz = classLoader.loadClass(referenceSelector);
+ if (clazz != null)
+ model = JavaBeanModelFactory
+ .getJavaBeanModelWithLazyLoad(clazz);
+ }
+ } catch (Exception e) {
+ // ignore
+ }
// something wrong
if (model == null) {
model = new JavaBeanModel(null, selector);
- currentModel.addProperty(model);
model.setError("don't exist");
+ model.setProperties(new ArrayList());
}
+ currentModel.addProperty(model);
buildSourceInputProperties(listType, model, false, true,
- resourceConfig);
+ resourceConfig, classLoader);
}
+ } else {
+ selector = selector.trim();
+ String[] properties = selector.split(SPACE_STRING);
+ if (properties != null) {
+ JavaBeanModel currentParent = currentModel;
+ for (int i = 0; i < properties.length; i++) {
+ String property = properties[i].trim();
+ Class currentClazz = currentParent.getBeanClass();
+ if (currentClazz != null
+ && property.equals(currentClazz.getName())) {
+
+ } else {
+ JavaBeanModel pm = findTheChildJavaBeanModel(property,
+ currentParent);
+ if (pm != null) {
+
+ } else {
+ pm = new JavaBeanModel(null, property);
+ pm.setProperties(new ArrayList());
+ pm.setError("don't exist");
+ currentParent.addProperty(pm);
+ }
+ currentParent = pm;
+ }
+ }
+ } else {
+ // if properties is null , how to process?
+ }
}
}
@@ -483,15 +530,25 @@
return null;
}
- protected JavaBeanModel findTheChildJavaBeanModelFromBeanId(String name,
+ /**
+ * Find the child JavaBeanModel from parent with the child name <br>
+ * If the parent JavabeanModel is "Collection" or "Array" , the
child
+ * JavabeanModel is the first child of the parent model,it means that the
+ * param "name" is useless with the status.
+ *
+ * @param name
+ * @param parentModel
+ * @return
+ */
+ protected JavaBeanModel findTheChildJavaBeanModel(String name,
JavaBeanModel parentModel) {
List list = parentModel.getProperties();
- if (parentModel.isList() || parentModel.isMany()) {
+ if (list == null)
+ return null;
+ if (parentModel.isList() || parentModel.isArray()) {
if (list.size() >= 1) {
JavaBeanModel m = (JavaBeanModel) list.get(0);
- if (m.getBeanClass().getName().equals(name)) {
- return m;
- }
+ return m;
}
}
Modified:
workspace/dart/plugins/trunk/org.jboss.tools.smooks.javabean/src/org/jboss/tools/smooks/javabean/model/BeanlabelProvider.java
===================================================================
---
workspace/dart/plugins/trunk/org.jboss.tools.smooks.javabean/src/org/jboss/tools/smooks/javabean/model/BeanlabelProvider.java 2008-09-02
06:26:03 UTC (rev 10008)
+++
workspace/dart/plugins/trunk/org.jboss.tools.smooks.javabean/src/org/jboss/tools/smooks/javabean/model/BeanlabelProvider.java 2008-09-02
06:56:25 UTC (rev 10009)
@@ -4,6 +4,8 @@
import org.eclipse.swt.graphics.Image;
import org.jboss.tools.smooks.javabean.JavaBeanActivator;
import org.jboss.tools.smooks.javabean.ui.JavaImageConstants;
+import org.jboss.tools.smooks.ui.SmooksUIActivator;
+import org.jboss.tools.smooks.utils.SmooksGraphConstants;
public class BeanlabelProvider extends LabelProvider {
@@ -22,6 +24,13 @@
String name = ((JavaBeanModel) element).getName();
if (name == null)
name = "<nonamed>";
+
+ Object error = ((JavaBeanModel) element).getError();
+ if (error != null) {
+ name = name + " " + "<" + error.toString() +
">";
+ return name;
+ }
+
Class typeRef = ((JavaBeanModel) element).getBeanClass();
String typeStr = "";
if (typeRef != null) {
@@ -32,7 +41,10 @@
typeStr = typeRef.getName();
}
}
- name = name + " " + typeStr;
+ if (!typeStr.equals("")) {
+ name = name + " " + typeStr;
+ }
+
return name;
}
return super.getText(element);
@@ -41,6 +53,11 @@
@Override
public Image getImage(Object element) {
if (element instanceof JavaBeanModel) {
+ Object error = ((JavaBeanModel) element).getError();
+ if (error != null) {
+ return SmooksUIActivator.getDefault().getImageRegistry().get(
+ SmooksGraphConstants.IMAGE_ERROR);
+ }
if (((JavaBeanModel) element).isPrimitive()) {
return this.getJavaAttributeImage();
} else {
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-02
06:26:03 UTC (rev 10008)
+++
workspace/dart/plugins/trunk/org.jboss.tools.smooks.javabean/src/org/jboss/tools/smooks/javabean/model/JavaBeanModel.java 2008-09-02
06:56:25 UTC (rev 10009)
@@ -16,6 +16,7 @@
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Iterator;
import java.util.List;
import org.apache.commons.beanutils.PropertyUtils;
@@ -105,6 +106,7 @@
private boolean lazyLoadProperties = true;
public boolean isList() {
+ if(beanClass == null) return false;
if (Collection.class.isAssignableFrom(beanClass)) {
if (this.propertyDescriptor != null) {
Method rmethod = propertyDescriptor.getReadMethod();
@@ -142,13 +144,14 @@
boolean lazyLoadProperties) {
this.lazyLoadProperties = lazyLoadProperties;
this.beanClass = beanClass;
+ this.name = beanName;
if (beanClass == null)
return;
- if (beanName == null) {
- beanName = beanClass.getSimpleName();
+ if(this.name == null){
+ this.name = beanClass.getSimpleName();
}
- this.name = beanName;
-
+
+
if (propertyDescriptor == null)
isRoot = true;
this.propertyDescriptor = propertyDescriptor;
@@ -180,7 +183,7 @@
setTypeRef(beanType);
this.parentClass = parentClass;
- if (!isMany() && !isList())
+ if (!isArray() && !isList())
setPrimitive(true);
return;
}
@@ -215,7 +218,8 @@
this.isPrimitive = isPrimitive;
}
- public boolean isMany() {
+ public boolean isArray() {
+ if(beanClass == null) return false;
if (beanClass.isArray()) {
Class beanType = beanClass.getComponentType();
setMany(true);
@@ -262,12 +266,13 @@
private List properties;
public List getProperties() {
+
if (properties == null) {
properties = new ArrayList();
Class beanType = beanClass;
if (this.componentClass != null) {
- if (isMany() || isList()) {
+ if (isArray() || isList()) {
JavaBeanModel proxyModel = new JavaBeanModel(
componentClass, componentClass.getSimpleName(),
null, beanClass, this.lazyLoadProperties);
@@ -278,7 +283,7 @@
return properties;
}
}
-
+ if(beanType == null) return null;
PropertyDescriptor[] pds = PropertyUtils
.getPropertyDescriptors(beanType);
@@ -333,4 +338,25 @@
this.error = error;
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#toString()
+ */
+ public String toString() {
+ StringBuffer buffer = new StringBuffer("JavaBean Name : " + name);
+ if (beanClass != null)
+ buffer.append(";Class : " + this.beanClass.getName());
+ if (this.properties != null) {
+ buffer.append("\n");
+ for (Iterator iterator = properties.iterator(); iterator.hasNext();) {
+ JavaBeanModel child = (JavaBeanModel) iterator.next();
+ buffer.append("\t");
+ buffer.append(child.toString());
+ buffer.append("\n");
+ }
+ }
+ return buffer.toString();
+ }
+
}