/** * Returns a date item associated with the specified item name. * * @param itemName Item name * @return Date value */ public Date getDate(String itemName) { try { return DateUtil.parseDate(getItem(itemName)); } catch (Exception e) { return null; } }
/** * Returns a date item associated with the specified item name. * * @param itemName Item name * @return Date value */ public Date getDate(String itemName) { try { return DateUtil.parseDate(getItem(itemName)); } catch (Exception e) { return null; } }
/** * Returns a map consisting of suffixes of context items that match the specified prefix. * * @param prefix Item name less any suffix. * @param firstOnly If true, only the first match is returned. Otherwise, all matches are * returned. * @return Map of suffixes whose prefix matches the specified value. The value of each map entry * is the value of the original context item. */ private Map<String, String> getSuffixes(String prefix, Boolean firstOnly) { HashMap<String, String> matches = new HashMap<String, String>(); prefix = normalizePrefix(prefix); int i = prefix.length(); for (String itemName : index.keySet()) { if (itemName.startsWith(prefix)) { String suffix = lookupItemName(itemName, false).substring(i); matches.put(suffix, getItem(itemName)); if (firstOnly) { break; } } } return matches; }
/** * Returns a map consisting of suffixes of context items that match the specified prefix. * * @param prefix Item name less any suffix. * @param firstOnly If true, only the first match is returned. Otherwise, all matches are * returned. * @return Map of suffixes whose prefix matches the specified value. The value of each map entry * is the value of the original context item. */ private Map<String, String> getSuffixes(String prefix, Boolean firstOnly) { HashMap<String, String> matches = new HashMap<>(); prefix = normalizePrefix(prefix); int i = prefix.length(); for (String itemName : index.keySet()) { if (itemName.startsWith(prefix)) { String suffix = lookupItemName(itemName, false).substring(i); matches.put(suffix, getItem(itemName)); if (firstOnly) { break; } } } return matches; }
/** * Unmarshals the marshaled context. Performs digital signature verification, then returns the * unmarshaled context items. * * @param marshaledContext Marshaled context * @param authSignature If set, the digital signature is verified. * @return The unmarshaled context. * @throws Exception Unspecified exception. */ public ContextItems unmarshal(String marshaledContext, String authSignature) throws Exception { ContextItems contextItems = new ContextItems(); contextItems.addItems(marshaledContext); String whichKey = contextItems.getItem(PROPNAME_KEY); String timestamp = contextItems.getItem(PROPNAME_TIME); if (authSignature != null && !signer.verify(authSignature, marshaledContext, timestamp, whichKey)) { throw new MarshalException("Invalid digital signature"); } return contextItems; } }
/** * Unmarshals the marshaled context. Performs digital signature verification, then returns the * unmarshaled context items. * * @param marshaledContext Marshaled context * @param authSignature If set, the digital signature is verified. * @return The unmarshaled context. * @throws Exception Unspecified exception. */ public ContextItems unmarshal(String marshaledContext, String authSignature) throws Exception { ContextItems contextItems = new ContextItems(); contextItems.addItems(marshaledContext); String whichKey = contextItems.getItem(PROPNAME_KEY); String timestamp = contextItems.getItem(PROPNAME_TIME); if (authSignature != null && !signer.verify(authSignature, marshaledContext, timestamp, whichKey)) { throw new MarshalException("Invalid digital signature"); } return contextItems; } }
/** * Returns an object of the specified class. The class must have an associated context * serializer registered. * * @param itemName Item name * @param clazz Class of item to be returned. * @return Deserialized item of specified class. * @throws ContextException If no context serializer found. */ @SuppressWarnings("unchecked") public <T> T getItem(String itemName, Class<T> clazz) throws ContextException { String item = getItem(itemName); if (item == null || item.isEmpty()) { return null; } IContextSerializer<?> contextSerializer = ContextSerializerRegistry.getInstance().get(clazz); if (contextSerializer == null) { throw new ContextException("No serializer found for type " + clazz.getName()); } return (T) contextSerializer.deserialize(item); }
/** * Returns an object of the specified class. The class must have an associated context * serializer registered. * * @param <T> The item's class. * @param itemName Item name * @param clazz Class of item to be returned. * @return Deserialized item of specified class. * @throws ContextException If no context serializer found. */ @SuppressWarnings("unchecked") public <T> T getItem(String itemName, Class<T> clazz) throws ContextException { String item = getItem(itemName); if (item == null || item.isEmpty()) { return null; } ISerializer<?> contextSerializer = ContextSerializerRegistry.getInstance().get(clazz); if (contextSerializer == null) { throw new ContextException("No serializer found for type " + clazz.getName()); } return (T) contextSerializer.deserialize(item); }