@Override
 public Collection<WritableContentType> parseContentTypes(
     WorkspaceId workspaceId, InputStream contentTypeDefinitionStream, MediaType mediaType)
     throws NullPointerException, InvalidReferenceException, IOException {
   TypeValidator validator =
       SmartContentSPI.getInstance().getTypeValidators().getValidators().get(mediaType);
   ContentTypeDefinitionParser parser =
       SmartContentSPI.getInstance().getContentTypeDefinitionParsers().getParsers().get(mediaType);
   if (validator == null || parser == null) {
     throw new IOException("Media type " + mediaType.toString() + " is not supported!");
   }
   if (!contentTypeDefinitionStream.markSupported()) {
     contentTypeDefinitionStream = new BufferedInputStream(contentTypeDefinitionStream);
   }
   try {
     if (!validator.isValid(contentTypeDefinitionStream)) {
       throw new IOException("Content does not meet definition!");
     }
     final Collection<WritableContentType> types =
         parser.parseStream(workspaceId, contentTypeDefinitionStream);
     if (logger.isDebugEnabled()) {
       for (WritableContentType contentType : types) {
         logger.debug("ID " + contentType.getContentTypeID());
       }
     }
     List<ContentTypeImpl> resultingTypes = mergeWithStoredContentTypes(types);
     return Collections.<WritableContentType>unmodifiableCollection(resultingTypes);
   } catch (InvalidReferenceException ex) {
     throw ex;
   } catch (Exception ex) {
     throw new IOException(ex);
   }
 }
 @Override
 public ContentType loadContentType(ContentTypeId contentTypeID) throws NullPointerException {
   final Collection<? extends ContentType> reads =
       SmartContentSPI.getInstance()
           .getContentTypeReader()
           .readContentTypeFromPersistentStorage(contentTypeID);
   if (reads.size() > 0) {
     return reads.iterator().next();
   } else {
     return null;
   }
 }
 protected List<ContentTypeImpl> mergeWithStoredContentTypes(
     final Collection<WritableContentType> types) throws IllegalArgumentException {
   final List<ContentTypeImpl> resultingTypes = new ArrayList<ContentTypeImpl>(types.size());
   final Collection<? extends ContentType> storedContentTypes;
   final ContentTypeId[] ids = new ContentTypeId[types.size()];
   int i = 0;
   for (ContentType type : types) {
     ids[i++] = type.getContentTypeID();
   }
   storedContentTypes =
       SmartContentSPI.getInstance()
           .getContentTypeReader()
           .readContentTypeFromPersistentStorage(ids);
   for (ContentType type : storedContentTypes) {
     final ContentTypeImpl contentTypeImpl = getContentTypeImpl(type);
     contentTypeImpl.setFromPersistentStorage(true);
     resultingTypes.add(contentTypeImpl);
   }
   if (logger.isDebugEnabled()) {
     logger.debug(
         new StringBuilder("After getting from persistent storage size is of 2b ReturnedList is ")
             .append(resultingTypes.size())
             .toString());
   }
   for (MutableContentType type : types) {
     if (logger.isDebugEnabled()) {
       logger.debug(new StringBuilder("Type ID is ").append(type.getContentTypeID()).toString());
     }
     int index = resultingTypes.indexOf(type);
     if (index >= 0) {
       logger.debug("Just merging");
       final ContentTypeImpl get = resultingTypes.get(index);
       merge(get, type);
       get.setFromPersistentStorage(true);
     } else {
       logger.debug("Adding to list");
       resultingTypes.add(getContentTypeImpl(type));
     }
   }
   return resultingTypes;
 }
 @Override
 public SearchResult<ContentType> search(Filter filter) {
   return SmartContentSPI.getInstance().getContentTypeSearcher().search(filter);
 }
 @Override
 public void reIndexType(ContentTypeId contentTypeId) {
   SmartContentSPI.getInstance().getContentTypeSearcher().reIndex(contentTypeId);
 }
 @Override
 public void reIndexTypes(WorkspaceId workspaceId) {
   SmartContentSPI.getInstance().getContentTypeSearcher().reIndex(workspaceId);
 }
 @Override
 public String getSearchFieldName(FieldDef fieldDef) {
   return SmartContentSPI.getInstance().getSearchFieldNameGenerator().getSearchFieldName(fieldDef);
 }