KEY
attribute inside IRFServiceWrapper. Tipically with a string like "com.mycompany.SampleService".
package com.mycompany;
import java.util.Collection;
import java.util.Iterator;
import com.sapportals.wcm.WcmException;
import com.sapportals.wcm.crt.component.IReconfigurable;
import com.sapportals.wcm.crt.component.StartupException;
import com.sapportals.wcm.crt.configuration.ConfigurationException;
import com.sapportals.wcm.crt.configuration.IConfiguration;
import com.sapportals.wcm.repository.IProperty;
import com.sapportals.wcm.repository.IResource;
import com.sapportals.wcm.repository.Property;
import com.sapportals.wcm.repository.PropertyName;
import com.sapportals.wcm.repository.ResourceException;
import com.sapportals.wcm.repository.manager.IRepositoryManager;
import com.sapportals.wcm.repository.manager.IResourceEvent;
import com.sapportals.wcm.repository.manager.IResourceEventReceiver;
import com.sapportals.wcm.repository.manager.ResourceEvent;
import com.sapportals.wcm.repository.service.AbstractRepositoryService;
import com.sapportals.wcm.repository.service.ServiceNotAvailableException;
import com.sapportals.wcm.util.events.IEvent;
public class SampleService extends AbstractRepositoryService implements IResourceEventReceiver, IReconfigurable {
private static final String TYPE = "com.mycompany.kmservice.SampleService";
private Collection repositoryManagers;
public SampleService() {
super();
}
public String getServiceType() {
return SampleService.TYPE;
}
protected void startUpImpl(Collection repositoryManagers) throws ConfigurationException, StartupException {
this.repositoryManagers = repositoryManagers;
Iterator it = repositoryManagers.iterator();
while (it.hasNext()){
try {
addRepositoryAssignment((IRepositoryManager) it.next());
} catch (ServiceNotAvailableException e) {
e.printStackTrace();
}
}
}
protected void shutDownImpl() {
Iterator it = repositoryManagers.iterator();
while (it.hasNext()){
try {
removeRepositoryAssignment((IRepositoryManager) it.next());
} catch (WcmException e) {
e.printStackTrace();
}
}
}
protected void addRepositoryAssignment(IRepositoryManager mgr) throws ServiceNotAvailableException {
try {
mgr.getEventBroker().register(this, ResourceEvent.GET_TEMPLATE);
} catch (WcmException e) {
e.printStackTrace();
}
}
protected void removeRepositoryAssignment(IRepositoryManager mgr) throws WcmException {
mgr.getEventBroker().unregister(this, ResourceEvent.GET_TEMPLATE);
}
public void received(IEvent event) {
IResourceEvent myEvent = (IResourceEvent) event;
try {
IResource res = myEvent.getResource();
PropertyName propertyNameHitCount = new PropertyName("http://sapportals.com/xmlns/cm","hitscount");
Property propHitCount = new Property(propertyNameHitCount,new Integer(0));
// We increase hitscount property value
if (res.getProperty(propertyNameHitCount)!=null) {
IProperty oldHitCount = res.getProperty(propertyNameHitCount);
String sOldHitCount = oldHitCount.getValueAsString();
int iOldHitCount = Integer.parseInt(sOldHitCount);
iOldHitCount++;
propHitCount = new Property(propertyNameHitCount,new Integer(iOldHitCount));
res.setProperty(propHitCount);
}
} catch (ResourceException e) {
e.printStackTrace();
}
}
public void reconfigure(IConfiguration arg0) throws ConfigurationException {
}
}