AttributeCompressionStrategy.java revision b334b83b7ac2d9a8c60d935cad0365506f13333b
/**
* Copyright 2013 ForgeRock AS.
*
* The contents of this file are subject to the terms of the Common Development and
* Distribution License (the License). You may not use this file except in compliance with the
* License.
*
* You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
* specific language governing permission and limitations under the License.
*
* When distributing Covered Software, include this CDDL Header Notice in each file and include
* the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
* Header, with the fields enclosed by brackets [] replaced by your own identifying
* information: "Portions copyright [year] [name of copyright owner]".
*/
/**
* Responsible for performing a specialised JSON compression based on the
* attribute name being stored in the JSON.
*
* The compression is a somewhat simple reduction of each Attribute Name
* to its initials. This works because we know the fields within the
* InternalSession.
*
* This approach is however brittle and only recommended if it will make
* the required difference in performance.
*
* @author robert.wapshott@forgerock.com
*/
public class AttributeCompressionStrategy implements BlobStrategy {
// Injected
private final TokenBlobUtils blobUtils;
}
}
/**
* Ensures the Token is a Session Token and performs the compression.
* @param token {@inheritDoc}
* @throws TokenStrategyFailedException {@inheritDoc}
*/
if (!isTokenValidForCompression(token)) {
return;
}
}
/**
* Ensures the Token is a Session Token and reverses the compression.
* @param token {@inheritDoc}
* @throws TokenStrategyFailedException {@inheritDoc}
*/
if (!isTokenValidForCompression(token)) {
return;
}
}
/**
* A simple heuristic for determining the Token is a Session Token containing JSON.
*
* @param token Non null Token to examine.
* @return True if it starts and ends with curly brackets.
*/
return false;
}
return false;
}
}
/**
* Update the Token with the compressed contents.
* @param token Non null
* @param map Non null
* @throws TokenStrategyFailedException If any error occured.
*/
}
/**
* Perform the keyword substitution.
*
* @param replacement A mapping of one value to another to perform.
* @param contents String to modify.
*/
}
return contents;
}
/**
* Generate the initials from the given name.
*
* Note: This function is intended to operate against Java field name syntax.
* As such it simply picks out the first character and all subsequent upper
* case characters from the String.
*
* @param name Non null string that follows Java field name syntax.
* @return The initials of the field.
*/
throw new IllegalArgumentException("Name was null");
}
StringBuilder r = new StringBuilder();
boolean start = true;
if (start) {
r.append(c);
start = false;
continue;
}
if (Character.isUpperCase(c)) {
r.append(c);
}
}
return r.toString();
}
/**
* Examines the class using reflection for all declared fields which are suitable
* for serialisation.
*
* @param c Non null class to examine.
*
* @return A non null but possibly empty collection of Fields.
*/
for (Field f : c.getDeclaredFields()) {
int modifiers = f.getModifiers();
r.add(f);
}
return r;
}
}