本文整理汇总了Java中org.jboss.forge.roaster.model.util.Strings类的典型用法代码示例。如果您正苦于以下问题:Java Strings类的具体用法?Java Strings怎么用?Java Strings使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Strings类属于org.jboss.forge.roaster.model.util包,在下文中一共展示了Strings类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getEntityTable
import org.jboss.forge.roaster.model.util.Strings; //导入依赖的package包/类
public static String getEntityTable(final JavaClass<?> entity)
{
String table = entity.getName();
if (entity.hasAnnotation(Entity.class))
{
Annotation<?> a = entity.getAnnotation(Entity.class);
if (!Strings.isNullOrEmpty(a.getStringValue("name")))
{
table = a.getStringValue("name");
}
else if (!Strings.isNullOrEmpty(a.getStringValue()))
{
table = a.getStringValue();
}
}
return table;
}
示例2: getIdClause
import org.jboss.forge.roaster.model.util.Strings; //导入依赖的package包/类
public static String getIdClause(JavaClass<?> entity, String entityTable)
{
for (Member<?> member : entity.getMembers())
{
if (member.hasAnnotation(Id.class))
{
String memberName = member.getName();
String id = null;
if (member instanceof Method)
{
// Getters are expected to obey JavaBean conventions
id = Strings.uncapitalize(memberName.substring(3));
}
if (member instanceof Field)
{
id = memberName;
}
char entityVariable = getJpqlEntityVariable(entityTable);
return "WHERE " + entityVariable + "." + id + " = " + ":entityId";
}
}
return null;
}
示例3: createJavaComponentFactoryClass
import org.jboss.forge.roaster.model.util.Strings; //导入依赖的package包/类
public static void createJavaComponentFactoryClass(JavaClassSource javaClass, CamelComponentDetails details, String camelComponentName,
String componentInstanceName, String configurationCode, Set<String> extraJavaImports) {
javaClass.addImport(details.getComponentClassQName());
if (extraJavaImports != null) {
for (String extra : extraJavaImports) {
javaClass.addImport(extra);
}
}
String componentClassName = details.getComponentClassName();
String methodName = "create" + Strings.capitalize(componentInstanceName) + "Component";
String body = componentClassName + " component = new " + componentClassName + "();" + configurationCode + "\nreturn component;";
javaClass.addMethod()
.setPublic()
.setReturnType(componentClassName)
.setName(methodName)
.setBody(body);
}
示例4: getOrderClause
import org.jboss.forge.roaster.model.util.Strings; //导入依赖的package包/类
public static String getOrderClause(JavaClass<?> entity, char entityVariable)
{
StringBuilder expressionBuilder = new StringBuilder();
// Add the ORDER BY clause
for (Member<?> member : entity.getMembers())
{
if (member.hasAnnotation(Id.class))
{
String memberName = member.getName();
String id = null;
if (member instanceof Method)
{
// Getters are expected to obey JavaBean conventions
id = Strings.uncapitalize(memberName.substring(3));
}
if (member instanceof Field)
{
id = memberName;
}
expressionBuilder.append("ORDER BY ");
expressionBuilder.append(entityVariable);
expressionBuilder.append('.');
expressionBuilder.append(id);
}
}
return expressionBuilder.toString();
}
示例5: mandatoryAttributeValue
import org.jboss.forge.roaster.model.util.Strings; //导入依赖的package包/类
/**
* Returns the mandatory String value of the given name
*
* @throws IllegalArgumentException if the value is not available in the given attribute map
*/
public static String mandatoryAttributeValue(Map<Object, Object> attributeMap, String name) {
Object value = attributeMap.get(name);
if (value != null) {
String text = value.toString();
if (!Strings.isBlank(text)) {
return text;
}
}
throw new IllegalArgumentException("The attribute value '" + name + "' did not get passed on from the previous wizard page");
}
示例6: loadCamelComponentDetails
import org.jboss.forge.roaster.model.util.Strings; //导入依赖的package包/类
/**
* Populates the details for the given component, returning a Result if it fails.
*/
public static Result loadCamelComponentDetails(CamelCatalog camelCatalog, String camelComponentName, CamelComponentDetails details) {
String json = camelCatalog.componentJSonSchema(camelComponentName);
if (json == null) {
return Results.fail("Could not find catalog entry for component name: " + camelComponentName);
}
List<Map<String, String>> data = JSonSchemaHelper.parseJsonSchema("component", json, false);
for (Map<String, String> row : data) {
String javaType = row.get("javaType");
if (!Strings.isNullOrEmpty(javaType)) {
details.setComponentClassQName(javaType);
}
String groupId = row.get("groupId");
if (!Strings.isNullOrEmpty(groupId)) {
details.setGroupId(groupId);
}
String artifactId = row.get("artifactId");
if (!Strings.isNullOrEmpty(artifactId)) {
details.setArtifactId(artifactId);
}
String version = row.get("version");
if (!Strings.isNullOrEmpty(version)) {
details.setVersion(version);
}
}
if (Strings.isNullOrEmpty(details.getComponentClassQName())) {
return Results.fail("Could not find fully qualified class name in catalog for component name: " + camelComponentName);
}
return null;
}
示例7: createCdiComponentProducerClass
import org.jboss.forge.roaster.model.util.Strings; //导入依赖的package包/类
public static void createCdiComponentProducerClass(JavaClassSource javaClass, CamelComponentDetails details, String camelComponentName,
String componentInstanceName, String configurationCode, Set<String> extraJavaImports) {
javaClass.addImport("javax.enterprise.inject.Produces");
javaClass.addImport("javax.inject.Singleton");
javaClass.addImport("javax.inject.Named");
javaClass.addImport(details.getComponentClassQName());
if (extraJavaImports != null) {
for (String extra : extraJavaImports) {
javaClass.addImport(extra);
}
}
String componentClassName = details.getComponentClassName();
String methodName = "create" + Strings.capitalize(componentInstanceName) + "Component";
String body = componentClassName + " component = new " + componentClassName + "();" + configurationCode + "\nreturn component;";
MethodSource<JavaClassSource> method = javaClass.addMethod()
.setPublic()
.setReturnType(componentClassName)
.setName(methodName)
.setBody(body);
method.addAnnotation("Named").setStringValue(camelComponentName);
method.addAnnotation("Produces");
method.addAnnotation("Singleton");
}
示例8: createSpringComponentFactoryClass
import org.jboss.forge.roaster.model.util.Strings; //导入依赖的package包/类
public static void createSpringComponentFactoryClass(JavaClassSource javaClass, CamelComponentDetails details, String camelComponentName,
String componentInstanceName, String configurationCode, Set<String> extraJavaImports) {
javaClass.addAnnotation("Component");
javaClass.addImport("org.springframework.beans.factory.config.BeanDefinition");
javaClass.addImport("org.springframework.beans.factory.annotation.Qualifier");
javaClass.addImport("org.springframework.context.annotation.Bean");
javaClass.addImport("org.springframework.context.annotation.Scope");
javaClass.addImport("org.springframework.stereotype.Component");
javaClass.addImport(details.getComponentClassQName());
if (extraJavaImports != null) {
for (String extra : extraJavaImports) {
javaClass.addImport(extra);
}
}
String componentClassName = details.getComponentClassName();
String methodName = "create" + Strings.capitalize(componentInstanceName) + "Component";
String body = componentClassName + " component = new " + componentClassName + "();" + configurationCode + "\nreturn component;";
MethodSource<JavaClassSource> method = javaClass.addMethod()
.setPublic()
.setReturnType(componentClassName)
.setName(methodName)
.setBody(body);
method.addAnnotation("Qualifier").setStringValue(camelComponentName);
method.addAnnotation("Bean");
method.addAnnotation("Scope").setLiteralValue("BeanDefinition.SCOPE_SINGLETON");
}
示例9: optionalAttributeValue
import org.jboss.forge.roaster.model.util.Strings; //导入依赖的package包/类
/**
* Returns the optional String value of the given name
*/
public static String optionalAttributeValue(Map<Object, Object> attributeMap, String name) {
Object value = attributeMap.get(name);
if (value != null) {
String text = value.toString();
if (!Strings.isBlank(text)) {
return text;
}
}
return null;
}
示例10: getCDIBeanName
import org.jboss.forge.roaster.model.util.Strings; //导入依赖的package包/类
private String getCDIBeanName(UIContextProvider context, String fqcn) throws FileNotFoundException {
JavaResource javaResource = getJavaResourceFromProject(context, fqcn);
JavaType<?> javaType = javaResource.getJavaType();
Annotation<?> named = javaType.getAnnotation(Named.class);
if (named.getStringValue() != null) {
return named.getStringValue();
}
return Strings.uncapitalize(javaType.getName());
}
示例11: resolveIdGetterName
import org.jboss.forge.roaster.model.util.Strings; //导入依赖的package包/类
public static String resolveIdGetterName(JavaClass<?> entity)
{
String result = null;
for (Member<?> member : entity.getMembers())
{
if (member.hasAnnotation(Id.class))
{
String name = member.getName();
String type = null;
if (member instanceof Method)
{
type = ((Method<?, ?>) member).getReturnType().getQualifiedName();
if (name.startsWith("get"))
{
name = name.substring(3);
}
}
else if (member instanceof Field)
{
type = ((Field<?>) member).getType().getQualifiedName();
}
if (type != null)
{
for (Method<?, ?> method : entity.getMethods())
{
// It's a getter
if (method.getParameters().size() == 0
&& (method.getReturnType() != null
&& type.equals(method.getReturnType().getQualifiedName())))
{
if (method.getName().toLowerCase().contains(name.toLowerCase()))
{
result = method.getName() + "()";
break;
}
}
}
}
if (result != null)
{
break;
}
else if (type != null && member.isPublic())
{
String memberName = member.getName();
// Cheat a little if the member is public
if (member instanceof Method && memberName.startsWith("get"))
{
memberName = memberName.substring(3);
memberName = Strings.uncapitalize(memberName);
}
result = memberName;
}
}
}
if (result == null)
{
throw new RuntimeException("Could not determine @Id field and getter method for @Entity ["
+ entity.getQualifiedName()
+ "]. Aborting.");
}
return result;
}
示例12: getSelectExpression
import org.jboss.forge.roaster.model.util.Strings; //导入依赖的package包/类
public static String getSelectExpression(JavaClass<?> entity, String entityTable)
{
char entityVariable = getJpqlEntityVariable(entityTable);
StringBuilder expressionBuilder = new StringBuilder();
expressionBuilder.append("SELECT DISTINCT ");
expressionBuilder.append(entityVariable);
expressionBuilder.append(" FROM ");
expressionBuilder.append(entityTable);
expressionBuilder.append(" ");
expressionBuilder.append(entityVariable);
for (Member<?> member : entity.getMembers())
{
if (member.hasAnnotation(OneToOne.class) || member.hasAnnotation(OneToMany.class)
|| member.hasAnnotation(ManyToMany.class) || member.hasAnnotation(ManyToOne.class))
{
String name = member.getName();
String associationField = null;
if (member instanceof Method)
{
if (name.startsWith("get"))
{
associationField = Strings.uncapitalize(name.substring(3));
}
}
else if (member instanceof Field)
{
associationField = name;
}
if (associationField == null)
{
throw new RuntimeException("Could not compute the association field for member:" + member.getName()
+ " in entity" + entity.getName());
}
else
{
expressionBuilder.append(" LEFT JOIN FETCH ");
expressionBuilder.append(entityVariable);
expressionBuilder.append('.');
expressionBuilder.append(associationField);
}
}
}
return expressionBuilder.toString();
}
示例13: asJavaClassName
import org.jboss.forge.roaster.model.util.Strings; //导入依赖的package包/类
public static String asJavaClassName(String name) {
name = dashToCamelCase(name);
return Strings.capitalize(name);
}
示例14: createComponentConfigurationSource
import org.jboss.forge.roaster.model.util.Strings; //导入依赖的package包/类
private void createComponentConfigurationSource(String packageName, ComponentModel model) throws MojoFailureException {
final JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
int pos = model.getJavaType().lastIndexOf(".");
String name = model.getJavaType().substring(pos + 1);
name = name.replace("Component", "ComponentConfiguration");
javaClass.setPackage(packageName).setName(name);
String doc = "Generated by camel-package-maven-plugin - do not edit this file!";
if (!Strings.isBlank(model.getDescription())) {
doc = model.getDescription() + "\n\n" + doc;
}
javaClass.getJavaDoc().setFullText(doc);
String prefix = "camel.component." + model.getScheme();
javaClass.addAnnotation("org.springframework.boot.context.properties.ConfigurationProperties").setStringValue("prefix", prefix);
for (ComponentOptionModel option : model.getComponentOptions()) {
// remove <?> as generic type as Roaster (Eclipse JDT) cannot use that
String type = option.getJavaType();
type = type.replaceAll("\\<\\?\\>", "");
// favor using Boolean types over boolean with Spring Boot
if ("boolean".equals(type)) {
type = "java.lang.Boolean";
}
PropertySource<JavaClassSource> prop = javaClass.addProperty(type, option.getName());
if ("true".equals(option.getDeprecated())) {
prop.getField().addAnnotation(Deprecated.class);
}
if (!Strings.isBlank(option.getDescription())) {
prop.getField().getJavaDoc().setFullText(option.getDescription());
}
if (!Strings.isBlank(option.getDefaultValue())) {
if ("java.lang.String".equals(option.getJavaType())) {
prop.getField().setStringInitializer(option.getDefaultValue());
} else if ("integer".equals(option.getType()) || "boolean".equals(option.getType())) {
prop.getField().setLiteralInitializer(option.getDefaultValue());
}
}
}
sortImports(javaClass);
String fileName = packageName.replaceAll("\\.", "\\/") + "/" + name + ".java";
File target = new File(srcDir, fileName);
try {
InputStream is = getClass().getClassLoader().getResourceAsStream("license-header-java.txt");
String header = loadText(is);
String code = sourceToString(javaClass);
code = header + code;
getLog().debug("Source code generated:\n" + code);
if (target.exists()) {
String existing = FileUtils.readFileToString(target);
if (!code.equals(existing)) {
FileUtils.write(target, code, false);
getLog().info("Updated existing file: " + target);
} else {
getLog().debug("No changes to existing file: " + target);
}
} else {
FileUtils.write(target, code);
getLog().info("Created file: " + target);
}
} catch (Exception e) {
throw new MojoFailureException("IOError with file " + target, e);
}
}
示例15: createDataFormatConfigurationSource
import org.jboss.forge.roaster.model.util.Strings; //导入依赖的package包/类
private void createDataFormatConfigurationSource(String packageName, DataFormatModel model) throws MojoFailureException {
final JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
int pos = model.getJavaType().lastIndexOf(".");
String name = model.getJavaType().substring(pos + 1);
name = name.replace("DataFormat", "DataFormatConfiguration");
javaClass.setPackage(packageName).setName(name);
String doc = "Generated by camel-package-maven-plugin - do not edit this file!";
if (!Strings.isBlank(model.getDescription())) {
doc = model.getDescription() + "\n\n" + doc;
}
javaClass.getJavaDoc().setFullText(doc);
String prefix = "camel.dataformat." + model.getModelName();
javaClass.addAnnotation("org.springframework.boot.context.properties.ConfigurationProperties").setStringValue("prefix", prefix);
for (DataFormatOptionModel option : model.getDataFormatOptions()) {
// skip option with name id in data format as we do not need that
if ("id".equals(option.getName())) {
continue;
}
// remove <?> as generic type as Roaster (Eclipse JDT) cannot use that
String type = option.getJavaType();
type = type.replaceAll("\\<\\?\\>", "");
// favor using Boolean types over boolean with Spring Boot
if ("boolean".equals(type)) {
type = "java.lang.Boolean";
}
PropertySource<JavaClassSource> prop = javaClass.addProperty(type, option.getName());
if ("true".equals(option.getDeprecated())) {
prop.getField().addAnnotation(Deprecated.class);
}
if (!Strings.isBlank(option.getDescription())) {
prop.getField().getJavaDoc().setFullText(option.getDescription());
}
if (!Strings.isBlank(option.getDefaultValue())) {
if ("java.lang.String".equals(option.getType())) {
prop.getField().setStringInitializer(option.getDefaultValue());
} else if ("integer".equals(option.getType()) || "boolean".equals(option.getType())) {
prop.getField().setLiteralInitializer(option.getDefaultValue());
}
}
}
sortImports(javaClass);
String fileName = packageName.replaceAll("\\.", "\\/") + "/" + name + ".java";
File target = new File(srcDir, fileName);
try {
InputStream is = getClass().getClassLoader().getResourceAsStream("license-header-java.txt");
String header = loadText(is);
String code = sourceToString(javaClass);
code = header + code;
getLog().debug("Source code generated:\n" + code);
if (target.exists()) {
String existing = FileUtils.readFileToString(target);
if (!code.equals(existing)) {
FileUtils.write(target, code, false);
getLog().info("Updated existing file: " + target);
} else {
getLog().debug("No changes to existing file: " + target);
}
} else {
FileUtils.write(target, code);
getLog().info("Created file: " + target);
}
} catch (Exception e) {
throw new MojoFailureException("IOError with file " + target, e);
}
}