List of usage examples for com.google.common.base CaseFormat UPPER_CAMEL
CaseFormat UPPER_CAMEL
To view the source code for com.google.common.base CaseFormat UPPER_CAMEL.
Click Source Link
From source file:com.geemvc.i18n.message.DefaultCompositeMessageResolver.java
protected String controllerName(RequestContext requestCtx) { Class<?> controllerClass = requestCtx.requestHandler().controllerClass(); String name = controllerClass.getSimpleName(); if (name.endsWith(controllerSuffix)) { name = name.replace(controllerSuffix, Str.EMPTY); } else if (name.endsWith(actionSuffix)) { name = name.replace(actionSuffix, Str.EMPTY); }/* w ww. j a v a 2 s.c o m*/ return CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, name); }
From source file:com.phoenixnap.oss.ramlapisync.generation.rules.spring.SpringRestClientMethodBodyRule.java
@Override public JMethod apply(ApiMappingMetadata endpointMetadata, CodeModelHelper.JExtMethod generatableType) { JBlock body = generatableType.get().body(); JCodeModel owner = generatableType.owner(); //build HttpHeaders JClass httpHeadersClass = owner.ref(HttpHeaders.class); JExpression headersInit = JExpr._new(httpHeadersClass); JVar httpHeaders = body.decl(httpHeadersClass, "httpHeaders", headersInit); //Declare Arraylist to contain the acceptable Media Types body.directStatement("// Add Accepts Headers and Body Content-Type"); JClass mediaTypeClass = owner.ref(MediaType.class); JClass refArrayListClass = owner.ref(ArrayList.class).narrow(mediaTypeClass); JVar acceptsListVar = body.decl(refArrayListClass, "acceptsList", JExpr._new(refArrayListClass)); //If we have a request body, lets set the content type of our request if (endpointMetadata.getRequestBody() != null) { body.invoke(httpHeaders, "setContentType") .arg(mediaTypeClass.staticInvoke("valueOf").arg(endpointMetadata.getRequestBodyMime())); }//from w w w . j a v a2 s . co m //If we have response bodies defined, we need to add them to our accepts headers list //TODO possibly restrict String documentDefaultType = endpointMetadata.getParent().getDocument().getMediaType(); //If a global mediatype is defined add it if (StringUtils.hasText(documentDefaultType)) { body.invoke(acceptsListVar, "add").arg(mediaTypeClass.staticInvoke("valueOf").arg(documentDefaultType)); } else { //default to application/json just in case body.invoke(acceptsListVar, "add").arg(mediaTypeClass.staticInvoke("valueOf").arg("application/json")); } //Iterate over Response Bodies and add each distinct mime type to accepts headers if (endpointMetadata.getResponseBody() != null && !endpointMetadata.getResponseBody().isEmpty()) { for (String responseMime : endpointMetadata.getResponseBody().keySet()) { if (!responseMime.equals(documentDefaultType) && !responseMime.equals("application/json")) { body.invoke(acceptsListVar, "add") .arg(mediaTypeClass.staticInvoke("valueOf").arg(responseMime)); } } } //Set accepts list as our accepts headers for the call body.invoke(httpHeaders, "setAccept").arg(acceptsListVar); //Get the parameters from the model and put them in a map for easy lookup List<JVar> params = generatableType.get().params(); Map<String, JVar> methodParamMap = new LinkedHashMap<>(); for (JVar param : params) { methodParamMap.put(param.name(), param); } //Build the Http Entity object JClass httpEntityClass = owner.ref(HttpEntity.class); JInvocation init = JExpr._new(httpEntityClass); if (endpointMetadata.getRequestBody() != null) { init.arg(methodParamMap.get(CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, endpointMetadata.getRequestBody().getName()))); } init.arg(httpHeaders); //Build the URL variable JExpression urlRef = JExpr.ref(baseUrlFieldName); JType urlClass = owner._ref(String.class); JExpression targetUrl = urlRef.invoke("concat").arg(endpointMetadata.getResource().getUri()); JVar url = body.decl(urlClass, "url", targetUrl); JVar uriBuilderVar = null; JVar uriComponentVar = null; //Initialise the UriComponentsBuilder JClass builderClass = owner.ref(UriComponentsBuilder.class); JExpression builderInit = builderClass.staticInvoke("fromHttpUrl").arg(url); //If we have any Query Parameters, we will use the URIBuilder to encode them in the URL if (!CollectionUtils.isEmpty(endpointMetadata.getRequestParameters())) { //iterate over the parameters and add calls to .queryParam for (ApiParameterMetadata parameter : endpointMetadata.getRequestParameters()) { builderInit = builderInit.invoke("queryParam").arg(parameter.getName()) .arg(methodParamMap.get(parameter.getName())); } } //Add these to the code model uriBuilderVar = body.decl(builderClass, "builder", builderInit); JClass componentClass = owner.ref(UriComponents.class); JExpression component = uriBuilderVar.invoke("build"); uriComponentVar = body.decl(componentClass, "uriComponents", component); //build request entity holder JVar httpEntityVar = body.decl(httpEntityClass, "httpEntity", init); //construct the HTTP Method enum JClass httpMethod = null; try { httpMethod = (JClass) owner._ref(HttpMethod.class); } catch (ClassCastException e) { } //get all uri params from metadata set and add them to the param map in code if (!CollectionUtils.isEmpty(endpointMetadata.getPathVariables())) { //Create Map with Uri Path Variables JClass uriParamMap = owner.ref(Map.class).narrow(String.class, Object.class); JExpression uriParamMapInit = JExpr._new(owner.ref(HashMap.class)); JVar uriParamMapVar = body.decl(uriParamMap, "uriParamMap", uriParamMapInit); endpointMetadata.getPathVariables().forEach( p -> body.invoke(uriParamMapVar, "put").arg(p.getName()).arg(methodParamMap.get(p.getName()))); JInvocation expandInvocation = uriComponentVar.invoke("expand").arg(uriParamMapVar); body.assign(uriComponentVar, expandInvocation); } //Determining response entity type JClass returnType = null; if (!endpointMetadata.getResponseBody().isEmpty()) { ApiBodyMetadata apiBodyMetadata = endpointMetadata.getResponseBody().values().iterator().next(); JClass genericType = findFirstClassBySimpleName(apiBodyMetadata.getCodeModel(), apiBodyMetadata.getName()); if (apiBodyMetadata.isArray()) { JClass arrayType = owner.ref(List.class); returnType = arrayType.narrow(genericType); } else { returnType = genericType; } } else { returnType = owner.ref(Object.class); } JExpression returnExpression = JExpr.dotclass(returnType);//assume not parameterized by default //check if return is parameterized if (!CollectionUtils.isEmpty(returnType.getTypeParameters())) { //if yes - build the parameterized type reference and change returnExpression //ParameterizedTypeReference<List<String>> typeRef = new ParameterizedTypeReference<List<String>>() {}; //Create Map with Uri Path Variables JClass paramTypeRefClass = owner.ref(ParameterizedTypeReference.class); paramTypeRefClass = paramTypeRefClass.narrow(returnType); JExpression paramTypeRefInit = JExpr._new(owner.anonymousClass(paramTypeRefClass)); returnExpression = body.decl(paramTypeRefClass, "typeReference", paramTypeRefInit); } //build rest template exchange invocation JInvocation jInvocation = JExpr._this().ref(restTemplateFieldName).invoke("exchange"); jInvocation.arg(uriComponentVar.invoke("encode").invoke("toUri")); jInvocation.arg(httpMethod.staticRef(endpointMetadata.getActionType().name())); jInvocation.arg(httpEntityVar); jInvocation.arg(returnExpression); body._return(jInvocation); return generatableType.get(); }
From source file:com.github.jcustenborder.kafka.connect.utils.templates.model.Example.java
private ObjectNode connectorJson() { ObjectNode node = ObjectMapperFactory.INSTANCE.createObjectNode(); String connectorName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, this.className.getSimpleName()) + "1"; node.put("name", connectorName); ObjectNode config = ObjectMapperFactory.INSTANCE.createObjectNode(); node.set("config", config); config.put("connector.class", this.className.getName()); config.put("tasks.max", "1"); if (SinkConnector.class.isAssignableFrom(this.className)) { config.put("topics", "topic1,topic2,topic3"); }//from w w w .ja v a 2s .c o m for (Map.Entry<String, String> kvp : this.config.entrySet()) { config.put(kvp.getKey(), kvp.getValue()); } if (null != this.transformations && !transformations.isEmpty()) { Set<String> transformKeys = this.transformations.keySet(); config.put("transforms", Joiner.on(',').join(transformKeys)); for (String transformKey : transformKeys) { Map<String, String> transformSettings = this.transformations.get(transformKey); for (Map.Entry<String, String> kvp : transformSettings.entrySet()) { final String key = String.format("transforms.%s.%s", transformKey, kvp.getKey()); config.put(key, kvp.getValue()); } } } return node; }
From source file:com.tactfactory.harmony.generator.BundleGenerator.java
/** * Generate Bundle metadata.// w ww . j a va 2 s . com * @param bundleOwnerName Owner name * @param bundleName Bundle name * @param bundleNameSpace Bundle namespace */ private void generateMeta(final String bundleOwnerName, final String bundleName, final String bundleNameSpace) { final String tplPath = this.getAdapter().getMetaBundleTemplatePath() + "/TemplateMetadata.java"; final String genPath = this.getAdapter().getMetaBundlePath(bundleOwnerName, bundleNameSpace, bundleName) + "/" + CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, bundleName) + "Metadata.java"; this.makeSource(tplPath, genPath, false); }
From source file:datamine.storage.idl.generator.java.InterfaceGenerator.java
public static String getGetterName(Field field) { FieldType type = field.getType();//from w w w. j a va 2 s . c o m if (type instanceof PrimitiveFieldType && ((PrimitiveFieldType) type).getPrimitiveType() == PrimitiveType.BOOL) { return new StringBuilder().append("is") .append(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, field.getName())).toString(); } return new StringBuilder().append("get") .append(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, field.getName())).toString(); }
From source file:com.tactfactory.harmony.platform.winphone.WinphoneProjectAdapter.java
@Override public List<IUpdater> getDatabaseFiles() { List<IUpdater> result = new ArrayList<IUpdater>(); String applicationName = CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, this.adapter.getApplicationMetadata().getName()); String templatePath = this.adapter.getTemplateSourceDataPath(); String filePath = this.adapter.getSourcePath() + this.adapter.getData() + "/"; result.add(new SourceFile(templatePath + "Base/ApplicationSqlAdapterBase.cs", String.format("%sBase/SqlAdapterBase.cs", filePath), true)); result.add(new ProjectUpdater(FileType.Compile, "Data/" + "Base/SqlAdapterBase.cs")); result.add(new SourceFile(templatePath + "Base/ApplicationSqlOpenHelperBase.cs", String.format("%sBase/%sSqlOpenHelperBase.cs", filePath, applicationName), true)); result.add(new ProjectUpdater(FileType.Compile, "Data/" + String.format("Base/%sSqlOpenHelperBase.cs", applicationName))); result.add(new SourceFile(templatePath + "ApplicationSqlAdapter.cs", String.format("%sSqlAdapter.cs", filePath), false)); result.add(new ProjectUpdater(FileType.Compile, "Data/" + "SqlAdapter.cs")); result.add(new SourceFile(templatePath + "ApplicationSqlOpenHelper.cs", String.format("%s%sSqlOpenHelper.cs", filePath, applicationName), false)); result.add(new ProjectUpdater(FileType.Compile, "Data/" + String.format("%sSqlOpenHelper.cs", applicationName))); return result; }
From source file:com.github.jcustenborder.kafka.connect.utils.config.MarkdownFormatter.java
static String schema(Schema schema) { String result;//ww w. j ava2 s.co m if (!Strings.isNullOrEmpty(schema.name())) { if (Time.LOGICAL_NAME.equals(schema.name())) { result = "[Time](https://kafka.apache.org/0102/javadoc/org/apache/kafka/connect/data/Time.html)"; } else if (Date.LOGICAL_NAME.equals(schema.name())) { result = "[Date](https://kafka.apache.org/0102/javadoc/org/apache/kafka/connect/data/Date.html)"; } else if (Timestamp.LOGICAL_NAME.equals(schema.name())) { result = "[Timestamp](https://kafka.apache.org/0102/javadoc/org/apache/kafka/connect/data/Timestamp.html)"; } else if (Decimal.LOGICAL_NAME.equals(schema.name())) { result = "[Decimal](https://kafka.apache.org/0102/javadoc/org/apache/kafka/connect/data/Decimal.html)"; } else { result = String.format("[%s](#%s)", schema.name(), schema.name()); } } else { if (Schema.Type.ARRAY == schema.type()) { result = String.format("Array of %s", schema(schema.valueSchema())); } else if (Schema.Type.MAP == schema.type()) { result = String.format("Map of <%s, %s>", schema(schema.keySchema()), schema(schema.valueSchema())); } else { result = String.format( "[%s](https://kafka.apache.org/0102/javadoc/org/apache/kafka/connect/data/Schema.Type.html#%s)", CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, schema.type().toString()), schema.type()); } } return result; }
From source file:datamine.storage.idl.generator.java.InterfaceGenerator.java
public static String getSetterName(Field field) { return new StringBuilder().append("set") .append(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, field.getName())).toString(); }
From source file:org.eclipse.che.api.factory.FactoryBuilder.java
/** * Validate compatibility of factory parameters. * * @param object//from www.ja v a2s. com * - object to validate factory parameters * @param methodsProvider * - class that provides methods with {@link org.eclipse.che.api.core.factory.FactoryParameter} * annotations * @param allowedMethodsProvider * - class that provides allowed methods * @param version * - version of factory * @param parentName * - parent parameter queryParameterName * @throws org.eclipse.che.api.core.ApiException */ void validateCompatibility(Object object, Class methodsProvider, Class allowedMethodsProvider, Version version, String parentName) throws ApiException { // get all methods recursively for (Method method : methodsProvider.getMethods()) { FactoryParameter factoryParameter = method.getAnnotation(FactoryParameter.class); // is it factory parameter if (factoryParameter != null) { String fullName = (parentName.isEmpty() ? "" : (parentName + ".")) + CaseFormat.UPPER_CAMEL .to(CaseFormat.LOWER_CAMEL, method.getName().substring(3).toLowerCase()); // check that field is set Object parameterValue; try { parameterValue = method.invoke(object); } catch (IllegalAccessException | InvocationTargetException | IllegalArgumentException e) { // should never happen LOG.error(e.getLocalizedMessage(), e); throw new ConflictException(FactoryConstants.INVALID_PARAMETER_MESSAGE); } // if value is null or empty collection or default value for primitives if (ValueHelper.isEmpty(parameterValue)) { // field must not be a mandatory, unless it's ignored or deprecated or doesn't suit to the version if (Obligation.MANDATORY.equals(factoryParameter.obligation()) && factoryParameter.deprecatedSince().compareTo(version) > 0 && factoryParameter.ignoredSince().compareTo(version) > 0 && method.getDeclaringClass().isAssignableFrom(allowedMethodsProvider)) { throw new ConflictException(FactoryConstants.MISSING_MANDATORY_MESSAGE); } } else if (!method.getDeclaringClass().isAssignableFrom(allowedMethodsProvider)) { throw new ConflictException(String .format(FactoryConstants.PARAMETRIZED_INVALID_PARAMETER_MESSAGE, fullName, version)); } else { // is parameter deprecated if (factoryParameter.deprecatedSince().compareTo(version) <= 0) { throw new ConflictException(String.format( FactoryConstants.PARAMETRIZED_INVALID_PARAMETER_MESSAGE, fullName, version)); } if (factoryParameter.setByServer()) { throw new ConflictException(String.format( FactoryConstants.PARAMETRIZED_INVALID_PARAMETER_MESSAGE, fullName, version)); } // use recursion if parameter is DTO object if (method.getReturnType().isAnnotationPresent(DTO.class)) { // validate inner objects such Git ot ProjectAttributes validateCompatibility(parameterValue, method.getReturnType(), method.getReturnType(), version, fullName); } else if (Map.class.isAssignableFrom(method.getReturnType())) { Type tp = ((ParameterizedType) method.getGenericReturnType()).getActualTypeArguments()[1]; Class secMapParamClass; if (tp instanceof ParameterizedType) { secMapParamClass = (Class) ((ParameterizedType) tp).getRawType(); } else { secMapParamClass = (Class) tp; } if (String.class.equals(secMapParamClass)) { if (ImportSourceDescriptor.class.equals(methodsProvider)) { sourceProjectParametersValidator.validate((ImportSourceDescriptor) object, version); } } else if (List.class.equals(secMapParamClass)) { // do nothing } else { if (secMapParamClass.isAnnotationPresent(DTO.class)) { Map<Object, Object> map = (Map) parameterValue; for (Map.Entry<Object, Object> entry : map.entrySet()) { validateCompatibility(entry.getValue(), secMapParamClass, secMapParamClass, version, fullName + "." + entry.getKey()); } } else { throw new RuntimeException("This type of fields is not supported by factory."); } } } } } } }
From source file:com.eucalyptus.reporting.units.Units.java
private String capitalize(final Object item) { return CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, item.toString()); }