List of usage examples for java.lang Enum valueOf
public static <T extends Enum<T>> T valueOf(Class<T> enumType, String name)
From source file:org.nuxeo.ecm.platform.jbpm.core.service.JbpmComponent.java
@Override public void registerContribution(Object contribution, String extensionPoint, ComponentInstance contributor) { ExtensionPoint ep = Enum.valueOf(ExtensionPoint.class, extensionPoint); try {//w w w. ja v a 2s . co m switch (ep) { case deployer: DeployerDescriptor desc = (DeployerDescriptor) contribution; deployerDesc.put(desc.getName(), desc.getKlass().newInstance()); break; case processDefinition: pdDesc.put((ProcessDefinitionDescriptor) contribution, contributor); break; case activeConfiguration: ActiveConfigurationDescriptor descriptor = (ActiveConfigurationDescriptor) contribution; activeConfigurationName = descriptor.getName(); break; case configurationPath: ConfigurationPathDescriptor configPath = (ConfigurationPathDescriptor) contribution; String path = configPath.getPath(); URL url = contributor.getRuntimeContext().getLocalResource(path); if (url == null) { throw new RuntimeException("Config not found: " + path); } if (RUNTIME_CONFIGURATION.equals(configPath.getName())) { log.error( "'runtime' is a reserved word for configuration. You should use another name for your configuration name"); } paths.put(configPath.getName(), url); break; case securityPolicy: SecurityPolicyDescriptor pmd = (SecurityPolicyDescriptor) contribution; service.addSecurityPolicy(pmd.getProcessDefinition(), pmd.getKlass().newInstance()); break; case typeFilter: TypeFilterDescriptor tfd = (TypeFilterDescriptor) contribution; typeFiltersContrib.put(tfd.getType(), tfd.getPDs()); break; } } catch (InstantiationException | IllegalAccessException e) { log.error("Error registering contribution", e); } }
From source file:org.apache.bval.util.KeyedAccess.java
/** * {@inheritDoc}/* w w w .j a v a2 s. co m*/ */ @Override public Object get(Object instance) { if (instance instanceof Map<?, ?>) { Map<?, ?> map = (Map<?, ?>) instance; Map<TypeVariable<?>, Type> typeArguments = TypeUtils.getTypeArguments(containerType, Map.class); Type keyType = TypeUtils.unrollVariables(typeArguments, MAP_TYPEVARS[0]); if (key == null || keyType == null || TypeUtils.isInstance(key, keyType)) { return map.get(key); } if (key instanceof String) { String name = (String) key; Class<?> rawKeyType = TypeUtils.getRawType(keyType, containerType); if (rawKeyType.isEnum()) { @SuppressWarnings({ "unchecked", "rawtypes" }) final Object result = map.get(Enum.valueOf((Class<? extends Enum>) rawKeyType, name)); return result; } for (Map.Entry<?, ?> e : map.entrySet()) { if (name.equals(e.getKey())) { return e.getValue(); } } } } return null; }
From source file:com.watabou.utils.Bundle.java
public <E extends Enum<E>> E getEnum(String key, Class<E> enumClass) { try {/* ww w. j a v a2s. c o m*/ return Enum.valueOf(enumClass, data.getString(key)); } catch (JSONException e) { return enumClass.getEnumConstants()[0]; } }
From source file:com.jaceace.utils.Bundle.java
public <E extends Enum<E>> E getEnum(String key, Class<E> enumClass) { try {//from w w w . j a va2 s. c o m return (E) Enum.valueOf(enumClass, data.getString(key)); } catch (JSONException e) { return enumClass.getEnumConstants()[0]; } }
From source file:com.joliciel.talismane.tokeniser.patterns.TokeniserPatternManagerImpl.java
private void configure(List<String> patternDescriptors) { String[] separatorDecisions = new String[] { SeparatorDecision.IS_NOT_SEPARATOR.toString(), SeparatorDecision.IS_SEPARATOR_AFTER.toString(), SeparatorDecision.IS_SEPARATOR_BEFORE.toString() }; List<String> testPatterns = new ArrayList<String>(); Map<SeparatorDecision, String> separatorDefaults = new HashMap<SeparatorDecision, String>(); for (String line : patternDescriptors) { if (line.startsWith("#")) continue; boolean lineProcessed = false; for (String separatorDecision : separatorDecisions) { if (line.startsWith(separatorDecision)) { if (line.length() > separatorDecision.length() + 1) { String separatorsForDefault = line.substring(separatorDecision.length() + 1); if (LOG.isTraceEnabled()) LOG.trace(separatorDecision + ": '" + separatorsForDefault + "'"); if (separatorsForDefault.length() > 0) separatorDefaults.put(Enum.valueOf(SeparatorDecision.class, separatorDecision), separatorsForDefault); }//ww w. j a v a 2 s . co m lineProcessed = true; break; } } if (lineProcessed) continue; if (line.trim().length() > 0) testPatterns.add(line.trim()); } this.separatorDefaults = separatorDefaults; this.testPatterns = testPatterns; }
From source file:org.apache.openjpa.persistence.validation.ValidatorImpl.java
public ValidatorImpl(Configuration conf) { if (conf instanceof OpenJPAConfiguration) { _conf = (OpenJPAConfiguration) conf; _log = _conf.getLog(OpenJPAConfiguration.LOG_RUNTIME); Object validatorFactory = _conf.getValidationFactoryInstance(); String mode = _conf.getValidationMode(); _mode = Enum.valueOf(ValidationMode.class, mode); if (validatorFactory != null) { if (validatorFactory instanceof ValidatorFactory) { _validatorFactory = (ValidatorFactory) validatorFactory; } else { // Supplied object was not an instance of a ValidatorFactory throw new IllegalArgumentException(_loc.get("invalid-factory").getMessage()); }// w w w .jav a 2 s . c om } } initialize(); }
From source file:edu.duke.cabig.c3pr.domain.Consent.java
public void setConsentingMethodsString(String consentingMethodsString) { consentingMethods = new ArrayList<ConsentingMethod>(); if (!StringUtils.isBlank(consentingMethodsString)) { StringTokenizer tokenizer = new StringTokenizer(consentingMethodsString, " : "); while (tokenizer.hasMoreTokens()) { ConsentingMethod consentingMethod = (ConsentingMethod) Enum.valueOf(ConsentingMethod.class, tokenizer.nextToken()); consentingMethods.add(consentingMethod); }/*from ww w . j av a 2 s .com*/ ; } }
From source file:com.justinmobile.core.dao.support.PropertyFilter.java
private void buildFilterName(String filterName) { // ????/* ww w. j a v a 2 s . com*/ String aliasPart = StringUtils.substringBefore(filterName, "_"); if (ALIAS.equals(aliasPart)) { String allPart = StringUtils.substringAfter(filterName, "_"); String firstPart = StringUtils.substringBefore(allPart, "_"); this.aliasName = StringUtils.substring(firstPart, 0, firstPart.length() - 1); String joinTypeCode = StringUtils.substring(firstPart, firstPart.length() - 1, firstPart.length()); this.joinType = Enum.valueOf(JoinType.class, joinTypeCode).getValue(); filterName = StringUtils.substringAfter(allPart, "_"); } // ?????matchTypepropertyTypeCode String firstPart = StringUtils.substringBefore(filterName, "_"); String matchTypeCode = StringUtils.substring(firstPart, 0, firstPart.length() - 1); String propertyTypeCode = StringUtils.substring(firstPart, firstPart.length() - 1, firstPart.length()); try { matchType = Enum.valueOf(MatchType.class, matchTypeCode); } catch (RuntimeException e) { throw new IllegalArgumentException( "filter??" + filterName + ",.", e); } try { propertyClass = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue(); } catch (RuntimeException e) { throw new IllegalArgumentException( "filter??" + filterName + ",.", e); } // ??OR String propertyNameStr = StringUtils.substringAfter(filterName, "_"); Assert.isTrue(StringUtils.isNotBlank(propertyNameStr), "filter??" + filterName + ",??."); propertyNames = StringUtils.splitByWholeSeparator(propertyNameStr, PropertyFilter.OR_SEPARATOR); }
From source file:com.github.carlomicieli.rest.resources.RollingStocksResource.java
@GET @Path("/era/{era}") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public Response getByEra(@PathParam("era") String era) { log.info("GET /rollingstocks/era/{}", era); try {/*from w ww .java 2 s . c o m*/ Era e = Enum.valueOf(Era.class, era); final RollingStockRepresentation[] rollingStocks = createArray(rsService.getAllRollingStocks(e)); return Response.ok(rollingStocks).cacheControl(getCacheControl()).build(); } catch (DataAccessException ex) { log.error(ex.getMessage()); throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } }
From source file:org.lunarray.model.descriptor.converter.def.DelegatingEnumConverterTool.java
/** {@inheritDoc} */ @SuppressWarnings("unchecked") // We're checking after the fact. @Override/*from ww w . j av a 2s .com*/ public <T> T convertToInstance(final Class<T> type, final String stringValue, final Locale locale) throws ConverterException { Validate.notNull(type, DelegatingEnumConverterTool.TYPE_NULL); T result = null; if (type.isEnum()) { DelegatingEnumConverterTool.LOGGER.debug("Converting to instance type {} with locale {} and value: {}", type, locale, stringValue); @SuppressWarnings("rawtypes") // No other way? final Class<? extends Enum> enumType = (Class<? extends Enum>) type; if (!StringUtil.isEmptyString(stringValue)) { result = (T) Enum.valueOf(enumType, stringValue); } } else { result = this.converterTool.convertToInstance(type, stringValue, locale); } return result; }