String namePrefix = attribute.getNamePrefix();
if (namePrefix == null) {
property = metaclass.findProperty(propertyName);
} else {
//
IMetaclass metaclassAttached = loader.getMetaclass(namePrefix,
attribute.getNamespace());
if (metaclassAttached != null) {
property = metaclassAttached.findProperty(propertyName);
isAttached = true;
} else {
LoggerManager.log(attribute.getNamespace() + " -> "
+ namePrefix + " is not found.");
return;
}
}
}
if (propertyName.equals(IConstants.XAML_DATA_CONTEXT)) {
property = null;
}
if (IConstants.XAML_COMMAND.equalsIgnoreCase(propertyName)
&& ICommand.class.isAssignableFrom(property.getType())
&& (target instanceof Widget)) {
addCommandExecuteListener(attribute.getContent(), (Widget) target);
}
if (property == null) {
if (options.get(IXWTLoader.DESIGN_MODE_PROPERTY) == Boolean.TRUE) {
return;
}
// prepare event
IEvent event = metaclass.findEvent(attrName);
if (event == null) {
return;
}
// add events for controls and items.
if (!(target instanceof Widget)) {
return;
}
loadData.updateEvent(context, (Widget) target, event, attribute
.getContent());
return;
}
String contentValue = attribute.getContent();
if ("MenuItem".equalsIgnoreCase(element.getName())
&& "Text".equalsIgnoreCase(attrName)) {
Attribute attributeAccelerator = element
.getAttribute("Accelerator");
if (attributeAccelerator != null) {
contentValue = contentValue + '\t'
+ getContentValue(attributeAccelerator.getContent());
}
}
if (contentValue != null && "Accelerator".equalsIgnoreCase(attrName)) {
contentValue = XWTMaps.getCombAccelerator(contentValue);
if (contentValue.contains("'")) {
contentValue = removeSubString(contentValue, "'");
}
}
if (contentValue != null
&& (Image.class.isAssignableFrom(property.getType()))) {
contentValue = getImagePath(attribute, contentValue);
}
if (contentValue != null
&& (URL.class.isAssignableFrom(property.getType()))) {
contentValue = getSourceURL(contentValue);
}
Object value = null;
DocumentObject[] children = attribute.getChildren();
boolean usingExistingValue = false;
if (contentValue == null) {
Class<?> type = property.getType();
if (Collection.class.isAssignableFrom(type)) {
value = getCollectionProperty(type, target, attribute, attrName);
} else {
Object directTarget = null;
if (TableViewerColumn.class.isAssignableFrom(type)
&& attrName.equalsIgnoreCase("columns")) {
children = DocumentObjectSorter.sortWithAttr(children,
"Index").toArray(
new DocumentObject[children.length]);
} else {
try {
Object propertyValue = property.getValue(target);
if (UserData.getWidget(propertyValue) != null) {
directTarget = propertyValue;
// use the existing property value as parent,
// not need to add the constraint
if (!property.isValueAsParent()) {
type = null;
usingExistingValue = true;
}
}
} catch (Exception e) {
}
}
if (directTarget == null) {
directTarget = target;
}
for (DocumentObject child : children) {
String name = child.getName();
String ns = child.getNamespace();
if (name.equalsIgnoreCase(IConstants.XAML_X_STATIC)
&& ns.equals(IConstants.XWT_X_NAMESPACE)) {
value = getStaticValue(child);
} else if (name
.equalsIgnoreCase(IConstants.XAML_STATICRESOURCES)
&& ns.equals(IConstants.XWT_NAMESPACE)) {
String key = child.getContent();
value = new StaticResourceBinding(loadData
.getCurrentWidget(), key);
} else if ((IConstants.XWT_X_NAMESPACE.equals(ns) && IConstants.XAML_X_ARRAY
.equalsIgnoreCase(name))) {
value = getArrayProperty(property.getType(),
directTarget, child, name);
} else if (property.getType().isArray()) {
value = getArrayProperty(property.getType(),
directTarget, attribute, name);
break;
} else if (isAssignableFrom(element, TableColumn.class)
&& isAssignableFrom(child, TableEditor.class)) {
value = child;
} else if (TableViewerColumn.class
.isAssignableFrom(property.getType())
&& attribute.getContent() != null) {
value = attribute.getContent();
} else {
if ("Null".equals(child.getName()) && IConstants.XWT_X_NAMESPACE.equals(child.getNamespace())) {
property.setValue(directTarget, null);
return;
} else {
value = doCreate(directTarget, (Element) child, type,
EMPTY_MAP);
if (value == null
&& type != null
&& !(type == Table.class
&& "TableColumn"
.equals(child.getName()) && Table.class
.isInstance(directTarget))) {
throw new XWTException(child.getName()
+ " cannot be a content of "
+ type.getName() + " "
+ target.getClass().getName() + "."
+ property.getName());
}
if (value instanceof IDynamicBinding) {
((IDynamicBinding) value).setType(attrName);
}
}
}
}
}
}
if (contentValue != null && value == null
&& !IConstants.XAML_COMMAND.equalsIgnoreCase(propertyName)) {
if (property.getType().isInstance(Class.class)) {
int index = contentValue.lastIndexOf(':');
if (index != -1) {
String prefix = contentValue.substring(0, index);
contentValue = findNamespace(attribute, prefix)
+ contentValue.substring(index);
}
}
value = loader.convertFrom(property.getType(), contentValue);
}
if (!usingExistingValue) {
if (value != null) {
Class<?> propertyType = property.getType();
if (!propertyType.isAssignableFrom(value.getClass())
|| (value instanceof IBinding && !(IBinding.class
.isAssignableFrom(propertyType)))) {
Object orginalValue = value;
IConverter converter = loader.findConvertor(value
.getClass(), propertyType);
if (converter != null) {
value = converter.convert(value);
if (value != null
&& orginalValue instanceof IBinding
&& !propertyType.isAssignableFrom(value
.getClass())) {
converter = loader.findConvertor(value.getClass(),
propertyType);
if (converter != null) {
value = converter.convert(value);
} else {
LoggerManager.log(new XWTException("Convertor "
+ value.getClass().getSimpleName()
+ "->" + propertyType.getSimpleName()
+ " is not found"));
}
}
} else {
LoggerManager.log(new XWTException("Convertor "
+ value.getClass().getSimpleName() + "->"
+ propertyType.getSimpleName()
+ " is not found"));
}
}
if (isAttached) {
UserData.setLocalData(target, property, value);
} else {
property.setValue(target, value);
}
} else {
if (value == null) {
value = property.getValue(target);
}
if (value != null) {
// create children.
for (DocumentObject child : children) {
String name = child.getName();
String ns = child.getNamespace();
if (!IConstants.XWT_X_NAMESPACE.equals(ns)
|| !IConstants.XAML_X_ARRAY
.equalsIgnoreCase(name)) {
Class<?> type = property.getType();
if (!Collection.class.isAssignableFrom(type)) {
doCreate(value, (Element) child, null,
EMPTY_MAP);
}
}
}
}
}
}
if (attribute.attributeNames(IConstants.XWT_NAMESPACE).length > 0) {
IMetaclass propertyMetaclass = loader.getMetaclass(property
.getType());
if (value == null) {
value = property.getValue(target);
}
if (value != null) {