package org.hswebframework.web.service.oauth2;

import org.hswebframework.utils.ClassUtils;
import org.hswebframework.web.authorization.oauth2.client.OAuth2RequestService;
import org.springframework.beans.factory.annotation.Autowired;

@SuppressWarnings("unchecked")
public abstract class AbstractOAuth2CrudService<E, PK> implements OAuth2CrudService<E, PK> {

    private Class<E> entityType;

    private Class<PK> primaryKeyType;

    private OAuth2RequestService oAuth2RequestService;

    public AbstractOAuth2CrudService() {
        entityType = (Class) ClassUtils.getGenericType(this.getClass(), 0);
        primaryKeyType = (Class) ClassUtils.getGenericType(this.getClass(), 1);
    }

    @Override
    public OAuth2RequestService getRequestService() {
        return oAuth2RequestService;
    }

    @Override
    public abstract String getServiceId();

    @Override
    public abstract String getUriPrefix();

    @Override
    public Class<E> getEntityType() {
        return entityType;
    }

    @Override
    public Class<PK> getPrimaryKeyType() {
        return primaryKeyType;
    }

    @Autowired
    public void setoAuth2RequestService(OAuth2RequestService oAuth2RequestService) {
        this.oAuth2RequestService = oAuth2RequestService;
    }
}

@@ -165,16 +165,143 @@
 ervice;%0A
+import org.hswebframework.web.commons.entity.factory.EntityFactory;%0Aimport org.hswebframework.web.service.CreateEntityService;%0A
 import o
@@ -452,16 +452,40 @@
 plements
+ CreateEntityService%3CE%3E,
  OAuth2C
@@ -630,24 +630,66 @@
 stService;%0A%0A
+    private EntityFactory entityFactory;%0A%0A
     public A
@@ -872,32 +872,231 @@
 s(), 1);%0A    %7D%0A%0A
+    @Override%0A    public E createEntity() %7B%0A        return entityFactory.newInstance(entityType);%0A    %7D%0A%0A    @Override%0A    public Class%3CE%3E getEntityInstanceType() %7B%0A        return entityType;%0A    %7D%0A%0A
     @Override%0A  
@@ -1484,24 +1484,154 @@
 ype;%0A    %7D%0A%0A
+    @Autowired%0A    public void setEntityFactory(EntityFactory entityFactory) %7B%0A        this.entityFactory = entityFactory;%0A    %7D%0A%0A
     @Autowir

add EntityFactory