Link zum Editieren der verknüpften Adresse bei Contact entfernt. Hat bereits mehrfach dazu geführt der zentrale

Adressdatensatz einer Einrichtung versehentlich verändert wurde.

DomainObjectztFactory: Formatierung 
Instituts verändert wurde


git-svn-id: https://svn.libreccm.org/ccm/trunk@1534 8810af33-2d31-482b-a856-94f89814c4df
master
jensp 2012-03-07 08:02:01 +00:00
parent 0eb2cad432
commit 79cf36996a
2 changed files with 142 additions and 140 deletions

View File

@ -69,11 +69,11 @@ public class GenericContactAddressPropertiesStep extends SimpleEditStep {
localize(), new EditAddressWorkflowLockedComponentAccess( localize(), new EditAddressWorkflowLockedComponentAccess(
reattachAddressSheet, itemModel), reattachAddressSheet. reattachAddressSheet, itemModel), reattachAddressSheet.
getSaveCancelSection().getCancelButton()); getSaveCancelSection().getCancelButton());
add(EDIT_ADDRESS_SHEET_NAME, (String) ContenttypesGlobalizationUtil. /*add(EDIT_ADDRESS_SHEET_NAME, (String) ContenttypesGlobalizationUtil.
globalize("cms.contenttypes.ui.contact.edit_address").localize(), globalize("cms.contenttypes.ui.contact.edit_address").localize(),
new EditAddressWorkflowLockedComponentAccess(editAddressSheet, new EditAddressWorkflowLockedComponentAccess(editAddressSheet,
itemModel), itemModel),
editAddressSheet.getSaveCancelSection().getCancelButton()); editAddressSheet.getSaveCancelSection().getCancelButton());*/
add(DELETE_ADDRESS_SHEET_NAME, add(DELETE_ADDRESS_SHEET_NAME,
(String) ContenttypesGlobalizationUtil.globalize( (String) ContenttypesGlobalizationUtil.globalize(
"cms.contenttypes.ui.contact.delete_address").localize(), "cms.contenttypes.ui.contact.delete_address").localize(),

View File

@ -34,34 +34,31 @@ import java.util.HashMap;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
/** /**
* This is a factory class to support instantiation of an appropriate * This is a factory class to support instantiation of an appropriate domain
* domain object class from a given data object. * object class from a given data object. <p> The architecture of the
* <p> * persistence and domain layers intentionally does not impose a simple
* The architecture of the persistence and domain layers intentionally * one-to-one correspondence between data object types and domain object
* does not impose a simple one-to-one correspondence between data object * classes. It is possible for multiple domain object classes to encapsulate a
* types and domain object classes. It is possible for multiple domain * given data object. It is also possible that a single domain object class can
* object classes to encapsulate a given data object. It is also possible * encapsulate data objects of different types. The primary factory design
* that a single domain object class can encapsulate data objects of * objectives are:
* different types. The primary factory design objectives are:
* *
* <ol> * <ol> <li> It should be easy for developers to produce a domain object from a
* <li> It should be easy for developers to produce a domain object from * given data object when it cannot be determined at compile time which domain
* a given data object when it cannot be determined at compile time * object class should be instantiated.
* which domain object class should be instantiated.
* *
* <li> The process of instantiating a domain object given a data object * <li> The process of instantiating a domain object given a data object should
* should be as flexible as possible by delegating to custom code, called * be as flexible as possible by delegating to custom code, called a
* a <code>DomainObjectInstantiator</code>, that can make use of any * <code>DomainObjectInstantiator</code>, that can make use of any properties of
* properties of the given data object. * the given data object.
* *
* <li> A data object of type X is not supported by the factory * <li> A data object of type X is not supported by the factory unless some
* unless some <code>DomainObjectInstantiator</code> has been registered * <code>DomainObjectInstantiator</code> has been registered with the factory
* with the factory for type X, and even then, it may be possible for * for type X, and even then, it may be possible for the instantiator code to
* the instantiator code to examine other properties of the data object * examine other properties of the data object and decide that the given data
* and decide that the given data object is not supported (presumably * object is not supported (presumably because there is no sensible way to
* because there is no sensible way to choose which domain object class * choose which domain object class should be instantiated for the particular
* should be instantiated for the particular data object). * data object). </ol>
* </ol>
* *
* @see DomainObjectInstantiator * @see DomainObjectInstantiator
* @see com.arsdigita.persistence.DataObject * @see com.arsdigita.persistence.DataObject
@ -70,14 +67,19 @@ import org.apache.log4j.Logger;
* @author Oumi Mehrotra * @author Oumi Mehrotra
* @version 1.0 * @version 1.0
* @version $Id: DomainObjectFactory.java 2170 2011-06-19 22:23:08Z pboy $ * @version $Id: DomainObjectFactory.java 2170 2011-06-19 22:23:08Z pboy $
**/ *
*/
public class DomainObjectFactory { public class DomainObjectFactory {
/** map of registered instantiators, keyed by data object type. */ /**
* map of registered instantiators, keyed by data object type.
*/
private static Map s_instantiators = new HashMap(); private static Map s_instantiators = new HashMap();
/**
/** private logger instance. */ * private logger instance.
private static final Logger s_log = Logger.getLogger(DomainObjectFactory.class); */
private static final Logger s_log = Logger.getLogger(
DomainObjectFactory.class);
/** /**
* Instantiates a domain object given a data object. * Instantiates a domain object given a data object.
@ -88,17 +90,19 @@ public class DomainObjectFactory {
* object.</p> * object.</p>
* *
* <p>The result may be null if there is no instantiator registered for the * <p>The result may be null if there is no instantiator registered for the
* dataObjectType of the specified <code>dataObject</code>, OR if the registered * dataObjectType of the specified
* instantiator does not support instantiation of the specified * <code>dataObject</code>, OR if the registered instantiator does not
* support instantiation of the specified
* <code>dataObject</code>.</p> * <code>dataObject</code>.</p>
* *
* @param dataObject The data object from which to instantiate * @param dataObject The data object from which to instantiate a domain
* a domain object. * object.
* *
* @return A domain object that encapuslates the given dataObject. Returns * @return A domain object that encapuslates the given dataObject. Returns
* <code>null</code>, if called with the <code>null</code> data object * <code>null</code>, if called with the
* parameter. The result may also be <code>null</code> if no domain object * <code>null</code> data object parameter. The result may also be
* could be instantiated for the given data object. * <code>null</code> if no domain object could be instantiated for the given
* data object.
* *
* @throws InstantiatorNotFoundException if no Instantiator could be found * @throws InstantiatorNotFoundException if no Instantiator could be found
* @throws PersistenceException * @throws PersistenceException
@ -109,17 +113,21 @@ public class DomainObjectFactory {
public static DomainObject newInstance(DataObject dataObject) public static DomainObject newInstance(DataObject dataObject)
throws PersistenceException, InstantiatorNotFoundException { throws PersistenceException, InstantiatorNotFoundException {
if ( dataObject == null ) { return null; } if (dataObject == null) {
return null;
}
if (s_log.isInfoEnabled()) { if (s_log.isInfoEnabled()) {
s_log.info("Instantiating " + dataObject.getOID()); s_log.info("Instantiating " + dataObject.getOID());
} }
/* A instantiator may delegate to another instantiator depending on the /*
data object. That other instantiator may in turn delegate to * A instantiator may delegate to another instantiator depending on the
a different instantiator, and so on. We get the final instantiator * data object. That other instantiator may in turn delegate to a
by recursed calls to resolveInstantiator until the returned * different instantiator, and so on. We get the final instantiator by
instantiator doesn't change. */ * recursed calls to resolveInstantiator until the returned instantiator
* doesn't change.
*/
DomainObjectInstantiator delegator = null; DomainObjectInstantiator delegator = null;
DomainObjectInstantiator delegate = DomainObjectInstantiator delegate =
@ -129,7 +137,9 @@ public class DomainObjectFactory {
s_log.debug("Initial delegate " + delegate); s_log.debug("Initial delegate " + delegate);
} }
/* keep calling resolveInstantiator until the result doesn't change */ /*
* keep calling resolveInstantiator until the result doesn't change
*/
while (delegate != null && delegate != delegator) { while (delegate != null && delegate != delegator) {
delegator = delegate; delegator = delegate;
delegate = delegator.resolveInstantiator(dataObject); delegate = delegator.resolveInstantiator(dataObject);
@ -140,8 +150,7 @@ public class DomainObjectFactory {
if (delegate == null) { if (delegate == null) {
throw new InstantiatorNotFoundException( throw new InstantiatorNotFoundException(
"No instantiator found for dataObject " + dataObject "No instantiator found for dataObject " + dataObject);
);
} }
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
@ -151,14 +160,14 @@ public class DomainObjectFactory {
} }
/** /**
* Instantiate a domain object given an OID. This method is a wrapper * Instantiate a domain object given an OID. This method is a wrapper around
* around newInstance(DataObject). * newInstance(DataObject).
* *
* @param oid the oid of the data object for which to instantiate * @param oid the oid of the data object for which to instantiate a domain
* a domain object. * object.
* *
* @return A domain object that encapuslates the dataObject identified * @return A domain object that encapuslates the dataObject identified by
* by <i>oid</i>. The result may be null if no domain object could be * <i>oid</i>. The result may be null if no domain object could be
* instantiated for the specified data object. * instantiated for the specified data object.
* *
* @throws DataObjectNotFoundException if object could not be retrieved. * @throws DataObjectNotFoundException if object could not be retrieved.
@ -170,21 +179,22 @@ public class DomainObjectFactory {
public static DomainObject newInstance(OID oid) public static DomainObject newInstance(OID oid)
throws InstantiatorNotFoundException { throws InstantiatorNotFoundException {
if ( oid == null ) { return null; } if (oid == null) {
return null;
}
Session session = SessionManager.getSession(); Session session = SessionManager.getSession();
if (session == null) { if (session == null) {
throw new RuntimeException("Could not retrieve a session from " + throw new RuntimeException("Could not retrieve a session from "
"the session manager while instantiating " + + "the session manager while instantiating "
"a class with OID = " + oid.toString()); + "a class with OID = " + oid.toString());
} }
DataObject dataObject = session.retrieve(oid); DataObject dataObject = session.retrieve(oid);
if (dataObject == null) { if (dataObject == null) {
throw new DataObjectNotFoundException throw new DataObjectNotFoundException("Could not retrieve a DataObject with "
("Could not retrieve a DataObject with " + + "OID = " + oid.toString());
"OID = " + oid.toString());
} }
return newInstance(dataObject); return newInstance(dataObject);
@ -192,28 +202,27 @@ public class DomainObjectFactory {
} }
/** /**
* Register an instantiator for the data object type specified * Register an instantiator for the data object type specified by
* by <i>dataObjectType</i>. The registered instantiator will be * <i>dataObjectType</i>. The registered instantiator will be used by
* used by newInstance() for data objects whose type is equal to * newInstance() for data objects whose type is equal to the type specified
* the type specified by <i>dataObjectType</i>. That is, * by <i>dataObjectType</i>. That is, when
* when <code>newInstance(x)</code> is executued, the specified * <code>newInstance(x)</code> is executued, the specified
* <i>instantiator</i> will be used if the specified * <i>instantiator</i> will be used if the specified <i>dataObjectType</i>
* <i>dataObjectType</i> is equal to <code>x.getObjectType()</code>. * is equal to
* <code>x.getObjectType()</code>.
* *
* <p> * <p> Any object type that does not have an instantiator registered with
* Any object type that does not have an instantiator registered with
* this factory is not supported by the factory. * this factory is not supported by the factory.
* *
* <p> * <p> If another instantiator was already registered for the specified
* If another instantiator was already registered for the specified
* object type, the previous instantiator is replaced and returned. * object type, the previous instantiator is replaced and returned.
* *
* @param dataObjectType The data object type for which to register * @param dataObjectType The data object type for which to register the
* the instantiator specified by <i>instantiator</i> * instantiator specified by <i>instantiator</i>
* *
* @param instantiator The instantiator that will handle data objects * @param instantiator The instantiator that will handle data objects of the
* of the data object type specified by <i>dataObjectType</i> when * data object type specified by <i>dataObjectType</i> when newInstance() is
* newInstance() is called. * called.
* *
* @pre dataObjectType!= null * @pre dataObjectType!= null
* *
@ -227,16 +236,15 @@ public class DomainObjectFactory {
* @see com.arsdigita.persistence.DataObject * @see com.arsdigita.persistence.DataObject
* @see DomainObject * @see DomainObject
*/ */
public synchronized static DomainObjectInstantiator public synchronized static DomainObjectInstantiator registerInstantiator(
registerInstantiator(ObjectType dataObjectType, ObjectType dataObjectType,
DomainObjectInstantiator instantiator) DomainObjectInstantiator instantiator) {
{
if (null == dataObjectType) { if (null == dataObjectType) {
throw new InstantiatorRegistryException("null", instantiator); throw new InstantiatorRegistryException("null", instantiator);
} }
return (DomainObjectInstantiator) return (DomainObjectInstantiator) s_instantiators.put(dataObjectType,
s_instantiators.put(dataObjectType, instantiator); instantiator);
} }
/** /**
@ -244,20 +252,21 @@ public class DomainObjectFactory {
* <code>registerInstantiator(ObjectType, DomainObjectInstantiator)</code>. * <code>registerInstantiator(ObjectType, DomainObjectInstantiator)</code>.
* *
* @param dataObjectType The fully qualified name of the data object type * @param dataObjectType The fully qualified name of the data object type
* for which to register the specified <i>instantiator</i>. * for which to register the specified <i>instantiator</i>. The qualified
* The qualified name is the model name followed by a '.' * name is the model name followed by a '.' followed by the object type name
* followed by the object type name (e.g. "com.arsdigita.kernel.Party"). * (e.g. "com.arsdigita.kernel.Party").
* *
* @param instantiator The instantiator that will handle data objects * @param instantiator The instantiator that will handle data objects of the
* of the type specified by <i>typeName</i> when this newInstance() is * type specified by <i>typeName</i> when this newInstance() is called.
* called.
* *
* @pre SessionManager.getMetadataRoot().getObjectType(dataObjectType) != null * @pre SessionManager.getMetadataRoot().getObjectType(dataObjectType) !=
* null
* *
* @return DomainObjectInstantiator The previous instantiator that was * @return DomainObjectInstantiator The previous instantiator that was
* registered with this factory for this object type. * registered with this factory for this object type.
* *
* @throws InstantiatorRegistryException if the dataObjectType does not exist * @throws InstantiatorRegistryException if the dataObjectType does not
* exist
* *
* @see #registerInstantiator(ObjectType, DomainObjectInstantiator) * @see #registerInstantiator(ObjectType, DomainObjectInstantiator)
*/ */
@ -276,21 +285,19 @@ public class DomainObjectFactory {
/** /**
* Get the registered instantiator for the specified object type. * Get the registered instantiator for the specified object type.
* *
* @param dataObjectType The data object type whose registered * @param dataObjectType The data object type whose registered instantiator
* instantiator is to be returned * is to be returned
* *
* @return The instantiator that is registered for the specified object * @return The instantiator that is registered for the specified object
* type. * type.
* *
* @see #registerInstantiator(ObjectType,DomainObjectInstantiator) * @see #registerInstantiator(ObjectType,DomainObjectInstantiator)
*/ */
public synchronized static DomainObjectInstantiator public synchronized static DomainObjectInstantiator getRegisteredInstantiator(
getRegisteredInstantiator(ObjectType dataObjectType) ObjectType dataObjectType) {
{
return (DomainObjectInstantiator) s_instantiators.get(dataObjectType); return (DomainObjectInstantiator) s_instantiators.get(dataObjectType);
} }
/** /**
* Wrapper around getRegisteredInstantiator(ObjectType). * Wrapper around getRegisteredInstantiator(ObjectType).
* *
@ -298,38 +305,34 @@ public class DomainObjectFactory {
* whose registered instantiator is to be returned * whose registered instantiator is to be returned
* *
* @return The instantiator that is registered for the specified object * @return The instantiator that is registered for the specified object
* type. The qualified name is the model name followed by a '.' * type. The qualified name is the model name followed by a '.' followed by
* followed by the object type name (e.g. "com.arsdigita.kernel.Party"). * the object type name (e.g. "com.arsdigita.kernel.Party").
* *
* @see #getRegisteredInstantiator(ObjectType) * @see #getRegisteredInstantiator(ObjectType)
* @see #registerInstantiator(ObjectType,DomainObjectInstantiator) * @see #registerInstantiator(ObjectType,DomainObjectInstantiator)
*/ */
public synchronized static DomainObjectInstantiator public synchronized static DomainObjectInstantiator getRegisteredInstantiator(
getRegisteredInstantiator(String dataObjectType) String dataObjectType) {
{
MetadataRoot meta = SessionManager.getMetadataRoot(); MetadataRoot meta = SessionManager.getMetadataRoot();
return getRegisteredInstantiator(meta.getObjectType(dataObjectType)); return getRegisteredInstantiator(meta.getObjectType(dataObjectType));
} }
/** /**
* Get the registered or inherited instantiator for the specified * Get the registered or inherited instantiator for the specified object
* object type. That is, get the instantiator that is registered * type. That is, get the instantiator that is registered for the specified
* for the specified object type or its closest supertype that has * object type or its closest supertype that has a registered instantiator
* a registered instantiator (or null if there is no supertype that * (or null if there is no supertype that has a registered instantiator).
* has a registered instantiator).
* *
* @param dataObjectType The data object type whose registered or * @param dataObjectType The data object type whose registered or inherited
* inherited instantiator is to be returned * instantiator is to be returned
* *
* @return The registered or inherited instantiator for the specified * @return The registered or inherited instantiator for the specified object
* object type. * type.
* *
* @see #registerInstantiator(ObjectType,DomainObjectInstantiator) * @see #registerInstantiator(ObjectType,DomainObjectInstantiator)
*/ */
public synchronized static DomainObjectInstantiator public synchronized static DomainObjectInstantiator getInstantiator(
getInstantiator(ObjectType dataObjectType) ObjectType dataObjectType) {
{
ObjectType type = dataObjectType; ObjectType type = dataObjectType;
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("Initial type " + (type == null ? null : type.getName())); s_log.debug("Initial type " + (type == null ? null : type.getName()));
@ -337,15 +340,17 @@ public class DomainObjectFactory {
while (type != null && !s_instantiators.containsKey(type)) { while (type != null && !s_instantiators.containsKey(type)) {
type = type.getSupertype(); type = type.getSupertype();
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("Parent type " + (type == null ? null : type.getName())); s_log.debug("Parent type " + (type == null ? null
: type.getName()));
} }
} }
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("Final type " + (type == null ? null : type.getName())); s_log.debug("Final type " + (type == null ? null : type.getName()));
} }
if (type != null) { if (type != null) {
DomainObjectInstantiator instantiator = (DomainObjectInstantiator) DomainObjectInstantiator instantiator =
s_instantiators.get(type); (DomainObjectInstantiator) s_instantiators.
get(type);
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("Found instantiator " + instantiator); s_log.debug("Found instantiator " + instantiator);
} }
@ -361,26 +366,23 @@ public class DomainObjectFactory {
* @param dataObjectType The fully qualified name of the data object type * @param dataObjectType The fully qualified name of the data object type
* whose registered or inherited instantiator is to be returned * whose registered or inherited instantiator is to be returned
* *
* @return The registered or inherited instantiator for the specified * @return The registered or inherited instantiator for the specified object
* object type. The qualified name is the model name followed by a '.' * type. The qualified name is the model name followed by a '.' followed by
* followed by the object type name (e.g. "com.arsdigita.kernel.Party"). * the object type name (e.g. "com.arsdigita.kernel.Party").
* *
* @see #getInstantiator(ObjectType) * @see #getInstantiator(ObjectType)
* @see #registerInstantiator(ObjectType,DomainObjectInstantiator) * @see #registerInstantiator(ObjectType,DomainObjectInstantiator)
*/ */
public synchronized static DomainObjectInstantiator public synchronized static DomainObjectInstantiator getInstantiator(
getInstantiator(String dataObjectType) String dataObjectType) {
{
MetadataRoot meta = SessionManager.getMetadataRoot(); MetadataRoot meta = SessionManager.getMetadataRoot();
return getInstantiator(meta.getObjectType(dataObjectType)); return getInstantiator(meta.getObjectType(dataObjectType));
} }
/** /**
* Package scope method for clearing the factory of registered instantiators. * Package scope method for clearing the factory of registered
* <P> * instantiators. <P> It is ONLY for use by Domain TestCases. <P> If you use
* It is ONLY for use by Domain TestCases. * this method outside that context, YOU WILL BE FLOGGED!!
* <P>
* If you use this method outside that context, YOU WILL BE FLOGGED!!
*/ */
static synchronized void resetFactory() { static synchronized void resetFactory() {
s_instantiators = new HashMap(); s_instantiators = new HashMap();