Package com.theoryinpractise.halbuilder.api

Examples of com.theoryinpractise.halbuilder.api.RepresentationException


     */
    public <T> T toClass(Class<T> anInterface) {
        if (InterfaceContract.newInterfaceContract(anInterface).isSatisfiedBy(this)) {
            return InterfaceRenderer.newInterfaceRenderer(anInterface).render(this);
        } else {
            throw new RepresentationException("Unable to write representation to " + anInterface.getName());
        }
    }
View Full Code Here


      JsonNode rootNode = mapper.readValue(new StringReader(source), JsonNode.class);

      return readResource(rootNode);
    } catch (Exception e) {
      throw new RepresentationException(e);
    }

  }
View Full Code Here

              throw new IllegalStateException("No representation reader for content type " + contentType + " registered.");
            }
            Constructor<? extends RepresentationReader> readerConstructor = readerClass.getConstructor(AbstractRepresentationFactory.class);
            return readerConstructor.newInstance(this).read(reader);
        } catch (Exception e) {
            throw new RepresentationException(e);
        }
    }
View Full Code Here

        for (Map.Entry<ContentType, Class<? extends RepresentationWriter>> entry : contentRenderers.entrySet()) {
            if (entry.getKey().matches(contentType)) {
                try {
                    return entry.getValue().newInstance();
                } catch (InstantiationException e) {
                    throw new RepresentationException(e);
                } catch (IllegalAccessException e) {
                    throw new RepresentationException(e);
                }
            }
        }

        throw new IllegalArgumentException("Unsupported contentType: " + contentType);
View Full Code Here

                    return returnValue;
                }
            });
            return proxy;
        } else {
            throw new RepresentationException("Unable to write representation to " + anInterface.getName());
        }
    }
View Full Code Here

        return namespaces;
    }

    public NamespaceManager withNamespace(String namespace, String href) {
        if (namespaces.containsKey(namespace)) {
            throw new RepresentationException(format("Duplicate namespace '%s' found for representation factory", namespace));
        }
        if (!href.contains("{rel}")) {
            throw new RepresentationException(format("Namespace '%s' does not include {rel} URI template argument.", namespace));
        }
        namespaces.put(namespace, href);
        return this;
    }
View Full Code Here

    public void validateNamespaces(String sourceRel) {
        for (String rel : WHITESPACE_SPLITTER.split(sourceRel)) {
            if (!rel.contains("://") && rel.contains(":")) {
                String[] relPart = rel.split(":");
                if (!namespaces.keySet().contains(relPart[0])) {
                    throw new RepresentationException(format("Undeclared namespace in rel %s for resource", rel));
                }
            }
        }
    }
View Full Code Here

        return href;
    }

    public String resolve(String ns) {
        if (!ns.contains(":")) {
            throw new RepresentationException("Namespaced value does not include : - not namespaced?");
        }
        String[] parts = ns.split(":");
        if (namespaces.containsKey(parts[0])) {
            return namespaces.get(parts[0]).replace("{rel}", parts[1]);
        } else {
            throw new RepresentationException("Unknown namespace key: " + parts[0]);
        }
    }
View Full Code Here

    public Object getValue(String name) {
        if (properties.containsKey(name)) {
            return properties.get(name);
        } else {
            throw new RepresentationException("Resource does not contain " + name);
        }
    }
View Full Code Here

     */
    public <T> T toClass(Class<T> anInterface) {
        if (InterfaceContract.newInterfaceContract(anInterface).isSatisfiedBy(this)) {
            return InterfaceRenderer.newInterfaceRenderer(anInterface).render(this);
        } else {
            throw new RepresentationException("Unable to write representation to " + anInterface.getName());
        }
    }
View Full Code Here

TOP

Related Classes of com.theoryinpractise.halbuilder.api.RepresentationException

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.