private DefaultDevice createDevice(String deviceName)
throws RepositoryException {
// Create the device and set it's name.
DefaultDevice device =
new DefaultDevice(deviceName, new HashMap(), getPolicyValueFactory());
// First add all the standard policies to the device.
String standardDeviceFileName = getXMLFilePath(
DeviceRepositoryConstants.STANDARD_DEVICE_DIRECTORY,
deviceName);
PolicySet standardPolicySet =
(PolicySet) loadZipObject(standardDeviceFileName, PolicySet.class);
if (standardPolicySet == null) {
// No standard device. This is bad since this is mandatory.
throw new RepositoryException(EXCEPTION_LOCALIZER.format(
"device-definition-missing", deviceName));
}
addPolicySetToDevice(standardPolicySet, device);
// Then add any custom policies to the device.
String customDeviceFileName = getXMLFilePath(
DeviceRepositoryConstants.CUSTOM_DEVICE_DIRECTORY,
deviceName);
PolicySet customPolicySet =
(PolicySet) loadZipObject(customDeviceFileName, PolicySet.class);
if (customPolicySet != null) {
// we had some custom polices, add them too.
addPolicySetToDevice(customPolicySet, device);
}
// Add the device patterns to the device.
Identification identification = loadIdentification();
final Map patterns = new HashMap();
IdentificationEntry idEntry = identification.find(deviceName);
if (idEntry != null) {
iterateGenericPatterns(idEntry, new GenericPatternIteratee() {
public void next(String pattern) {
// NOTE: yes this is intentional, why this must be a
// map I have no idea - a list would be fine.
patterns.put(pattern, null);
}
});
if (patterns.size() != 0) {
device.setPatterns(patterns);
}
}
// Add the device TACs to the device.
TacIdentification tacIdentification = loadTacIdentification();
if (tacIdentification != null) {
TacIdentificationEntry tacEntry = tacIdentification.find(
deviceName);
if (tacEntry != null) {
Set tacSet = convertTacEntryToTacSet(tacEntry);
if (tacSet.size() != 0) {
device.setTACValues(tacSet);
}
}
}
return device;
}