Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

IResource.setProperty Error

Hi.

I want to set values in the properties using the following code (I always get an error):

public class DocumentService 
	extends AbstractRepositoryService 
	implements IReconfigurable, IResourceEventReceiver {
		
	private static Location _log = Location.getLocation(DocumentService.class);
  	private static final String _TYPE = "DocumentService";
  	private static final String _FOLDER = "MyFolder";
  	
  	public DocumentService() { super(); }
  	public String getServiceType() { return _TYPE; }

	protected void startUpImpl(Collection mgrs) throws ConfigurationException, StartupException {
		try {
			Iterator iterator = mgrs.iterator();
			while (iterator.hasNext()) {	
				Object o = iterator.next();
				if (o instanceof IRepositoryManager) {
					IRepositoryManager man = (IRepositoryManager) o;
					addRepositoryAssignment(man);
				}
			}	
		}
		catch(Exception ex) { _log.errorT("startUpImpl", ex.getMessage()); }
	}
	
	protected void shutDownImpl() { 
	  	
	}
	
	protected void addRepositoryAssignment(IRepositoryManager rm) throws ServiceNotAvailableException {
		try {
			IResourceEventBroker reb = rm.getEventBroker(); 
			reb.register(this, ResourceEvent.CREATE_CHILD_TEMPLATE);			
		}
		catch(Exception ex) { _log.errorT("addRepositoryAssignment", ex.getMessage()); }
	}

	protected void removeRepositoryAssignment(IRepositoryManager mgr) throws WcmException {
		try {
			IResourceEventBroker reb = mgr.getEventBroker(); 
			reb.unregister(this, ResourceEvent.CREATE_CHILD_TEMPLATE);
		}
		catch(Exception ex) { _log.errorT("removeRepositoryAssignment", ex.getMessage()); }
	}
	
	public void reconfigure(IConfiguration config) throws ConfigurationException {
		this.stateHandler.preReconfigure();	
		this.config = config;
		this.stateHandler.postReconfigure();
	}
	
	public void received(IEvent event) {
		try {
			if (event instanceof ResourceEvent) {

				if (event.isLike(ResourceEvent.CREATE_CHILD_TEMPLATE)) {					

					ResourceEvent resEvent = (ResourceEvent) event;		
						
					IResource resFolder = resEvent.getResource();
					
					

					if (resFolder.isCollection() && resFolder.getName().equals(_FOLDER)) {
						Object obj = resEvent.getParameter();
						if ((obj != null) && (obj instanceof IResource)) {
							IResource resDoc = (IResource) obj;
							
							//resDoc.checkOut();
							//resDoc.che
							
							PropertyName name = new PropertyName("http://sapportals.com/xmlns/cm/", "my_property");
							IProperty oldProp = resDoc.getProperty(name);
							

							if (oldProp != null) {
							
								_log.errorT("received", "value=" + oldProp.getStringValue()); //no error. 
							}
							
							Property newProp = new Property(name, "bobobo");
							resDoc.setProperty(newProp); //Resource Exception with message "null" or Exception with message "n/a"

						
						}			
					}
				}
			}
		}
		catch(Exception ex) { _log.errorT("received", ex.getMessage()); }
	}	  
}

Can you help me?

Best Regards,

Timur Semenchuk.

Former Member
Not what you were looking for? View more on this topic or Ask a question