List of usage examples for java.lang Class isEnum
public boolean isEnum()
From source file:com.mstiles92.plugins.stileslib.config.ConfigObject.java
@SuppressWarnings("rawtypes") protected Enum getEnum(Class clazz, String string) throws Exception { if (!clazz.isEnum()) throw new Exception("Class " + clazz.getName() + " is not an enum."); for (Object constant : clazz.getEnumConstants()) { if (((Enum) constant).toString().equals(string)) { return (Enum) constant; }/* ww w . j a v a 2 s.c o m*/ } throw new Exception("String " + string + " not a valid enum constant for " + clazz.getName()); }
From source file:org.amplafi.hivemind.factory.servicessetter.ServicesSetterImpl.java
/** * @param propertyType//from w ww . j av a 2 s .c o m * @return true class can be wired up as a service */ @Override public boolean isWireableClass(Class<?> propertyType) { if ( // exclude primitives or other things that are not mockable in any form propertyType.isPrimitive() || propertyType.isAnnotation() || propertyType.isArray() || propertyType.isEnum() // generated classes || propertyType.getCanonicalName() == null // exclude java classes || propertyType.getPackage().getName().startsWith("java")) { return false; } else { // exclude things that are explicitly labeled as not being injectable NotService notService = propertyType.getAnnotation(NotService.class); return notService == null; } }
From source file:de.iteratec.iteraplan.businesslogic.exchange.elasticExcel.excelimport.EntityDataImporter.java
/** * @param typeName// w ww . j a v a 2 s . com * @param cellValue * @return the enum value for the given typeName and the enum value given as String in the cell value; * or null if the value is not found. */ @SuppressWarnings({ "unchecked", "rawtypes" }) private Object resolveJavaEnum(String typeName, Object cellValue) { Object result = null; try { Class<?> clazz = Class.forName(typeName); if (clazz.isEnum()) { return Enum.valueOf(((Class<Enum>) clazz), cellValue.toString()); } else { logError("Type {0} is not an enum. Can not find value for {1}", typeName, cellValue.toString()); } } catch (ClassNotFoundException e) { logError("Error setting {0} to {1}: {2} {3}", typeName, cellValue.toString(), e.getClass().getName(), e.getMessage()); } catch (SecurityException e) { logError("Error setting {0} to {1}: {2} {3}", typeName, cellValue.toString(), e.getClass().getName(), e.getMessage()); } catch (IllegalArgumentException e) { logError("Error setting {0} to {1}: {2} {3}", typeName, cellValue.toString(), e.getClass().getName(), e.getMessage()); } return result; }
From source file:org.castor.jaxb.reflection.FieldAnnotationProcessingServiceTest.java
@Test public final void testWithXmlID() { Class<WithXmlID> clazz = WithXmlID.class; Assert.assertFalse(clazz.isEnum()); Assert.assertNotNull(fieldAnnotationProcessingService); Field[] fields = clazz.getDeclaredFields(); for (int i = 0; i < fields.length; i++) { Field field = fields[i];//from w w w . j a va 2 s . co m JaxbFieldNature fi = new JaxbFieldNature(new FieldInfo(field.getName())); fieldAnnotationProcessingService.processAnnotations(fi, field.getAnnotations()); if ("anythingInAList".equals(field.getName())) { Assert.assertTrue(fi.hasXmlID()); } } }
From source file:org.castor.jaxb.reflection.FieldAnnotationProcessingServiceTest.java
@Test public final void testWithXmlList() { Class<WithXmlList> clazz = WithXmlList.class; Assert.assertFalse(clazz.isEnum()); Assert.assertNotNull(fieldAnnotationProcessingService); Field[] fields = clazz.getDeclaredFields(); for (int i = 0; i < fields.length; i++) { Field field = fields[i];//w w w. ja v a 2 s. co m JaxbFieldNature fi = new JaxbFieldNature(new FieldInfo(field.getName())); fieldAnnotationProcessingService.processAnnotations(fi, field.getAnnotations()); if ("anythingInAList".equals(field.getName())) { Assert.assertTrue(fi.hasXmlList()); } } }
From source file:org.castor.jaxb.reflection.FieldAnnotationProcessingServiceTest.java
@Test public final void testWithXmlValue() { Class<WithXmlValue> clazz = WithXmlValue.class; Assert.assertFalse(clazz.isEnum()); Assert.assertNotNull(fieldAnnotationProcessingService); Field[] fields = clazz.getDeclaredFields(); for (int i = 0; i < fields.length; i++) { Field field = fields[i];//from w w w . j a va 2 s . co m JaxbFieldNature fi = new JaxbFieldNature(new FieldInfo(field.getName())); fieldAnnotationProcessingService.processAnnotations(fi, field.getAnnotations()); if ("anythingInAList".equals(field.getName())) { Assert.assertTrue(fi.hasXmlValue()); } } }
From source file:org.castor.jaxb.reflection.FieldAnnotationProcessingServiceTest.java
@Test public final void testWithXmlIDREF() { Class<WithXmlIDREF> clazz = WithXmlIDREF.class; Assert.assertFalse(clazz.isEnum()); Assert.assertNotNull(fieldAnnotationProcessingService); Field[] fields = clazz.getDeclaredFields(); for (int i = 0; i < fields.length; i++) { Field field = fields[i];//from w w w.j ava 2s.co m JaxbFieldNature fi = new JaxbFieldNature(new FieldInfo(field.getName())); fieldAnnotationProcessingService.processAnnotations(fi, field.getAnnotations()); if ("anythingInAList".equals(field.getName())) { Assert.assertTrue(fi.hasXmlIDREF()); } } }
From source file:org.castor.jaxb.reflection.FieldAnnotationProcessingServiceTest.java
@Test public final void testWithXmlMixed() { Class<WithXmlMixed> clazz = WithXmlMixed.class; Assert.assertFalse(clazz.isEnum()); Assert.assertNotNull(fieldAnnotationProcessingService); Field[] fields = clazz.getDeclaredFields(); for (int i = 0; i < fields.length; i++) { Field field = fields[i];/*from w w w. ja v a 2 s . c o m*/ JaxbFieldNature fi = new JaxbFieldNature(new FieldInfo(field.getName())); fieldAnnotationProcessingService.processAnnotations(fi, field.getAnnotations()); if ("anythingInAList".equals(field.getName())) { Assert.assertTrue(fi.hasXmlMixed()); } } }
From source file:org.castor.jaxb.reflection.FieldAnnotationProcessingServiceTest.java
@Test public void testWithEnumValue() { Class<WithEnumValue> clazz = WithEnumValue.class; Assert.assertTrue(clazz.isEnum()); Assert.assertNotNull(fieldAnnotationProcessingService); Field[] fields = clazz.getDeclaredFields(); for (int i = 0; i < fields.length; i++) { Field field = fields[i];/*w ww. j a v a 2 s . c o m*/ JaxbFieldNature fi = new JaxbFieldNature(new FieldInfo(field.getName())); fieldAnnotationProcessingService.processAnnotations(fi, field.getAnnotations()); if ("ONE".equals(field.getName())) { Assert.assertTrue(fi.hasXmlEnumValue()); } } }
From source file:be.fedict.eid.dss.model.bean.ConfigurationBean.java
/** * {@inheritDoc}/*from w w w. ja v a 2s . c om*/ */ public void setValue(ConfigProperty configProperty, String index, Object value) { String propertyValue; if (null != value) { Class<?> expectedType = configProperty.getType(); Class<?> type = value.getClass(); if (!expectedType.isAssignableFrom(type)) { throw new IllegalArgumentException("value has incorrect type: " + type.getClass().getName()); } Object castedValue = expectedType.cast(value); if (expectedType.isEnum()) { Enum<?> enumValue = (Enum<?>) castedValue; propertyValue = enumValue.name(); } else { propertyValue = castedValue.toString(); if (propertyValue.trim().isEmpty()) { propertyValue = null; } } } else { propertyValue = null; } String propertyName = getPropertyName(configProperty, index); ConfigPropertyEntity configPropertyEntity = this.entityManager.find(ConfigPropertyEntity.class, propertyName); if (null == configPropertyEntity) { configPropertyEntity = new ConfigPropertyEntity(propertyName, propertyValue); this.entityManager.persist(configPropertyEntity); } else { configPropertyEntity.setValue(propertyValue); } }