use of org.whole.lang.reflect.FeatureDescriptor in project whole by wholeplatform.
the class XmlSpecific2XsiBuilderAdapter method _elementEntity.
protected void _elementEntity(EntityDescriptor<?> context) {
// FIXME unions
if (!EntityUtils.isData(context) && !(context.isAbstract() && context.isPolymorphic())) {
// was getConcreteSubtypesInLanguage().size() > 1)) {
;
// sets an empty string if content entity maps to a string data type
FeatureDescriptor fd = getContentFeatureMapping(context);
if (fd != null && builder.wCurrentIndexOf() <= context.indexOf(fd)) {
EntityDescriptor<?> ed = getContentEntityMapping(context);
// FIXME lists/unions
if (ed.getDataKind().isString()) {
builder.wFeature(fd);
DataTypeUtils.buildFromPersistenceString(builder, ed, "");
}
}
builder._wEntity(context);
}
}
use of org.whole.lang.reflect.FeatureDescriptor in project whole by wholeplatform.
the class AbstractMappingStrategy method getElementFeatureMappings.
public Collection<FeatureDescriptor> getElementFeatureMappings(EntityDescriptor<?> context, QName name) {
Set<CompiledMapping> mappings = indexes.findMappings(ElementMapping, context, name.getLocalPart());
if (mappings.isEmpty())
mappings = Collections.singleton(indexes.findMapping(AnyElementMapping, context));
Set<FeatureDescriptor> featureMappings = new HashSet<FeatureDescriptor>(mappings.size());
for (CompiledMapping mapping : mappings) featureMappings.add(mapping.fd);
return featureMappings;
}
use of org.whole.lang.reflect.FeatureDescriptor in project whole by wholeplatform.
the class DefaultValueFactory method setUniqueDefault.
public static void setUniqueDefault(IEntity entity) {
final String defaultPrefix = entity.wStringValue();
entity.wAddRequestEventHandler(new IdentityRequestEventHandler() {
int max = 0;
void updateMax(int value) {
if (value > max)
max = value;
}
public String notifyRequested(final IEntity source, FeatureDescriptor feature, String value) {
if (value.equals(defaultPrefix)) {
final EntityDescriptor<?> sourceDescriptor = source.wGetEntityDescriptor();
final EntityDescriptor<?> parentDescriptor = source.wGetParent().wGetEntityDescriptor();
GenericTraversalFactory.instance.topDown(new AbstractVisitor() {
public void visit(IEntity entity) {
if (entity == source)
return;
if (sourceDescriptor.equals(entity.wGetEntityDescriptor()) && parentDescriptor.equals(entity.wGetParent().wGetEntityDescriptor())) {
String strValue = entity.wStringValue();
if (strValue.startsWith(defaultPrefix)) {
try {
int value = Integer.parseInt(strValue.substring(defaultPrefix.length()));
updateMax(value);
} catch (NumberFormatException e) {
} catch (IndexOutOfBoundsException e) {
}
}
}
}
}, false).visit(EntityUtils.getCompoundRoot(source));
source.wSetValue(value = defaultPrefix + ++max);
source.wRemoveRequestEventHandler(this);
}
return value;
}
});
}
use of org.whole.lang.reflect.FeatureDescriptor in project whole by wholeplatform.
the class PojoUtils method createInstanceUsingConstructor.
public static Object createInstanceUsingConstructor(IEntity fromEntity, PojoDeclaration pojoDeclaration, Library library) throws Exception {
ReferenceType referenceType = pojoDeclaration.getName();
Class<?> clazz = Class.forName(referenceType.getValue(), true, ReflectionFactory.getPlatformClassLoader());
Constructor constructor = findConstructor(pojoDeclaration);
int params = constructor.getParameters().wSize();
List<Class<?>> parameterTypes = new ArrayList<Class<?>>(params);
List<Object> initargs = new ArrayList<Object>(params);
IBindingManager bindings = BindingManagerFactory.instance.createArguments();
Expression findPropertyByTemplate = (Expression) PojoTemplateManager.instance().create("findPropertyByTemplate");
Expression findParameterByTemplate = (Expression) PojoTemplateManager.instance().create("findParameterByTemplate");
IEntityIterator<Parameter> iterator = BehaviorUtils.<Parameter>compileAndLazyEvaluate(findParameterByTemplate, constructor, bindings);
while (iterator.hasNext()) {
iterator.next();
Property property = BehaviorUtils.<Property>evaluateFirstResult(findPropertyByTemplate, pojoDeclaration, bindings);
Type type = property.getType();
Name template = property.getTemplate();
FeatureDescriptor fd = fromEntity.wGetEntityDescriptor().getFeatureDescriptorEnum().valueOf(template.wStringValue());
IEntity fieldEntity = fromEntity.wGet(fd);
parameterTypes.add(getClass(type));
initargs.add(Matcher.match(PrimitiveType, type) ? fieldEntity.wGetValue() : create(fieldEntity, library));
}
return clazz.getConstructor(parameterTypes.toArray(new Class<?>[0])).newInstance(initargs.toArray());
}
use of org.whole.lang.reflect.FeatureDescriptor in project whole by wholeplatform.
the class PojoUtils method translate.
public static void translate(IEntity fromEntity, Object toObject, PojoDeclaration pojoDeclaration, Library library) {
// translate inherited properties
IEntityIterator<ReferenceType> superPojosIterator = IteratorFactory.<ReferenceType>childIterator();
superPojosIterator.reset(pojoDeclaration.getTypes());
for (ReferenceType superType : superPojosIterator) {
PojoDeclaration superDeclaration = (PojoDeclaration) findProductDeclaration(superType, library);
translate(fromEntity, toObject, superDeclaration, library);
}
// translate declared properties
IEntityIterator<Property> iterator = IteratorFactory.<Property>childIterator();
iterator.reset(pojoDeclaration.getProperties());
EntityDescriptor<?> ed = fromEntity.wGetEntityDescriptor();
Property property = null;
try {
while (iterator.hasNext()) {
property = iterator.next();
if (isReadOnly(property))
continue;
Type type = property.getType();
Name template = property.getTemplate();
FeatureDescriptor fd = ed.getFeatureDescriptorEnum().valueOf(template.wStringValue());
IEntity fieldEntity = fromEntity.wGet(fd);
if (!EntityUtils.isNotResolver(fieldEntity))
continue;
if (Matcher.match(PrimitiveType, type))
setPropertyValue(property, toObject, fieldEntity.wGetValue());
else
setPropertyValue(property, toObject, create(fieldEntity, library));
}
} catch (Exception e) {
throw new IllegalStateException("Cannot translate property: " + property, e);
}
}
Aggregations