001package org.nuxeo.box.api.marshalling.jsonparsing;
002
003import org.nuxeo.box.api.marshalling.dao.BoxCollaboration;
004import org.nuxeo.box.api.marshalling.dao.BoxCollection;
005import org.nuxeo.box.api.marshalling.dao.BoxComment;
006import org.nuxeo.box.api.marshalling.dao.BoxEmailAlias;
007import org.nuxeo.box.api.marshalling.dao.BoxEvent;
008import org.nuxeo.box.api.marshalling.dao.BoxEventCollection;
009import org.nuxeo.box.api.marshalling.dao.BoxFile;
010import org.nuxeo.box.api.marshalling.dao.BoxFileVersion;
011import org.nuxeo.box.api.marshalling.dao.BoxFolder;
012import org.nuxeo.box.api.marshalling.dao.BoxGroup;
013import org.nuxeo.box.api.marshalling.dao.BoxItem;
014import org.nuxeo.box.api.marshalling.dao.BoxLock;
015import org.nuxeo.box.api.marshalling.dao.BoxPreview;
016import org.nuxeo.box.api.marshalling.dao.BoxRealTimeServer;
017import org.nuxeo.box.api.marshalling.dao.BoxResourceType;
018import org.nuxeo.box.api.marshalling.dao.BoxServerError;
019import org.nuxeo.box.api.marshalling.dao.BoxTypedObject;
020import org.nuxeo.box.api.marshalling.dao.BoxUser;
021import org.nuxeo.box.api.marshalling.dao.BoxWebLink;
022import org.nuxeo.box.api.marshalling.interfaces.IBoxType;
023
024import java.util.Collection;
025
026public class BoxResourceHub extends BaseBoxResourceHub {
027
028    public BoxResourceHub() {
029        super();
030    }
031
032    @Override
033    @SuppressWarnings("rawtypes")
034    public Class getClass(IBoxType type) {
035        if (getConcreteClassForIBoxType().equals(type.getClass())) {
036            return getObjectClassGivenConcreteIBoxType(type);
037        } else {
038            return super.getClass(type);
039        }
040    }
041
042    @Override
043    public Collection<IBoxType> getAllTypes() {
044        return getLowerCaseStringToTypeMap().values();
045    }
046
047    @Override
048    protected Class getObjectClassGivenConcreteIBoxType(IBoxType type) {
049        switch ((BoxResourceType) type) {
050        case FILE:
051            return BoxFile.class;
052        case PREVIEW:
053            return BoxPreview.class;
054        case FOLDER:
055            return BoxFolder.class;
056        case WEB_LINK:
057            return BoxWebLink.class;
058        case USER:
059            return BoxUser.class;
060        case GROUP:
061            return BoxGroup.class;
062        case FILE_VERSION:
063            return BoxFileVersion.class;
064        case ITEM:
065            return BoxItem.class;
066        case COMMENT:
067            return BoxComment.class;
068        case COLLABORATION:
069            return BoxCollaboration.class;
070        case EMAIL_ALIAS:
071            return BoxEmailAlias.class;
072        case EVENT:
073            return BoxEvent.class;
074        case EVENTS:
075            return BoxEventCollection.class;
076        case REALTIME_SERVER:
077            return BoxRealTimeServer.class;
078        case LOCK:
079            return BoxLock.class;
080        case ERROR:
081            return BoxServerError.class;
082        case ITEMS:
083        case FILES:
084        case USERS:
085        case COMMENTS:
086        case FILE_VERSIONS:
087        case COLLABORATIONS:
088        case EMAIL_ALIASES:
089            return BoxCollection.class;
090        default:
091            return BoxTypedObject.class;
092        }
093    }
094
095    @SuppressWarnings("rawtypes")
096    @Override
097    protected Class getConcreteClassForIBoxType() {
098        return BoxResourceType.class;
099    }
100
101    @Override
102    public IBoxType getTypeFromLowercaseString(String type) {
103        return getLowerCaseStringToTypeMap().get(type);
104    }
105
106    @Override
107    protected void initializeTypes() {
108        super.initializeTypes();
109        initializeEnumTypes(BoxResourceType.class);
110    }
111}