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

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


        throw new UnsupportedOperationException("no mediaType defined for scalar values");
    }
   
    @Override
    public ScalarValueReprRenderer with(final ObjectAdapter objectAdapter) {
        final EncodableFacet facet = objectAdapter.getSpecification().getFacet(EncodableFacet.class);
        if (facet == null) {
            throw ReprRendererException.create("Not an (encodable) value", objectAdapter.titleString());
        }
        final Object value = JsonValueEncoder.asObject(objectAdapter);
View Full Code Here


        if (objectSpec == null) {
            String reason = "ObjectSpec is null, cannot validate";
            argRepr.mapPut("invalidReason", reason);
            throw new IllegalArgumentException(reason);
        }
        final EncodableFacet encodableFacet = objectSpec.getFacet(EncodableFacet.class);
        if (encodableFacet == null) {
            String reason = "ObjectSpec expected to have an EncodableFacet";
            argRepr.mapPut("invalidReason", reason);
            throw new IllegalArgumentException(reason);
        }
       
        if(!argRepr.mapHas("value")) {
            String reason = "No 'value' key";
            argRepr.mapPut("invalidReason", reason);
            throw new IllegalArgumentException(reason);
        }
        final JsonRepresentation argValueRepr = argRepr.getRepresentation("value");
        if(argValueRepr == null) {
            return null;
        }
        if (!argValueRepr.isValue()) {
            String reason = "Representation must be of a value";
            argRepr.mapPut("invalidReason", reason);
            throw new IllegalArgumentException(reason);
        }

        final JsonValueConverter jvc = converterBySpec.get(objectSpec.getSpecId());
        if(jvc == null) {
            // best effort
            if (argValueRepr.isString()) {
                final String argStr = argValueRepr.asString();
                return encodableFacet.fromEncodedString(argStr);
            }

            final String reason = "Unable to parse value";
            argRepr.mapPut("invalidReason", reason);
            throw new IllegalArgumentException(reason);
        }

        final ObjectAdapter asAdapter = jvc.asAdapter(argValueRepr);
        if(asAdapter != null) {
            return asAdapter;
        }
       
        // last attempt
        if (argValueRepr.isString()) {
            final String argStr = argValueRepr.asString();
            return encodableFacet.fromEncodedString(argStr);
        }

        final String reason = "Could not parse value '" + argValueRepr.asString() + "' as a " + objectSpec.getFullIdentifier();
        argRepr.mapPut("invalidReason", reason);
        throw new IllegalArgumentException(reason);
View Full Code Here

        final JsonValueConverter jvc = converterBySpec.get(objectSpec.getSpecId());
        if(jvc != null) {
            jvc.appendValueAndFormat(objectAdapter, repr);
        } else {
            final EncodableFacet encodableFacet = objectSpec.getFacet(EncodableFacet.class);
            if (encodableFacet == null) {
                throw new IllegalArgumentException("objectSpec expected to have EncodableFacet");
            }
            Object value = objectAdapter != null? encodableFacet.toEncodedString(objectAdapter): NullNode.getInstance();
            append(repr, value, "string", "string");
        }
    }
View Full Code Here

        if(jvc != null) {
            return jvc.asObject(objectAdapter);
        }
       
        // else
        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

            if(returnedAdapter != null) {
                final ScalarValueReprRenderer renderer = new ScalarValueReprRenderer(rendererContext, null, result);
View Full Code Here

                    final ObjectAdapter adapter = getAdapterManager().adapterFor(object);
                    Oid oid = adapter.getOid();
                    return oid != null? oid.enString(getOidMarshaller()): encodedValueOf(adapter);
                }
                private String encodedValueOf(ObjectAdapter adapter) {
                    EncodableFacet facet = adapter.getSpecification().getFacet(EncodableFacet.class);
                    return facet != null? facet.toEncodedString(adapter): adapter.toString();
                }
                @Override
                public String classNameOf(Object object) {
                    final ObjectAdapter adapter = getAdapterManager().adapterFor(object);
                    final String className = adapter.getSpecification().getFullIdentifier();
View Full Code Here

            this.objectAsSerializable = (Serializable) object;
            initialized();
            return;
        }

        final EncodableFacet encodeableFacet = adapter.getSpecification().getFacet(EncodableFacet.class);
        if (encodeableFacet != null) {
            this.objectAsEncodedString = encodeableFacet.toEncodedString(adapter);
            initialized();
            return;
        }

        throw new IllegalArgumentException("Object wrapped by standalone adapter is not serializable and its specificatoin does not have an EncodeableFacet");
View Full Code Here

    public ObjectAdapter getAdapter() {
        if (objectAsSerializable != null) {
            return IsisContext.getPersistenceSession().getAdapterManager().adapterFor(objectAsSerializable);
        } else {
            final ObjectSpecification spec = IsisContext.getSpecificationLoader().loadSpecification(getClassName());
            final EncodableFacet encodeableFacet = spec.getFacet(EncodableFacet.class);
            return encodeableFacet.fromEncodedString(objectAsEncodedString);
        }
    }
View Full Code Here

                    isisMetaModel.setAttributesForValue(xmlValueElement, valueNos.getShortIdentifier());

                    // return parsed string, else encoded string, else title.
                    String valueStr;
                    final ParseableFacet parseableFacet = fieldNos.getFacet(ParseableFacet.class);
                    final EncodableFacet encodeableFacet = fieldNos.getFacet(EncodableFacet.class);
                    if (parseableFacet != null) {
                        valueStr = parseableFacet.parseableTitle(value);
                    } else if (encodeableFacet != null) {
                        valueStr = encodeableFacet.toEncodedString(value);
                    } else {
                        valueStr = value.titleString();
                    }

                    final boolean notEmpty = (valueStr.length() > 0);
View Full Code Here

        Object assocData;
        if (objectAssoc.isOneToManyAssociation()) {
            final ObjectAdapter collAdapter = objectAssoc.get(adapter);
            assocData = createCollectionData(collAdapter);
        } else if (objectAssoc.getSpecification().isEncodeable()) {
            final EncodableFacet facet = objectAssoc.getSpecification().getFacet(EncodableFacet.class);
            final ObjectAdapter value = objectAssoc.get(adapter);
            assocData = facet.toEncodedString(value);
        } else if (objectAssoc.isOneToOneAssociation()) {
            final ObjectAdapter referencedAdapter = ((OneToOneAssociation) objectAssoc).get(adapter);
            assocData = createReferenceData(referencedAdapter);
        } else {
            throw new UnknownTypeException(objectAssoc);
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.