Java源码示例:com.bazaarvoice.jolt.SpecDriven
示例1
public <T extends PathEvaluatingTraversal> T build( Object rawObj ) {
if ( ! ( rawObj instanceof String ) ) {
throw new SpecException( "Invalid spec, RHS should be a String or array of Strings. Value in question : " + rawObj );
}
// Prepend "root" to each output path.
// This is needed for the "identity" transform, eg if we are just supposed to put the input into the output
// what key do we put it under?
String outputPathStr = (String) rawObj;
if ( StringTools.isBlank( outputPathStr ) ) {
outputPathStr = SpecDriven.ROOT_KEY;
}
else {
outputPathStr = SpecDriven.ROOT_KEY + "." + outputPathStr;
}
return buildFromPath( outputPathStr );
}
示例2
@SuppressWarnings("unchecked")
public static JoltTransform getCustomTransform(final ClassLoader classLoader, final String customTransformType, final Object specJson) throws Exception {
final Class clazz = classLoader.loadClass(customTransformType);
if(SpecDriven.class.isAssignableFrom(clazz)){
final Constructor constructor = clazz.getConstructor(Object.class);
return (JoltTransform)constructor.newInstance(specJson);
}else{
return (JoltTransform)clazz.newInstance();
}
}
示例3
@SuppressWarnings("unchecked")
public static JoltTransform getCustomTransform(final ClassLoader classLoader, final String customTransformType, final Object specJson) throws Exception {
final Class clazz = classLoader.loadClass(customTransformType);
if(SpecDriven.class.isAssignableFrom(clazz)){
final Constructor constructor = clazz.getConstructor(Object.class);
return (JoltTransform)constructor.newInstance(specJson);
}else{
return (JoltTransform)clazz.newInstance();
}
}
示例4
@SuppressWarnings("unchecked")
public static JoltTransform getCustomTransform(final ClassLoader classLoader, final String customTransformType, final Object specJson) throws Exception {
final Class clazz = classLoader.loadClass(customTransformType);
if(SpecDriven.class.isAssignableFrom(clazz)){
final Constructor constructor = clazz.getConstructor(Object.class);
return (JoltTransform)constructor.newInstance(specJson);
}else{
return (JoltTransform)clazz.newInstance();
}
}
示例5
/**
* Process an element from the Chainr Spec into a ChainrEntry class.
* This method tries to validate the syntax of the Chainr spec, whereas
* the ChainrInstantiator deals with loading the Transform classes.
*
* @param chainrEntryObj the unknown Object from the Chainr list
* @param index the index of the chainrEntryObj, used in reporting errors
*/
public ChainrEntry( int index, Object chainrEntryObj, ClassLoader classLoader ) {
if ( ! (chainrEntryObj instanceof Map ) ) {
throw new SpecException( "JOLT ChainrEntry expects a JSON map - Malformed spec" + getErrorMessageIndexSuffix() );
}
@SuppressWarnings( "unchecked" ) // We know it is a Map due to the check above
Map<String,Object> chainrEntryMap = (Map<String, Object>) chainrEntryObj;
this.index = index;
String opString = extractOperationString( chainrEntryMap );
if ( opString == null ) {
throw new SpecException( "JOLT Chainr 'operation' must implement Transform or ContextualTransform" + getErrorMessageIndexSuffix() );
}
if ( STOCK_TRANSFORMS.containsKey( opString ) ) {
operationClassName = STOCK_TRANSFORMS.get( opString );
}
else {
operationClassName = opString;
}
joltTransformClass = loadJoltTransformClass( classLoader );
spec = chainrEntryMap.get( ChainrEntry.SPEC_KEY );
isSpecDriven = SpecDriven.class.isAssignableFrom( joltTransformClass );
if ( isSpecDriven && ! chainrEntryMap.containsKey( SPEC_KEY ) ) {
throw new SpecException( "JOLT Chainr - Transform className:" + joltTransformClass.getName() + " requires a spec" + getErrorMessageIndexSuffix() );
}
}
示例6
@Test(dataProvider = "shiftrKeyOrderingTestCases" )
public void testKeyOrdering( String testName, Map<String,Object> spec, List<String> expectedOrder ) {
ShiftrCompositeSpec root = new ShiftrCompositeSpec( SpecDriven.ROOT_KEY, spec );
for ( int index = 0; index < expectedOrder.size(); index++) {
String expected = expectedOrder.get( index );
Assert.assertEquals( expected, root.getComputedChildren().get( index ).pathElement.getCanonicalForm(), testName );
}
}