cancel
Showing results for 
Search instead for 
Did you mean: 

Retrieving Allowed Values of a property.

Former Member
0 Kudos

Hi,

I created a custom property and have like 5 or 6 values assigned to it.

From the API, as mentioned below, I could only find a way to get these values if they are set to a resource and if the property is a multi-valued.

String namespace = "http://com.sap.netweaver.bc.rf.sample/xmlns/sample";

String name = "property";

IPropertyName propertyName = new PropertyName(namespace, name);

IProperty property = resource.getProperty(propertyName);

if( property.isMultivalued() ) {

// property is multi valued

List values = property.getValues();

...........................

If the property is not Multi-Valued and not set to a resource, is there any way to retrieve all the "Allowed Values" for that particular property.

I appreciate if anyone can throw some light on it.

Thanks,

Ravi.

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

You might not need all this code (depending on what you are doing, and what items you may already have),

the part relevant to fething the allowed values is at the bottom:



IResource fileresource=//however you're getting it.

IPropertyConfigurationService propConfigService = (IPropertyConfigurationService) ResourceFactory.getInstance().getServiceFactory().getService(
"PropertyConfigurationService");
IMetaModel mm = propConfigService.getMetaModel();
metaContext = mm.createEmptyMetaContext();
metaContext.setResource(fileresource);
metaContext.setResourceContext(fileresource.getContext());
IMutablePropertyMap propertymap = fileresource.getProperties().getMutable();
metaContext.setPropertyMap(propertymap);

propName = new PropertyName("yourNamespace", "yourPropertyName");

IMetaName metaname = propConfigService.getMetaModel().searchByPropertyName(propName);
IMetaValueListIterator iml = metaname.allowedValueIterator( metaContext );

while (iml.hasNext()) {
	IMetaValue vl = iml.next();
	String myvalue = vl.getValue();
//... do something with it
}

randall@rkdataservices.com

Former Member
0 Kudos

You might not need all this code (depending on what you are doing, and what items you may already have), the part relevant to fething the allowed values is at the bottom:



IResource fileresource=//however you're getting it.

IPropertyConfigurationService propConfigService = (IPropertyConfigurationService) ResourceFactory.getInstance().getServiceFactory().getService(
"PropertyConfigurationService");
IMetaModel mm = propConfigService.getMetaModel();
metaContext = mm.createEmptyMetaContext();
metaContext.setResource(fileresource);
metaContext.setResourceContext(fileresource.getContext());
IMutablePropertyMap propertymap = fileresource.getProperties().getMutable();
metaContext.setPropertyMap(propertymap);

propName = new PropertyName("yourNamespace", "yourPropertyName");

IMetaName metaname = propConfigService.getMetaModel().searchByPropertyName(propName);
IMetaValueListIterator iml = metaname.allowedValueIterator( metaContext );
IMetaContext metaContext=
while (iml.hasNext()) {
	IMetaValue vl = iml.next();
	String myvalue = vl.getValue();
//... do something with it
}