if (resource == null && headers == null)
throw new IllegalArgumentException("Cannot create module identity");
// Build the resource
if (resource == null) {
ResourceBuilder builder = new DictionaryResourceBuilder().load(headers);
resource = builder.getResource();
}
this.resource = resource;
// Build the headers
ResourceIdentity resourceIdentity = resource.getIdentity();
Hashtable<String, String> clonedHeaders = new Hashtable<String, String>();
if (headers != null) {
Enumeration<String> keys = headers.keys();
while(keys.hasMoreElements()) {
String key = keys.nextElement();
String value = headers.get(key);
clonedHeaders.put(key, value);
}
}
if (clonedHeaders.get(Constants.GRAVIA_IDENTITY_CAPABILITY) == null) {
String identityHeader = getIdentityHeader(resourceIdentity);
clonedHeaders.put(Constants.GRAVIA_IDENTITY_CAPABILITY, identityHeader);
}
this.headers = new UnmodifiableDictionary<String, String>(new CaseInsensitiveDictionary<String>(clonedHeaders));
// Verify the resource & headers identity
ResourceIdentity headersIdentity = new DictionaryResourceBuilder().load(clonedHeaders).getResource().getIdentity();
if (!resourceIdentity.equals(headersIdentity))
throw new IllegalArgumentException("Resource and header identity does not match: " + resourceIdentity);
}