use of com.canoo.dp.impl.server.legacy.ServerAttribute in project dolphin-platform by canoo.
the class PropertyBinderImpl method bind.
public <T> Binding bind(final Property<T> property, final Qualifier<T> qualifier) {
Assert.requireNonNull(property, "property");
Assert.requireNonNull(qualifier, "qualifier");
if (property instanceof PropertyImpl) {
try {
final PropertyImpl p = (PropertyImpl) property;
final Field attributeField = ReflectionHelper.getInheritedDeclaredField(PropertyImpl.class, "attribute");
final ServerAttribute attribute = (ServerAttribute) ReflectionHelper.getPrivileged(attributeField, p);
if (attribute == null) {
throw new NullPointerException("attribute == null");
}
attribute.setQualifier(qualifier.getIdentifier());
return new Binding() {
@Override
public void unbind() {
attribute.setQualifier(null);
}
};
} catch (Exception e) {
throw new BindingException("Can not bind the given property to the qualifier! Property: " + property + ", qualifier: " + qualifier, e);
}
} else {
throw new BindingException("Can not bind the given property to the qualifier! Property: " + property + ", qualifier: " + qualifier);
}
}
use of com.canoo.dp.impl.server.legacy.ServerAttribute in project dolphin-platform by canoo.
the class TestModelCreation method testWithListReferenceModel.
@Test
public void testWithListReferenceModel() {
final ServerModelStore serverModelStore = createServerModelStore();
final BeanManager manager = createBeanManager(serverModelStore);
ListReferenceModel model = manager.create(ListReferenceModel.class);
assertThat(model, notNullValue());
assertThat(model.getObjectList(), empty());
assertThat(model.getPrimitiveList(), empty());
List<ServerPresentationModel> dolphinModels = serverModelStore.findAllPresentationModelsByType(ListReferenceModel.class.getName());
assertThat(dolphinModels, hasSize(1));
ServerPresentationModel dolphinModel = dolphinModels.get(0);
List<ServerAttribute> attributes = dolphinModel.getAttributes();
assertThat(attributes, contains(allOf(hasProperty("propertyName", is(RemotingConstants.SOURCE_SYSTEM)), hasProperty("value", is(RemotingConstants.SOURCE_SYSTEM_SERVER)), hasProperty("qualifier", nullValue()))));
List<ServerPresentationModel> classModels = serverModelStore.findAllPresentationModelsByType(PlatformRemotingConstants.DOLPHIN_BEAN);
assertThat(classModels, contains(hasProperty("attributes", containsInAnyOrder(allOf(hasProperty("propertyName", is(PlatformRemotingConstants.JAVA_CLASS)), hasProperty("value", is(ListReferenceModel.class.getName())), hasProperty("qualifier", nullValue())), allOf(hasProperty("propertyName", is("objectList")), hasProperty("value", is(DolphinBeanConverterFactory.FIELD_TYPE_DOLPHIN_BEAN)), hasProperty("qualifier", nullValue())), allOf(hasProperty("propertyName", is("primitiveList")), hasProperty("value", is(StringConverterFactory.FIELD_TYPE_STRING)), hasProperty("qualifier", nullValue())), allOf(hasProperty("propertyName", is(RemotingConstants.SOURCE_SYSTEM)), hasProperty("value", is(RemotingConstants.SOURCE_SYSTEM_SERVER)), hasProperty("qualifier", nullValue()))))));
}
use of com.canoo.dp.impl.server.legacy.ServerAttribute in project dolphin-platform by canoo.
the class TestModelCreation method testWithSimpleModel.
@Test
public void testWithSimpleModel() {
final ServerModelStore serverModelStore = createServerModelStore();
final EventDispatcher dispatcher = createEventDispatcher(serverModelStore);
final BeanRepository beanRepository = createBeanRepository(serverModelStore, dispatcher);
final BeanManager manager = createBeanManager(serverModelStore, beanRepository, dispatcher);
SimpleTestModel model = manager.create(SimpleTestModel.class);
assertThat(model, notNullValue());
assertThat(model.getTextProperty(), notNullValue());
assertThat(model.getTextProperty().get(), nullValue());
assertThat(beanRepository.isManaged(model), is(true));
List<ServerPresentationModel> dolphinModels = serverModelStore.findAllPresentationModelsByType(SimpleTestModel.class.getName());
assertThat(dolphinModels, hasSize(1));
ServerPresentationModel dolphinModel = dolphinModels.get(0);
List<ServerAttribute> attributes = dolphinModel.getAttributes();
assertThat(attributes, containsInAnyOrder(allOf(hasProperty("propertyName", is("text")), hasProperty("value", nullValue()), hasProperty("qualifier", nullValue())), allOf(hasProperty("propertyName", is(RemotingConstants.SOURCE_SYSTEM)), hasProperty("value", is(RemotingConstants.SOURCE_SYSTEM_SERVER)), hasProperty("qualifier", nullValue()))));
List<ServerPresentationModel> classModels = serverModelStore.findAllPresentationModelsByType(PlatformRemotingConstants.DOLPHIN_BEAN);
assertThat(classModels, contains(hasProperty("attributes", containsInAnyOrder(allOf(hasProperty("propertyName", is(PlatformRemotingConstants.JAVA_CLASS)), hasProperty("value", is(SimpleTestModel.class.getName())), hasProperty("qualifier", nullValue())), allOf(hasProperty("propertyName", is("text")), hasProperty("value", is(StringConverterFactory.FIELD_TYPE_STRING)), hasProperty("qualifier", nullValue())), allOf(hasProperty("propertyName", is(RemotingConstants.SOURCE_SYSTEM)), hasProperty("value", is(RemotingConstants.SOURCE_SYSTEM_SERVER)), hasProperty("qualifier", nullValue()))))));
}
use of com.canoo.dp.impl.server.legacy.ServerAttribute in project dolphin-platform by canoo.
the class TestModelCreation method testWithAllPrimitiveDatatypes.
@Test
public void testWithAllPrimitiveDatatypes() {
final ServerModelStore serverModelStore = createServerModelStore();
final EventDispatcher dispatcher = createEventDispatcher(serverModelStore);
final BeanRepository beanRepository = createBeanRepository(serverModelStore, dispatcher);
final BeanManager manager = createBeanManager(serverModelStore, beanRepository, dispatcher);
PrimitiveDataTypesModel model = manager.create(PrimitiveDataTypesModel.class);
assertThat(model, notNullValue());
assertThat(model.getTextProperty(), notNullValue());
assertThat(model.getTextProperty().get(), nullValue());
assertThat(beanRepository.isManaged(model), is(true));
List<ServerPresentationModel> dolphinModels = serverModelStore.findAllPresentationModelsByType(PrimitiveDataTypesModel.class.getName());
assertThat(dolphinModels, hasSize(1));
ServerPresentationModel dolphinModel = dolphinModels.get(0);
List<ServerAttribute> attributes = dolphinModel.getAttributes();
assertThat(attributes, hasSize(9));
for (Attribute attribute : attributes) {
if (RemotingConstants.SOURCE_SYSTEM.equals(attribute.getPropertyName())) {
assertThat(attribute.getValue(), Matchers.<Object>is(RemotingConstants.SOURCE_SYSTEM_SERVER));
} else {
assertThat(attribute.getValue(), nullValue());
}
assertThat(attribute.getQualifier(), nullValue());
}
final List<ServerPresentationModel> classModels = serverModelStore.findAllPresentationModelsByType(PlatformRemotingConstants.DOLPHIN_BEAN);
assertThat(classModels, hasSize(1));
final PresentationModel classModel = classModels.get(0);
final List<Attribute> classAttributes = classModel.getAttributes();
assertThat(classAttributes, hasSize(10));
for (Attribute attribute : classAttributes) {
if (PlatformRemotingConstants.JAVA_CLASS.equals(attribute.getPropertyName())) {
assertThat(attribute.getValue(), Matchers.<Object>is(PrimitiveDataTypesModel.class.getName()));
} else if (RemotingConstants.SOURCE_SYSTEM.equals(attribute.getPropertyName())) {
assertThat(attribute.getValue(), Matchers.<Object>is(RemotingConstants.SOURCE_SYSTEM_SERVER));
} else {
switch(attribute.getPropertyName()) {
case "byteProperty":
assertThat(attribute.getValue(), Matchers.<Object>is(ByteConverterFactory.FIELD_TYPE_BYTE));
break;
case "shortProperty":
assertThat(attribute.getValue(), Matchers.<Object>is(ShortConverterFactory.FIELD_TYPE_SHORT));
break;
case "integerProperty":
assertThat(attribute.getValue(), Matchers.<Object>is(IntegerConverterFactory.FIELD_TYPE_INT));
break;
case "longProperty":
assertThat(attribute.getValue(), Matchers.<Object>is(LongConverterFactory.FIELD_TYPE_LONG));
break;
case "floatProperty":
assertThat(attribute.getValue(), Matchers.<Object>is(FloatConverterFactory.FIELD_TYPE_FLOAT));
break;
case "doubleProperty":
assertThat(attribute.getValue(), Matchers.<Object>is(DoubleConverterFactory.FIELD_TYPE_DOUBLE));
break;
case "booleanProperty":
assertThat(attribute.getValue(), Matchers.<Object>is(BooleanConverterFactory.FIELD_TYPE_BOOLEAN));
break;
case "textProperty":
assertThat(attribute.getValue(), Matchers.<Object>is(StringConverterFactory.FIELD_TYPE_STRING));
break;
default:
fail("Unknown attribute found: " + attribute);
break;
}
}
assertThat(attribute.getQualifier(), nullValue());
}
}
use of com.canoo.dp.impl.server.legacy.ServerAttribute in project dolphin-platform by canoo.
the class TestModelCreation method testWithAnnotatedSimpleModel.
@Test
public void testWithAnnotatedSimpleModel() {
final ServerModelStore serverModelStore = createServerModelStore();
final EventDispatcher dispatcher = createEventDispatcher(serverModelStore);
final BeanRepository beanRepository = createBeanRepository(serverModelStore, dispatcher);
final BeanManager manager = createBeanManager(serverModelStore, beanRepository, dispatcher);
SimpleAnnotatedTestModel model = manager.create(SimpleAnnotatedTestModel.class);
assertThat(model, notNullValue());
assertThat(model.getMyProperty(), notNullValue());
assertThat(model.getMyProperty().get(), nullValue());
assertThat(beanRepository.isManaged(model), is(true));
List<ServerPresentationModel> dolphinModels = serverModelStore.findAllPresentationModelsByType(SimpleAnnotatedTestModel.class.getName());
assertThat(dolphinModels, hasSize(1));
ServerPresentationModel dolphinModel = dolphinModels.get(0);
List<ServerAttribute> attributes = dolphinModel.getAttributes();
assertThat(attributes, containsInAnyOrder(allOf(hasProperty("propertyName", is("myProperty")), hasProperty("value", nullValue()), hasProperty("qualifier", nullValue())), allOf(hasProperty("propertyName", is(RemotingConstants.SOURCE_SYSTEM)), hasProperty("value", is(RemotingConstants.SOURCE_SYSTEM_SERVER)), hasProperty("qualifier", nullValue()))));
List<ServerPresentationModel> classModels = serverModelStore.findAllPresentationModelsByType(PlatformRemotingConstants.DOLPHIN_BEAN);
assertThat(classModels, contains(hasProperty("attributes", containsInAnyOrder(allOf(hasProperty("propertyName", is(PlatformRemotingConstants.JAVA_CLASS)), hasProperty("value", is(SimpleAnnotatedTestModel.class.getName())), hasProperty("qualifier", nullValue())), allOf(hasProperty("propertyName", is("myProperty")), hasProperty("value", is(StringConverterFactory.FIELD_TYPE_STRING)), hasProperty("qualifier", nullValue())), allOf(hasProperty("propertyName", is(RemotingConstants.SOURCE_SYSTEM)), hasProperty("value", is(RemotingConstants.SOURCE_SYSTEM_SERVER)), hasProperty("qualifier", nullValue()))))));
}
Aggregations