use of org.whole.lang.reflect.FeatureDescriptor in project whole by wholeplatform.
the class CommonsDataTypePersistenceParser method getFeatureDescriptor.
public static FeatureDescriptor getFeatureDescriptor(String fdUri, boolean loadOnDemand, IBindingManager bm) {
int index = fdUri.indexOf('#');
if (index > 0) {
String languageUri = fdUri.substring(0, index);
if (ReflectionFactory.hasLanguageKit(languageUri, loadOnDemand, bm)) {
ILanguageKit lk = ReflectionFactory.getLanguageKit(languageUri, loadOnDemand, bm);
FeatureDescriptor fd = lk.getFeatureDescriptorEnum().valueOf(fdUri.substring(index + 1));
if (fd != null)
return fd;
}
}
return null;
}
use of org.whole.lang.reflect.FeatureDescriptor in project whole by wholeplatform.
the class AbstractEntityResolver method wResolveWith.
public <T extends IEntity> T wResolveWith(EntityDescriptor<T> ed) {
T newChild = GenericEntityFactory.instance.create(ed);
if (ed.getEntityKind().isComposite()) {
for (IEntity element : elements) newChild.wAdd(EntityUtils.clone(element));
} else {
Set<FeatureDescriptor> features = new HashSet<FeatureDescriptor>(newChild.wGetEntityDescriptor().getEntityFeatureDescriptors());
features.retainAll(namedFeaturesMap.keySet());
for (FeatureDescriptor fd : features) newChild.wSet(fd, EntityUtils.clone(this.wGet(fd)));
}
wGetParent().wSet(this, newChild);
return newChild;
}
use of org.whole.lang.reflect.FeatureDescriptor in project whole by wholeplatform.
the class EntityUtils method merge.
public static final IEntity merge(IEntity merger, IEntity mergee, IEntityComparator<IEntity> comparator, boolean orderAware) {
IEntity initialMerger = merger;
IEntity initialMergee = mergee;
merger = merger.wGetAdaptee(false);
mergee = mergee.wGetAdaptee(false);
EntityDescriptor<?> mergerED = merger.wGetEntityDescriptor();
if (!mergerED.equals(mergee.wGetEntityDescriptor())) {
IEntity parent = initialMerger.wGetParent();
if (!EntityUtils.isNull(parent)) {
int index = parent.wIndexOf(initialMerger);
if (parent.wGetEntityDescriptor(index).isLanguageSupertypeOf(mergee.wGetEntityDescriptor()))
setCloneIfReparenting(parent, index, mergee);
return parent.wGet(index);
} else
return initialMergee;
}
switch(mergerED.getEntityKind()) {
case SIMPLE:
for (FeatureDescriptor fd : mergerED.getEntityFeatureDescriptors()) {
IEntity mergerFeature = merger.wGet(fd).wGetAdaptee(false);
IEntity mergeeFeature = mergee.wGet(fd).wGetAdaptee(false);
if (mergerFeature.wGetEntityDescriptor().equals(mergeeFeature.wGetEntityDescriptor()))
merge(mergerFeature, mergeeFeature, comparator, orderAware);
else
merger.wSet(fd, cloneIfParented(mergeeFeature));
}
break;
case COMPOSITE:
if (mergerED.getCompositeKind().isOrdered() && orderAware) {
int i = 0, j = 0;
while (i < merger.wSize() && j < mergee.wSize()) {
IEntity mergerChild = merger.wGet(i).wGetAdaptee(false);
while (j < mergee.wSize()) {
IEntity mergeeChild = mergee.wGet(j++).wGetAdaptee(false);
if (comparator.equals(mergerChild, mergeeChild))
merger.wSet(i, cloneIfParented(merge(mergerChild, mergeeChild, comparator, orderAware)));
else {
merger.wAdd(++i, cloneIfParented(mergeeChild));
break;
}
}
i++;
}
while (j < mergee.wSize()) merger.wAdd(cloneIfParented(mergee.wGet(j++).wGetAdaptee(false)));
} else {
IEntityIterator<IEntity> mergeeIterator = IteratorFactory.childIterator();
mergeeIterator.reset(mergee);
while (mergeeIterator.hasNext()) {
IEntity mergeeChild = mergeeIterator.next();
if (comparator.contains(merger, mergeeChild)) {
IEntity mergerChild = comparator.get(merger, mergeeChild);
merger.wSet(mergeeChild, merge(mergerChild, mergeeChild, comparator, orderAware));
} else {
merger.wAdd(cloneIfParented(mergeeChild));
}
}
}
break;
default:
case DATA:
// do not merge data entities
break;
}
return initialMerger;
}
use of org.whole.lang.reflect.FeatureDescriptor in project whole by wholeplatform.
the class GenericCloneVisitor method setChildren.
protected void setChildren(IEntity entity, IEntity entityClone) {
IEntity oldSelfEntity2 = getBindings().wGet("self");
for (int index = 0; index < entity.wSize(); index++) {
int resultSize = entityClone.wSize();
stagedVisitIfNeeded(entityClone.wGet(index));
// was applyIfNeeded(entity.wGet(index));
int nextResultSize = entityClone.wSize();
index += (nextResultSize - resultSize);
if (isResultIterator()) {
IEntityIterator<?> iterator = getResultIterator();
setResultIterator(null);
IEntity selfEntity = getBindings().wGet("self");
if (selfEntity != oldSelfEntity2)
getBindings().wDef("self", selfEntity = oldSelfEntity2);
iterator.reset(selfEntity);
FeatureDescriptor resultChildDescriptor = entityClone.wGetFeatureDescriptor(index);
if (EntityUtils.isComposite(entityClone)) {
entityClone.wRemove(index--);
if (iterator.hasNext()) {
ITransactionScope resettableScope = BindingManagerFactory.instance.createTransactionScope();
getBindings().wEnterScope(resettableScope);
resultSize = entityClone.wSize();
for (IEntity value : iterator) {
nextResultSize = entityClone.wSize();
index += (nextResultSize - resultSize);
if (BindingManagerFactory.instance.isVoid(value))
resultSize = nextResultSize;
else {
entityClone.wAdd(++index, EntityUtils.convertCloneIfReparenting(value, resultChildDescriptor));
resultSize = entityClone.wSize();
}
resettableScope.commit();
}
resettableScope.rollback();
getBindings().wExitScope();
}
} else {
IEntity value = null;
if (iterator.hasNext()) {
ITransactionScope resettableScope = BindingManagerFactory.instance.createTransactionScope();
getBindings().wEnterScope(resettableScope);
for (IEntity r : iterator) {
if (!BindingManagerFactory.instance.isVoid(r))
value = r;
resettableScope.commit();
}
resettableScope.rollback();
getBindings().wExitScope();
}
if (value != null)
entityClone.wSet(index, EntityUtils.convertCloneIfReparenting(value, resultChildDescriptor));
else
entityClone.wRemove(index);
}
} else {
IEntity value = getResult();
if (value != null && !BindingManagerFactory.instance.isVoid(value)) {
FeatureDescriptor resultChildDescriptor = entityClone.wGetFeatureDescriptor(index);
entityClone.wSet(index, EntityUtils.convertCloneIfReparenting(value, resultChildDescriptor));
} else
entityClone.wRemove(index);
}
}
}
use of org.whole.lang.reflect.FeatureDescriptor in project whole by wholeplatform.
the class DerivedBehaviorFactory method createDerivationContext.
public static DerivationContext createDerivationContext() {
DerivationContext dc = new DerivationContext();
dc.addDerivationRules(TestEventsEntityDescriptorEnum.Rectangle, new AbstractEntityDerivationRule<Rectangle>() {
public IEntity derive(Rectangle entity, FeatureDescriptor fd, IEntity value) {
switch(fd.getOrdinal()) {
case TestEventsFeatureDescriptorEnum.base_ord:
try {
return TestEventsEntityFactory.instance.createVal(entity.getPerimeter().wIntValue() / 2 - entity.getHeight().wIntValue());
} catch (Exception e) {
}
try {
return TestEventsEntityFactory.instance.createVal(entity.getArea().wIntValue() / entity.getHeight().wIntValue());
} catch (ArithmeticException e) {
throw new RequestException();
}
case TestEventsFeatureDescriptorEnum.height_ord:
try {
return TestEventsEntityFactory.instance.createVal(entity.getPerimeter().wIntValue() / 2 - entity.getBase().wIntValue());
} catch (Exception e) {
}
try {
return TestEventsEntityFactory.instance.createVal(entity.getArea().wIntValue() / entity.getBase().wIntValue());
} catch (ArithmeticException e) {
throw new RequestException();
}
case TestEventsFeatureDescriptorEnum.area_ord:
return TestEventsEntityFactory.instance.createVal(entity.getBase().wIntValue() * entity.getHeight().wIntValue());
case TestEventsFeatureDescriptorEnum.perimeter_ord:
return TestEventsEntityFactory.instance.createVal((entity.getBase().wIntValue() + entity.getHeight().wIntValue()) * 2);
default:
return value;
}
}
public void invalidate(Labels entity, FeatureDescriptor fd, IEntity oldValue, IEntity newValue) {
// switch (fd.getOrdinal()) {
//
// case TestEventsFeatureDescriptorEnum.base_ord:
// case TestEventsFeatureDescriptorEnum.height_ord:
// entity.wRemove(TestEventsFeatureDescriptorEnum.area);
// entity.wRemove(TestEventsFeatureDescriptorEnum.perimeter);
// break;
// }
}
});
dc.addDerivationRules(TestEventsEntityDescriptorEnum.Labels, new AbstractEntityDerivationRule<Labels>() {
public IEntity derive(Labels entity, FeatureDescriptor fd, IEntity value) {
switch(fd.getOrdinal()) {
case TestEventsFeatureDescriptorEnum.simpleDerived_ord:
return TestEventsEntityFactory.instance.createLabel(entity.getSimple().wStringValue() + ".suffix");
case TestEventsFeatureDescriptorEnum.simpleDerivedDerived_ord:
return TestEventsEntityFactory.instance.createLabel("prefix." + entity.getSimpleDerived().wStringValue());
default:
return value;
}
}
public void invalidate(Labels entity, FeatureDescriptor fd, IEntity oldValue, IEntity newValue) {
switch(fd.getOrdinal()) {
case TestEventsFeatureDescriptorEnum.simple_ord:
// FIXME initialization rule remove only if derived
entity.wRemove(TestEventsFeatureDescriptorEnum.simpleDerived);
break;
case TestEventsFeatureDescriptorEnum.simpleDerived_ord:
entity.wRemove(TestEventsFeatureDescriptorEnum.simpleDerivedDerived);
break;
}
}
});
return dc;
}
Aggregations