當前位置: 首頁>>代碼示例>>Java>>正文


Java Inflector類代碼示例

本文整理匯總了Java中org.javalite.common.Inflector的典型用法代碼示例。如果您正苦於以下問題:Java Inflector類的具體用法?Java Inflector怎麽用?Java Inflector使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Inflector類屬於org.javalite.common包,在下文中一共展示了Inflector類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createMethod

import org.javalite.common.Inflector; //導入依賴的package包/類
protected StringWriter createMethod(EntityNodePath path, boolean bulk, String method) throws Exception {
    Template template = getMethodTemplate(path, bulk, method);
    if (template == null) {
        // TODO Can't get here. Handle if it still gets here
        return new StringWriter();
    }

    VelocityContext context = new VelocityContext();
    context.put("inflector", Inflector.class);
    context.put("generator", this);
    context.put("path", path);
    if (bulk) {
        context.put("param_names", new RoutePattern(path.getBulkPath()).getParameterNames());
    } else {
        context.put("param_names", new RoutePattern(path.getSinglePath()).getParameterNames());
    }

    StringWriter writer = new StringWriter();
    template.merge(context, writer);
    return writer;
}
 
開發者ID:minnal,項目名稱:minnal,代碼行數:22,代碼來源:ResourceClassTestGenerator.java

示例2: createApplicationConfiguration

import org.javalite.common.Inflector; //導入依賴的package包/類
private ApplicationConfiguration createApplicationConfiguration() {
	ApplicationConfiguration configuration = new ApplicationConfiguration(Inflector.tableize(applicationName));
	DatabaseConfiguration databaseConfiguration = new DatabaseConfiguration();
	databaseConfiguration.setDriverClass("org.h2.Driver");
	databaseConfiguration.setIdleConnectionTestPeriod(300);
	databaseConfiguration.setMinSize(5);
	databaseConfiguration.setMaxSize(10);
	databaseConfiguration.setPackagesToScan(Arrays.asList(getBasePackage()));
	databaseConfiguration.setUrl("jdbc:h2:mem:test;MODE=MySQL;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE");
	databaseConfiguration.setUsername("sa");
	Map<String, String> properties = new HashMap<String, String>();
	properties.put("hibernate.ejb.naming_strategy", "org.hibernate.cfg.ImprovedNamingStrategy");
	properties.put("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
	properties.put("hibernate.current_session_context_class", "thread");
	properties.put("hibernate.hbm2ddl.auto", "create-drop");
	databaseConfiguration.setProviderProperties(properties);
	configuration.setPackagesToScan(Arrays.asList(getBasePackage()));
	configuration.setDatabaseConfiguration(databaseConfiguration);
	configuration.setInstrumentationEnabled(enableInstrumentation);
	return configuration;
}
 
開發者ID:minnal,項目名稱:minnal,代碼行數:22,代碼來源:ApplicationConfigGenerator.java

示例3: toXml

import org.javalite.common.Inflector; //導入依賴的package包/類
/**
 * Generates a XML document from content of this list.
 *
 * @param pretty pretty format (human readable), or one line text.
 * @param declaration true to include XML declaration at the top
 * @param attrs list of attributes to include. No arguments == include all attributes.
 * @return generated XML.
 */
public String toXml(boolean pretty, boolean declaration, String... attrs) {
    String topNode = Inflector.pluralize(Inflector.underscore(metaModel.getModelClass().getSimpleName()));

    hydrate();

    StringBuilder sb = new StringBuilder();
    if(declaration) {
        sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
        if (pretty) sb.append('\n');
    }
    sb.append('<').append(topNode).append('>');
    if (pretty) { sb.append('\n'); }
    for (T t : delegate) {
        t.toXmlP(sb, pretty, pretty ? "  " : "", attrs);
    }
    sb.append("</").append(topNode).append('>');
    if (pretty) { sb.append('\n'); }
    return sb.toString();
}
 
開發者ID:javalite,項目名稱:activejdbc,代碼行數:28,代碼來源:LazyList.java

示例4: generate

import org.javalite.common.Inflector; //導入依賴的package包/類
@Override
public void generate() {
    String packageName = entityClass.getPackage().getName() + ".generated";
    String testClass = entityClass.getSimpleName() + "ResourceTest";

    StringBuffer buffer = new StringBuffer();
    for (EntityNodePath path : paths) {
        createMethods(path, buffer);
    }

    VelocityContext context = new VelocityContext();
    context.put("inflector", Inflector.class);
    context.put("package_name", packageName);
    context.put("methods", buffer.toString());
    context.put("resource_class", testClass);
    context.put("base_test_class", baseTestClass);

    StringWriter writer = new StringWriter();
    createResourceTestClassTemplate.merge(context, writer);

    File folder = createPackage(packageName, TEST_JAVA_FOLDER);
    String fileName = testClass + ".java";
    File file = new File(folder, fileName);
    if (file.exists()) {
        File renamedFile = new File(folder, fileName + ".bk");
        if (!file.renameTo(renamedFile)) {
            throw new IllegalStateException("Failed while renaming the file " + file.getPath() + " to " + renamedFile.getPath());
        }
        file = new File(folder, fileName);
    }
    writeFile(CodeUtils.format(writer.toString()), file);
}
 
開發者ID:minnal,項目名稱:minnal,代碼行數:33,代碼來源:ResourceClassTestGenerator.java

示例5: createApplicationClass

import org.javalite.common.Inflector; //導入依賴的package包/類
protected void createApplicationClass() {
	String applicationClass = Inflector.shortName(getApplicationClassName());
	String applicationConfigClass = Inflector.shortName(getApplicationConfigClassName());
	VelocityContext context = new VelocityContext();
	context.put("packageName", getBasePackage());
	context.put("applicationClassName", applicationClass);
	context.put("applicationConfigClassName", applicationConfigClass);
	context.put("enableJpa", enableJpa);
	writeFile(createApplicationTemplate, context, new File(createPackage(getBasePackage()), applicationClass + ".java"));
}
 
開發者ID:minnal,項目名稱:minnal,代碼行數:11,代碼來源:ApplicationGenerator.java

示例6: createApplicationConfigClass

import org.javalite.common.Inflector; //導入依賴的package包/類
protected void createApplicationConfigClass() {
	String applicationConfigClass = Inflector.shortName(getApplicationConfigClassName());
	VelocityContext context = new VelocityContext();
	context.put("packageName", getBasePackage());
	context.put("applicationConfigClassName", applicationConfigClass);
	writeFile(createApplicationConfigTemplate, context, new File(createPackage(getBasePackage()), applicationConfigClass + ".java"));
}
 
開發者ID:minnal,項目名稱:minnal,代碼行數:8,代碼來源:ApplicationGenerator.java

示例7: generate

import org.javalite.common.Inflector; //導入依賴的package包/類
@Override
public void generate() {
	logger.info("Generating the model class {} under the package {}", model.getName(), getDomainPackage());
	VelocityContext context = new VelocityContext();
	context.put("inflector", Inflector.class);
	context.put("model", model);
	context.put("packageName", getDomainPackage());
	
	writeFile(createModelTemplate, context, new File(createPackage(getDomainPackage()), model.getName() + ".java"));
}
 
開發者ID:minnal,項目名稱:minnal,代碼行數:11,代碼來源:ModelGenerator.java

示例8: buildPath

import org.javalite.common.Inflector; //導入依賴的package包/類
private void buildPath(List<EntityNode> path) {
	StringWriter writer = new StringWriter();
	Iterator<EntityNode> iterator = iterator();
	StringBuffer prefix = new StringBuffer();
	EntityNode parent = null;
	StringWriter pathName = new StringWriter();
	while (iterator.hasNext()) {
		EntityNode node = iterator.next();
		String name = node.getResourceName();
		
		pathName.append(node.getName());
		writer.append("/").append(name);
		if (iterator.hasNext()) {
			writer.append("/{" + namingStrategy.getPathSegment(node.getName() + "Id") + "}");
			pathName.append("_");
		}
		
		if (! iterator.hasNext()) {
			if (parent != null) {
				prefix = prefix.length() == 0 ? prefix.append(name) : prefix.append(".").append(name);
			}
			addSearchFields(prefix.toString(), node);
		}
		parent = node;
	}
	bulkPath = writer.toString();
	singlePath = bulkPath + "/{id}";
	name = Inflector.camelize(pathName.toString());
}
 
開發者ID:minnal,項目名稱:minnal,代碼行數:30,代碼來源:EntityNode.java

示例9: getFilter

import org.javalite.common.Inflector; //導入依賴的package包/類
public static Filter getFilter(MultivaluedMap<String, String> queryParams, final List<String> paramNames) {
	Filter filter = getFilter(queryParams);
	for (Entry<String, List<String>> entry : queryParams.entrySet()) {
		if (! paramNames.contains(entry.getKey())) {
			continue;
		}
		if (entry.getValue().size() == 1) {
			filter.addCondition(Inflector.camelize(entry.getKey(), false), entry.getValue().get(0));
		} else {
			filter.addCondition(Inflector.camelize(entry.getKey(), false), Operator.in, entry.getValue());
		}
	}
	return filter;
}
 
開發者ID:minnal,項目名稱:minnal,代碼行數:15,代碼來源:ResourceUtil.java

示例10: createMethodBody

import org.javalite.common.Inflector; //導入依賴的package包/類
/**
 * Creates the method body
 * 
 * @param context
 * @return
 */
protected String createMethodBody(VelocityContext context) {
	context.put("inflector", Inflector.class);
	context.put("path", resourcePath.getNodePath());
	context.put("param_names", getRoutePattern().getParameterNames());
	
	Template template = getTemplate();
	StringWriter writer = new StringWriter();
	
	logger.debug("Creating the method body with context {} and template {} for the resource path {} and method {}", context, template.getName(), resourcePath, getHttpMethod());
	template.merge(context, writer);
	return writer.toString();
}
 
開發者ID:minnal,項目名稱:minnal,代碼行數:19,代碼來源:AbstractMethodCreator.java

示例11: toResponse

import org.javalite.common.Inflector; //導入依賴的package包/類
@Override
public Response toResponse(ConstraintViolationException exception) {
	ConstraintViolationException ex = (ConstraintViolationException) exception;
	List<FieldError> errors = new ArrayList<FieldError>();
	for (ConstraintViolation<?> violation : ex.getConstraintViolations()) {
		errors.add(new FieldError(Inflector.underscore(violation.getPropertyPath().toString()), violation.getMessage(), violation.getInvalidValue()));
	}
	Map<String, List<FieldError>> message = new HashMap<String, List<FieldError>>();
	message.put("fieldErrors", errors);
	return Response.status(UnprocessableEntityStatusType.INSTANCE).entity(message).build();
}
 
開發者ID:minnal,項目名稱:minnal,代碼行數:12,代碼來源:ConstraintViolationExceptionHandler.java

示例12: init

import org.javalite.common.Inflector; //導入依賴的package包/類
@Override
public void init() {
    applicationName = Inflector.camelize(baseDir.getName().toLowerCase().replace('-', '_'));
}
 
開發者ID:minnal,項目名稱:minnal,代碼行數:5,代碼來源:AbstractGenerator.java

示例13: getBasePackage

import org.javalite.common.Inflector; //導入依賴的package包/類
protected String getBasePackage() {
    return "com." + Inflector.underscore(applicationName).replace('_', '.');
}
 
開發者ID:minnal,項目名稱:minnal,代碼行數:4,代碼來源:AbstractGenerator.java

示例14: getEntityName

import org.javalite.common.Inflector; //導入依賴的package包/類
@Override
public String getEntityName(Class<?> entityClass) {
	return Inflector.camelize(Inflector.underscore(entityClass.getSimpleName()), false);
}
 
開發者ID:minnal,項目名稱:minnal,代碼行數:5,代碼來源:UnderscoreNamingStrategy.java

示例15: getResourceName

import org.javalite.common.Inflector; //導入依賴的package包/類
@Override
public String getResourceName(String entityName) {
	return Inflector.tableize(entityName);
}
 
開發者ID:minnal,項目名稱:minnal,代碼行數:5,代碼來源:UnderscoreNamingStrategy.java


注:本文中的org.javalite.common.Inflector類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。