List of usage examples for java.lang Class getCanonicalName
public String getCanonicalName()
From source file:com.norconex.commons.lang.xml.EnhancedXMLStreamWriter.java
public void writeAttributeClass(String localName, Class<?> value) throws XMLStreamException { if (value == null) { writeAttributeObject(localName, null); } else {//w w w . ja va2s . co m writeAttributeObject(localName, value.getCanonicalName()); } }
From source file:org.carewebframework.ui.ExceptionController.java
/** * Appends the stack trace for the specified exception to the display. * /* ww w .ja va 2s . com*/ * @param err Exception whose stack trace will be appended. */ private void appendStackTrace(final Throwable err) { if (err != null) { final Class<?> clazz = err.getClass(); final String msg = err.getMessage(); //final Throwable cause = err.getCause();//should be null this.txtStackTrace.setValue(StringUtils.defaultString(this.txtStackTrace.getValue()) + StringUtils.trimToEmpty(clazz.getCanonicalName()) + ": " + StringUtils.trimToEmpty(msg) + "\n"); for (final StackTraceElement element : err.getStackTrace()) { this.txtStackTrace.setValue( StringUtils.defaultString(this.txtStackTrace.getValue()) + String.valueOf(element) + "\n"); } } }
From source file:org.openmrs.module.kenyarx.mapping.ObjectObsMarshaller.java
/** * Finds the mapping for the specified class * @param clazz the class/*from w w w .j a va 2 s .co m*/ * @return the mapping */ private ClassConceptMapping getMapping(Class<?> clazz) { if (mappings != null) { for (ClassConceptMapping mapping : mappings) { if (mapping.getTargetClass().equals(clazz)) { return mapping; } } } throw new RuntimeException("No mapping found for " + clazz.getCanonicalName()); }
From source file:info.archinnov.achilles.internals.context.ConfigurationContext.java
public void injectDependencies(TupleTypeFactory tupleTypeFactory, UserTypeFactory userTypeFactory, AbstractEntityProperty<?> entityProperty) { LOGGER.info("Start injecting dependencies to meta classes"); final Class<?> entityClass = entityProperty.entityClass; final String className = entityClass.getCanonicalName(); if (currentKeyspace.isPresent()) { LOGGER.debug("Injecting current global keyspace"); entityProperty.injectKeyspace(currentKeyspace.get()); }//www . j a v a 2s . com if (schemaNameProvider.isPresent()) { LOGGER.debug("Injecting schema name provider"); entityProperty.inject(schemaNameProvider.get()); } LOGGER.debug("Injecting default bean factory"); entityProperty.inject(defaultBeanFactory); LOGGER.debug("Injecting Jackson mapper"); entityProperty.inject(jacksonMapperFactory.getMapper(entityClass)); LOGGER.debug("Injecting global Insert strategy"); entityProperty.inject(globalInsertStrategy); if (!interceptors.isEmpty()) { LOGGER.debug("Injecting bean interceptors"); interceptors.stream().filter(x -> x.acceptEntity(entityClass)).map(x -> (Interceptor) x) .forEach(entityProperty.interceptors::add); } // Adding PreMutate Bean validator as the LAST interceptor if (beanValidator != null && isClassConstrained(entityClass)) { LOGGER.debug("Injecting Bean validator (JSR 303)"); if (entityProperty.isTable()) { entityProperty.interceptors.add((Interceptor) preMutateBeanValidationInterceptor); } // Add PostLoad interceptor as the FIRST interceptor if (postLoadBeanValidationInterceptor.isPresent()) { entityProperty.interceptors.add(0, (Interceptor) postLoadBeanValidationInterceptor.get()); } } LOGGER.debug("Injecting global consistency levels"); entityProperty.injectConsistencyLevels(session, this); LOGGER.debug("Injecting runtime codecs"); entityProperty.injectRuntimeCodecs(runtimeCodecs); LOGGER.debug("Injecting user type factory and tuple type factory"); entityProperty.inject(userTypeFactory, tupleTypeFactory); }
From source file:com.crossbusiness.resiliency.aspect.spring.AnnotationCircuitBreakerAspect.java
public Object breakCircuit(final ProceedingJoinPoint pjp, CircuitBreaker circuitBreakerConfig) throws Throwable { Object result = null;/* w w w .j a v a2 s. c o m*/ final String method = pjp.getSignature().toLongString(); CircuitBreakerStatus status = null; try { final MethodSignature sig = (MethodSignature) pjp.getStaticPart().getSignature(); registry.registeredMehtodIfnecessary(method, circuitBreakerConfig); status = registry.getStatusWithHalfOpenExclusiveLockTry(method); if (status.equals(CircuitBreakerStatus.OPEN)) { log.info("CIRCUIT STATUS: OPEN. Method {} can not be executed. try later!", method); throw new OpenCircuitException(); } else if (status.equals(CircuitBreakerStatus.HALF_OPEN)) { log.info( "CIRCUIT STATUS: HALF_OPEN. Another thread has the exclusive lock for half open. Method {} can not be executed.", method); throw new OpenCircuitException(); } else if (status.equals(CircuitBreakerStatus.CLOSED)) { log.info("CIRCUIT STATUS: CLOSED. execute method {}", method); result = proceed(pjp); } else if (status.equals(CircuitBreakerStatus.HALF_OPEN_EXCLUSIVE)) { log.info( "CIRCUIT STATUS: HALF_OPEN_EXCLUSIVE. This thread win the exclusive lock for the half open call. execute method: {}", method); result = proceed(pjp); log.info( "CIRCUIT STATUS: HALF_OPEN_EXCLUSIVE. method execution was successfull. now close circuit for method {}", method); registry.closeAndUnlock(method); } } catch (CircuitBreakerMethodExecutionException e) { Throwable throwable = e.getCause(); for (Class<? extends Throwable> clazz : registry.getfailureIndications(method)) { if (clazz.isAssignableFrom(throwable.getClass())) { // detected a failure log.info("detected failure. failure indication: {} \nException:", clazz.getCanonicalName(), throwable); if (status.equals(CircuitBreakerStatus.CLOSED) && registry.sameClosedCycleInLocalAndGlobaleContext(method)) { log.info("Valid failure: method call and failure are in the same CLOSED cycle."); registry.addFailureAndOpenCircuitIfThresholdAchived(method); } else if (status.equals(CircuitBreakerStatus.HALF_OPEN_EXCLUSIVE)) { registry.keepOpenAndUnlock(method); } throw throwable; } } // thrown exception is not a failureIndication if (status.equals(CircuitBreakerStatus.HALF_OPEN_EXCLUSIVE)) { log.info( "CIRCUIT STATUS: HALF_OPEN_EXCLUSIVE. method execution was successfull. now close circuit for method {}", method); registry.closeAndUnlock(method); } // throw the original method execution exception upper to the method invoker throw throwable; } finally { registry.cleanUp(method); } return result; }
From source file:io.leishvl.core.xml.PubMedXmlBinder.java
@Override @SuppressWarnings("unchecked") protected <T> JAXBElement<T> createType(final T obj) { Object element;/*from www . j a va2s . c o m*/ Class<?> clazz = obj.getClass(); if (clazz.equals(PubmedArticleSet.class)) { element = PUBMED_XML_FACTORY.createPubmedArticleSet(); } else if (clazz.equals(PubmedArticle.class)) { element = PUBMED_XML_FACTORY.createPubmedArticle(); } else { throw new IllegalArgumentException("Unsupported type: " + clazz.getCanonicalName()); } return (JAXBElement<T>) element; }
From source file:edu.internet2.middleware.grouper.changeLog.provisioning.ProvisioningConsumer.java
/** * If necessary, instantiate the connector class. * Initialize the connector./*from w w w.j a v a 2 s. co m*/ * * @param consumerName */ private void loadAndInitConnectorIfNecessary(String consumerName) throws Exception { if (this.connector == null) { String theClassName = GrouperLoaderConfig .getPropertyString("changeLog.consumer." + consumerName + ".connector.class"); Class<?> theClass = GrouperUtil.forName(theClassName); if (LOG.isDebugEnabled()) { LOG.debug("Creating instance of class " + theClass.getCanonicalName()); } connector = (EventProvisioningConnector) GrouperUtil.newInstance(theClass); setConfigProperties(consumerName); } connector.init(consumerName); }
From source file:com.ryantenney.metrics.spring.AbstractMetricMethodInterceptor.java
AbstractMetricMethodInterceptor(final MetricRegistry metricRegistry, final Class<?> targetClass, final Class<A> annotationClass, final MethodFilter methodFilter) { this.metricRegistry = metricRegistry; this.targetClass = targetClass; this.annotationClass = annotationClass; this.metrics = new HashMap<MethodKey, AnnotationMetricPair<A, M>>(); LOG.debug("Creating method interceptor for class {}", targetClass.getCanonicalName()); LOG.debug("Scanning for @{} annotated methods", annotationClass.getSimpleName()); ReflectionUtils.doWithMethods(targetClass, this, methodFilter); }
From source file:com.sqewd.open.dal.core.persistence.csv.CSVPersister.java
protected void load(final Class<?> type) throws Exception { if (!type.isAnnotationPresent(Entity.class)) throw new Exception("Class [" + type.getCanonicalName() + "] has not been annotated as an Entity."); synchronized (cache) { if (cache.containsKey(type.getCanonicalName())) return; Entity eann = type.getAnnotation(Entity.class); String fname = eann.recordset() + "." + format.name(); String path = datadir + "/" + fname; File fi = new File(path); if (!fi.exists()) throw new Exception("Cannot find file [" + path + "] for entity [" + type.getCanonicalName() + "]"); List<AbstractEntity> entities = new ArrayList<AbstractEntity>(); char sep = ','; if (format == EnumImportFormat.TSV) { sep = '\t'; }//from ww w . j a v a2 s. c o m CSVReader reader = new CSVReader(new FileReader(path), sep, '"'); String[] header = null; while (true) { String[] data = reader.readNext(); if (data == null) { break; } if (header == null) { header = data; continue; } if (data.length < header.length) { continue; } AbstractEntity record = parseRecord(type, header, data); if (record == null) { log.warn("Parse returned NULL"); continue; } entities.add(record); } cache.put(type.getCanonicalName(), entities); reader.close(); } }
From source file:com.netflix.governator.configuration.ArchaiusConfigurationProvider.java
protected static Supplier<?> getDynamicSupplier(Class<?> type, String key, String defaultValue, DynamicPropertyFactory propertyFactory) { if (type.isAssignableFrom(String.class)) { return new PropertyWrapperSupplier<String>(propertyFactory.getStringProperty(key, defaultValue)); } else if (type.isAssignableFrom(Integer.class)) { return new PropertyWrapperSupplier<Integer>( propertyFactory.getIntProperty(key, defaultValue == null ? 0 : Integer.parseInt(defaultValue))); } else if (type.isAssignableFrom(Double.class)) { return new PropertyWrapperSupplier<Double>(propertyFactory.getDoubleProperty(key, defaultValue == null ? 0.0 : Double.parseDouble(defaultValue))); } else if (type.isAssignableFrom(Long.class)) { return new PropertyWrapperSupplier<Long>( propertyFactory.getLongProperty(key, defaultValue == null ? 0L : Long.parseLong(defaultValue))); } else if (type.isAssignableFrom(Boolean.class)) { return new PropertyWrapperSupplier<Boolean>(propertyFactory.getBooleanProperty(key, defaultValue == null ? false : Boolean.parseBoolean(defaultValue))); }/* ww w .ja va 2s . c o m*/ throw new RuntimeException("Unsupported value type " + type.getCanonicalName()); }