return Arrays.<PathElement>asList( new DollarPathElement( key ) );
}
else if ( key.contains("[") ) {
if ( StringUtils.countMatches( key, "[" ) != 1 || StringUtils.countMatches( key, "]" ) != 1 ) {
throw new SpecException( "Invalid key:" + key + " has too many [] references.");
}
// is canonical array?
if ( key.charAt( 0 ) == '[' && key.charAt( key.length() - 1 ) == ']') {
return Arrays.<PathElement>asList( new ArrayPathElement( key ) );
}
// Split syntactic sugar of "photos[]" --> [ "photos", "[]" ]
// or "bob-&(3,1)-smith[&0]" --> [ "bob-&(3,1)-smith", "[&(0,0)]" ]
String canonicalKey = key.replace( "[", ".[" );
String[] subkeys = canonicalKey.split( "\\." );
List<PathElement> subElements = parse( subkeys ); // at this point each sub key should be a valid key, so just recall parse
for ( int index = 0; index < subElements.size() - 1; index++ ) {
PathElement v = subElements.get( index );
if ( v instanceof ArrayPathElement ) {
throw new SpecException( "Array [..] must be the last thing in the key, was:" + key );
}
}
return subElements;
}
else if ( key.contains("&") ) {
if ( key.contains("*") )
{
throw new SpecException("Can't mix * with & ) ");
}
return Arrays.<PathElement>asList( new AmpPathElement( key ) );
}
else if ( "*".equals( key ) ) {
return Arrays.<PathElement>asList( new StarAllPathElement( key ) );