
org.nakedobjects.plugins.remoting.client.facets.CollectionRemoveFromFacetWrapProxy Maven / Gradle / Ivy
package org.nakedobjects.plugins.remoting.client.facets;
import org.apache.log4j.Logger;
import org.nakedobjects.metamodel.adapter.NakedObject;
import org.nakedobjects.metamodel.commons.exceptions.NakedObjectException;
import org.nakedobjects.metamodel.facets.DecoratingFacet;
import org.nakedobjects.metamodel.facets.collections.modify.CollectionRemoveFromFacet;
import org.nakedobjects.metamodel.facets.collections.modify.CollectionRemoveFromFacetAbstract;
import org.nakedobjects.plugins.remoting.shared.ObjectEncoder;
import org.nakedobjects.plugins.remoting.shared.ServerFacade;
import org.nakedobjects.plugins.remoting.shared.data.IdentityData;
import org.nakedobjects.plugins.remoting.shared.data.ObjectData;
import org.nakedobjects.runtime.context.NakedObjectsContext;
import org.nakedobjects.runtime.persistence.ConcurrencyException;
/**
* A reflection peer for changing one-to-many fields remotely, instead of on the local machine. Any requests
* to add or remove elements from the field will be passed over the network to the server for completion. Only
* requests on persistent objects are passed to the server; on a transient object the request will always be
* dealt with locally.
*
*
* If any of the objects involved have been changed on the server by another process then a
* ConcurrencyException will be passed back to the client and re-thrown.
*
*/
public final class CollectionRemoveFromFacetWrapProxy extends CollectionRemoveFromFacetAbstract implements
DecoratingFacet {
private final static Logger LOG = Logger.getLogger(CollectionRemoveFromFacetWrapProxy.class);
private final ServerFacade connection;
private final ObjectEncoder encoder;
private final CollectionRemoveFromFacet underlyingFacet;
private final String name;
public CollectionRemoveFromFacetWrapProxy(
final CollectionRemoveFromFacet underlyingFacet,
final ServerFacade connection,
final ObjectEncoder encoder,
final String name) {
super(underlyingFacet.getFacetHolder());
this.underlyingFacet = underlyingFacet;
this.connection = connection;
this.encoder = encoder;
this.name = name;
}
public CollectionRemoveFromFacet getDecoratedFacet() {
return underlyingFacet;
}
/**
* Remove an associated object (the element) from the specified NakedObject in the association field
* represented by this object.
*/
public void remove(final NakedObject inObject, final NakedObject associate) {
if (ProxyUtil.executeRemotely(inObject)) {
LOG.debug("clear association remotely " + inObject + "/" + associate);
try {
final IdentityData targetReference = encoder.createIdentityData(inObject);
final IdentityData associateReference = encoder.createIdentityData(associate);
ObjectData[] updates;
updates = connection
.clearAssociation(NakedObjectsContext.getAuthenticationSession(), name, targetReference, associateReference);
ProxyUtil.updateChangedObjects(updates, encoder);
} catch (final ConcurrencyException e) {
throw ProxyUtil.concurrencyException(e);
} catch (final NakedObjectException e) {
LOG.error("remote exception: " + e.getMessage(), e);
throw e;
}
} else {
LOG.debug("clear association locally " + inObject + "/" + associate);
underlyingFacet.remove(inObject, associate);
}
}
}
// Copyright (c) Naked Objects Group Ltd.
© 2015 - 2025 Weber Informatics LLC | Privacy Policy