List of usage examples for org.springframework.expression.spel.support StandardEvaluationContext StandardEvaluationContext
public StandardEvaluationContext(Object rootObject)
From source file:org.springframework.cloud.netflix.turbine.CommonsInstanceDiscovery.java
/** * Helper that fetches the cluster name. Cluster is a Turbine concept and not a commons * concept. By default we choose the amazon serviceId as the cluster. A custom * implementation can be plugged in by overriding this method. *///from w w w .java 2s . com protected String getClusterName(Object object) { StandardEvaluationContext context = new StandardEvaluationContext(object); Object value = this.clusterNameExpression.getValue(context); if (value != null) { return value.toString(); } return null; }
From source file:org.springframework.cloud.stream.app.hdfs.dataset.sink.HdfsDatasetSinkConfiguration.java
private static PartitionStrategy parsePartitionExpression(String expression) { List<String> expressions = Arrays.asList(expression.split("/")); ExpressionParser parser = new SpelExpressionParser(); PartitionStrategy.Builder psb = new PartitionStrategy.Builder(); StandardEvaluationContext ctx = new StandardEvaluationContext(psb); for (String expr : expressions) { try {/*from w ww . ja va2 s . co m*/ Expression e = parser.parseExpression(expr); psb = e.getValue(ctx, PartitionStrategy.Builder.class); } catch (SpelParseException spe) { if (!expr.trim().endsWith(")")) { throw new StoreException("Invalid partitioning expression '" + expr + "' - did you forget the closing parenthesis?", spe); } else { throw new StoreException("Invalid partitioning expression '" + expr + "'!", spe); } } catch (SpelEvaluationException see) { throw new StoreException("Invalid partitioning expression '" + expr + "' - failed evaluation!", see); } catch (NullPointerException npe) { throw new StoreException("Invalid partitioning expression '" + expr + "' - was evaluated to null!", npe); } } return psb.build(); }
From source file:org.springframework.data.mongodb.core.convert.MappingMongoConverter.java
private <S extends Object> S read(final MongoPersistentEntity<S> entity, final DBObject dbo) { final StandardEvaluationContext spelCtx = new StandardEvaluationContext(dbo); spelCtx.addPropertyAccessor(DBObjectPropertyAccessor.INSTANCE); if (applicationContext != null) { spelCtx.setBeanResolver(new BeanFactoryResolver(applicationContext)); }/*www. ja v a2s . c o m*/ final MappedConstructor constructor = new MappedConstructor(entity, mappingContext); SpELAwareParameterValueProvider delegate = new SpELAwareParameterValueProvider(spelExpressionParser, spelCtx); ParameterValueProvider provider = new DelegatingParameterValueProvider(constructor, dbo, delegate); final BeanWrapper<MongoPersistentEntity<S>, S> wrapper = BeanWrapper.create(entity, provider, conversionService); // Set properties not already set in the constructor entity.doWithProperties(new PropertyHandler<MongoPersistentProperty>() { public void doWithPersistentProperty(MongoPersistentProperty prop) { boolean isConstructorProperty = constructor.isConstructorParameter(prop); boolean hasValueForProperty = dbo.containsField(prop.getFieldName()); if (!hasValueForProperty || isConstructorProperty) { return; } Object obj = getValueInternal(prop, dbo, spelCtx, prop.getSpelExpression()); wrapper.setProperty(prop, obj, useFieldAccessOnly); } }); // Handle associations entity.doWithAssociations(new AssociationHandler<MongoPersistentProperty>() { public void doWithAssociation(Association<MongoPersistentProperty> association) { MongoPersistentProperty inverseProp = association.getInverse(); Object obj = getValueInternal(inverseProp, dbo, spelCtx, inverseProp.getSpelExpression()); try { wrapper.setProperty(inverseProp, obj); } catch (IllegalAccessException e) { throw new MappingException(e.getMessage(), e); } catch (InvocationTargetException e) { throw new MappingException(e.getMessage(), e); } } }); return wrapper.getBean(); }