+
+
+ public static void loadXmlLookupMap(String version, DynamicJAXBContext jaxbContext ) {
+
+ @SuppressWarnings("rawtypes")
+ List<Descriptor> descriptorsList = jaxbContext.getXMLContext().getDescriptors();
+ HashMap<String, DynamicType> types = new HashMap<String, DynamicType>();
+
+ for (@SuppressWarnings("rawtypes")
+ Descriptor desc : descriptorsList) {
+
+ DynamicType entity = jaxbContext.getDynamicType(desc.getAlias());
+ String entityName = desc.getDefaultRootElement();
+ types.put(entityName, entity);
+ }
+ xmlElementLookup.put(version, types);
+ }
+
+
+ public static DynamicType getDynamicTypeForVersion(String version, String type) throws CrudException {
+
+ DynamicType dynamicType;
+ // If we haven't already loaded in the available OXM models, then do so now.
+ if (versionContextMap == null || versionContextMap.isEmpty()) {
+ loadModels();
+ } else if (!versionContextMap.containsKey(version)) {
+ logger.error(CrudServiceMsgs.OXM_LOAD_ERROR, "Error loading oxm model: " + version);
+ throw new CrudException("Error loading oxm model: " + version, Status.INTERNAL_SERVER_ERROR);
+ }
+
+ // First try to match the Java-type based on hyphen to camel case
+ // translation
+ String javaTypeName = CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, type);
+ dynamicType = versionContextMap.get(version).getDynamicType(javaTypeName);
+
+ if (xmlElementLookup.containsKey(version)) {
+ if (dynamicType == null) {
+ // Try to lookup by xml root element by exact match
+ dynamicType = xmlElementLookup.get(version).get(type);
+ }
+
+ if (dynamicType == null) {
+ // Try to lookup by xml root element by lowercase
+ dynamicType = xmlElementLookup.get(version).get(type.toLowerCase());
+ }
+
+ if (dynamicType == null) {
+ // Direct lookup as java-type name
+ dynamicType = versionContextMap.get(version).getDynamicType(type);
+ }
+ }
+
+ return dynamicType;
+ }
+
+ /**
+ * Retrieves the list of all Loaded OXM versions.
+ *
+ * @return - A List of Strings of all loaded OXM versions.
+ *
+ * @throws CrudException
+ */
+ public static List<String> getLoadedOXMVersions() throws CrudException {
+
+ // If we haven't already loaded in the available OXM models, then do so now.
+ if (versionContextMap == null || versionContextMap.isEmpty()) {
+ loadModels();
+ }
+
+ // If there are still no models available, then there's not much we can do...
+ if (versionContextMap.isEmpty()) {
+ logger.error(CrudServiceMsgs.OXM_LOAD_ERROR, "No available OXM schemas to get versions for.");
+ throw new CrudException("No available OXM schemas to get versions for.", Status.INTERNAL_SERVER_ERROR);
+ }
+
+ List<String> versions = new ArrayList<String>();
+ for (String versionKey : versionContextMap.keySet()) {
+
+ Matcher matcher = versionPattern.matcher(versionKey);
+ if (matcher.find()) {
+ versions.add ("V"+ matcher.group(1));
+ }
+ }
+ return versions;
+ }