Example usage for java.lang.reflect Proxy getInvocationHandler

List of usage examples for java.lang.reflect Proxy getInvocationHandler

Introduction

In this page you can find the example usage for java.lang.reflect Proxy getInvocationHandler.

Prototype

@CallerSensitive
public static InvocationHandler getInvocationHandler(Object proxy) throws IllegalArgumentException 

Source Link

Document

Returns the invocation handler for the specified proxy instance.

Usage

From source file:com.interface21.aop.framework.AopProxy.java

/**
 * Equality means interceptors and interfaces are ==.
 * This will only work with J2SE dynamic proxies,   not with CGLIB ones
 * (as CGLIB doesn't delegate equals calls to proxies).
 * @see java.lang.Object#equals(java.lang.Object)
 * @param other may be a dynamic proxy wrapping an instance
 * of this class//from   w  w w . ja  v  a  2s  .com
 */
public boolean equals(Object other) {
    if (other == null)
        return false;
    if (other == this)
        return true;

    AopProxy aopr2 = null;
    if (other instanceof AopProxy) {
        aopr2 = (AopProxy) other;
    } else if (Proxy.isProxyClass(other.getClass())) {
        InvocationHandler ih = Proxy.getInvocationHandler(other);
        if (!(ih instanceof AopProxy))
            return false;
        aopr2 = (AopProxy) ih;
    } else {
        // Not a valid comparison
        return false;
    }

    // If we get here, aopr2 is the other AopProxy
    if (this == aopr2)
        return true;

    if (!Arrays.equals(aopr2.config.getProxiedInterfaces(), this.config.getProxiedInterfaces()))
        return false;

    // List equality is cool
    if (!aopr2.config.getMethodPointcuts().equals(this.config.getMethodPointcuts()))
        return false;

    return true;
}

From source file:org.nuxeo.runtime.remoting.transporter.TransporterClient.java

/**
 * Needs to be called by user when no longer need to make calls on remote
 * POJO. Otherwise will maintain remote connection until this is called.
 *///from w w w  .j  ava2s .  c  om
public static void destroyTransporterClient(Object transporterClient) {
    if (transporterClient instanceof Proxy) {
        InvocationHandler handler = Proxy.getInvocationHandler(transporterClient);
        if (handler instanceof TransporterClient) {
            TransporterClient client = (TransporterClient) handler;
            client.disconnect();
        } else {
            throw new IllegalArgumentException("Object is not a transporter client.");
        }
    } else {
        throw new IllegalArgumentException("Object is not a transporter client.");
    }
}

From source file:org.kuali.kra.questionnaire.QuestionnaireLookupableHelperServiceTest.java

/**
 * //from w  w  w .j a  v  a2  s . com
 * This method to test getCustomActionUrls for someone with "MODIFY_QUESTIONNAIRE" permission
 * should have edit/view/copy action links
 * @throws Exception
 */
@Test
public void testCustomActionUrlWithVIEW_QUESTIONNAIRE() throws Throwable {
    final QuestionnaireAuthorizationService questionnaireAuthorizationService = context
            .mock(QuestionnaireAuthorizationService.class);
    Method m = QuestionnaireLookupableHelperServiceImpl.class.getMethod("setQuestionnaireAuthorizationService",
            QuestionnaireAuthorizationService.class);
    Proxy.getInvocationHandler(questionnaireLookupableHelperServiceImpl).invoke(
            questionnaireLookupableHelperServiceImpl, m, new Object[] { questionnaireAuthorizationService });

    context.checking(new Expectations() {
        {
            one(questionnaireAuthorizationService).hasPermission(PermissionConstants.MODIFY_QUESTIONNAIRE);
            will(returnValue(false));
            one(questionnaireAuthorizationService).hasPermission(PermissionConstants.VIEW_QUESTIONNAIRE);
            will(returnValue(true));
        }
    });
    MaintenanceDocumentBase maintDocument = (MaintenanceDocumentBase) documentService
            .getNewDocument(KcServiceLocator.getService(MaintenanceDocumentDictionaryService.class)
                    .getDocumentTypeName(Questionnaire.class));
    maintDocument.getDocumentHeader().setDocumentDescription("test 1");
    maintDocument.getNewMaintainableObject().setBusinessObject(createQuestionnaire("test1", "desc 1"));
    maintDocument.getNewMaintainableObject().setMaintenanceAction(KRADConstants.MAINTENANCE_NEW_ACTION);
    documentService.routeDocument(maintDocument, null, null);
    // not sure why it is not persisted in DB.  also need to do this save, so getcustomactionurls can retrieve it with bos
    Questionnaire questionnaire = (Questionnaire) maintDocument.getNewMaintainableObject().getDataObject();
    questionnaire.setDocumentNumber(maintDocument.getDocumentNumber());
    KNSServiceLocator.getBusinessObjectService()
            .save((Questionnaire) maintDocument.getNewMaintainableObject().getDataObject());
    List pkNames = new ArrayList();
    pkNames.add("id");

    List<HtmlData> htmldata = questionnaireLookupableHelperServiceImpl
            .getCustomActionUrls(maintDocument.getNewMaintainableObject().getBusinessObject(), pkNames);
    Assert.assertEquals(htmldata.size(), 1);
    Assert.assertEquals(
            "../maintenanceQn.do?businessObjectClassName=" + Questionnaire.class.getName()
                    + "&methodToCall=edit" + "&id=" + questionnaire.getId() + "&readOnly=true",
            ((AnchorHtmlData) htmldata.get(0)).getHref(), ((AnchorHtmlData) htmldata.get(0)).getHref());
}

From source file:no.sesat.search.datamodel.BeanDataNodeInvocationHandler.java

/**
 * obj may be null./*from ww  w .ja  v  a  2 s .  c  o m*/
 */
@Override
protected void addChild(final Object obj) {

    if (null != obj) {

        assert isDataObjectOrNode(obj) : "my own properties should only be Data(Object|Node)s";
        assert isSerializable(obj) : "Object not serializable: " + obj;
        final BeanDataObjectInvocationHandler<?> childsNewHandler = (BeanDataObjectInvocationHandler<?>) Proxy
                .getInvocationHandler(obj);

        /// XXX Application bottleneck. See https://jira.sesam.no/jira/browse/SEARCH-3591
        ///       BeanContextSupport.add synchronises against the static variable BeanContext.globalHierarchyLock
        ///        so every thread in the jvm must queue one at a time here :'(
        ///       Worse is that this synchronisation is requested behavor by BeanContext.add
        /// We workaround it by instead locking against the datamodel we know we are restricted within.
        ((BeanContextSupport) context).add(childsNewHandler.getBeanContextChild(),
                absoluteContext.dataModelLock);

    }
}

From source file:org.apache.olingo.ext.proxy.commons.AbstractCollectionInvocationHandler.java

public <ET extends EntityType<?>> boolean addRef(final ET element) {
    if (element instanceof Proxy && Proxy.getInvocationHandler(element) instanceof EntityInvocationHandler) {
        final EntityInvocationHandler handler = EntityInvocationHandler.class
                .cast(Proxy.getInvocationHandler(element));
        final URI id = handler.getEntity().getId();
        if (id == null) {
            return false;
        }/*from   w  ww  .j a va 2s  .com*/

        return referenceItems.add(id.toASCIIString());
    }

    return false;
}

From source file:org.apache.olingo.fit.proxy.ChangeDetectionTestITCase.java

protected EntityInvocationHandler getInvocationHandler(final EntityType<?> entity) {
    return (EntityInvocationHandler) Proxy.getInvocationHandler(entity);
}

From source file:org.apache.olingo.fit.proxy.EntityUpdateTestITCase.java

@Test
public void concurrentModification() {
    Order order = getContainer().getOrders().getByKey(8).load();
    final String etag = ((EntityInvocationHandler) Proxy.getInvocationHandler(order)).getETag();
    assertTrue(StringUtils.isNotBlank(etag));

    order.setShelfLife(BigDecimal.TEN);

    getContainer().flush();//w  ww  .  jav a 2 s. com

    order = getContainer().getOrders().getByKey(8).load();
    assertEquals(BigDecimal.TEN, order.getShelfLife());
}

From source file:org.apache.olingo.fit.proxy.EntityRetrieveTestITCase.java

@Test
public void checkForETag() {
    final Order order = getContainer().getOrders().getByKey(8).load();
    assertTrue(StringUtils.isNotBlank(((EntityInvocationHandler) Proxy.getInvocationHandler(order)).getETag()));
}

From source file:org.apache.olingo.fit.proxy.ChangeDetectionTestITCase.java

protected ComplexInvocationHandler getInvocationHandler(final ComplexType<?> complex) {
    return (ComplexInvocationHandler) Proxy.getInvocationHandler(complex);
}

From source file:org.apache.olingo.fit.proxy.ChangeDetectionTestITCase.java

protected EntityCollectionInvocationHandler<?> getInvocationHandler(final EntityCollection<?, ?, ?> complex) {
    return (EntityCollectionInvocationHandler<?>) Proxy.getInvocationHandler(complex);
}