com.adaptrex.core.ext.ExtConfig Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of adaptrex-core Show documentation
Show all versions of adaptrex-core Show documentation
The Core Adaptrex Framework
The newest version!
/*
* Copyright 2012 Adaptrex, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.adaptrex.core.ext;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.servlet.ServletContext;
import com.adaptrex.core.persistence.api.AdaptrexPersistenceManager;
import com.adaptrex.core.Adaptrex;
/*
* TODO: Do we switch this to model only config and simplify throughout?
*/
public class ExtConfig {
private String factoryName; // Only necessary to configure rest path (we include non default factory name
private String className;
private String modelName;
private List includes = new ArrayList();
private List excludes = new ArrayList();
private List associations = new ArrayList();
private ExtConfig parentConfig;
private AdaptrexPersistenceManager apm;
private Class> entityClass;
public ExtConfig(ServletContext context, String entityClassName) {
this(context, entityClassName, null);
};
public ExtConfig(ServletContext context, String entityClassName, String factoryName) {
this.factoryName = factoryName;
this.apm = Adaptrex.get(context).getPersistenceManager(factoryName);
this.entityClass = apm.getAdaptrexEntity(entityClassName).getJavaClass();
this.modelName = entityClassName;
this.className = entityClassName;
}
public ExtConfig (AdaptrexPersistenceManager opm, String entityClassName) {
this(opm, entityClassName, null);
}
public ExtConfig (AdaptrexPersistenceManager opm, String entityClassName, String factoryName) {
this.apm = opm;
this.factoryName = factoryName;
this.entityClass = opm.getAdaptrexEntity(entityClassName).getJavaClass();
if (this.entityClass == null) {
return;
}
this.modelName = this.entityClass.getSimpleName();
this.className = this.entityClass.getSimpleName();
}
public ExtConfig setParentConfig(ExtConfig parentConfig) {
this.parentConfig = parentConfig;
return this;
}
public ExtConfig setClassName(String className) {
this.className = className;
return this;
}
public ExtConfig setModelName(String name) {
this.modelName = name;
return this;
}
public ExtConfig setIncludes(List include) {
this.includes = include;
return this;
}
public ExtConfig setExcludes(List exclude) {
this.excludes = exclude;
return this;
}
public ExtConfig setAssociations(List associations) {
this.associations = associations;
return this;
}
public ExtConfig setIncludes(String include) {
if (include == null) {return this;}
this.includes = Arrays.asList(include.split(","));
return this;
}
public ExtConfig setExcludes(String exclude) {
if (exclude == null) {return this;}
this.excludes = Arrays.asList(exclude.split(","));
return this;
}
public ExtConfig setAssociations(String associations) {
if (associations == null) {return this;}
this.associations = Arrays.asList(associations.split(","));
return this;
}
public ExtConfig getParentConfig() {
return parentConfig;
}
public String getFactoryName() {
return factoryName;
}
public String getClassName() {
return className;
}
public String getModelName() {
return modelName;
}
public List getIncludes() {
return includes;
}
public List getExcludes() {
return excludes;
}
public List getAssociations() {
return associations;
}
public AdaptrexPersistenceManager getORMPersistenceManager() {
return apm;
}
public Class> getEntityClass() {
return entityClass;
}
}