InternalContext context = getStateContext(portletContext);
//
if (!context.isStateful())
{
throw new InvalidPortletIdException("Cannot configure producer offered portlets", portletId);
}
StatefulContext statefulContext = (StatefulContext)context;
// Get the container
Portlet referencedPortlet = super.getPortlet(context.getPortletContext());
// We need the referenced portlet
if (referencedPortlet == null)
{
throw new PortletInvokerException("The portlet " + context.getPortletContext() + " referenced by this clone " + portletId + " is not available");
}
// Get the portlet info
PortletInfo referencedPortletInfo = referencedPortlet.getInfo();
//
PreferencesInfo prefs = referencedPortletInfo.getPreferences();
// Clone the current state
PropertyMap properties = new SimplePropertyMap(statefulContext.getProperties());
// Clone argument
for (PropertyChange change : changes)
{
String key = change.getKey();
int type = change.getType();
// If the original value exist and is read only we perform a reset instead
PreferenceInfo pref = prefs.getPreference(key);
if (pref != null)
{
if (Boolean.TRUE.equals(pref.isReadOnly()))
{
type = PropertyChange.PREF_RESET;
}
}
//
if (type == PropertyChange.PREF_UPDATE)
{
properties.setProperty(key, change.getValue());
}
else
{
properties.remove(key);
}
}
//
if (statefulContext.isLocal())
{
LocalContext localContext = (LocalContext)statefulContext;
String stateId = localContext.getStateId();
try
{
persistenceManager.updateState(stateId, properties);
}
catch (NoSuchStateException e)
{
throw new NoSuchPortletException(e, portletId);
}
catch (InvalidStateIdException e)
{
throw new InvalidPortletIdException(e, portletId);
}
return PortletContext.createPortletContext(portletId);
}
else
{