📄 configurationdictionary.java
字号:
ConfigurationDictionary createCopyIfRealAndRemoveLocation() { if (doesNotContainRealProperties()) { return null; } return createCopyAndRemoveLocation(); } ConfigurationDictionary createCopyAndRemoveLocation() { ConfigurationDictionary cd = createCopy(); cd.remove(ConfigurationAdminFactory.BUNDLE_LOCATION); cd.remove(ConfigurationAdminFactory.DYNAMIC_BUNDLE_LOCATION); return cd; } boolean doesNotContainRealProperties() { int numberOfProperties = size(); if (numberOfProperties > 5) { return false; } if (get(ConfigurationAdminFactory.SERVICE_PID) != null) --numberOfProperties; if (get(ConfigurationAdminFactory.FACTORY_PID) != null) --numberOfProperties; if (get(ConfigurationAdminFactory.BUNDLE_LOCATION) != null) --numberOfProperties; if (get(ConfigurationAdminFactory.DYNAMIC_BUNDLE_LOCATION) != null) --numberOfProperties; if (get(ConfigurationAdminFactory.DUMMY_PROPERTY) != null) --numberOfProperties; return numberOfProperties == 0; } private void updateLowercaseToOriginalCase() { Enumeration keys = originalCase.keys(); while (keys.hasMoreElements()) { String originalKey = (String) keys.nextElement(); updateLowercaseToOriginalCase(originalKey); } } private void updateLowercaseToOriginalCase(String originalKey) { if (originalKey == null) { return; } String lowercaseKey = originalKey.toLowerCase(); if (!lowercaseToOriginalCase.containsKey(lowercaseKey)) { lowercaseToOriginalCase.put(lowercaseKey, originalKey); } } static public ConfigurationDictionary createDeepCopy(Dictionary in) { Hashtable h = copyDictionary(in); return new ConfigurationDictionary(h); } static public Hashtable copyDictionary(Dictionary in) { if (in == null) { return null; } Hashtable out = new Hashtable(); Enumeration keys = in.keys(); while (keys.hasMoreElements()) { Object key = keys.nextElement(); Object origVal = in.get(key); Object val = copyValue(origVal); // The R3 tests prefers keys with different case to be // silently unified. We really prefer IllegalArgumentException String s = (String) key; String lower = s.toLowerCase(); if (!s.equals(lower)) { Object lowerVal = in.get(lower); if (null != lowerVal) { if (Activator.r3TestCompliant()) { key = lower; } else { // Accept different case when actual value id // reference-equal // This solves problem when incoming dictionary has // case-insensitive get/lookup // If not reference-equal, throw // IllegalArgumentException if (lowerVal != origVal) { throw new IllegalArgumentException( "same key exists with different case: " + key + "/" + lower); } } } } out.put(key, val); } return out; } static private Object copyValue(Object in) { if (in == null) { return null; } if (in.getClass().isArray()) { return copyArray(in); } else if (in instanceof Vector) { return copyVector((Vector) in); } else { return in; } } static private Vector copyVector(Vector in) { if (in == null) { return null; } Vector out = new Vector(); Enumeration elements = in.elements(); while (elements.hasMoreElements()) { out.addElement(copyValue(elements.nextElement())); } return out; } static private Object copyArray(Object in) { if (in == null) { return null; } int length = Array.getLength(in); Object out = Array .newInstance(in.getClass().getComponentType(), length); for (int i = 0; i < length; ++i) { Array.set(out, i, copyValue(Array.get(in, i))); } return out; } static void validateDictionary(Dictionary dictionary) throws IllegalArgumentException { if (dictionary == null) { return; } Enumeration keys = dictionary.keys(); while (keys.hasMoreElements()) { Object key = keys.nextElement(); if (key.getClass() != String.class) { throw new IllegalArgumentException("The key " + key + " is not of type java.lang.String."); } try { validateValue(dictionary.get(key)); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("The value for key " + key + " is not of correct type: " + e.getMessage()); } /* * if(Activator.r3TestCompliant()) { String s = (String)key; String * lower = s.toLowerCase(); if(!s.equals(lower)) { if(null != * dictionary.get(lower)) { throw new IllegalArgumentException("key '" + * s + "'" + " also appears with different " + "case '" + lower + * "'"); } } } */ } } static private void validateValue(Object value) throws IllegalArgumentException { if (value == null) { return; } Class valueClass = value.getClass(); if (valueClass.isArray()) { validateArray(value); } else if (valueClass == Vector.class) { validateVector((Vector) value); } else { if (!allowedObjectTypes.containsKey(valueClass)) { throw new IllegalArgumentException(valueClass.toString() + " is not an allowed type."); } } } static private void validateArray(Object array) { Class componentType = array.getClass().getComponentType(); int length = Array.getLength(array); if (componentType.isArray() || componentType == Vector.class) { for (int i = 0; i < length; ++i) { Object o = Array.get(array, i); if (o != null) { Class objectClass = o.getClass(); if (objectClass != componentType) { throw new IllegalArgumentException( "Objects with different type in array. " + "Found " + objectClass.toString() + " " + "Expected " + componentType.toString()); } validateValue(o); } } } else { if (!allowedPrimitiveTypes.containsKey(componentType) && !allowedObjectTypes.containsKey(componentType)) { throw new IllegalArgumentException( "Illegal component type for arrays: " + componentType.toString()); } for (int i = 0; i < length; ++i) { Object o = Array.get(array, i); if (o != null) { Class objectClass = o.getClass(); if (componentType.isPrimitive()) { objectClass = (Class) classToPrimitiveType .get(objectClass); } if (objectClass != componentType) { throw new IllegalArgumentException( "Objects with different type in array. " + "Found " + objectClass.toString() + " " + "Expected " + componentType.toString()); } } } } } static private void validateVector(Vector vector) { for (int i = 0; i < vector.size(); ++i) { Object element = vector.elementAt(i); validateValue(element); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -