@Test public void testScanExtensionTypes() throws DataFormatException { ModelScanner scanner = new ModelScanner(ResourceWithExtensionsA.class); RuntimeResourceDefinition def = (RuntimeResourceDefinition) scanner.getClassToElementDefinitions().get(ResourceWithExtensionsA.class); assertEquals( RuntimeChildCompositeDatatypeDefinition.class, def.getChildByNameOrThrowDataFormatException("identifier").getClass()); RuntimeChildDeclaredExtensionDefinition ext = def.getDeclaredExtension("http://foo/#f1"); assertNotNull(ext); BaseRuntimeElementDefinition<?> valueString = ext.getChildByName("valueString"); assertNotNull(valueString); ext = def.getDeclaredExtension("http://foo/#f2"); assertNotNull(ext); valueString = ext.getChildByName("valueString"); assertNotNull(valueString); ext = def.getDeclaredExtension("http://bar/#b1"); assertNotNull(ext); RuntimeChildDeclaredExtensionDefinition childExt = ext.getChildExtensionForUrl("http://bar/#b1/1"); assertNotNull(childExt); BaseRuntimeElementDefinition<?> valueDate = childExt.getChildByName("valueDate"); assertNotNull(valueDate); childExt = ext.getChildExtensionForUrl("http://bar/#b1/2"); assertNotNull(childExt); childExt = childExt.getChildExtensionForUrl("http://bar/#b1/2/1"); assertNotNull(childExt); valueDate = childExt.getChildByName("valueDate"); assertNotNull(valueDate); }
private synchronized Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> scanResourceTypes(Collection<Class<? extends IElement>> theResourceTypes) { myInitializing = true; List<Class<? extends IBase>> typesToScan = new ArrayList<Class<? extends IBase>>(); if (theResourceTypes != null) { typesToScan.addAll(theResourceTypes); } if (myCustomTypes != null) { typesToScan.addAll(myCustomTypes); myCustomTypes = null; } ModelScanner scanner = new ModelScanner(this, myVersion.getVersion(), myClassToElementDefinition, typesToScan); if (myRuntimeChildUndeclaredExtensionDefinition == null) { myRuntimeChildUndeclaredExtensionDefinition = scanner.getRuntimeChildUndeclaredExtensionDefinition(); } Map<String, BaseRuntimeElementDefinition<?>> nameToElementDefinition = new HashMap<String, BaseRuntimeElementDefinition<?>>(); nameToElementDefinition.putAll(myNameToElementDefinition); for (Entry<String, BaseRuntimeElementDefinition<?>> next : scanner.getNameToElementDefinitions().entrySet()) { if (!nameToElementDefinition.containsKey(next.getKey())) { nameToElementDefinition.put(next.getKey(), next.getValue()); } } Map<String, RuntimeResourceDefinition> nameToResourceDefinition = new HashMap<String, RuntimeResourceDefinition>(); nameToResourceDefinition.putAll(myNameToResourceDefinition); for (Entry<String, RuntimeResourceDefinition> next : scanner.getNameToResourceDefinition().entrySet()) { if (!nameToResourceDefinition.containsKey(next.getKey())) { nameToResourceDefinition.put(next.getKey(), next.getValue()); } } Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> classToElementDefinition = new HashMap<Class<? extends IBase>, BaseRuntimeElementDefinition<?>>(); classToElementDefinition.putAll(myClassToElementDefinition); classToElementDefinition.putAll(scanner.getClassToElementDefinitions()); for (BaseRuntimeElementDefinition<?> next : classToElementDefinition.values()) { if (next instanceof RuntimeResourceDefinition) { if ("Bundle".equals(next.getName())) { if (!IBaseBundle.class.isAssignableFrom(next.getImplementingClass())) { throw new ConfigurationException( "Resource type declares resource name Bundle but does not implement IBaseBundle"); } } } } Map<String, RuntimeResourceDefinition> idToElementDefinition = new HashMap<String, RuntimeResourceDefinition>(); idToElementDefinition.putAll(myIdToResourceDefinition); idToElementDefinition.putAll(scanner.getIdToResourceDefinition()); myNameToElementDefinition = nameToElementDefinition; myClassToElementDefinition = classToElementDefinition; myIdToResourceDefinition = idToElementDefinition; myNameToResourceDefinition = nameToResourceDefinition; myNameToResourceType = scanner.getNameToResourceType(); myInitialized = true; return classToElementDefinition; }