Example usage for org.springframework.util Assert isInstanceOf

List of usage examples for org.springframework.util Assert isInstanceOf

Introduction

In this page you can find the example usage for org.springframework.util Assert isInstanceOf.

Prototype

public static void isInstanceOf(Class<?> type, @Nullable Object obj) 

Source Link

Document

Assert that the provided object is an instance of the provided class.

Usage

From source file:org.openregistry.core.domain.jpa.sor.JpaSorPersonImpl.java

public void addName(final SorName sorName) {
    Assert.isInstanceOf(JpaSorNameImpl.class, sorName);
    this.names.add(sorName);
}

From source file:com.github.hateoas.forms.spring.AffordanceBuilderFactory.java

@Override
public AffordanceBuilder linkTo(final Object invocationValue) {

    Assert.isInstanceOf(DummyInvocationUtils.LastInvocationAware.class, invocationValue);
    DummyInvocationUtils.LastInvocationAware invocations = (DummyInvocationUtils.LastInvocationAware) invocationValue;

    DummyInvocationUtils.MethodInvocation invocation = invocations.getLastInvocation();
    final Method invokedMethod = invocation.getMethod();
    MethodParameters parameters = new MethodParameters(invokedMethod);
    String pathMapping = MAPPING_DISCOVERER.getMapping(invokedMethod);

    Map<String, ActionInputParameter> requestParams = ActionDescriptorBuilder.getRequestParams(parameters,
            invocation.getArguments());/* www  .j ava 2s. c  o m*/
    Set<String> params = requestParams.keySet();
    String query = join(params);
    String mapping = StringUtils.isEmpty(query) ? pathMapping : pathMapping + "{?" + query + "}";

    PartialUriTemplate partialUriTemplate = new PartialUriTemplate(
            AffordanceBuilder.getBuilder().build().toString() + mapping);

    Iterator<Object> classMappingParameters = invocations.getObjectParameters();

    Map<String, Object> values = new HashMap<String, Object>();
    Iterator<String> names = partialUriTemplate.getVariableNames().iterator();
    while (classMappingParameters.hasNext()) {
        values.put(names.next(), classMappingParameters.next());
    }

    for (Object argument : invocation.getArguments()) {
        if (names.hasNext()) {
            values.put(names.next(), argument);
        }
    }

    ActionDescriptor actionDescriptor = ActionDescriptorBuilder.createActionDescriptor(parameters,
            invokedMethod, values, invocation.getArguments(), requestParams);
    if (paramsOnBody && !Affordance.isSafe(actionDescriptor.getHttpMethod())) {
        partialUriTemplate = new PartialUriTemplate(
                AffordanceBuilder.getBuilder().build().toString() + pathMapping);
    }
    return new AffordanceBuilder(partialUriTemplate.expand(values),
            Collections.singletonList(actionDescriptor));
}

From source file:net.sf.gazpachoquest.questionnaire.resolver.SectionBySectionResolver.java

@Override
protected SectionBreadcrumb findPreviousBreadcrumb(final QuestionnaireDefinition questionnaireDefinition,
        final Questionnaire questionnaire, final SectionBreadcrumb lastBreadcrumb,
        final Integer lastBreadcrumbPosition) {
    if (lastBreadcrumbPosition == INITIAL_POSITION) {
        return null;
    }/*from  ww  w .java  2 s. c  o m*/
    Breadcrumb breadcrumb = breadcrumbService.findByQuestionnaireIdAndPosition(questionnaire.getId(),
            lastBreadcrumbPosition - 1);
    Assert.isInstanceOf(SectionBreadcrumb.class, breadcrumb);
    return (SectionBreadcrumb) breadcrumb;
}

From source file:ro.codecamp.ebp.core.util.ServerOsgiBundleXmlWebApplicationContext.java

/**
 * {@inheritDoc}/*  w w w  . j av a2  s. co  m*/
 */
@Override
public BundleContext getBundleContext() {
    BundleContext bundleContext = super.getBundleContext();
    if (bundleContext == null) {

        // Attempt to locate the BundleContext in the ServletContext
        if (this.servletContext != null) {
            Object bundleContextFromServletContext = this.servletContext.getAttribute(BUNDLE_CONTEXT_ATTRIBUTE);
            if (bundleContextFromServletContext != null) {
                Assert.isInstanceOf(BundleContext.class, bundleContextFromServletContext);
                this.logger.debug("Using the BundleContext stored in the ServletContext as '{}'.");
                bundleContext = (BundleContext) bundleContextFromServletContext;
                setBundleContext(bundleContext);
            }
        }

        // If still not set, fall back to the parent
        if (bundleContext == null) {
            ApplicationContext parent = getParent();
            if (parent instanceof ConfigurableOsgiBundleApplicationContext) {
                this.logger.debug("Using the parent ApplicationContext's BundleContext");
                bundleContext = ((ConfigurableOsgiBundleApplicationContext) parent).getBundleContext();
                setBundleContext(bundleContext);
            }
        }
    }
    return bundleContext;
}

From source file:org.openregistry.core.domain.jpa.sor.JpaSorRoleImpl.java

public void setSystemOfRecord(SystemOfRecord systemOfRecord) {
    Assert.isInstanceOf(JpaSystemOfRecordImpl.class, systemOfRecord);
    this.systemOfRecord = (JpaSystemOfRecordImpl) systemOfRecord;
}

From source file:org.LexGrid.LexBIG.caCore.test.rest.RESTTest.java

public void testRESTHTMLInvalidURLParenthesis() throws Exception {
    try {/*from  www  .  ja v a 2 s  .c om*/
        callRestfulService(
                "GetHTML?query=org.LexGrid.concepts.Entity&org.LexGrid.concepts.Entity[@_entityCode=29506000][@_entityCodeNamespace=SNOMED%20Clinical%20Terms]]");
    } catch (Exception e) {
        Assert.isInstanceOf(IOException.class, e);
        assertTrue(e.getMessage().contains("HTTP response code: 400"));
        return;
    }
    fail();
}

From source file:com.productone.spring.ServerOsgiBundleXmlWebApplicationContext.java

/**
 * {@inheritDoc}/*from ww w  .  jav a2 s  .c o m*/
 */
@Override
public BundleContext getBundleContext() {
    BundleContext bundleContext = super.getBundleContext();
    if (bundleContext == null) {

        // Attempt to locate the BundleContext in the ServletContext
        if (this.servletContext != null) {
            Object bundleContextFromServletContext = this.servletContext.getAttribute(BUNDLE_CONTEXT_ATTRIBUTE);
            if (bundleContextFromServletContext != null) {
                Assert.isInstanceOf(BundleContext.class, bundleContextFromServletContext);
                this.logger.debug("Using the BundleContext stored in the ServletContext as '{}'.",
                        BUNDLE_CONTEXT_ATTRIBUTE);
                bundleContext = (BundleContext) bundleContextFromServletContext;
                setBundleContext(bundleContext);
            }
        }

        // If still not set, fall back to the parent
        if (bundleContext == null) {
            ApplicationContext parent = getParent();
            if (parent instanceof ConfigurableOsgiBundleApplicationContext) {
                this.logger.debug("Using the parent ApplicationContext's BundleContext");
                bundleContext = ((ConfigurableOsgiBundleApplicationContext) parent).getBundleContext();
                setBundleContext(bundleContext);
            }
        }
    }
    return bundleContext;
}

From source file:org.openregistry.core.domain.jpa.sor.JpaSorRoleImpl.java

public void setPersonStatus(final Type personStatus) {
    Assert.isInstanceOf(JpaTypeImpl.class, personStatus);
    this.personStatus = (JpaTypeImpl) personStatus;
}

From source file:org.LexGrid.LexBIG.caCore.test.rest.RESTTest.java

public void testRESTXMLInvalidCriteriaObject() throws Exception {
    try {/*from w w w  . j  a v a  2  s . c  o m*/
        callRestfulService(
                "GetXML?query=org.LexGrid.concepts.Entity&org.LexGrid.concepts.EntityINVALID[@_entityCode=29506000]");
    } catch (Exception e) {
        Assert.isInstanceOf(IOException.class, e);
        assertTrue(e.getMessage().contains("HTTP response code: 400"));
        return;
    }
    fail();
}

From source file:org.openregistry.core.domain.jpa.sor.JpaSorRoleImpl.java

public void setTerminationReason(final Type reason) {
    Assert.isInstanceOf(JpaTypeImpl.class, reason);
    this.terminationReason = (JpaTypeImpl) reason;
}