Package com.bazaarvoice.jolt.exception

Examples of com.bazaarvoice.jolt.exception.SpecException



    private List<Transform> getTransforms( List<Object> operations, int start, int end ) {

        if ( operations.isEmpty() ) {
            throw new SpecException( "JOLT Chainr passed an empty JSON array.");
        }

        List<Transform> transformList = new ArrayList<Transform>(operations.size());

        for ( int index = start; index < end; index++ ) {
View Full Code Here


     * @return an initialized ChanirEntry
     */
    private ChainrEntry processChainrEntry( int index, Object chainrEntryObj ) {

        if ( ! (chainrEntryObj instanceof Map ) ) {
            throw new SpecException( "JOLT Chainr expects a JSON array of objects - Malformed spec at index:" + index );
        }

        Map<String,Object> chainrEntryMap = (Map<String, Object>) chainrEntryObj;

        Object opNameObj = chainrEntryMap.get( OPERATION_KEY );
        if ( opNameObj == null || !(opNameObj instanceof String)) {
            throw new SpecException( "JOLT Chainr needs a 'operation' of type String, spec index:" + index );
        }

        String operation = opNameObj.toString().toLowerCase();
        Object specObj = chainrEntryMap.get( SPEC_KEY );
        String className = null;

        if ( CUSTOM_TRANSFORM_IDENTIFIER.equals( operation ) ) {

            Object classNameObj = chainrEntryMap.get( CLASSNAME_KEY );
            if ((classNameObj == null) || !(classNameObj instanceof String)) {
                throw new SpecException( "JOLT 'java' operation requires a 'className' parameter.  Chainr spec index:" + index );
            }

            className = (String) classNameObj;
        }
        else if ( ! STOCK_TRANSFORMS.containsKey( operation ) ) {
            throw new SpecException( "JOLT Chainr does not know/support operation: " + operation + ".  Chainr spec index:" + index);
        }

        return new ChainrEntry( index, operation, specObj, className );
    }
View Full Code Here

            } else {
                opClass = STOCK_TRANSFORMS.get( operation );
            }

            if ( opClass == null ) {
                throw new SpecException( "JOLT Chainr does not support operation: " + operation + ".  Chainr spec index:" + index);
            }

            if ( ! Transform.class.isAssignableFrom( opClass ) ) {
                throw new SpecException( "JOLT Chainr class:" + className + " does not implement Transform.  Chainr spec index:" + index );
            }

            return opClass;
        }
View Full Code Here

            Class opClass;
            try {
                opClass = Class.forName( className );
                if (Chainr.class.isAssignableFrom( opClass )) {
                    throw new SpecException( "Attempt to nest Chainr inside itself at Chainr spec index:" + index );
                }

            } catch ( ClassNotFoundException e ) {
                throw new SpecException( "JOLT Chainr could not find custom transform class :"+className + ".  Chainr spec index:" + index, e );
            }

            if ( Transform.class.isAssignableFrom( opClass ) ) {
                return (Class<Transform>) opClass;
            }
            else {
                throw new SpecException( "Custom transform class :"+className + " does not implement the Transform interface.  Chainr spec index:" + index );
            }
        }
View Full Code Here

            try {
                // If the opClass is a SpecTransform, we try to construct it with the provided spec.
                if ( SpecTransform.class.isAssignableFrom( transformClass ) ) {

                    if ( spec == null ) {
                        throw new SpecException( "JOLT Chainr - operation:" + operation + " implemented by className:" + transformClass.getCanonicalName() + " requires a spec." );
                    }

                    try {
                        // Lookup a Constructor with a Single "Object" arg.
                        Constructor<? extends Transform> constructor = transformClass.getConstructor( new Class[] {Object.class} );

                        return constructor.newInstance( spec );
                    } catch ( NoSuchMethodException nsme ) {
                        // This means the transform class "violated" the marker interface
                        throw new SpecException( "JOLT Chainr encountered an exception constructing SpecTransform className:" + transformClass.getCanonicalName() + ".  Specifically, no single arg constructor found.", nsme );
                    }
                }
                else {
                    // The opClass is just a Transform, so just create a newInstance of it.
                    return transformClass.newInstance();
                }
            } catch ( Exception e ) {
                // FYI 3 exceptions are known to be thrown here
                // IllegalAccessException, InvocationTargetException, InstantiationException
                throw new SpecException( "JOLT Chainr encountered an exception constructing Transform className:" + transformClass.getCanonicalName(), e );
            }
        }
View Full Code Here

     * @throws com.bazaarvoice.jolt.exception.SpecException for a malformed spec
     */
    public Shiftr( Object spec ) {

        if ( spec == null ){
            throw new SpecException( "Shiftr expected a spec of Map type, got 'null'." );
        }
        if ( ! ( spec instanceof Map ) ) {
            throw new SpecException( "Shiftr expected a spec of Map type, got " + spec.getClass().getSimpleName() );
        }

        rootSpec = new ShiftrCompositeSpec( ROOT_KEY, (Map<String, Object>) spec );
    }
View Full Code Here

    protected abstract char getToken();

    public BasePathReference( String refStr ) {

        if ( refStr == null || refStr.length() == 0 || getToken() != refStr.charAt( 0 ) ) {
            throw new SpecException( "Invalid reference key=" + refStr + " either blank or doesn't start with correct character=" + getToken() );
        }

        int pathIndex = 0;

        try {
            if ( refStr.length() > 1 ) {

                String meat = refStr.substring( 1 );

                pathIndex = Integer.parseInt( meat );
            }
        }
        catch( NumberFormatException nfe ) {
            throw new SpecException( "Unable to parse '" + getToken() + "' reference key:" + refStr, nfe );
        }

        if ( pathIndex < 0 ) {
            throw new SpecException( "Reference:" + refStr + " can not have a negative value."  );
        }

        this.pathIndex = pathIndex;
    }
View Full Code Here

    protected abstract char getToken();

    public BasePathAndGroupReference( String refStr ) {

        if ( refStr == null || refStr.length() == 0 || getToken() != refStr.charAt( 0 ) ) {
            throw new SpecException( "Invalid reference key=" + refStr + " either blank or doesn't start with correct character=" + getToken() );
        }

        int pI = 0;
        int kG = 0;

        try {
            if ( refStr.length() > 1 ) {

                String meat = refStr.substring( 1 );

                if( meat.length() >= 3 && meat.startsWith( "(" ) && meat.endsWith( ")" ) ) {

                    // "&(1,2)" -> "1,2".split( "," ) -> String[] { "1", "2" }    OR
                    // "&(3)"   -> "3".split( "," ) -> String[] { "3" }

                    String parenMeat = meat.substring( 1, meat.length() -1 );
                    String[] intStrs = parenMeat.split( "," );
                    if ( intStrs.length > 2 ) {
                        throw new SpecException( "Invalid Reference=" + refStr );
                    }

                    pI = Integer.parseInt( intStrs[0] );
                    if ( intStrs.length == 2 ) {
                        kG = Integer.parseInt( intStrs[1] );
                    }
                }
                else {   // &2
                    pI = Integer.parseInt( meat );
                }
            }
        }
        catch( NumberFormatException nfe ) {
            throw new SpecException( "Unable to parse '" + getToken() + "' reference key:" + refStr, nfe );
        }

        if ( pI < 0 || kG < 0 ) {
            throw new SpecException( "Reference:" + refStr + " can not have a negative value."  );
        }

        pathIndex = pI;
        keyGroup = kG;
    }
View Full Code Here

public class AtPathElement extends BasePathElement implements MatchablePathElement {
    public AtPathElement( String key ) {
        super(key);

        if ( ! "@".equals( key ) ) {
            throw new SpecException( "'References Input' key '@', can only be a single '@'.  Offending key : " + key );
        }
    }
View Full Code Here

    public ArrayPathElement( String key ) {
        super(key);

        if ( key.charAt( 0 ) != '[' || key.charAt( key.length() - 1 ) != ']') {
            throw new SpecException( "Invalid ArrayPathElement key:" + key );
        }

        ArrayPathType apt;
        PathReference r = null;
        String aI = "";

        if ( key.length() == 2 ) {
            apt = ArrayPathType.AUTO_EXPAND;
            canonicalForm = "[]";
        }
        else {
            String meat = key.substring( 1, key.length() - 1 )// trim the [ ]

            if ( AmpReference.TOKEN.equals( meat.charAt( 0 ) ) ) {
                r = new AmpReference( meat );
                apt = ArrayPathType.REFERENCE;

                canonicalForm = "[" + r.getCanonicalForm() + "]";
            }
            else if ( HashReference.TOKEN.equals( meat.charAt( 0 ) ) ) {
                r = new HashReference( meat );
                apt = ArrayPathType.HASH;

                canonicalForm = "[" + r.getCanonicalForm() + "]";
            }
            else {
                try {
                    Integer.parseInt( meat );
                    apt = ArrayPathType.EXPLICIT_INDEX;

                    canonicalForm = "[" + meat + "]";
                    aI = meat;
                }
                catch ( NumberFormatException nfe ){
                    throw new SpecException( "Unable to parse explicit array index of:" + meat + " from key:" + key );
                }
            }
        }

        arrayPathType = apt;
View Full Code Here

TOP

Related Classes of com.bazaarvoice.jolt.exception.SpecException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.