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

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


                getLogger().log(
                        Level.INFO,
                        "Get the metadata for " + getServiceRef() + " at "
                                + resource.getReference());
                Representation rep = resource.get(MediaType.APPLICATION_XML);
                this.metadata = new Metadata(rep, resource.getReference());
            } catch (ResourceException e) {
                getLogger().log(
                        Level.SEVERE,
                        "Can't get the metadata for " + getServiceRef()
                                + " (response's status: "
View Full Code Here


     * @return The ETag value for the given entity.
     */
    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()) {
View Full Code Here

     *         the given entity, if this is a media resource. It returns null
     *         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) {
View Full Code Here

     * @return The reference of the binary representation of the given entity,
     *         if this is a media resource. It returns null otherwise.
     */
    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) {
View Full Code Here

     *      Operations</a>
     */
    public Representation invokeComplex(String service,
            Series<Parameter> parameters) throws ResourceException {
        Representation result = null;
        Metadata metadata = (Metadata) getMetadata();
        if (metadata != null && service != null) {
            // Look for the FunctionImport element.
            FunctionImport function = null;
            for (EntityContainer container : metadata.getContainers()) {
                for (FunctionImport f : container.getFunctionImports()) {
                    if (service.equals(f.getName())) {
                        function = f;
                        break;
                    }
View Full Code Here

    public void loadProperty(Object entity, String propertyName) {
        if (getMetadata() == null || entity == null) {
            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);
                }
                Iterator<?> iterator = createQuery(
                        getSubpath(entity, propertyName), propertyClass)
                        .iterator();

                ReflectUtils.setProperty(entity, propertyName,
                        association.isToMany(), iterator, propertyClass);
            } catch (Exception e) {
                getLogger().log(
                        Level.WARNING,
                        "Can't set the property " + propertyName + " of "
                                + entity.getClass() + " for the service"
                                + getServiceRef(), e);
            }
        } else {
            ClientResource resource = createResource(getSubpath(entity,
                    propertyName));
            try {
                Representation rep = resource.get();

                try {
                    String value = getSimpleValue(rep, propertyName);
                    Property property = metadata.getProperty(entity,
                            propertyName);
                    ReflectUtils.setProperty(entity, property, value);
                } catch (Exception e) {
                    getLogger().log(
                            Level.WARNING,
View Full Code Here

        if (getMetadata() == null || source == null) {
            return;
        }
        if (target != null) {
            // TODO Take into acount the case where the target does exist.
            Metadata metadata = (Metadata) getMetadata();
            ClientResource resource = createResource(metadata
                    .getSubpath(source) + "/$links/" + sourceProperty);

            try {
                // TODO Fix chunked request with net client connector
                StringBuilder sb = new StringBuilder("<uri xmlns=\"");
                sb.append(WCF_DATASERVICES_NAMESPACE);
                sb.append("\">");
                sb.append(getServiceRef().toString());
                sb.append(metadata.getSubpath(target));
                sb.append("</uri>");

                StringRepresentation r = new StringRepresentation(
                        sb.toString(), MediaType.APPLICATION_XML);
                resource.put(r);
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
View Full Code Here

     *            The output directory.
     * @throws Exception
     */
    public void generate(File outputDir) throws Exception {
        Service service = new Service(serviceRef);
        Metadata metadata = (Metadata) service.getMetadata();
        if (metadata == null) {
            throw new Exception("Can't get the metadata for this service: "
                    + serviceRef);
        }

        Configuration fmc = new Configuration();
        fmc.setDefaultEncoding(CharacterSet.UTF_8.getName());

        // Generate classes
        String rootTemplates = "clap://class/org/restlet/ext/odata/internal/templates";
        Representation complexTmpl = new StringRepresentation(
                new ClientResource(rootTemplates + "/complexType.ftl").get()
                        .getText());
        Representation entityTmpl = new StringRepresentation(
                new ClientResource(rootTemplates + "/entityType.ftl").get()
                        .getText());
        Representation serviceTmpl = new StringRepresentation(
                new ClientResource(rootTemplates + "/service.ftl").get()
                        .getText());

        for (Schema schema : metadata.getSchemas()) {
            if ((schema.getEntityTypes() != null && !schema.getEntityTypes()
                    .isEmpty())
                    || (schema.getComplexTypes() != null && !schema
                            .getComplexTypes().isEmpty())) {
                String packageName = TypeUtils.getPackageName(schema);
                File packageDir = new File(outputDir, packageName.replace(".",
                        System.getProperty("file.separator")));
                packageDir.mkdirs();

                // For each entity type
                for (EntityType type : schema.getEntityTypes()) {
                    String className = type.getClassName();
                    Map<String, Object> dataModel = new HashMap<String, Object>();
                    dataModel.put("type", type);
                    dataModel.put("schema", schema);
                    dataModel.put("metadata", metadata);
                    dataModel.put("className", className);
                    dataModel.put("packageName", packageName);

                    TemplateRepresentation templateRepresentation = new TemplateRepresentation(
                            entityTmpl, fmc, dataModel, MediaType.TEXT_PLAIN);
                    templateRepresentation.setCharacterSet(CharacterSet.UTF_8);

                    // Write the template representation as a Java class
                    templateRepresentation.write(new FileOutputStream(new File(
                            packageDir, type.getClassName() + ".java")));
                }
                for (ComplexType type : schema.getComplexTypes()) {
                    String className = type.getClassName();
                    Map<String, Object> dataModel = new HashMap<String, Object>();
                    dataModel.put("type", type);
                    dataModel.put("schema", schema);
                    dataModel.put("metadata", metadata);
                    dataModel.put("className", className);
                    dataModel.put("packageName", packageName);

                    TemplateRepresentation templateRepresentation = new TemplateRepresentation(
                            complexTmpl, fmc, dataModel, MediaType.TEXT_PLAIN);
                    templateRepresentation.setCharacterSet(CharacterSet.UTF_8);

                    // Write the template representation as a Java class
                    templateRepresentation.write(new FileOutputStream(new File(
                            packageDir, type.getClassName() + ".java")));
                }
            }
        }
        if (metadata.getContainers() != null
                && !metadata.getContainers().isEmpty()) {
            for (EntityContainer entityContainer : metadata.getContainers()) {
                Schema schema = entityContainer.getSchema();
                // Generate Service subclass
                StringBuffer className = new StringBuffer();

                if (serviceClassName != null) {
                    // Try to use the Client preference
                    if (entityContainer.isDefaultEntityContainer()) {
                        className.append(serviceClassName);
                    } else if (metadata.getContainers().size() == 1) {
                        className.append(serviceClassName);
                    } else {
                        className.append(schema.getNamespace()
                                .getNormalizedName().substring(0, 1)
                                .toUpperCase());
View Full Code Here

            String targetUri = createTargetUri();

            ClientResource resource = service.createResource(new Reference(
                    targetUri));

            Metadata metadata = (Metadata) service.getMetadata();
            if (metadata == null) {
                throw new Exception(
                        "Can't execute the query without the service's metadata.");
            }
View Full Code Here

TOP

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

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.