Noch ein paar Ergänzungen für das Publizieren von Assoziationen.
git-svn-id: https://svn.libreccm.org/ccm/trunk@1558 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
d7327b5e9a
commit
b6c7d1587f
|
|
@ -1,6 +1,5 @@
|
|||
package com.arsdigita.cms;
|
||||
|
||||
import com.arsdigita.domain.DomainObject;
|
||||
import com.arsdigita.persistence.metadata.Property;
|
||||
|
||||
/**
|
||||
|
|
@ -10,11 +9,29 @@ import com.arsdigita.persistence.metadata.Property;
|
|||
*/
|
||||
public interface AssociationCopier {
|
||||
|
||||
boolean copyReverseProperty(CustomCopy source,
|
||||
DomainObject target,
|
||||
Property property,
|
||||
DomainObject value,
|
||||
ItemCopier copier);
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Return the property which is handled by this implementation. Format:
|
||||
* </p>
|
||||
* <p>
|
||||
* {@code $type::$property}
|
||||
* </p>
|
||||
* <p>
|
||||
* Where {@code $type} is the fully qualified name of the class/type owing
|
||||
* the property and {@code property} is the name the property. Example
|
||||
* </p>
|
||||
* <p>
|
||||
* {@code com.arsdigita.cms.contenttypes.GenericPerson::publications}
|
||||
* </p>
|
||||
* <p>
|
||||
* This indicates that the implementation handles a property
|
||||
* {@code publications} added to the {@code GenericPerson} type by some
|
||||
* module via an PDL association.
|
||||
* </p>
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String forProperty();
|
||||
|
||||
boolean copyProperty(CustomCopy source, Property property, ItemCopier copier);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,77 @@
|
|||
package com.arsdigita.cms;
|
||||
|
||||
import com.arsdigita.persistence.metadata.Property;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Jens Pelzetter
|
||||
* @version $Id$
|
||||
*/
|
||||
public final class AssociationCopierLoader {
|
||||
|
||||
private static final AssociationCopierLoader INSTANCE =
|
||||
new AssociationCopierLoader();
|
||||
private static final Logger logger =
|
||||
Logger.getLogger(AssociationCopierLoader.class);
|
||||
private Map<String, AssociationCopier> copiers =
|
||||
new HashMap<String, AssociationCopier>();
|
||||
|
||||
private AssociationCopierLoader() {
|
||||
final String[] assocCopierNames = CMSConfig.getInstance().
|
||||
getAssocCopiers();
|
||||
|
||||
for (String assocCopierName : assocCopierNames) {
|
||||
loadAssocCopier(assocCopierName);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadAssocCopier(final String name) {
|
||||
final Class<?> clazz;
|
||||
try {
|
||||
clazz = Class.forName(name);
|
||||
} catch (ClassNotFoundException ex) {
|
||||
logger.warn(String.format("No class found for name '%s'. Skiping.",
|
||||
name),
|
||||
ex);
|
||||
return;
|
||||
}
|
||||
|
||||
if (clazz.isAssignableFrom(AssociationCopier.class)) {
|
||||
try {
|
||||
final AssociationCopier copier = (AssociationCopier) clazz.
|
||||
newInstance();
|
||||
|
||||
copiers.put(copier.forProperty(), copier);
|
||||
} catch (InstantiationException ex) {
|
||||
logger.warn(String.format(
|
||||
"Failed to instaniate copier '%s'. Skiping.",
|
||||
name),
|
||||
ex);
|
||||
} catch (IllegalAccessException ex) {
|
||||
logger.warn(String.format(
|
||||
"Failed to instaniate copier '%s'. Skiping.",
|
||||
name),
|
||||
ex);
|
||||
}
|
||||
} else {
|
||||
logger.warn(String.format("Class '%s' is not an implementation of "
|
||||
+ "the AssociationCopier interface. "
|
||||
+ "Skiping",
|
||||
name));
|
||||
}
|
||||
}
|
||||
|
||||
public static AssociationCopierLoader getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public AssociationCopier getAssociationCopierFor(final Property property,
|
||||
final CustomCopy source) {
|
||||
return copiers.get(String.format("%s::%s",
|
||||
source.getClass().getName(),
|
||||
property.getName()));
|
||||
}
|
||||
}
|
||||
|
|
@ -621,6 +621,14 @@ public final class CMSConfig extends AbstractConfig {
|
|||
Parameter.REQUIRED,
|
||||
true);
|
||||
|
||||
/**
|
||||
* Copiers for associations not known yet. For example for associations
|
||||
* with the generic types defined in this module from another module.
|
||||
*/
|
||||
private final Parameter m_assocCopiers = new StringArrayParameter("com.arsdigita.cms.publish.association_copiers",
|
||||
Parameter.REQUIRED,
|
||||
new String[]{});
|
||||
|
||||
// ///////////////////////////////////////////
|
||||
// publishToFile package related parameter
|
||||
// ///////////////////////////////////////////
|
||||
|
|
@ -704,6 +712,7 @@ public final class CMSConfig extends AbstractConfig {
|
|||
|
||||
register(m_useOldStyleItemLifecycleItemPane);
|
||||
register(m_threadPublishing);
|
||||
register(m_assocCopiers);
|
||||
|
||||
// publishToFile package related parameter
|
||||
// Moved to publishToFile.PublishToFileConfig as of version 6.0.2
|
||||
|
|
@ -1122,4 +1131,8 @@ public final class CMSConfig extends AbstractConfig {
|
|||
public Boolean getThreadedPublishing() {
|
||||
return (Boolean) get(m_threadPublishing);
|
||||
}
|
||||
|
||||
public String[] getAssocCopiers() {
|
||||
return (String[]) get(m_assocCopiers);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1947,6 +1947,14 @@ public class ContentItem extends VersionedACSObject implements CustomCopy {
|
|||
}
|
||||
}
|
||||
|
||||
final AssociationCopierLoader assocCopierLoader =
|
||||
AssociationCopierLoader.getInstance();
|
||||
final AssociationCopier assocCopier = assocCopierLoader.
|
||||
getAssociationCopierFor(property, source);
|
||||
if (assocCopier != null) {
|
||||
return assocCopier.copyProperty(source, property, copier);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue