Package org.restlet.ext.odata.internal.edm

Examples of org.restlet.ext.odata.internal.edm.EntityType


     */
    private String getTag(Object entity) {
        String result = null;
        if (entity != null) {
            Metadata metadata = (Metadata) getMetadata();
            EntityType type = metadata.getEntityType(entity.getClass());

            StringBuilder sb = new StringBuilder();
            boolean found = false;
            for (Property property : type.getProperties()) {
                if (property.isConcurrent()) {
                    found = true;
                    Object value = null;
                    try {
                        value = ReflectUtils.invokeGetter(entity,
View Full Code Here


     *         otherwise.
     */
    private Reference getValueEditRef(Object entity) {
        if (entity != null) {
            Metadata metadata = (Metadata) getMetadata();
            EntityType type = metadata.getEntityType(entity.getClass());
            if (type.isBlob() && type.getBlobValueEditRefProperty() != null) {
                try {
                    return (Reference) ReflectUtils.invokeGetter(entity, type
                            .getBlobValueEditRefProperty().getName());
                } catch (Exception e) {
                    getLogger().warning(
                            "Cannot get the value of the property "
                                    + type.getBlobValueEditRefProperty()
                                            .getName() + " on " + entity);
                }
            } else {
                getLogger().warning(
                        "This entity is not a media resource " + entity);
View Full Code Here

     */
    public Reference getValueRef(Object entity) {
        if (entity != null) {
            Metadata metadata = (Metadata) getMetadata();

            EntityType type = metadata.getEntityType(entity.getClass());
            if (type.isBlob() && type.getBlobValueRefProperty() != null) {
                try {
                    return (Reference) ReflectUtils.invokeGetter(entity, type
                            .getBlobValueRefProperty().getName());
                } catch (Exception e) {
                    getLogger().warning(
                            "Cannot get the value of the property "
                                    + type.getBlobValueRefProperty().getName()
                                    + " on " + entity);
                }
            } else {
                getLogger().warning(
                        "This entity is not a media resource " + entity);
View Full Code Here

            return;
        }

        Metadata metadata = (Metadata) getMetadata();

        EntityType type = metadata.getEntityType(entity.getClass());
        AssociationEnd association = metadata
                .getAssociation(type, propertyName);

        if (association != null) {
            EntityType propertyEntityType = association.getType();
            try {
                Class<?> propertyClass = ReflectUtils.getSimpleClass(entity,
                        propertyName);
                if (propertyClass == null) {
                    propertyClass = TypeUtils.getJavaClass(propertyEntityType);
View Full Code Here

    public Entry toEntry(final Object entity) {
        Entry result = null;

        if (entity != null) {
            Metadata metadata = (Metadata) getMetadata();
            EntityType type = metadata.getEntityType(entity.getClass());
            if (type != null) {
                final SaxRepresentation r = new SaxRepresentation(
                        MediaType.APPLICATION_XML) {

                    @Override
                    public void write(XmlWriter writer) throws IOException {
                        try {
                            // Attribute for nullable values.
                            AttributesImpl nullAttrs = new AttributesImpl();
                            nullAttrs.addAttribute(
                                    WCF_DATASERVICES_METADATA_NAMESPACE,
                                    "null", null, "boolean", "true");

                            writer.forceNSDecl(
                                    WCF_DATASERVICES_METADATA_NAMESPACE, "m");
                            writer.forceNSDecl(WCF_DATASERVICES_NAMESPACE, "d");
                            writer.startElement(
                                    WCF_DATASERVICES_METADATA_NAMESPACE,
                                    "properties");
                            write(writer, entity, nullAttrs);
                            writer.endElement(
                                    WCF_DATASERVICES_METADATA_NAMESPACE,
                                    "properties");
                        } catch (SAXException e) {
                            throw new IOException(e.getMessage());
                        }
                    }

                    private void write(XmlWriter writer, Object entity,
                            AttributesImpl nullAttrs) throws SAXException {
                        for (Field field : entity.getClass()
                                .getDeclaredFields()) {
                            String getter = "get"
                                    + field.getName().substring(0, 1)
                                            .toUpperCase()
                                    + field.getName().substring(1);
                            Property prop = ((Metadata) getMetadata())
                                    .getProperty(entity, field.getName());
                            if (prop != null) {
                                writeProperty(writer, entity, prop, getter,
                                        nullAttrs);
                            }
                        }
                    }

                    private void writeProperty(XmlWriter writer, Object entity,
                            Property prop, String getter,
                            AttributesImpl nullAttrs) throws SAXException {
                        for (Method method : entity.getClass()
                                .getDeclaredMethods()) {
                            if (method.getReturnType() != null
                                    && getter.equals(method.getName())
                                    && method.getParameterTypes().length == 0) {
                                Object value = null;
                                try {
                                    value = method.invoke(entity,
                                            (Object[]) null);
                                } catch (Exception e) {

                                }
                                if (value != null) {
                                    writer.startElement(
                                            WCF_DATASERVICES_NAMESPACE,
                                            prop.getName());
                                    if (prop instanceof ComplexProperty) {
                                        write(writer, value, nullAttrs);
                                    } else {
                                        writer.characters(TypeUtils.toEdm(
                                                value, prop.getType()));
                                    }
                                    writer.endElement(
                                            WCF_DATASERVICES_NAMESPACE,
                                            prop.getName());
                                } else {
                                    if (prop.isNullable()) {
                                        writer.emptyElement(
                                                WCF_DATASERVICES_NAMESPACE,
                                                prop.getName(), prop.getName(),
                                                nullAttrs);
                                    } else {
                                        getLogger().warning(
                                                "The following property has a null value but is not marked as nullable: "
                                                        + prop.getName());
                                        writer.emptyElement(
                                                WCF_DATASERVICES_NAMESPACE,
                                                prop.getName());
                                    }
                                }
                                break;
                            }
                        }
                    }
                };

                if (type.isBlob()) {
                    result = new Entry() {
                        @Override
                        public void writeInlineContent(XmlWriter writer)
                                throws SAXException {
                            try {
View Full Code Here

TOP

Related Classes of org.restlet.ext.odata.internal.edm.EntityType

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.