Package org.apache.isis.core.metamodel.adapter

Examples of org.apache.isis.core.metamodel.adapter.ObjectAdapter


        this.underlyingFacet = underlyingFacet;
    }

    @Override
    public ObjectAdapter invoke(final ObjectAction owningAction, final ObjectAdapter targetAdapter, final ObjectAdapter[] parameterAdapters) {
        final ObjectAdapter result = getTransactionManager().executeWithinTransaction(new TransactionalClosureWithReturnAbstract<ObjectAdapter>() {
            @Override
            public ObjectAdapter execute() {
                return underlyingFacet.invoke(owningAction, targetAdapter, parameterAdapters);
            }
        });
View Full Code Here


        return result;
    }

    @Override
    public ObjectAdapter invoke(final ObjectAdapter targetAdapter, final ObjectAdapter[] parameterAdapters) {
        final ObjectAdapter result = getTransactionManager().executeWithinTransaction(new TransactionalClosureWithReturnAbstract<ObjectAdapter>() {
            @Override
            public ObjectAdapter execute() {
                return underlyingFacet.invoke(targetAdapter, parameterAdapters);
            }
        });
View Full Code Here

        if (LOG.isDebugEnabled()) {
            LOG.debug("includeField(: " + log("place", place) + andlog("fieldNames", fieldNames) + andlog("annotation", annotation) + ")");
        }

        final ObjectAdapter object = place.getObject();
        final Element xmlElement = place.getXmlElement();

        // we use a copy of the path so that we can safely traverse collections
        // without side-effects
        final Vector originalNames = fieldNames;
        final Vector names = new Vector();
        for (final java.util.Enumeration e = originalNames.elements(); e.hasMoreElements();) {
            names.addElement(e.nextElement());
        }

        // see if we have any fields to process
        if (names.size() == 0) {
            return true;
        }

        // take the first field name from the list, and remove
        final String fieldName = (String) names.elementAt(0);
        names.removeElementAt(0);

        if (LOG.isDebugEnabled()) {
            LOG.debug("includeField(Pl, Vec, Str):" + log("processing field", fieldName) + andlog("left", "" + names.size()));
        }

        // locate the field in the object's class
        final ObjectSpecification nos = object.getSpecification();
        ObjectAssociation field = null;
        try {
            // HACK: really want a ObjectSpecification.hasField method to
            // check first.
            field = nos.getAssociation(fieldName);
        } catch (final ObjectSpecificationException ex) {
            if (LOG.isInfoEnabled()) {
                LOG.info("includeField(Pl, Vec, Str): could not locate field, skipping");
            }
            return false;
        }

        // locate the corresponding XML element
        // (the corresponding XSD element will later be attached to xmlElement
        // as its userData)
        if (LOG.isDebugEnabled()) {
            LOG.debug("includeField(Pl, Vec, Str): locating corresponding XML element");
        }
        final Vector xmlFieldElements = elementsUnder(xmlElement, field.getId());
        if (xmlFieldElements.size() != 1) {
            if (LOG.isInfoEnabled()) {
                LOG.info("includeField(Pl, Vec, Str): could not locate " + log("field", field.getId()) + andlog("xmlFieldElements.size", "" + xmlFieldElements.size()));
            }
            return false;
        }
        final Element xmlFieldElement = (Element) xmlFieldElements.elementAt(0);

        if (names.size() == 0 && annotation != null) {
            // nothing left in the path, so we will apply the annotation now
            isisMetaModel.setAnnotationAttribute(xmlFieldElement, annotation);
        }

        final Place fieldPlace = new Place(object, xmlFieldElement);

        if (field instanceof OneToOneAssociation) {
            if (field.getSpecification().getAssociations(Contributed.EXCLUDED).size() == 0) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("includeField(Pl, Vec, Str): field is value; done");
                }
                return false;
            }

            if (LOG.isDebugEnabled()) {
                LOG.debug("includeField(Pl, Vec, Str): field is 1->1");
            }

            final OneToOneAssociation oneToOneAssociation = ((OneToOneAssociation) field);
            final ObjectAdapter referencedObject = oneToOneAssociation.get(fieldPlace.getObject());

            if (referencedObject == null) {
                return true; // not a failure if the reference was null
            }

            final boolean appendedXml = appendXmlThenIncludeRemaining(fieldPlace, referencedObject, names, annotation);
            if (LOG.isDebugEnabled()) {
                LOG.debug("includeField(Pl, Vec, Str): 1->1: invoked appendXmlThenIncludeRemaining for " + log("referencedObj", referencedObject) + andlog("returned", "" + appendedXml));
            }

            return appendedXml;

        } else if (field instanceof OneToManyAssociation) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("includeField(Pl, Vec, Str): field is 1->M");
            }

            final OneToManyAssociation oneToManyAssociation = (OneToManyAssociation) field;
            final ObjectAdapter collection = oneToManyAssociation.get(fieldPlace.getObject());
            final CollectionFacet facet = collection.getSpecification().getFacet(CollectionFacet.class);

            if (LOG.isDebugEnabled()) {
                LOG.debug("includeField(Pl, Vec, Str): 1->M: " + log("collection.size", "" + facet.size(collection)));
            }
            boolean allFieldsNavigated = true;
View Full Code Here

                final Element xmlValueElement = xmlFieldElement; // more
                                                                 // meaningful
                                                                 // locally
                                                                 // scoped name

                ObjectAdapter value;
                try {
                    value = valueAssociation.get(adapter);

                    final ObjectSpecification valueNos = value.getSpecification();

                    // XML
                    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);
                    if (notEmpty) {
                        xmlValueElement.appendChild(getXmlDocument().createTextNode(valueStr));
                    } else {
                        isisMetaModel.setIsEmptyAttribute(xmlValueElement, true);
                    }

                } catch (final Exception ex) {
                    LOG.warn("objectToElement(NO): " + log("field", fieldName) + ": getField() threw exception - skipping XML generation");
                }

                // XSD
                xsdFieldElement = schema.createXsElementForNofValue(xsElement, xmlValueElement, FacetUtil.getFacetsByType(valueAssociation));

            } else if (field instanceof OneToOneAssociation) {

                if (LOG.isDebugEnabled()) {
                    LOG.debug("objectToElement(NO): " + log("field", fieldName) + " is OneToOneAssociation");
                }

                final OneToOneAssociation oneToOneAssociation = ((OneToOneAssociation) field);
                final String fullyQualifiedClassName = nos.getFullIdentifier();
                final Element xmlReferenceElement = xmlFieldElement; // more
                                                                     // meaningful
                                                                     // locally
                                                                     // scoped
                                                                     // name

                ObjectAdapter referencedObjectAdapter;

                try {
                    referencedObjectAdapter = oneToOneAssociation.get(adapter);

                    // XML
                    isisMetaModel.setAttributesForReference(xmlReferenceElement, schema.getPrefix(), fullyQualifiedClassName);

                    if (referencedObjectAdapter != null) {
                        isisMetaModel.appendIsisTitle(xmlReferenceElement, referencedObjectAdapter.titleString());
                    } else {
                        isisMetaModel.setIsEmptyAttribute(xmlReferenceElement, true);
                    }

                } catch (final Exception ex) {
                    LOG.warn("objectToElement(NO): " + log("field", fieldName) + ": getAssociation() threw exception - skipping XML generation");
                }

                // XSD
                xsdFieldElement = schema.createXsElementForNofReference(xsElement, xmlReferenceElement, oneToOneAssociation.getSpecification().getFullIdentifier(), FacetUtil.getFacetsByType(oneToOneAssociation));

            } else if (field instanceof OneToManyAssociation) {

                if (LOG.isDebugEnabled()) {
                    LOG.debug("objectToElement(NO): " + log("field", fieldName) + " is OneToManyAssociation");
                }

                final OneToManyAssociation oneToManyAssociation = (OneToManyAssociation) field;
                final Element xmlCollectionElement = xmlFieldElement; // more
                                                                      // meaningful
                                                                      // locally
                                                                      // scoped
                                                                      // name

                ObjectAdapter collection;
                try {
                    collection = oneToManyAssociation.get(adapter);
                    final ObjectSpecification referencedTypeNos = oneToManyAssociation.getSpecification();
                    final String fullyQualifiedClassName = referencedTypeNos.getFullIdentifier();
View Full Code Here

    // //////////////////////////////////////
   
    @Override
    public Clob downloadLayout(Object domainObject) {
       
        final ObjectAdapter adapterFor = adapterManager.adapterFor(domainObject);
        final ObjectSpecification objectSpec = adapterFor.getSpecification();
       
        final LayoutMetadataReaderFromJson propertiesReader = new LayoutMetadataReaderFromJson();
        final String json = propertiesReader.asJson(objectSpec);
       
        return new Clob(objectSpec.getShortIdentifier() +".layout.json", mimeTypeApplicationJson, json);
View Full Code Here

       
        // given
        iswf.persist(iswf.fixtures.smpl2);
        iswf.bounceSystem();

        final ObjectAdapter retrievedAdapter = getStore().loadInstanceAndAdapt((TypedOid) epv2Adapter.getOid());
       
        assertNotSame(epv2Adapter, retrievedAdapter);
        assertEquals(((SimpleEntity)epv2Adapter.getObject()).getName(), ((SimpleEntity)retrievedAdapter.getObject()).getName());
        assertEquals(epv2Adapter.getOid(), retrievedAdapter.getOid());
    }
View Full Code Here

        // when
        final List<ObjectAdapter> retrievedAdapters = getStore().loadInstancesAndAdapt(new PersistenceQueryFindByTitle(epvSpecification, epv2Adapter.titleString()));
       
        // then
        assertEquals(1, retrievedAdapters.size());
        final ObjectAdapter retrievedAdapter = retrievedAdapters.get(0);

        assertNotSame(epv2Adapter, retrievedAdapter);
        assertEquals(((SimpleEntity)epv2Adapter.getObject()).getName(), ((SimpleEntity)retrievedAdapter.getObject()).getName());
        assertEquals(epv2Adapter.getOid(), retrievedAdapter.getOid());
    }
View Full Code Here

        // when
        final List<ObjectAdapter> retrievedAdapters = getStore().loadInstancesAndAdapt(new PersistenceQueryFindAllInstances(epvSpecification));
       
        // then
        assertEquals(1, retrievedAdapters.size());
        final ObjectAdapter retrievedAdapter = retrievedAdapters.get(0);

        assertNotSame(epv2Adapter, retrievedAdapter);
        assertEquals(((SimpleEntity)epv2Adapter.getObject()).getName(), ((SimpleEntity)retrievedAdapter.getObject()).getName());
        assertEquals(epv2Adapter.getOid(), retrievedAdapter.getOid());
    }
View Full Code Here

        // when
        final List<ObjectAdapter> retrievedAdapters = getStore().loadInstancesAndAdapt(new PersistenceQueryFindAllInstances(epvSpecification, 2, 2));
       
        // then
        assertEquals(2, retrievedAdapters.size());
        final ObjectAdapter retrievedAdapter = retrievedAdapters.get(0);

        assertNotSame(epv4Adapter, retrievedAdapter);
        assertEquals(((SimpleEntity)epv4Adapter.getObject()).getName(), ((SimpleEntity)retrievedAdapter.getObject()).getName());
        assertEquals(epv4Adapter.getOid(), retrievedAdapter.getOid());
    }
View Full Code Here

    }

    public ObjectAdapter remapAsPersistent(Object pojo, RootOid persistentOid) {
        ensureSessionInProgress();
        ensureObjectIsNotPersistent(pojo);
        final ObjectAdapter adapter = adapterFor(pojo);
        getPersistenceSession().remapAsPersistent(adapter, persistentOid);
        return adapter;
    }
View Full Code Here

TOP

Related Classes of org.apache.isis.core.metamodel.adapter.ObjectAdapter

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.