use only under adult supervision
|
saidone.org -
use only under adult supervision |
|
Main menu
Home
About Projects
AlfMarkSwamp
Links
ush.itaghers.org saidone@ush gameknot virtualmagister Misc
Unless otherwise specified, all contents of this site are licensed under a Creative Commons Attribution-ShareAlike 3.0 Italy License.
|
Extend Alfresco services for your purposes - posted by saidone on Wed, 22 Jun 2011 21:31:10 GMT
Let's see how Alfresco (leveraging on Spring and Java peculiarities) offers a clean way to customize even the most internal and low level services, here's how.First: Java inheritance. We should write some code that inherit the basic stuff from parent and ancestors, and add our methods and properties or (a bit dangerous) trying to overwrite inherited methods. You should know the exact class to extend, and you can find them declared in some of the spring context files inside the alfresco war, for example if you want to add something to NodeService, you should extend DbNodeServiceImpl, to add to FileFolderService the class to extend is FileFolderServiceImpl, and so on. Here's a minimal example of an extension to the NodeService (simply adds an odd method that return the nearest ancestor of a node that matches a given type):
package org.saidone.alfresco.service;
import org.alfresco.repo.node.db.DbNodeServiceImpl;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
public final class NodeService extends DbNodeServiceImpl {
public NodeService() {
super();
}
public NodeRef getNearestAncestorByType(NodeRef nodeRef, QName typeQName) {
NodeRef parentNodeRef = null;
do {
parentNodeRef = (this.getPrimaryParent(nodeRef)).getParentRef();
if (parentNodeRef != null) {
if (this.getType(parentNodeRef).equals(typeQName)) return parentNodeRef;
nodeRef = parentNodeRef;
}
}
while (parentNodeRef != null);
return parentNodeRef;
}
}
Second: declare you mint new service within Spring. We should now declare the service we've just customized in the Spring context of our module (with module I think about a bunch of java backed code that you want to execute in Alfresco, as a set of java backed webscript, custom actions, custom behaviours, etc.). This service is obviously 100% compatible with the Alfresco one (if we have only added methods) and we should not worry about older classes we have in the module. We should only tell to our webscript, action or something else to use our service instead of the built in one, here's the bean declaration for service and an example webscript:
<bean id="customNodeService" class="org.saidone.alfresco.service.NodeService" parent="dbNodeService"> </bean>That's almost all, we are now ready to use the customized NodeService within our java code, as usual:
import org.saidone.alfresco.service.NodeService;
public abstract class GenericWebScript extends AbstractWebScript {
protected NodeService nodeService;
public void setNodeService(NodeService nodeService) {
this.nodeService = nodeService;
}
[...]
Tweet No comments yet. Post a new comment back to home |
[[[[[[[ served by kugelmass ]]]]]]]
I spent a lot of money on booze, birds and fast cars. The rest I just squandered. - George Best
|
|