Example usage for java.lang Class getClass

List of usage examples for java.lang Class getClass

Introduction

In this page you can find the example usage for java.lang Class getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:org.openmrs.api.context.ServiceContext.java

/**
 * Allow other services to be added to our service layer <br>
 * <br>/*from   w w  w.jav  a2 s. c o  m*/
 * Classes will be found/loaded with the ModuleClassLoader <br>
 * <br>
 * <code>params</code>[0] = string representing the service interface<br>
 * <code>params</code>[1] = service instance
 *
 * @param params list of parameters
 */
@SuppressWarnings("unchecked")
public void setModuleService(List<Object> params) {
    String classString = (String) params.get(0);
    Object classInstance = params.get(1);

    if (classString == null || classInstance == null) {
        throw new APIException("service.unable.find", (Object[]) null);
    }

    Class cls = null;

    // load the given 'classString' class from either the openmrs class
    // loader or the system class loader depending on if we're in a testing
    // environment or not (system == testing, openmrs == normal)
    try {
        if (!useSystemClassLoader) {
            cls = OpenmrsClassLoader.getInstance().loadClass(classString);

            if (cls != null && log.isDebugEnabled()) {
                try {
                    log.debug("cls classloader: " + cls.getClass().getClassLoader() + " uid: "
                            + cls.getClass().getClassLoader().hashCode());
                } catch (Exception e) {
                    /*pass*/}
            }
        } else if (useSystemClassLoader) {
            try {
                cls = Class.forName(classString);
                if (log.isDebugEnabled()) {
                    log.debug("cls2 classloader: " + cls.getClass().getClassLoader() + " uid: "
                            + cls.getClass().getClassLoader().hashCode());
                    //pay attention that here, cls = Class.forName(classString), the system class loader and
                    //cls2 is the openmrs class loader, like above.
                    log.debug("cls==cls2: "
                            + String.valueOf(cls == OpenmrsClassLoader.getInstance().loadClass(classString)));
                }
            } catch (Exception e) {
                /*pass*/}
        }
    } catch (ClassNotFoundException e) {
        throw new APIException("service.unable.set", new Object[] { classString }, e);
    }

    // add this module service to the normal list of services
    setService(cls, classInstance);

    //Run onStartup for all services implementing the OpenmrsService interface.
    if (OpenmrsService.class.isAssignableFrom(classInstance.getClass())) {
        moduleOpenmrsServices.put(classString, (OpenmrsService) classInstance);
        runOpenmrsServiceOnStartup((OpenmrsService) classInstance, classString);
    }
}

From source file:ch.entwine.weblounge.common.impl.content.SearchQueryImpl.java

/**
 * This method is called if a certain type of object is expected by someone.
 * If this is not the case (e. g. query configuration is in good shape, then
 * someone tries to "finish" a configuration part) we throw an
 * <code>IllegalStateException</code>.
 * /*ww  w  .j  a  v  a  2 s.  c  om*/
 * @throws IllegalStateException
 *           if no or a different object is expected
 */
private void ensureExpectation(Class<?> c) throws IllegalStateException {
    if (expectation == null)
        throw new IllegalStateException(
                "Malformed query configuration. No " + c.getClass().getName() + " is expected at this time");
    if (!expectation.getCanonicalName().equals(c.getCanonicalName()))
        throw new IllegalStateException("Malformed query configuration. Something of type "
                + c.getClass().getName() + " is expected at this time");
    expectation = null;
}

From source file:ch.entwine.weblounge.common.impl.content.SearchQueryImpl.java

/**
 * Make sure that an object of type <code>c</code> is on the stack, throw an
 * <code>IllegalStateException</code> otherwise.
 * /*  w ww  . ja  v a 2s . c o  m*/
 * @throws IllegalStateException
 *           if no object of type <code>c</code> was found on the stack
 */
protected void ensureConfigurationObject(Class<?> c) throws IllegalStateException {
    for (Object o : stack) {
        if (c.isAssignableFrom(o.getClass()))
            return;
    }
    throw new IllegalStateException(
            "Malformed query configuration. No " + c.getClass().getName() + " is expected at this time");
}

From source file:ch.entwine.weblounge.common.impl.content.SearchQueryImpl.java

/**
 * Make sure that an array of type <code>c</code> is on the stack, throw an
 * <code>IllegalStateException</code> otherwise.
 * /*from  w w w  . j a  va2  s .co  m*/
 * @throws IllegalStateException
 *           if no array of type <code>c</code> was found on the stack
 */
protected void ensureConfigurationArray(Class<?> c) throws IllegalStateException {
    for (Object o : stack) {
        if (o.getClass().isArray() && c.isAssignableFrom(o.getClass().getComponentType()))
            return;
    }
    throw new IllegalStateException(
            "Malformed query configuration. No " + c.getClass().getName() + " is expected at this time");
}

From source file:org.apache.axis2.jaxws.server.dispatcher.ProviderDispatcher.java

public Object createRequestParameters(MessageContext request) {
    // First we need to know what kind of Provider instance we're going
    // to be invoking against
    Class providerType = getProviderType();

    // REVIEW: This assumes there is only one endpoint description on the service.  Is that always the case?
    EndpointDescription endpointDesc = request.getEndpointDescription();

    // Now that we know what kind of Provider we have, we can create the 
    // right type of Block for the request parameter data
    Object requestParamValue = null;
    Message message = request.getMessage();
    if (message != null) {

        // Enable MTOM if indicated
        if (endpointDesc.isMTOMEnabled()) {
            message.setMTOMEnabled(true);
        }/*from  www  .j a  v a  2 s.  co  m*/

        // Save off the protocol info so we can use it when creating the response message.
        Protocol messageProtocol = message.getProtocol();
        // Determine what type blocks we want to create (String, Source, etc) based on Provider Type
        BlockFactory factory = createBlockFactory(providerType);

        Service.Mode providerServiceMode = endpointDesc.getServiceMode();

        if (providerServiceMode != null && providerServiceMode == Service.Mode.MESSAGE) {
            if (log.isDebugEnabled()) {
                log.debug("Provider type is " + providerType.getClass().getName());
            }
            if (providerType.equals(SOAPMessage.class)) {
                // We can get the SOAPMessage directly from the message itself
                if (log.isDebugEnabled()) {
                    log.debug("Number Message attachments=" + message.getAttachmentIDs().size());
                }
            }
            if (providerType.equals(OMElement.class)) {
                //Register the ContextListener for performance.
                ContextListenerUtils.registerProviderOMListener(request);
                // TODO avoid call to message.getValue due to
                // current unnecessary message transformation in
                // message.getValue.  Once message.getValue is fixed,
                // this code block is unnecessary, though no harm
                // will come if it remains.  rott
                requestParamValue = message.getAsOMElement();
            } else {
                requestParamValue = message.getValue(null, factory);
            }
            if (requestParamValue == null) {
                if (log.isDebugEnabled()) {
                    log.debug(
                            "There are no elements to unmarshal.  ProviderDispatch will pass a null as input");
                }
            }
        } else {
            // If it is not MESSAGE, then it is PAYLOAD (which is the default); only work with the body 
            Block block = message.getBodyBlock(null, factory);
            if (block != null) {
                try {
                    requestParamValue = block.getBusinessObject(true);
                    if (requestParamValue instanceof OMBlock) {
                        // Provider<OMBlock> is not supported, so we need to get the OMElement out
                        if (log.isDebugEnabled()) {
                            log.debug(
                                    "request parameter business object is OMBlock.  Now retrieving OMElement from OMBlock.");
                        }
                        requestParamValue = ((OMBlock) requestParamValue).getOMElement();
                    }
                } catch (WebServiceException e) {
                    throw ExceptionFactory.makeWebServiceException(e);
                } catch (XMLStreamException e) {
                    throw ExceptionFactory.makeWebServiceException(e);
                }
            } else {
                if (log.isDebugEnabled()) {
                    log.debug(
                            "No body blocks in SOAPMessage, Calling provider method with null input parameters");
                }
                requestParamValue = null;
            }
        }
    }

    return requestParamValue;
}

From source file:org.solmix.datax.support.InvokerObject.java

protected Object lookupValue(Class<?> targetType, MethodArgInfo invokerInfo, Annotation[] annotaions,
        GenericParameterNode node) {/*from   w  w  w .  ja  v  a  2  s .  com*/
    Param param = findParam(annotaions);
    Object founded = null;
    Object argument = null;
    String expression = invokerInfo == null ? null : invokerInfo.getExpression();
    if (expression == null) {
        expression = param == null ? null : param.expression();
    }
    if (expression != null) {
        if (velocity == null) {
            velocity = new VelocityExpression(container);
            vmContext = velocity.prepareContext(request, requestContext);
        }
        argument = velocity.evaluateValue(expression, vmContext);
    }
    if (invokerInfo != null && invokerInfo.getValue() != null) {
        argument = invokerInfo.getValue();
    }
    //??value?
    if (argument != null) {
        return adaptValue(targetType, argument, node, param == null ? null : param.javaClass(),
                param == null ? null : param.collectionClass(), param == null ? null : param.javaKeyClass());
    } else {
        //??
        if (isCollection(targetType)) {
            throw new InvokerException(
                    new StringBuilder().append("Not specify data ,can't parse Collection resource:")
                            .append(targetType.getClass()).toString());
        } else {
            //?
            founded = lookupResource(targetType, param);
        }
    }
    return founded;
}

From source file:org.openhab.binding.km200.internal.KM200Comm.java

/**
 * This function checks the virtual state of a service
 *
 *//*  www. j a  v  a 2 s  .  co  m*/
public State getVirtualState(KM200CommObject object, Class<? extends Item> itemType, String service) {
    State state = null;
    String type = object.getServiceType();
    logger.debug("Check virtual state of: {} type: {} item: {}", service, type, itemType.getName());

    switch (type) {
    case "switchProgram":
        KM200SwitchProgramService sPService = ((KM200SwitchProgramService) device.serviceMap
                .get(object.getParent()).getValueParameter());
        String[] servicePath = service.split("/");
        String virtService = servicePath[servicePath.length - 1];
        if (virtService.equals("weekday")) {
            if (itemType.isAssignableFrom(StringItem.class)) {
                String val = sPService.getActiveDay();
                if (val == null) {
                    return null;
                }
                state = new StringType(val);
            } else {
                logger.warn("Bindingtype not supported for day service: {}", itemType.getClass());
                return null;
            }
        } else if (virtService.equals("nbrCycles")) {
            if (itemType.isAssignableFrom(NumberItem.class)) {
                Integer val = sPService.getNbrCycles();
                if (val == null) {
                    return null;
                }
                state = new DecimalType(val);
            } else {
                logger.warn("Bindingtype not supported for nbrCycles service: {}", itemType.getClass());
                return null;
            }
        } else if (virtService.equals("cycle")) {
            if (itemType.isAssignableFrom(NumberItem.class)) {
                Integer val = sPService.getActiveCycle();
                if (val == null) {
                    return null;
                }
                state = new DecimalType(val);
            } else {
                logger.warn("Bindingtype not supported for cycle service: {}", itemType.getClass());
                return null;
            }
        } else if (virtService.equals(sPService.getPositiveSwitch())) {
            if (itemType.isAssignableFrom(NumberItem.class)) {
                Integer val = sPService.getActivePositiveSwitch();
                if (val == null) {
                    return null;
                }
                state = new DecimalType(val);
            } else if (itemType.isAssignableFrom(DateTimeItem.class)) {
                Integer val = sPService.getActivePositiveSwitch();
                if (val == null) {
                    return null;
                }
                Calendar rightNow = Calendar.getInstance();
                Integer hour = val % 60;
                Integer minute = val - (hour * 60);
                rightNow.set(Calendar.HOUR_OF_DAY, hour);
                rightNow.set(Calendar.MINUTE, minute);
                state = new DateTimeType(rightNow);
            } else {
                logger.warn("Bindingtype not supported for cycle service: {}", itemType.getClass());
                return null;
            }
        } else if (virtService.equals(sPService.getNegativeSwitch())) {
            if (itemType.isAssignableFrom(NumberItem.class)) {
                Integer val = sPService.getActiveNegativeSwitch();
                if (val == null) {
                    return null;
                }
                state = new DecimalType(val);
            } else if (itemType.isAssignableFrom(DateTimeItem.class)) {
                Integer val = sPService.getActiveNegativeSwitch();
                if (val == null) {
                    return null;
                }
                Calendar rightNow = Calendar.getInstance();
                Integer hour = val % 60;
                Integer minute = val - (hour * 60);
                rightNow.set(Calendar.HOUR_OF_DAY, hour);
                rightNow.set(Calendar.MINUTE, minute);
                state = new DateTimeType(rightNow);
            } else {
                logger.warn("Bindingtype not supported for cycle service: {}", itemType.getClass());
                return null;
            }
        }
        break;
    case "errorList":
        KM200ErrorService eService = ((KM200ErrorService) device.serviceMap.get(object.getParent())
                .getValueParameter());
        String[] nServicePath = service.split("/");
        String nVirtService = nServicePath[nServicePath.length - 1];
        /* Go through the parameters and read the values */
        switch (nVirtService) {
        case "nbrErrors":
            if (itemType.isAssignableFrom(NumberItem.class)) {
                Integer val = eService.getNbrErrors();
                if (val == null) {
                    return null;
                }
                state = new DecimalType(val);
            } else {
                logger.warn("Bindingtype not supported for error number service: {}", itemType.getClass());
                return null;
            }
            break;
        case "error":
            if (itemType.isAssignableFrom(NumberItem.class)) {
                Integer val = eService.getActiveError();
                if (val == null) {
                    return null;
                }
                state = new DecimalType(val);
            } else {
                logger.warn("Bindingtype not supported for error service: {}", itemType.getClass());
                return null;
            }
            break;
        case "errorString":
            if (itemType.isAssignableFrom(StringItem.class)) {
                String val = eService.getErrorString();
                if (val == null) {
                    return null;
                }
                state = new StringType(val);
            } else {
                logger.warn("Bindingtype not supported for error string service: {}", itemType.getClass());
                return null;
            }
            break;
        }
        break;
    }
    return state;

}

From source file:com.wabacus.system.assistant.ReportAssistant.java

public void setMethodInfoToColBean(ReportBean rbean) {
    if (rbean.getPojoClassObj() == null)
        return;//from w  ww.j  a v a 2s .c o  m
    List<ColBean> lstColBeans = rbean.getDbean().getLstCols();
    if (lstColBeans == null || lstColBeans.size() == 0)
        return;
    Class pojoclass = rbean.getPojoClassObj();
    String propertyTmp = null;
    CrossListReportColBean clrcbeanTmp;
    for (ColBean cbeanTmp : lstColBeans) {
        try {
            if (cbeanTmp == null)
                continue;
            propertyTmp = cbeanTmp.getProperty();
            if (propertyTmp == null || propertyTmp.trim().equals(""))
                continue;
            if (cbeanTmp.isNonValueCol() || cbeanTmp.isSequenceCol() || cbeanTmp.isControlCol())
                continue;
            clrcbeanTmp = (CrossListReportColBean) cbeanTmp
                    .getExtendConfigDataForReportType(CrossListReportType.KEY);
            if (clrcbeanTmp != null && clrcbeanTmp.isDynamicColGroup())
                continue;//??
            String setMethodName = "set" + propertyTmp.substring(0, 1).toUpperCase() + propertyTmp.substring(1);
            Method setMethod = pojoclass.getMethod(setMethodName,
                    new Class[] { cbeanTmp.getDatatypeObj().getJavaTypeClass() });
            cbeanTmp.setSetMethod(setMethod);

            String getMethodName = "get" + propertyTmp.substring(0, 1).toUpperCase() + propertyTmp.substring(1);
            Method getMethod = pojoclass.getMethod(getMethodName, new Class[] {});
            cbeanTmp.setGetMethod(getMethod);
        } catch (Exception e) {
            throw new WabacusConfigLoadingException("POJO" + pojoclass.getClass().getName()
                    + "?" + rbean.getPath() + "" + propertyTmp + "get/set", e);
        }
    }
}

From source file:net.sf.morph.reflect.reflectors.BaseReflector.java

private boolean isReflectableInternal(Class reflectedType) {
    initialize();/*from  www  .  jav  a  2 s .c o  m*/

    if (reflectedType == null) {
        throw new ReflectionException(
                "Cannot determine if a null reflectedType is reflectable; please supply a reflectedType to the "
                        + getClass().getName() + ".isReflectable method");
    }

    // try to pull the isReflectable information from the cache
    if (isCachingIsReflectableCalls()) {
        Boolean isReflectable = (Boolean) getReflectableCallCache().get(reflectedType);
        if (isReflectable != null) {
            return isReflectable.booleanValue();
        }
    }

    try {
        boolean isReflectable = isReflectableImpl(reflectedType);
        if (isCachingIsReflectableCalls()) {
            getReflectableCallCache().put(reflectedType, new Boolean(isReflectable));
        }
        return isReflectable;
    } catch (ReflectionException e) {
        throw e;
    } catch (Exception e) {
        if (e instanceof RuntimeException && !isWrappingRuntimeExceptions()) {
            throw (RuntimeException) e;
        }
        throw new ReflectionException(
                "Unable to determine if class '" + reflectedType.getClass().getName() + "' is reflectable", e);
    }
}