List of usage examples for java.lang Class toString
public String toString()
From source file:net.mojodna.sprout.SproutAutoLoaderPlugIn.java
@SuppressWarnings("unchecked") private void loadAction(final Class bean) { final Annotation[] annotations = bean.getAnnotations(); for (int i = 0; i < annotations.length; i++) { final Annotation a = annotations[i]; final Class type = a.annotationType(); if (type.equals(SproutAction.class)) { final SproutAction form = (SproutAction) a; final String path = form.path(); final Class<ActionConfig> mappingClass = form.mappingClass(); final String scope = form.scope(); final String name = form.name(); final boolean validate = form.validate(); final String input = form.input(); final SproutProperty[] properties = form.properties(); final SproutForward[] forwards = form.forwards(); ActionConfig actionConfig = null; try { Constructor<ActionConfig> constructor = mappingClass.getDeclaredConstructor(new Class[] {}); actionConfig = constructor.newInstance(new Object[] {}); } catch (NoSuchMethodException nsme) { log.error("Failed to create a new instance of " + mappingClass.toString() + ", " + nsme.getMessage()); } catch (InstantiationException ie) { log.error("Failed to create a new instance of " + mappingClass.toString() + ", " + ie.getMessage()); } catch (IllegalAccessException iae) { log.error("Failed to create a new instance of " + mappingClass.toString() + ", " + iae.getMessage()); } catch (InvocationTargetException ite) { log.error("Failed to create a new instance of " + mappingClass.toString() + ", " + ite.getMessage()); }//from www.j av a2 s . c om if (actionConfig != null) { actionConfig.setPath(path); actionConfig.setType(bean.getName()); actionConfig.setScope(scope); actionConfig.setValidate(validate); if (name.length() > 0) { actionConfig.setName(name); } if (input.length() > 0) { actionConfig.setInput(input); } if (properties != null && properties.length > 0) { Map actionConfigBeanMap = new BeanMap(actionConfig); for (int j = 0; j < properties.length; j++) { actionConfigBeanMap.put(properties[j].property(), properties[j].value()); } } if (forwards != null && forwards.length > 0) { for (int j = 0; j < forwards.length; j++) { String fcModule = forwards[j].module(); actionConfig.addForwardConfig(makeForward(forwards[j].name(), forwards[j].path(), forwards[j].redirect(), fcModule.length() == 0 ? null : fcModule)); } } } if (log.isDebugEnabled()) { log.debug("Action " + path + " -> " + bean.getName()); } getModuleConfig().addActionConfig(actionConfig); } } }
From source file:net.di2e.ecdr.commons.CDRMetacard.java
protected <T> T getAttributeValue(Attribute attribute, Class<T> returnType) { Serializable data = attribute.getValue(); if (returnType.isAssignableFrom(data.getClass())) { return returnType.cast(data); } else {//w w w.j av a 2s.c o m if (LOGGER.isDebugEnabled()) { LOGGER.trace(data.getClass().toString() + " can not be assigned to " + returnType.toString()); } } return null; }
From source file:com.newmainsoftech.spray.slingong.datastore.Slim3AnnotationTransactionAspectPointcutTest.java
@SuppressWarnings("unused") @Test/*w ww . j a va 2 s .co m*/ public void test_GlobalTransaction_class() throws Throwable { final String globalTransactionClassKnownName = "org.slim3.datastore.GlobalTransaction"; final Class<GlobalTransaction> globalTransactionClass = GlobalTransaction.class; Assert.assertEquals( String.format( "Pointcut expressions in %1$s class MAY need update regarding %2$s class " + "refactoring from %3$s to %4$s.", Slim3AnnotationTransactionAspect.class.getName(), globalTransactionClass.getSimpleName(), globalTransactionClassKnownName, globalTransactionClass.getName()), globalTransactionClassKnownName, globalTransactionClass.getName()); String methodName = "commit"; try { Method method = globalTransactionClass.getMethod(methodName, (Class<?>[]) null); } catch (NoSuchMethodException exception) { Assert.fail(String.format( "Pointcut expressions in %1$s class MAY need update because " + "%2$s method is not found among public methods of %3$s any longer.", Slim3AnnotationTransactionAspect.class.getName(), methodName, globalTransactionClass.toString())); } methodName = "rollback"; try { Method method = globalTransactionClass.getMethod(methodName, (Class<?>[]) null); } catch (NoSuchMethodException exception) { Assert.fail(String.format( "Pointcut expressions in %1$s class MAY need update because " + "%2$s method is not found among public methods of %3$s any longer.", Slim3AnnotationTransactionAspect.class.getName(), methodName, globalTransactionClass.toString())); } int putMethodCount = 0; int deleteMethodCount = 0; Method[] methodArrays = globalTransactionClass.getMethods(); for (Method method : methodArrays) { if ("put".equals(method.getName())) { putMethodCount++; } else if (method.getName().startsWith("delete")) { deleteMethodCount++; } } // for Assert.assertTrue( String.format( "Pointcut expressions in %1$s class MAY need update because " + "%2$s method is not found among public methods of %3$s any longer.", Slim3AnnotationTransactionAspect.class.getName(), "put", globalTransactionClass.toString()), (putMethodCount > 0)); Assert.assertTrue(String.format( "Pointcut expressions in %1$s class MAY need update because " + "%2$s method is not found among public methods of %3$s any longer.", Slim3AnnotationTransactionAspect.class.getName(), "delete", globalTransactionClass.toString()), (deleteMethodCount > 0)); }
From source file:pt.webdetails.cda.exporter.AbstractExporter.java
protected String getColType(final Class<?> columnClass) throws ExporterException { if (columnClass.equals(String.class)) { return "String"; } else if (columnClass.equals(Boolean.class)) { return "Boolean"; } else if (columnClass.equals(Integer.class) || columnClass.equals(Short.class) || columnClass.equals(Byte.class)) { return "Integer"; } else if (Number.class.isAssignableFrom(columnClass)) { return "Numeric"; } else if (Date.class.isAssignableFrom(columnClass)) { return "Date"; } else if (columnClass.equals(Object.class)) { // todo: Quick and dirty hack, as the formula never knows what type is returned. return "String"; } else if (columnClass.equals(byte[].class) || Blob.class.isAssignableFrom(columnClass)) { return "Blob"; } else {//www . j a v a 2 s.com // Unsupported. However, instead of bombing out, we'll try to cast to toString //throw new ExporterException("CDA exporter doesn't know how to handle: " + columnClass.toString(), null); logger.warn("CDA exporter doesn't know how to handle:" + columnClass.toString() + "; Returning String to allow it to continue"); return "String"; } }
From source file:org.jgentleframework.context.injecting.AbstractBeanFactory.java
/** * Gets the bean instance./* w w w. j a v a 2 s . c o m*/ * * @param selector * the selector * @return the bean instance * @throws Exception */ protected Object getBeanInstance(Selector selector) throws Exception { Object result = null; if (ReflectUtils.isCast(CoreInstantiationSelector.class, selector)) { CoreInstantiationSelector coreSelector = (CoreInstantiationSelector) selector; Class<?> type = coreSelector.getType(); Class<?> targetClass = coreSelector.getTargetClass(); Definition definition = coreSelector.getDefinition(); String mappingName = coreSelector.getReferenceName(); String scopeName = null; // validate definition = definition == null ? this.definitionManager.getDefinition(targetClass) : definition; Class<?> defClass = (Class<?>) definition.getKey(); if (!defClass.equals(targetClass)) { if (log.isErrorEnabled()) { log.error( "The given definition is not corresponding to class '" + targetClass.toString() + "'!", new InOutDependencyException()); } } scopeName = Utils.createScopeName(type, targetClass, definition, mappingName); // setup scopeName to selector selector.setScopeName(scopeName); // creates scope info, default is SINGLETON synchronized (scopeList) { if (!scopeList.containsKey(scopeName)) { scopeList.put(scopeName, Scope.SINGLETON); } } ScopeImplementation scopeImple = null; scopeImple = this.objectBeanFactory.createScopeInstance(scopeName); result = getBeanFromScope(scopeImple, selector, scopeName); // Checking FactoryBean if (FactoryBean.class.isAssignableFrom(targetClass)) { FactoryBean factoryBean = (FactoryBean) result; String nameScopeFac = scopeName + ":" + FactoryBean.class.toString(); if (factoryBean.isSingleton()) { synchronized (mapDirectList) { if (mapDirectList.containsKey(nameScopeFac)) { return this.objectBeanFactory.getMapDirectList().get(nameScopeFac); } else { Object resultFac = CommonFactory.singleton().executeFactoryBean(factoryBean, targetClass); mapDirectList.put(nameScopeFac, resultFac); return resultFac; } } } else { return CommonFactory.singleton().executeFactoryBean(factoryBean, targetClass); } } } else Assertor.throwRunTimeException("The selector is invalid !!"); return result; }
From source file:org.opentestsystem.delivery.testadmin.domain.schedule.ScheduledStudent.java
@SuppressWarnings("unchecked") private <T> T convertTo(final String value, final Class<T> clazz) { try {//w w w .j a va 2 s.co m if (String.class.isAssignableFrom(clazz)) { return (T) value; } else if (Number.class.isAssignableFrom(clazz)) { return clazz.getConstructor(String.class).newInstance(value); } else if (DateTime.class.isAssignableFrom(clazz)) { return (T) DateTime.parse(value); } else if (Enum.class.isAssignableFrom(clazz)) { Method getEnum = null; try { getEnum = clazz.getDeclaredMethod("getEnumByValue", String.class); } catch (final NoSuchMethodException me) { getEnum = clazz.getMethod("valueOf", String.class); } return (T) getEnum.invoke(null, value); } else { throw new EligibilityException("eligibility.value.convert.error", new String[] { value, clazz.toString() }); } } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { throw new EligibilityException("eligibility.value.convert.error", new String[] { value, clazz.toString() }, e); } }
From source file:org.jgentleframework.services.objectpooling.context.PoolScope.java
@Override public Object getBean(Selector selector, String scopeName, ObjectBeanFactory objFactory) { Object result = null;//from w ww. j av a 2 s . c om Provider provider = objFactory.getProvider(); Class<?> targetClass = selector.getTargetClass(); Definition definition = selector.getDefinition(); Pooling poolingConfig = definition.getAnnotation(Pooling.class); if (poolingConfig == null) { poolingConfig = provider.getBean(Pooling.class); } PoolScope scope = null; Map<String, ScopeInstance> scopeList = objFactory.getScopeList(); synchronized (scopeList) { scope = (PoolScope) scopeList.get(scopeName); } synchronized (scopeName) { Pool pool = this.poolServices.get(scopeName); if (pool != null) { synchronized (pool) { result = this.obtainInstance(pool, poolingConfig, targetClass); } } else { Class<? extends Pool> clazz = null; switch (scope) { case CommonPool: clazz = org.jgentleframework.services.objectpooling.CommonPool.class; break; case StackPool: clazz = org.jgentleframework.services.objectpooling.StackPool.class; break; case WeakPool: clazz = org.jgentleframework.services.objectpooling.WeakPool.class; break; default: if (log.isErrorEnabled()) { log.error("The specified scope is invalid !", new IllegalStateException()); } } if (clazz != null) { Binder binder = new Binder(provider); binder.bind("config", "definition", "selector").to(poolingConfig, definition, selector) .in(clazz).id(clazz.toString()).scope(Scope.SINGLETON); binder.flush(); pool = (Pool) provider.getBeanBoundToDefinition(clazz.toString()); this.poolServices.put(scopeName, pool); result = this.obtainInstance(pool, poolingConfig, targetClass); } else { if (log.isErrorEnabled()) { log.error("The specified scope is invalid !", new IllegalStateException()); } } } } return result; }
From source file:net.sourceforge.jabm.VariableBindingsIterator.java
@SuppressWarnings({ "rawtypes", "unchecked" }) public VariableRange parseVariableRange(String rangeSpecification, Class type) { Matcher matcher = rangePattern.matcher(rangeSpecification); if (matcher.matches()) { VariableRange result = new VariableRange(); String minStr = matcher.group(1); String incrStr = matcher.group(2); String maxStr = matcher.group(3); if (type.isAssignableFrom(int.class) || type.isAssignableFrom(long.class)) { result.setMin(new UntypedLong(Long.parseLong(minStr))); result.setIncrement(new UntypedLong(Long.parseLong(incrStr))); result.setMax(new UntypedLong(Long.parseLong(maxStr))); } else if (type.isAssignableFrom(double.class) || type.isAssignableFrom(float.class)) { result.setMin(new UntypedDouble(Double.parseDouble(minStr))); result.setIncrement(new UntypedDouble(Double.parseDouble(incrStr))); result.setMax(new UntypedDouble(Double.parseDouble(maxStr))); } else {/*from w ww . j av a 2 s. co m*/ throw new IllegalArgumentException(type.toString()); } return result; } throw new IllegalArgumentException("Could not parse range specification: " + rangeSpecification); }
From source file:edu.arizona.kra.institutionalproposal.negotiationlog.service.NegotiationLogMigrationServiceImpl.java
/** * Finds the NegotiationsGroupingBase type of object depending on the provided code, or returns the default one, if none found. * Once it finds a default object for a given code, it will store it in the "cache" map for default objs=defaultNegotiationBOs * @param clazz/* w w w .j av a 2s . co m*/ * @param code * @param defaultCode * @return */ private <T extends NegotiationsGroupingBase> T findNegotiationTypeByCode(Class<T> clazz, String code, String defaultCode) { Map<String, String> criteria = new HashMap(); Collection<T> negotiationTypeBOs = null; //if no code provided, use the default one if (!StringUtils.isEmpty(code)) { criteria.put("code", code); negotiationTypeBOs = getBusinessObjectService().findMatching(clazz, criteria); } if (StringUtils.isEmpty(code) || negotiationTypeBOs == null || negotiationTypeBOs.isEmpty()) { //Code in didn't match any of the new ones.... setting it to the default one LOG.debug(clazz.toString() + " for Code " + code + " not found. Using default:" + defaultCode); String key = defaultCode + ":" + clazz.getName(); if (!defaultNegotiationBOs.containsKey(key)) { criteria.put("code", defaultCode); negotiationTypeBOs = getBusinessObjectService().findMatching(clazz, criteria); if (negotiationTypeBOs == null || negotiationTypeBOs.isEmpty()) { LOG.error("Cannot find " + clazz.toString() + " default with code:" + defaultCode); throw new NegotiationMigrationException( "Cannot find " + clazz.toString() + " default with code:" + defaultCode); } defaultNegotiationBOs.put(key, (NegotiationsGroupingBase) negotiationTypeBOs.iterator().next()); } return (T) defaultNegotiationBOs.get(key); } return (T) negotiationTypeBOs.iterator().next(); }
From source file:org.linagora.linshare.core.rac.impl.QuotaResourceAccessControlImpl.java
protected boolean isAuthorized(Account actor, Account targetedAccount, PermissionType permission, Quota entry, Class<?> clazz, Object... opt) { Validate.notNull(actor);//www .j a v a 2 s. c om Validate.notNull(permission); if (actor.hasAllRights()) return true; if (permission.equals(PermissionType.GET)) { if (hasReadPermission(actor, targetedAccount, entry, opt)) return true; } else if (permission.equals(PermissionType.LIST)) { if (hasListPermission(actor, targetedAccount, entry, opt)) return true; } else if (permission.equals(PermissionType.CREATE)) { if (hasCreatePermission(actor, targetedAccount, entry, opt)) return true; } else if (permission.equals(PermissionType.UPDATE)) { if (hasUpdatePermission(actor, targetedAccount, entry, opt)) return true; } else if (permission.equals(PermissionType.DELETE)) { if (hasDeletePermission(actor, targetedAccount, entry, opt)) return true; } if (clazz != null) { StringBuilder sb = getActorStringBuilder(actor); sb.append(" is trying to access to unauthorized resource named "); sb.append(clazz.toString()); appendOwner(sb, entry, opt); logger.error(sb.toString()); } return false; }