allProperties.addAll(removedProperties);
}
Iterator allPropertiesIter = allProperties.iterator();
while (allPropertiesIter.hasNext())
{
FragmentPropertyImpl property = (FragmentPropertyImpl)allPropertiesIter.next();
property.setFragment(baseFragmentElementImpl);
String propertyScope = property.getScope();
String propertyScopeValue = property.getScopeValue();
if (updateAllScopes || ((scope == null) && (propertyScope == null)) || ((scope != null) && scope.equals(propertyScope)))
{
// classify property by scopes and create scoped lists
if (propertyScope == null)
{
if (globalFragmentPropertyList == null)
{
globalFragmentPropertyList = new DatabasePageManagerCachedFragmentPropertyList(baseFragmentElementImpl.getBaseFragmentsElement().getPath());
}
}
else if ((subject != null) && GROUP_AND_ROLE_PROPERTY_SCOPES_ENABLED)
{
boolean subjectHasPrincipal = false;
if (propertyScope.equals(USER_PROPERTY_SCOPE))
{
subjectHasPrincipal = ((userPrincipal != null) && userPrincipal.getName().equals(propertyScopeValue));
}
else if (propertyScope.equals(GROUP_PROPERTY_SCOPE))
{
subjectHasPrincipal = (SubjectHelper.getPrincipal(subject, Group.class, propertyScopeValue) != null);
}
else if (propertyScope.equals(ROLE_PROPERTY_SCOPE))
{
subjectHasPrincipal = (SubjectHelper.getPrincipal(subject, Role.class, propertyScopeValue) != null);
}
if (subjectHasPrincipal)
{
if (principalPartialFragmentPropertyLists == null)
{
principalPartialFragmentPropertyLists = new HashMap();
}
String principalKey = getFragmentPropertyListPrincipalKey(propertyScope, propertyScopeValue);
DatabasePageManagerCachedFragmentPropertyList principalPartialFragmentPropertyList = (DatabasePageManagerCachedFragmentPropertyList)principalPartialFragmentPropertyLists.get(principalKey);
if (principalPartialFragmentPropertyList == null)
{
principalPartialFragmentPropertyList = new DatabasePageManagerCachedFragmentPropertyList(propertyScope, principalKey);
principalPartialFragmentPropertyLists.put(principalKey, principalPartialFragmentPropertyList);
}
}
}
else if ((subject != null) && propertyScope.equals(USER_PROPERTY_SCOPE))
{
if ((userPrincipal != null) && userPrincipal.getName().equals(propertyScopeValue))
{
if (principalPartialFragmentPropertyLists == null)
{
principalPartialFragmentPropertyLists = new HashMap();
}
DatabasePageManagerCachedFragmentPropertyList principalPartialFragmentPropertyList = (DatabasePageManagerCachedFragmentPropertyList)principalPartialFragmentPropertyLists.get(userPrincipalKey);
if (principalPartialFragmentPropertyList == null)
{
principalPartialFragmentPropertyList = new DatabasePageManagerCachedFragmentPropertyList(USER_PROPERTY_SCOPE, userPrincipalKey);
principalPartialFragmentPropertyLists.put(userPrincipalKey, principalPartialFragmentPropertyList);
}
}
}
}
}
// populate properties lists for cache updates and
// update persistent properties
Iterator propertiesIter = properties.iterator();
while (propertiesIter.hasNext())
{
FragmentPropertyImpl storeProperty = (FragmentPropertyImpl)propertiesIter.next();
String storePropertyScope = storeProperty.getScope();
String storePropertyScopeValue = storeProperty.getScopeValue();
if (updateAllScopes || ((scope == null) && (storePropertyScope == null)) || ((scope != null) && scope.equals(storePropertyScope)))
{
// classify and decompose update into individual caches:
// allow update only if scoped properties list created above
// exists since the subject matching rules are checked there
updateTransaction = (updateTransaction || (storeProperty.getIdentity() != 0));
boolean store = false;
if (storePropertyScope == null)
{
if (globalFragmentPropertyList != null)
{
globalFragmentPropertyList.add(storeProperty);
store = true;
}
}
else if (subject != null)
{
if (principalPartialFragmentPropertyLists != null)
{
String principalKey = getFragmentPropertyListPrincipalKey(storePropertyScope, storePropertyScopeValue);
DatabasePageManagerCachedFragmentPropertyList principalPartialFragmentPropertyList = (DatabasePageManagerCachedFragmentPropertyList)principalPartialFragmentPropertyLists.get(principalKey);
if (principalPartialFragmentPropertyList != null)
{
principalPartialFragmentPropertyList.add(storeProperty);
store = true;
}
}
}
// store persistent property object
if (store)
{
getPersistenceBrokerTemplate().store(storeProperty);
}
}
}
if (removedProperties != null)
{
Iterator removedPropertiesIter = removedProperties.iterator();
while (removedPropertiesIter.hasNext())
{
FragmentPropertyImpl deleteProperty = (FragmentPropertyImpl)removedPropertiesIter.next();
deleteProperty.setFragment(baseFragmentElementImpl);
String deletePropertyScope = deleteProperty.getScope();
String deletePropertyScopeValue = deleteProperty.getScopeValue();
if (updateAllScopes || ((scope == null) && (deletePropertyScope == null)) || ((scope != null) && scope.equals(deletePropertyScope)))
{
// classify and decompose delete: allow delete only
// if scoped properties list created above exists
// since the subject matching rules are checked there