001/* 002 * Copyright 2013 Box, Inc. All rights reserved. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.nuxeo.box.api.marshalling.jsonparsing; 017 018import org.nuxeo.box.api.marshalling.dao.BoxCollaboration; 019import org.nuxeo.box.api.marshalling.dao.BoxCollection; 020import org.nuxeo.box.api.marshalling.dao.BoxComment; 021import org.nuxeo.box.api.marshalling.dao.BoxEmailAlias; 022import org.nuxeo.box.api.marshalling.dao.BoxEvent; 023import org.nuxeo.box.api.marshalling.dao.BoxEventCollection; 024import org.nuxeo.box.api.marshalling.dao.BoxFile; 025import org.nuxeo.box.api.marshalling.dao.BoxFileVersion; 026import org.nuxeo.box.api.marshalling.dao.BoxFolder; 027import org.nuxeo.box.api.marshalling.dao.BoxGroup; 028import org.nuxeo.box.api.marshalling.dao.BoxItem; 029import org.nuxeo.box.api.marshalling.dao.BoxLock; 030import org.nuxeo.box.api.marshalling.dao.BoxPreview; 031import org.nuxeo.box.api.marshalling.dao.BoxRealTimeServer; 032import org.nuxeo.box.api.marshalling.dao.BoxResourceType; 033import org.nuxeo.box.api.marshalling.dao.BoxServerError; 034import org.nuxeo.box.api.marshalling.dao.BoxTypedObject; 035import org.nuxeo.box.api.marshalling.dao.BoxUser; 036import org.nuxeo.box.api.marshalling.dao.BoxWebLink; 037import org.nuxeo.box.api.marshalling.interfaces.IBoxType; 038 039import java.util.Collection; 040 041public class BoxResourceHub extends BaseBoxResourceHub { 042 043 public BoxResourceHub() { 044 super(); 045 } 046 047 @Override 048 @SuppressWarnings("rawtypes") 049 public Class getClass(IBoxType type) { 050 if (getConcreteClassForIBoxType().equals(type.getClass())) { 051 return getObjectClassGivenConcreteIBoxType(type); 052 } else { 053 return super.getClass(type); 054 } 055 } 056 057 @Override 058 public Collection<IBoxType> getAllTypes() { 059 return getLowerCaseStringToTypeMap().values(); 060 } 061 062 @Override 063 protected Class getObjectClassGivenConcreteIBoxType(IBoxType type) { 064 switch ((BoxResourceType) type) { 065 case FILE: 066 return BoxFile.class; 067 case PREVIEW: 068 return BoxPreview.class; 069 case FOLDER: 070 return BoxFolder.class; 071 case WEB_LINK: 072 return BoxWebLink.class; 073 case USER: 074 return BoxUser.class; 075 case GROUP: 076 return BoxGroup.class; 077 case FILE_VERSION: 078 return BoxFileVersion.class; 079 case ITEM: 080 return BoxItem.class; 081 case COMMENT: 082 return BoxComment.class; 083 case COLLABORATION: 084 return BoxCollaboration.class; 085 case EMAIL_ALIAS: 086 return BoxEmailAlias.class; 087 case EVENT: 088 return BoxEvent.class; 089 case EVENTS: 090 return BoxEventCollection.class; 091 case REALTIME_SERVER: 092 return BoxRealTimeServer.class; 093 case LOCK: 094 return BoxLock.class; 095 case ERROR: 096 return BoxServerError.class; 097 case ITEMS: 098 case FILES: 099 case USERS: 100 case COMMENTS: 101 case FILE_VERSIONS: 102 case COLLABORATIONS: 103 case EMAIL_ALIASES: 104 return BoxCollection.class; 105 default: 106 return BoxTypedObject.class; 107 } 108 } 109 110 @SuppressWarnings("rawtypes") 111 @Override 112 protected Class getConcreteClassForIBoxType() { 113 return BoxResourceType.class; 114 } 115 116 @Override 117 public IBoxType getTypeFromLowercaseString(String type) { 118 return getLowerCaseStringToTypeMap().get(type); 119 } 120 121 @Override 122 protected void initializeTypes() { 123 super.initializeTypes(); 124 initializeEnumTypes(BoxResourceType.class); 125 } 126}