Package org.apache.isis.core.metamodel.facets.object.encodeable

Examples of org.apache.isis.core.metamodel.facets.object.encodeable.EncodableFacet


        return description;
    }

    @Override
    public void undo() {
        final EncodableFacet facet = value.getFacet(EncodableFacet.class);
        final Object obj = facet.fromEncodedString(oldValue);
        final ObjectAdapter adapter = getAdapterManager().adapterFor(obj);
        value.setAssociation(object, adapter);
        // have commented this out because it isn't needed; the transaction
        // manager will do this
        // for us on endTransaction. Still, if I'm wrong and it is needed,
View Full Code Here


        super(resourceContext, linkFollower, representationType, representation);
    }

    @Override
    public ScalarValueReprRenderer with(final ObjectAdapter objectAdapter) {
        final EncodableFacet facet = objectAdapter.getSpecification().getFacet(EncodableFacet.class);
        if (facet == null) {
            throw JsonApplicationException.create(HttpStatusCode.INTERNAL_SERVER_ERROR, "Not an (encodable) value", objectAdapter.titleString());
        }
        final Object value = jsonValueEncoder.asObject(objectAdapter);
View Full Code Here

    public ObjectAdapter asAdapter(final ObjectSpecification objectSpec, final JsonRepresentation representation) {
        if (objectSpec == null) {
            throw new IllegalArgumentException("objectSpec cannot be null");
        }
        final EncodableFacet encodableFacet = objectSpec.getFacet(EncodableFacet.class);
        if (encodableFacet == null) {
            throw new IllegalArgumentException("objectSpec expected to have EncodableFacet");
        }
        if (representation == null) {
            throw new IllegalArgumentException("representation cannot be null");
        }
        if (!representation.isValue()) {
            throw new IllegalArgumentException("representation must be of a value");
        }

        // special case handling for JSON built-ins
        if (isBoolean(objectSpec)) {
            if (!representation.isBoolean()) {
                throwIncompatibleException(objectSpec, representation);
            }
            final String argStr = "" + representation.asBoolean();
            return encodableFacet.fromEncodedString(argStr);
        }

        if (isInteger(objectSpec)) {
            if (representation.isInt()) {
                final String argStr = "" + representation.asInt();
                return encodableFacet.fromEncodedString(argStr);
            }
            // best effort
            if (representation.isString()) {
                final String argStr = representation.asString();
                return encodableFacet.fromEncodedString(argStr);
            }
            // give up
            throwIncompatibleException(objectSpec, representation);
        }

        if (isLong(objectSpec)) {
            if (!representation.isLong()) {
                throwIncompatibleException(objectSpec, representation);
            }
            final String argStr = "" + representation.asLong();
            return encodableFacet.fromEncodedString(argStr);
        }

        if (isBigInteger(objectSpec)) {
            if (representation.isBigInteger()) {
                final String argStr = "" + representation.asBigInteger();
                return encodableFacet.fromEncodedString(argStr);
            }
            // best effort
            if (representation.isLong()) {
                final String argStr = "" + representation.asLong();
                return encodableFacet.fromEncodedString(argStr);
            }
            if (representation.isInt()) {
                final String argStr = "" + representation.asInt();
                return encodableFacet.fromEncodedString(argStr);
            }
            if (representation.isString()) {
                final String argStr = representation.asString();
                return encodableFacet.fromEncodedString(argStr);
            }
            // give up
            throwIncompatibleException(objectSpec, representation);
        }

        if (isBigDecimal(objectSpec)) {
            if (representation.isBigDecimal()) {
                final String argStr = "" + representation.asBigDecimal();
                return encodableFacet.fromEncodedString(argStr);
            }
            // best effort
            if (representation.isBigInteger()) {
                final String argStr = "" + representation.asBigInteger();
                return encodableFacet.fromEncodedString(argStr);
            }
            if (representation.isDouble()) {
                final String argStr = "" + representation.asDouble();
                return encodableFacet.fromEncodedString(argStr);
            }
            if (representation.isLong()) {
                final String argStr = "" + representation.asLong();
                return encodableFacet.fromEncodedString(argStr);
            }
            if (representation.isInt()) {
                final String argStr = "" + representation.asInt();
                return encodableFacet.fromEncodedString(argStr);
            }
            if (representation.isString()) {
                final String argStr = representation.asString();
                return encodableFacet.fromEncodedString(argStr);
            }
            // give up
            throwIncompatibleException(objectSpec, representation);
        }

        if (isDouble(objectSpec)) {
            if (representation.isDouble()) {
                final String argStr = "" + representation.asDouble();
                return encodableFacet.fromEncodedString(argStr);
            }
            // best effort
            if (representation.isLong()) {
                final String argStr = "" + representation.asLong();
                return encodableFacet.fromEncodedString(argStr);
            }
            if (representation.isInt()) {
                final String argStr = "" + representation.asInt();
                return encodableFacet.fromEncodedString(argStr);
            }
            if (representation.isString()) {
                final String argStr = representation.asString();
                return encodableFacet.fromEncodedString(argStr);
            }
            // give up
            throwIncompatibleException(objectSpec, representation);
        }

        if (!representation.isString()) {
            throw new ExpectedStringRepresentingValueException();
        }
        final String argStr = representation.asString();
        return encodableFacet.fromEncodedString(argStr);
    }
View Full Code Here

        if (isBoolean(objectSpec) || isInteger(objectSpec) || isLong(objectSpec) || isBigInteger(objectSpec) || isDouble(objectSpec) || isBigDecimal(objectSpec)) {
            // simply return
            return objectAdapter.getObject();
        }

        final EncodableFacet encodableFacet = objectSpec.getFacet(EncodableFacet.class);
        if (encodableFacet == null) {
            throw new IllegalArgumentException("objectSpec expected to have EncodableFacet");
        }
        return encodableFacet.toEncodedString(objectAdapter);
    }
View Full Code Here

            renderer.render();
            return ResultType.LIST;
        }

        final EncodableFacet encodableFacet = returnType.getFacet(EncodableFacet.class);
        if (encodableFacet != null) {
            // scalar

            final RendererFactory factory = getRendererFactoryRegistry().find(RepresentationType.SCALAR_VALUE);
View Full Code Here

        // Root object specification
        final ObjectSpecification rootSpecification = mockery.mock(ObjectSpecification.class);
        final OneToOneAssociation nameField = mockery.mock(OneToOneAssociation.class);
        final ObjectSpecification nameSpecification = mockery.mock(ObjectSpecification.class, "name specification");
        final EncodableFacet encodeableFacet = mockery.mock(EncodableFacet.class);

        mockery.checking(new Expectations() {
            {
                atLeast(1).of(rootSpecification).isCollection();
                will(returnValue(false));
View Full Code Here

            final ObjectAdapter fieldValue = association.get(object);
            final String fieldName = association.getId();
            if (fieldValue == null) {
                data.put(fieldName, (Object) null);
            } else if (association.getSpecification().isEncodeable()) {
                final EncodableFacet encodeableFacet = fieldValue.getSpecification().getFacet(EncodableFacet.class);
                data.put(fieldName, encodeableFacet.toEncodedString(fieldValue));
            } else if (association instanceof OneToManyAssociation) {
                final List<JSONObject> collection = new ArrayList<JSONObject>();
                final CollectionFacet facet = fieldValue.getSpecification().getFacet(CollectionFacet.class);
                for (final ObjectAdapter element : facet.iterable(fieldValue)) {
                    collection.add(encodeTransientData(element, savedObject));
View Full Code Here

            if (association.getSpecification().isEncodeable()) {
                if (fieldValue == null) {
                    ((OneToOneAssociation) association).initAssociation(object, null);
                } else {
                    final EncodableFacet encodeableFacet = association.getSpecification().getFacet(EncodableFacet.class);
                    final ObjectAdapter fromEncodedString = encodeableFacet.fromEncodedString((String) fieldValue);
                    ((OneToOneAssociation) association).initAssociation(object, fromEncodedString);
                }
            } else if (association instanceof OneToManyAssociation) {
                final JSONArray collection = (JSONArray) fieldValue;
                for (int i = 0; i < collection.length(); i++) {
View Full Code Here

        captureTitleHintIfPossible(adapter);
    }

    private void init(final ObjectAdapter adapter) {
        final ObjectSpecification specification = specMemento.getSpecification();
        final EncodableFacet encodableFacet = specification.getFacet(EncodableFacet.class);
        final boolean isEncodable = encodableFacet != null;
        if (isEncodable) {
            encodableValue = encodableFacet.toEncodedString(adapter);
            type = Type.ENCODEABLE;
        } else {
            final Oid oid = adapter.getOid();
            if (oid.isTransient()) {
                transientMemento = new Memento(adapter);
View Full Code Here

    public void testFacetPickedUp() {

        facetFactory.process(new ProcessClassContext(MyEncodableUsingEncoderDecoderName.class, methodRemover, facetedMethod));

        final EncodableFacet facet = facetedMethod.getFacet(EncodableFacet.class);
        assertNotNull(facet);
        assertTrue(facet instanceof EncodableFacetAbstract);
    }
View Full Code Here

TOP

Related Classes of org.apache.isis.core.metamodel.facets.object.encodeable.EncodableFacet

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.