use of org.eclipse.scout.rt.platform.classid.ClassIdentifier in project scout.rt by eclipse.
the class ClassIdentifierTest method testTemplateClassUsingShortestPath.
@Test
public void testTemplateClassUsingShortestPath() {
ClassIdentifier aid = new ClassIdentifier(Foo.A.class, AbstractTemplate.InnerClass.class);
ClassIdentifier bid = new ClassIdentifier(Foo.B.class, AbstractTemplate.InnerClass.class);
assertFalse(aid.equals(bid));
assertNotSame(aid.getClasses()[0], bid.getClasses()[0]);
assertSame(aid.getLastSegment(), bid.getLastSegment());
}
use of org.eclipse.scout.rt.platform.classid.ClassIdentifier in project scout.rt by eclipse.
the class ClassIdentifierTest method testCreateWithContextAndCalss.
@Test
public void testCreateWithContextAndCalss() {
ClassIdentifier cid = new ClassIdentifier(String.class);
ClassIdentifier cid2 = new ClassIdentifier(cid, Long.class);
assertNotSame(cid, cid2);
assertArrayEquals(new Class[] { String.class, Long.class }, cid2.getClasses());
}
use of org.eclipse.scout.rt.platform.classid.ClassIdentifier in project scout.rt by eclipse.
the class ClassIdentifierTest method testTemplateClassUsingFullPath.
@Test
public void testTemplateClassUsingFullPath() {
ClassIdentifier aid = new ClassIdentifier(Foo.A.class, Foo.A.InnerClass.class);
ClassIdentifier bid = new ClassIdentifier(Foo.B.class, Foo.B.InnerClass.class);
assertFalse(aid.equals(bid));
assertNotSame(aid.getClasses()[0], bid.getClasses()[0]);
assertSame(aid.getLastSegment(), bid.getLastSegment());
}
use of org.eclipse.scout.rt.platform.classid.ClassIdentifier in project scout.rt by eclipse.
the class ExtensionRegistry method createModelMoveDescriptorFor.
@Override
public <T> MoveDescriptor<T> createModelMoveDescriptorFor(T modelObject, Iterator<?> parentModelObjectIterator) {
if (modelObject == null) {
throw new IllegalExtensionException("modelObject must not be null.");
}
Set<ExtensionRegistryMoveItem> moveItems = null;
m_readWriteLock.readLock().lock();
try {
moveItems = getModelMoveItemsFor(modelObject.getClass(), parentModelObjectIterator);
} finally {
m_readWriteLock.readLock().unlock();
}
if (CollectionUtility.isEmpty(moveItems)) {
return null;
}
// collapse multiple move items into one move descriptor
ClassIdentifier newContainer = null;
Double newOrder = null;
for (ExtensionRegistryMoveItem item : moveItems) {
if (item.getNewModelContainerClassIdentifier() != null) {
newContainer = item.getNewModelContainerClassIdentifier();
}
if (item.getNewModelOrder() != null) {
newOrder = item.getNewModelOrder();
}
}
return new MoveDescriptor<T>(modelObject, newContainer, newOrder);
}
use of org.eclipse.scout.rt.platform.classid.ClassIdentifier in project scout.rt by eclipse.
the class ExtensionRegistry method autoRegisterInternal.
protected void autoRegisterInternal(Class<?> extensionClass, Class<?> declaringClass, ClassIdentifier ownerClassIdentifier, ClassIdentifier ownerClassIdentifierFromDeclaring, Double order) {
if (extensionClass == null) {
throw new IllegalExtensionException("Extension or contribution cannot be null.");
}
boolean isExtension = IExtension.class.isAssignableFrom(extensionClass);
Class<?> extensionGeneric = null;
if (isExtension) {
extensionGeneric = TypeCastUtility.getGenericsParameterClass(extensionClass, IExtension.class);
}
if (ownerClassIdentifier == null) {
if (isExtension) {
// 1. try type parameter of extension
InheritOuterExtensionScope inheritOuterExtensionScope = extensionClass.getAnnotation(InheritOuterExtensionScope.class);
if (inheritOuterExtensionScope == null || inheritOuterExtensionScope.value()) {
ownerClassIdentifier = new ClassIdentifier(ownerClassIdentifierFromDeclaring, extensionGeneric);
} else {
ownerClassIdentifier = new ClassIdentifier(extensionGeneric);
}
}
if (ownerClassIdentifier == null) {
// 2. try @Extends annotation
Extends extendsAnnotation = getExtendsAnnotation(extensionClass);
if (extendsAnnotation != null) {
int pathToContainerLength = extendsAnnotation.pathToContainer().length;
if (pathToContainerLength > 0) {
Class[] segments = new Class[pathToContainerLength + 1];
System.arraycopy(extendsAnnotation.pathToContainer(), 0, segments, 0, pathToContainerLength);
segments[pathToContainerLength] = extendsAnnotation.value();
ownerClassIdentifier = new ClassIdentifier(segments);
} else {
ownerClassIdentifier = new ClassIdentifier(extendsAnnotation.value());
}
}
if (ownerClassIdentifier == null) {
// 3. inherit owner from declaring type
ownerClassIdentifier = ownerClassIdentifierFromDeclaring;
}
}
}
if (Modifier.isStatic(extensionClass.getModifiers())) {
// not required
declaringClass = null;
}
registerInternal(ownerClassIdentifier, declaringClass, extensionClass, order, extensionGeneric, isExtension);
if (isExtension) {
// only step in if it is an "unmanaged" extension.
// managed scout objects (e.g. AbstractCompositeField) create their inner classes itself, therefore inner classes must not be registered
List<Class<?>> innerExtensionClasses = collectInnerExtensionClasses(extensionClass);
for (Class<?> innerExtensionClass : innerExtensionClasses) {
autoRegisterInternal(innerExtensionClass, extensionClass, null, ownerClassIdentifier, null);
}
} else {
// step into all static inner classes for form field data if the inner class itself has an @Extends annotation: this is a row data extension
boolean isFormFieldData = AbstractFormFieldData.class.isAssignableFrom(extensionClass);
if (isFormFieldData) {
List<Class<?>> innerExtensionClasses = collectInnerExtensionClasses(extensionClass);
for (Class<?> innerExtensionClass : innerExtensionClasses) {
if (innerExtensionClass.isAnnotationPresent(Extends.class) && Modifier.isStatic(innerExtensionClass.getModifiers())) {
autoRegisterInternal(innerExtensionClass, extensionClass, null, ownerClassIdentifier, null);
}
}
}
}
}
Aggregations