List of usage examples for java.lang Class toString
public String toString()
From source file:org.apache.tapestry.param.ParameterManager.java
private void setup(IRequestCycle cycle) { boolean debug = LOG.isDebugEnabled(); if (debug)// ww w .j a v a 2 s .c om LOG.debug(_component + ": connecting parameters and properties"); List list = new ArrayList(); IComponentSpecification spec = _component.getSpecification(); IResourceResolver resolver = _component.getPage().getEngine().getResourceResolver(); IParameterConnector disabledConnector = null; Collection names = spec.getParameterNames(); Iterator i = names.iterator(); while (i.hasNext()) { String name = (String) i.next(); if (debug) LOG.debug("Connecting parameter " + name + "."); IBinding binding = _component.getBinding(name); if (binding == null) { if (debug) LOG.debug("Not bound."); continue; } IParameterSpecification pspec = spec.getParameter(name); Direction direction = pspec.getDirection(); if (direction != Direction.IN && direction != Direction.FORM) { if (debug) LOG.debug("Parameter is " + pspec.getDirection().getName() + "."); continue; } if (!direction.getAllowInvariant() && binding.isInvariant()) throw new ConnectedParameterException( Tapestry.format("ParameterManager.incompatible-direction-and-binding", new Object[] { name, _component.getExtendedId(), direction.getDisplayName(), binding }), _component, name, null, binding.getLocation(), null); String propertyName = pspec.getPropertyName(); if (debug && !name.equals(propertyName)) LOG.debug("Connecting to property " + propertyName + "."); // Next,verify that there is a writable property with the same // name as the parameter. PropertyInfo propertyInfo = PropertyFinder.getPropertyInfo(_component.getClass(), propertyName); if (propertyInfo == null) { throw new ConnectedParameterException( Tapestry.format("ParameterManager.no-accessor", _component.getExtendedId(), propertyName), _component, name, propertyName, binding.getLocation(), null); } if (!propertyInfo.isReadWrite()) { throw new ConnectedParameterException(Tapestry.format("ParameterManager.property-not-read-write", _component.getExtendedId(), propertyName), _component, name, propertyName, binding.getLocation(), null); } // Check if the parameter type matches the property type Class propertyType = propertyInfo.getType(); Class parameterType = getType(pspec.getType(), resolver); if (parameterType == null) { throw new ConnectedParameterException( Tapestry.format("ParameterManager.java-type-not-specified", name, _component.getExtendedId()), _component, name, propertyName, binding.getLocation(), null); } if (!propertyType.equals(parameterType)) { throw new ConnectedParameterException( Tapestry.format("ParameterManager.type-mismatch", new String[] { name, _component.getExtendedId(), parameterType.toString(), propertyType.toString() }), _component, name, propertyName, binding.getLocation(), null); } // Here's where we will sniff it for type, for the moment // assume its some form of object (not scalar) type. IParameterConnector connector = createConnector(_component, name, binding, propertyType, parameterType); // Static bindings are set here and then forgotten // about. Dynamic bindings are kept for later. if (binding.isInvariant()) { if (debug) LOG.debug("Setting invariant value using " + connector + "."); try { connector.setParameter(cycle); } catch (BindingException ex) { throw new ConnectedParameterException( Tapestry.format("ParameterManager.static-initialization-failure", propertyName, _component.getExtendedId(), binding.toString()), _component, name, propertyName, ex); } continue; } if (debug) LOG.debug("Adding " + connector + "."); // To properly support forms elements, the disabled parameter // must always be processed last. if (name.equals("disabled")) disabledConnector = connector; else list.add(connector); } if (disabledConnector != null) list.add(disabledConnector); // Convert for List to array _connectors = (IParameterConnector[]) list.toArray(new IParameterConnector[list.size()]); }
From source file:org.energyos.espi.common.repositories.jpa.ResourceRepositoryImpl.java
@Override public <T extends IdentifiedObject> Long findIdByXPath(Long id1, Long id2, Long id3, Long id4, Class<T> clazz) { try {//from w w w . j a v a 2 s .c om String findIdByXPath = (String) clazz.getDeclaredField("QUERY_FIND_ID_BY_XPATH").get(String.class); Query query = em.createNamedQuery(findIdByXPath).setParameter("o1Id", id1).setParameter("o2Id", id2) .setParameter("o3Id", id3).setParameter("o4Id", id4); return (Long) query.getSingleResult(); } catch (NoSuchFieldException | IllegalAccessException e) { System.out.printf("**** findIdByXPath(Long id1, Long id2, Long id3, Long id4) Exception: %s - %s\n", clazz.toString(), e.toString()); throw new RuntimeException(e); } }
From source file:net.malariagen.gatk.test.WalkerTest.java
/** * execute the test, given the following: * @param name the name of the test/*from w w w . j a v a 2 s . co m*/ * @param args the argument list * @param expectedException the expected exception or null */ public static void executeTest(String name, String args, Class<?> expectedException) { CommandLineGATK instance = new CommandLineGATK(); String[] command = Utils.escapeExpressions(args); // add the logging level to each of the integration test commands // command = Utils.appendArray(command, "-et", ENABLE_REPORTING ? "STANDARD" : "NO_ET"); // run the executable boolean gotAnException = false; try { System.out.println( String.format("Executing test %s with GATK arguments: %s", name, Utils.join(" ", command))); CommandLineExecutable.start(instance, command); } catch (Exception e) { gotAnException = true; if (expectedException != null) { // we expect an exception System.out.println(String.format("Wanted exception %s, saw %s", expectedException, e.getClass())); if (expectedException.isInstance(e)) { // it's the type we expected System.out.println(String.format(" => %s PASSED", name)); } else { e.printStackTrace(); Assert.fail(String.format("Test %s expected exception %s but got %s instead", name, expectedException, e.getClass())); } } else { // we didn't expect an exception but we got one :-( throw new RuntimeException(e); } } // catch failures from the integration test if (expectedException != null) { if (!gotAnException) // we expected an exception but didn't see it Assert.fail(String.format("Test %s expected exception %s but none was thrown", name, expectedException.toString())); } else { if (CommandLineExecutable.result != 0) { throw new RuntimeException("Error running the GATK with arguments: " + args); } } }
From source file:org.socialsignin.spring.data.dynamodb.repository.support.FieldAndGetterReflectionEntityInformation.java
/** * Creates a new {@link FieldAndGetterReflectionEntityInformation} inspecting the * given domain class for a getter carrying the given annotation. * //from www . j av a2 s . co m * @param domainClass * must not be {@literal null}. * @param annotation * must not be {@literal null}. */ public FieldAndGetterReflectionEntityInformation(Class<T> domainClass, final Class<? extends Annotation> annotation) { super(domainClass); Assert.notNull(annotation); ReflectionUtils.doWithMethods(domainClass, new MethodCallback() { public void doWith(Method method) { if (method.getAnnotation(annotation) != null) { FieldAndGetterReflectionEntityInformation.this.method = method; return; } } }); if (method == null) { ReflectionUtils.doWithFields(domainClass, new FieldCallback() { public void doWith(Field field) { if (field.getAnnotation(annotation) != null) { FieldAndGetterReflectionEntityInformation.this.field = field; return; } } }); } Assert.isTrue(this.method != null || this.field != null, String.format("No field or method annotated with %s found!", annotation.toString())); Assert.isTrue(this.method == null || this.field == null, String.format("Both field and method annotated with %s found!", annotation.toString())); if (method != null) { ReflectionUtils.makeAccessible(method); } }
From source file:org.apache.kylin.cube.upgrade.common.CubeMetadataUpgrade.java
public static void upgradeOrVerify(Class upgradeClass, String[] args, boolean firstStepInChain, boolean lastStepInChain) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { if (!(args != null && (args.length == 1))) { System.out.println("Usage: java CubeMetadataUpgrade <metadata_export_folder>"); System.out.println(//from w w w . j a v a 2 s . c o m ", where metadata_export_folder is the folder containing your current metadata's dump (Upgrade program will not modify it directly, relax."); return; } String currentMetaDumpFolderPath = args[0]; CubeMetadataUpgrade instance; File currentMetaDumpFolder = new File(currentMetaDumpFolderPath); if (!currentMetaDumpFolder.exists()) { System.out.println("Provided folder doesn't exist: '" + currentMetaDumpFolderPath + "'"); return; } if (!currentMetaDumpFolder.isDirectory()) { System.out.println("Provided folder is not a directory: '" + currentMetaDumpFolderPath + "'"); return; } String newMetadataUrl; if (firstStepInChain) { newMetadataUrl = currentMetaDumpFolder.getAbsolutePath() + "_workspace";//upgrades metadata store in a copy named xx_workspace try { FileUtils.deleteDirectory(new File(newMetadataUrl)); FileUtils.copyDirectory(currentMetaDumpFolder, new File(newMetadataUrl)); } catch (IOException e) { throw new RuntimeException(e); } } else { newMetadataUrl = currentMetaDumpFolder.getAbsolutePath(); } instance = (CubeMetadataUpgrade) upgradeClass.getConstructor(String.class).newInstance(newMetadataUrl); instance.upgradeNonCompatibleMeta(); logger.info("================================================================="); logger.info("Run {} completed", upgradeClass.toString()); logger.info("================================================================="); if (instance.errorMsgs.size() > 0) { logger.info("Here are the error/warning messages, you may need check:"); for (String s : instance.errorMsgs) { logger.error(s); } } else { logger.info("No error or warning messages; The migration is success."); } if (lastStepInChain) { instance.upgradeCompatibleMeta(); instance.verify(); } }
From source file:it.appify.generator.WebAppGenerator.java
protected TypeSpec.Builder overrideStoreCurrentAppState(TypeSpec.Builder webappBuilder, Class<?> webAppModel) { return webappBuilder.addMethod(MethodSpec.methodBuilder("storeCurrentAppState") .addAnnotation(Override.class).addModifiers(Modifier.PROTECTED) .addCode(//from w ww. j a v a 2 s.c o m "if(getStorageService()!=null){" + "$T model = ($T) getCurrentAppState();" + "model.setTimestamp(System.currentTimeMillis());" + "getStorageService().store($S,model);" + "}", webAppModel, webAppModel, webAppModel.toString()) .build()); }
From source file:org.malaguna.cmdit.bbeans.AbstractBean.java
/** * Method that obtains the selected row from a UIComponent. It can check super class * // ww w.j a v a2 s. c o m * @param anEvent */ protected Object selectRowFromEvent(UIComponent tmpComponent, Class<?> clazz, boolean checkSuper) { Object tmpRowData = null; if (tmpComponent != null) { while (null != tmpComponent && !(tmpComponent instanceof UIData)) tmpComponent = tmpComponent.getParent(); if (tmpComponent != null && (tmpComponent instanceof UIData)) { tmpRowData = ((UIData) tmpComponent).getRowData(); boolean checked = clazz.isAssignableFrom(tmpRowData.getClass()); if (!checked && checkSuper) { checked = clazz.isInstance(tmpRowData); } if (!checked) { setErrorMessage("Casting from event error:", "Error de casting para el objeto fila: se esperaba [" + clazz.toString() + "] y es [" + tmpRowData.getClass().toString() + "]"); tmpRowData = null; } } } return tmpRowData; }
From source file:com.apdplat.platform.struts.APDPlatPackageBasedActionConfigBuilder.java
/** * Converts the class name into an action name using the ActionNameBuilder. * * @param actionClass The action class.//from w ww . j av a2s . c om * @return The action name. */ protected String determineActionName(Class<?> actionClass) { String actionName = actionNameBuilder.build(actionClass.getSimpleName()); if (LOG.isTraceEnabled()) { LOG.trace("Got actionName for class [#0] of [#1]", actionClass.toString(), actionName); } return actionName; }
From source file:com.chinamobile.bcbsp.workermanager.WorkerManager.java
/** * Construct WorkerManger./* w w w.jav a 2s. c o m*/ * @param workerManagerClass extends WorkerManager * @param conf Configuration * @return WorkerManager object */ public static WorkerManager constructWorkerManager(Class<? extends WorkerManager> workerManagerClass, final Configuration conf) { try { Constructor<? extends WorkerManager> c = workerManagerClass.getConstructor(Configuration.class); return c.newInstance(conf); } catch (Exception e) { throw new RuntimeException( "Failed construction of " + "WorkerManager: " + workerManagerClass.toString(), e); } }