/*
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see
P extends Policy * @param behaviour Behaviour * @param definition PolicyDefinition
* @param policyInterface P * @return invocation handler */ public
InvocationHandler createHandler(Behaviour behaviour, PolicyDefinition
definition, P policyInterface) { return new TransactionHandler
(behaviour, definition, policyInterface); } /** * Transaction Invocation Handler. * * @param
policy interface */ private class TransactionHandler
implements InvocationHandler { private Behaviour behaviour; private PolicyDefinition
definition; private P policyInterface; /** * Construct */ public TransactionHandler(Behaviour behaviour, PolicyDefinition
definition, P policyInterface)
{
this.behaviour = behaviour;
this.definition = definition;
this.policyInterface = policyInterface;
}
/* (non-Javadoc)
* @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[])
*/
@SuppressWarnings("unchecked")
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
{
// Handle Object level methods
if (method.getName().equals("toString"))
{
return policyInterface.toString();
}
else if (method.getName().equals("hashCode"))
{
return policyInterface.hashCode();
}
else if (method.getName().equals("equals"))
{
return policyInterface.equals(args[0]);
}
// Invoke policy based on its notification frequency
Object result = null;
if (behaviour.getNotificationFrequency().equals(NotificationFrequency.FIRST_EVENT))
{
Map