Package org.openengsb.core.api.model

Examples of org.openengsb.core.api.model.OpenEngSBModelEntry


        SubModel sub2 = new SubModel();
        sub2.setId("sub2");
        sub2.setName("test2");
        model.setSubs(Arrays.asList(sub1, sub2));
        ModelWrapper wrapper = ModelWrapper.wrap(model);
        wrapper.addOpenEngSBModelEntry(new OpenEngSBModelEntry("test", "test", String.class));
        wrapper.addOpenEngSBModelEntry(new OpenEngSBModelEntry("test2", "test2", String.class));
        return model;
    }
View Full Code Here


    @Test
    public void tryConvertJSONIntoModelWithAdditionalSerializer_shouldThrowNoException() throws Exception {
        NullModel model = createTestModel();
        ModelWrapper wrapper = ModelWrapper.wrap(model);
        wrapper.addOpenEngSBModelEntry(new OpenEngSBModelEntry("number", 42, Integer.class));
        String result = mapper.writeValueAsString(model);

        NullModel other = JsonUtils.convertObject(result, NullModel.class);
        List<OpenEngSBModelEntry> entries = ModelWrapper.wrap(other).getOpenEngSBModelTail();
        assertThat(model.getId(), is(other.getId()));
        assertThat(model.getValue(), is(other.getValue()));
        assertThat(model.getSubs().size(), is(other.getSubs().size()));
        assertThat(model.getSubs().get(0).getId(), is(other.getSubs().get(0).getId()));
        assertThat(model.getSubs().get(0).getName(), is(other.getSubs().get(0).getName()));
        assertThat(model.getSubs().get(1).getId(), is(other.getSubs().get(1).getId()));
        assertThat(model.getSubs().get(1).getName(), is(other.getSubs().get(1).getName()));
        assertThat(entries.size(), is(3));
        assertThat(entries.contains(new OpenEngSBModelEntry("test", "test", String.class)), is(true));
        assertThat(entries.contains(new OpenEngSBModelEntry("test2", "test2", String.class)), is(true));
        assertThat(entries.contains(new OpenEngSBModelEntry("number", 42, Integer.class)), is(true));
    }
View Full Code Here

                continue;
            }
            Object value = getValueForProperty(propertyDescriptor, object);
            Class<?> propertyClass = propertyDescriptor.getPropertyType();
            if (propertyClass.isPrimitive()) {
                entries.add(new OpenEngSBModelEntry(propertyDescriptor.getName(), value, ClassUtils
                    .primitiveToWrapper(propertyClass)));
            } else {
                entries.add(new OpenEngSBModelEntry(propertyDescriptor.getName(), value, propertyClass));
            }
        }

        for (Map.Entry<String, EDBObjectEntry> objectEntry : object.entrySet()) {
            EDBObjectEntry entry = objectEntry.getValue();
            Class<?> entryType;
            try {
                entryType = model.getClassLoader().loadClass(entry.getType());
                entries.add(new OpenEngSBModelEntry(entry.getKey(), entry.getValue(), entryType));
            } catch (ClassNotFoundException e) {
                LOGGER.error("Unable to load class {} of the model tail", entry.getType());
            }
        }
        return ModelUtils.createModel(model, entries);
View Full Code Here

        }

        @Override
        public OpenEngSBModelEntry deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
            JsonToken token = jp.getCurrentToken();
            OpenEngSBModelEntry entry = new OpenEngSBModelEntry();
            if (token != JsonToken.START_OBJECT) {
                return null;
            } else {
                // skip the JsonToken.START_OBJECT token
                token = jp.nextValue();
            }
            do {
                if (token == JsonToken.END_OBJECT) {
                    Object value = createValueOfEntry(entry);
                    if (value != null) {
                        entry.setValue(value);
                    }
                    return entry;
                } else {
                    if (jp.getCurrentName().equals("key")) {
                        entry.setKey(jp.getValueAsString());
                    } else if (jp.getCurrentName().equals("value")) {
                        entry.setValue(jp.getValueAsString());
                    } else if (jp.getCurrentName().equals("type")) {
                        try {
                            entry.setType(findType(jp.getValueAsString()));
                        } catch (ClassNotFoundException e) {
                            LOGGER.error("Did not find class of type " + jp.getValueAsString(), e);
                            break;
                        }
                    }
View Full Code Here

        return entries;
    }
   
    @Override
    public List<OpenEngSBModelEntry> toOpenEngSBModelValues() {
        List<OpenEngSBModelEntry> entries = Arrays.asList(new OpenEngSBModelEntry("id", id, String.class),
            new OpenEngSBModelEntry("name", name, String.class),
            new OpenEngSBModelEntry("date", date, Date.class),
            new OpenEngSBModelEntry("test", enumeration, ENUM.class));
        for (int i = 0; i < list.size(); i++) {
            entries.add(new OpenEngSBModelEntry("list" + i, list.get(i), String.class));
        }
        if (sub != null) {
            entries.add(new OpenEngSBModelEntry("sub.id", sub.getId(), String.class));
            entries.add(new OpenEngSBModelEntry("sub.value", sub.getValue(), String.class));
        }
        return entries;
    }
View Full Code Here

TOP

Related Classes of org.openengsb.core.api.model.OpenEngSBModelEntry

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.