Java Code Examples for org.apache.cxf.common.util.StringUtils#capitalize()

The following examples show how to use org.apache.cxf.common.util.StringUtils#capitalize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResponseWrapper.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Override
public WrapperBeanClass getWrapperBeanClass(final Method method) {
    javax.xml.ws.ResponseWrapper resWrapper = method.getAnnotation(javax.xml.ws.ResponseWrapper.class);
    javax.jws.WebMethod webMethod = method.getAnnotation(javax.jws.WebMethod.class);
    String methName = webMethod == null ? null : webMethod.operationName();
    if (StringUtils.isEmpty(methName)) {
        methName = method.getName();
    }
    String resClassName = getClassName();
    String resNs = null;

    if (resWrapper != null) {
        resClassName = resWrapper.className().length() > 0 ? resWrapper.className() : resClassName;
        resNs = resWrapper.targetNamespace().length() > 0 ? resWrapper.targetNamespace() : null;
    }
    if (resClassName == null) {
        resClassName = getPackageName(method) + ".jaxws."
            + StringUtils.capitalize(methName)
            + "Response";
    }

    WrapperBeanClass jClass = new WrapperBeanClass();
    jClass.setFullClassName(resClassName);
    jClass.setNamespace(resNs);
    return jClass;
}
 
Example 2
Source File: RequestWrapper.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Override
public WrapperBeanClass getWrapperBeanClass(final Method method) {
    javax.xml.ws.RequestWrapper reqWrapper = method.getAnnotation(javax.xml.ws.RequestWrapper.class);
    javax.jws.WebMethod webMethod = method.getAnnotation(javax.jws.WebMethod.class);
    String methName = webMethod == null ? null : webMethod.operationName();
    if (StringUtils.isEmpty(methName)) {
        methName = method.getName();
    }
    String reqClassName = getClassName();
    String reqNs = null;

    if (reqWrapper != null) {
        reqClassName = reqWrapper.className().length() > 0 ? reqWrapper.className() : reqClassName;
        reqNs = reqWrapper.targetNamespace().length() > 0 ? reqWrapper.targetNamespace() : null;
    }
    if (reqClassName == null) {
        reqClassName = getPackageName(method) + ".jaxws." + StringUtils.capitalize(methName);
    }

    WrapperBeanClass jClass = new WrapperBeanClass();
    jClass.setFullClassName(reqClassName);
    jClass.setNamespace(reqNs);
    return jClass;
}
 
Example 3
Source File: NameUtil.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected static String toMixedCaseVariableName(String[] ss,
                                         boolean startUpper,
                                         boolean cdrUpper) {
    if (cdrUpper) {
        for (int i = 1; i < ss.length; i++) {
            ss[i] = StringUtils.capitalize(ss[i]);
        }
    }
    StringBuilder sb = new StringBuilder();
    if (ss.length > 0) {
        sb.append(startUpper ? ss[0] : ss[0].toLowerCase());
        for (int i = 1; i < ss.length; i++) {
            sb.append(ss[i]);
        }
    }
    return sb.toString();
}
 
Example 4
Source File: JavaClass.java    From cxf with Apache License 2.0 6 votes vote down vote up
public JavaMethod appendGetter(JavaField field) {
    String getterName = "get" + StringUtils.capitalize(field.getName());
    JavaMethod jMethod = new JavaMethod(this);
    jMethod.setName(getterName);
    jMethod.setReturn(new JavaReturn(field.getParaName(),
                                     field.getType(),
                                     field.getTargetNamespace()));

    JavaCodeBlock block = new JavaCodeBlock();
    JavaExpression exp = new JavaExpression();
    exp.setValue("return this." + field.getParaName());
    block.getExpressions().add(exp);

    jMethod.setJavaCodeBlock(block);

    addMethod(jMethod);
    return jMethod;
}
 
Example 5
Source File: JavaClass.java    From cxf with Apache License 2.0 6 votes vote down vote up
public JavaMethod appendSetter(JavaField field) {
    String setterName = "set" + StringUtils.capitalize(field.getName());
    JavaMethod jMethod = new JavaMethod(this);
    jMethod.setReturn(new JavaReturn("return", "void", null));
    String paramName = getSetterParamName(field.getParaName());
    jMethod.addParameter(new JavaParameter(paramName,
                                           field.getType(),
                                           field.getTargetNamespace()));
    JavaCodeBlock block = new JavaCodeBlock();
    JavaExpression exp = new JavaExpression();
    exp.setValue("this." + field.getParaName() + " = " + paramName);
    block.getExpressions().add(exp);

    jMethod.setJavaCodeBlock(block);

    jMethod.setName(setterName);
    addMethod(jMethod);
    return jMethod;
}
 
Example 6
Source File: SourceGenerator.java    From cxf with Apache License 2.0 6 votes vote down vote up
private String getClassName(String clsName, boolean interfaceIsGenerated, Set<String> typeClassNames) {
    String name = null;
    if (interfaceIsGenerated) {
        name = clsName;
    } else {
        name = generateInterfaces ? clsName + "Impl" : clsName;
    }
    name = StringUtils.capitalize(name);
    for (String typeName : typeClassNames) {
        String localName = typeName.substring(typeName.lastIndexOf('.') + 1);
        if (name.equalsIgnoreCase(localName)) {
            name += "Resource";
        }
    }
    return name;
}
 
Example 7
Source File: PrimitiveSearchCondition.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected static Object getPrimitiveValue(String name, Object value) {

        int index = name.indexOf('.');
        if (index != -1) {
            String[] names = name.split("\\.");
            name = name.substring(index + 1);
            if (value != null && !InjectionUtils.isPrimitive(value.getClass())) {
                try {
                    String nextPart = StringUtils.capitalize(names[1]);
                    Method m = value.getClass().getMethod("get" + nextPart, new Class[]{});
                    value = m.invoke(value, new Object[]{});
                } catch (Throwable ex) {
                    throw new RuntimeException();
                }
            }
            return getPrimitiveValue(name, value);
        }
        return value;

    }
 
Example 8
Source File: BeanType.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * This is a hack to get the write method from the implementation class for an interface.
 */
private Method getWriteMethodFromImplClass(Class<?> impl, PropertyDescriptor pd) throws Exception {
    String name = pd.getName();
    name = "set" + StringUtils.capitalize(name);

    return impl.getMethod(name, new Class[] {
        pd.getPropertyType()
    });
}
 
Example 9
Source File: AbstractTypeCreator.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected QName createCollectionQName(TypeClassInfo info, AegisType type) {
    String ns;

    if (type.isComplex()) {
        ns = type.getSchemaType().getNamespaceURI();
    } else {
        ns = tm.getMappingIdentifierURI();
    }
    if (WSDLConstants.NS_SCHEMA_XSD.equals(ns)) {
        ns = HTTP_CXF_APACHE_ORG_ARRAYS;
    }

    String localName = "ArrayOf" + StringUtils.capitalize(type.getSchemaType().getLocalPart());
    if (info.nonDefaultAttributes()) {
        localName += "-";
        if (info.getMinOccurs() >= 0) {
            localName += info.getMinOccurs();
        }
        localName += "-";
        if (info.getMaxOccurs() >= 0) {
            localName += info.getMaxOccurs();
        }
        if (info.isFlat()) {
            localName += "Flat";
        }
    }

    return new QName(ns, localName);
}
 
Example 10
Source File: ResourceInjector.java    From cxf with Apache License 2.0 4 votes vote down vote up
private static String resourceNameToSetter(String resName) {
    return "set" + StringUtils.capitalize(resName);
}
 
Example 11
Source File: JMSEndpoint.java    From cxf with Apache License 2.0 4 votes vote down vote up
private static String getPropSetterName(String name) {
    return "set" + StringUtils.capitalize(name);
}
 
Example 12
Source File: AbstractSearchConditionVisitor.java    From cxf with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("rawtypes")
private ClassValue doGetPrimitiveFieldClass(PrimitiveStatement ps,
                                            String name, Class<?> valueCls, Type type, Object value,
                                            Set<String> set) {
    boolean isCollection = InjectionUtils.isSupportedCollectionOrArray(valueCls);
    Class<?> actualCls = isCollection ? InjectionUtils.getActualType(type) : valueCls;
    CollectionCheckInfo collInfo = null;
    int index = name.indexOf('.');
    if (index != -1) {
        String[] names = name.split("\\.");
        name = name.substring(index + 1);
        if (value != null && !InjectionUtils.isPrimitive(actualCls)) {
            try {
                String nextPart = StringUtils.capitalize(names[1]);

                Method m = actualCls.getMethod("get" + nextPart, new Class[]{});
                if (isCollection) {
                    value = ((Collection)value).iterator().next();
                    set.add(names[0]);
                }
                value = m.invoke(value, new Object[]{});
                valueCls = value.getClass();
                type = m.getGenericReturnType();
            } catch (Throwable ex) {
                throw new RuntimeException(ex);
            }
            return doGetPrimitiveFieldClass(ps, name, valueCls, type, value, set);
        }
    } else if (isCollection) {
        set.add(name);
        Collection coll = (Collection)value;
        value = coll.isEmpty() ? null : coll.iterator().next();
        valueCls = actualCls;
        if (ps instanceof CollectionCheckStatement) {
            collInfo = ((CollectionCheckStatement)ps).getCollectionCheckInfo();
        }
    }

    Class<?> cls = null;
    if (primitiveFieldTypeMap != null) {
        cls = primitiveFieldTypeMap.get(name);
    }
    if (cls == null) {
        cls = valueCls;
    }
    return new ClassValue(cls, value, collInfo, set);
}
 
Example 13
Source File: AbstractSearchConditionParser.java    From cxf with Apache License 2.0 4 votes vote down vote up
private static String getMethodNameSuffix(String name) {
    return StringUtils.capitalize(name);
}
 
Example 14
Source File: SchemaJavascriptBuilder.java    From cxf with Apache License 2.0 4 votes vote down vote up
private void deserializeElement(XmlSchemaComplexType type, ParticleInfo itemInfo) {
    if (itemInfo.isGroup()) {
        for (ParticleInfo childElement : itemInfo.getChildren()) {
            deserializeElement(type, childElement);
        }
        return;
    }

    XmlSchemaType itemType = itemInfo.getType();
    boolean simple = itemType instanceof XmlSchemaSimpleType
                     || JavascriptUtils.notVeryComplexType(itemType);
    boolean mtomCandidate = JavascriptUtils.mtomCandidateType(itemType);
    String accessorName = "set" + StringUtils.capitalize(itemInfo.getJavascriptName());
    utils.appendLine("cxfjsutils.trace('processing " + itemInfo.getJavascriptName() + "');");
    XmlSchemaElement element = (XmlSchemaElement)itemInfo.getParticle();
    QName elementQName = XmlSchemaUtils.getElementQualifiedName(element, xmlSchema);
    String elementNamespaceURI = elementQName.getNamespaceURI();
    boolean elementNoNamespace = "".equals(elementNamespaceURI);
    XmlSchema elementSchema = null;
    if (!elementNoNamespace) {
        elementSchema = xmlSchemaCollection.getSchemaByTargetNamespace(elementNamespaceURI);
    }
    boolean qualified = !elementNoNamespace
                        && XmlSchemaUtils.isElementQualified(element, itemInfo.isGlobal(), xmlSchema,
                                                             elementSchema);

    if (!qualified) {
        elementNamespaceURI = "";
    }

    String localName = elementQName.getLocalPart();
    String valueTarget = "item";

    if (itemInfo.isOptional() || itemInfo.isArray()) {
        utils.startIf("curElement != null && cxfjsutils.isNodeNamedNS(curElement, '"
                      + elementNamespaceURI + "', '" + localName + "')");
        if (itemInfo.isArray()) {
            utils.appendLine("item = [];");
            utils.startDo();
            valueTarget = "arrayItem";
            utils.appendLine("var arrayItem = null;");
        }
    }

    utils.appendLine("var value = null;");
    utils.startIf("!cxfjsutils.isElementNil(curElement)");
    if (itemInfo.isAnyType()) {
        // use our utility
        utils.appendLine(valueTarget + " = org_apache_cxf_deserialize_anyType(cxfjsutils, curElement);");
    } else if (simple) {
        if (mtomCandidate) {
            utils.appendLine(valueTarget + " = cxfjsutils.deserializeBase64orMom(curElement);");
        } else {
            utils.appendLine("value = cxfjsutils.getNodeText(curElement);");
            utils.appendLine(valueTarget + " = " + utils.javascriptParseExpression(itemType, "value")
                             + ";");
        }
    } else {
        XmlSchemaComplexType complexType = (XmlSchemaComplexType)itemType;
        QName baseQName = complexType.getQName();
        if (baseQName == null) {
            baseQName = element.getQName();
        }

        String elTypeJsName = nameManager.getJavascriptName(baseQName);
        utils.appendLine(valueTarget + " = " + elTypeJsName + "_deserialize(cxfjsutils, curElement);");
    }

    utils.endBlock(); // the if for the nil.
    if (itemInfo.isArray()) {
        utils.appendLine("item.push(arrayItem);");
        utils.appendLine("curElement = cxfjsutils.getNextElementSibling(curElement);");
        utils.endBlock();
        utils.appendLine("  while(curElement != null && cxfjsutils.isNodeNamedNS(curElement, '"
                         + elementNamespaceURI + "', '" + localName + "'));");
    }
    utils.appendLine("newobject." + accessorName + "(item);");
    utils.appendLine("var item = null;");
    if (!itemInfo.isArray()) {
        utils.startIf("curElement != null");
        utils.appendLine("curElement = cxfjsutils.getNextElementSibling(curElement);");
        utils.endBlock();
    }
    if (itemInfo.isOptional() || itemInfo.isArray()) {
        utils.endBlock();
    }
}
 
Example 15
Source File: SchemaJavascriptBuilder.java    From cxf with Apache License 2.0 4 votes vote down vote up
private void constructOneItem(XmlSchemaComplexType type, final String elementPrefix,
                              String typeObjectName, ItemInfo itemInfo) {

    String accessorSuffix = StringUtils.capitalize(itemInfo.getJavascriptName());

    String accessorName = typeObjectName + "_get" + accessorSuffix;
    String getFunctionProperty = typeObjectName + ".prototype.get" + accessorSuffix;
    String setFunctionProperty = typeObjectName + ".prototype.set" + accessorSuffix;
    accessors.append("//\n");
    accessors.append("// accessor is " + getFunctionProperty + "\n");
    accessors.append("// element get for " + itemInfo.getJavascriptName() + "\n");
    if (itemInfo.isAny()) {
        accessors.append("// - xs:any\n");
    } else {
        if (itemInfo.getType() != null) {
            accessors.append("// - element type is " + itemInfo.getType().getQName() + "\n");
        }
    }

    if (itemInfo.isOptional()) {
        accessors.append("// - optional element\n");
    } else {
        accessors.append("// - required element\n");

    }

    if (itemInfo.isArray()) {
        accessors.append("// - array\n");

    }

    if (itemInfo.isNillable()) {
        accessors.append("// - nillable\n");
    }

    accessors.append("//\n");
    accessors.append("// element set for " + itemInfo.getJavascriptName() + "\n");
    accessors.append("// setter function is is " + setFunctionProperty + "\n");
    accessors.append("//\n");
    accessors.append("function " + accessorName + "() { return this._" + itemInfo.getJavascriptName()
                     + ";}\n\n");
    accessors.append(getFunctionProperty + " = " + accessorName + ";\n\n");
    accessorName = typeObjectName + "_set" + accessorSuffix;
    accessors.append("function " + accessorName + "(value) { this._" + itemInfo.getJavascriptName()
                     + " = value;}\n\n");
    accessors.append(setFunctionProperty + " = " + accessorName + ";\n");

    if (itemInfo.isOptional() || (itemInfo.isNillable() && !itemInfo.isArray())) {
        utils.appendLine("this._" + itemInfo.getJavascriptName() + " = null;");
    } else if (itemInfo.isArray()) {
        utils.appendLine("this._" + itemInfo.getJavascriptName() + " = [];");
    } else if (itemInfo.isAny() || itemInfo.getType() instanceof XmlSchemaComplexType) {
        // even for required complex elements, we leave them null.
        // otherwise, we could end up in a cycle or otherwise miserable. The
        // application code is responsible for this.
        utils.appendLine("this._" + itemInfo.getJavascriptName() + " = null;");
    } else {

        if (itemInfo.getDefaultValue() == null) {
            itemInfo.setDefaultValue(utils.getDefaultValueForSimpleType(itemInfo.getType()));
        }
        utils.appendLine("this._" + itemInfo.getJavascriptName() + " = " + itemInfo.getDefaultValue()
                         + ";");
    }
}
 
Example 16
Source File: JaxWsServiceConfiguration.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Override
public Class<?> getRequestWrapper(Method selected) {
    if (this.requestMethodClassNotFoundCache.contains(selected)) {
        return null;
    }
    Class<?> cachedClass = requestMethodClassCache.get(selected);
    if (cachedClass != null) {
        return cachedClass;
    }

    Method m = getDeclaredMethod(selected);

    RequestWrapper rw = m.getAnnotation(RequestWrapper.class);
    String clsName = "";
    if (rw == null) {
        clsName = getPackageName(selected) + ".jaxws." + StringUtils.capitalize(selected.getName());
    } else {
        clsName = rw.className();
    }

    if (clsName.length() > 0) {
        cachedClass = requestMethodClassCache.get(clsName);
        if (cachedClass != null) {
            requestMethodClassCache.put(selected, cachedClass);
            return cachedClass;
        }
        try {
            Class<?> r = ClassLoaderUtils.loadClass(clsName, implInfo.getEndpointClass());
            requestMethodClassCache.put(clsName, r);
            requestMethodClassCache.put(selected, r);
            if (m.getParameterTypes().length == 1 && r.equals(m.getParameterTypes()[0])) {
                LOG.log(Level.WARNING, "INVALID_REQUEST_WRAPPER", new Object[] {clsName,
                        m.getParameterTypes()[0].getName()});
            }
            return r;
        } catch (ClassNotFoundException e) {
            //do nothing, we will mock a schema for wrapper bean later on
        }
    }
    requestMethodClassNotFoundCache.add(selected);
    return null;
}
 
Example 17
Source File: JaxWsServiceConfiguration.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Override
public Class<?> getResponseWrapper(Method selected) {
    if (this.responseMethodClassNotFoundCache.contains(selected)) {
        return null;
    }
    Class<?> cachedClass = responseMethodClassCache.get(selected);
    if (cachedClass != null) {
        return cachedClass;
    }

    Method m = getDeclaredMethod(selected);

    ResponseWrapper rw = m.getAnnotation(ResponseWrapper.class);
    String clsName = "";
    if (rw == null) {
        clsName = getPackageName(selected) + ".jaxws." + StringUtils.capitalize(selected.getName())
                  + "Response";
    } else {
        clsName = rw.className();
    }

    if (clsName.length() > 0) {
        cachedClass = responseMethodClassCache.get(clsName);
        if (cachedClass != null) {
            responseMethodClassCache.put(selected, cachedClass);
            return cachedClass;
        }
        try {
            Class<?> r = ClassLoaderUtils.loadClass(clsName, implInfo.getEndpointClass());
            responseMethodClassCache.put(clsName, r);
            responseMethodClassCache.put(selected, r);

            if (r.equals(m.getReturnType())) {
                LOG.log(Level.WARNING, "INVALID_RESPONSE_WRAPPER", new Object[] {clsName,
                        m.getReturnType().getName()});
            }

            return r;
        } catch (ClassNotFoundException e) {
            //do nothing, we will mock a schema for wrapper bean later on
        }
    }
    responseMethodClassNotFoundCache.add(selected);
    return null;
}
 
Example 18
Source File: WrapperClassGenerator.java    From cxf with Apache License 2.0 4 votes vote down vote up
private void createWrapperClass(MessagePartInfo wrapperPart,
                                    MessageInfo messageInfo,
                                    OperationInfo op,
                                    Method method,
                                    boolean isRequest) {


    ClassWriter cw = createClassWriter();
    if (cw == null) {
        LOG.warning(op.getName() + " requires a wrapper bean but problems with"
            + " ASM has prevented creating one. Operation may not work correctly.");
        return;
    }
    QName wrapperElement = messageInfo.getName();
    boolean anonymous = factory.getAnonymousWrapperTypes();

    String pkg = getPackageName(method) + ".jaxws_asm" + (anonymous ? "_an" : "");
    String className = pkg + "."
        + StringUtils.capitalize(op.getName().getLocalPart());
    if (!isRequest) {
        className = className + "Response";
    }
    String pname = pkg + ".package-info";
    Class<?> def = findClass(pname, method.getDeclaringClass());
    if (def == null) {
        generatePackageInfo(pname, wrapperElement.getNamespaceURI(),
                            method.getDeclaringClass());
    }

    def = findClass(className, method.getDeclaringClass());
    String origClassName = className;
    int count = 0;
    while (def != null) {
        Boolean b = messageInfo.getProperty("parameterized", Boolean.class);
        if (b != null && b) {
            className = origClassName + (++count);
            def = findClass(className, method.getDeclaringClass());
        } else {
            wrapperPart.setTypeClass(def);
            wrapperBeans.add(def);
            return;
        }
    }
    String classFileName = periodToSlashes(className);
    cw.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, classFileName, null,
             "java/lang/Object", null);

    AnnotationVisitor av0 = cw.visitAnnotation("Ljavax/xml/bind/annotation/XmlRootElement;", true);
    av0.visit("name", wrapperElement.getLocalPart());
    av0.visit("namespace", wrapperElement.getNamespaceURI());
    av0.visitEnd();

    av0 = cw.visitAnnotation("Ljavax/xml/bind/annotation/XmlAccessorType;", true);
    av0.visitEnum("value", "Ljavax/xml/bind/annotation/XmlAccessType;", "FIELD");
    av0.visitEnd();

    av0 = cw.visitAnnotation("Ljavax/xml/bind/annotation/XmlType;", true);
    if (!anonymous) {
        av0.visit("name", wrapperElement.getLocalPart());
        av0.visit("namespace", wrapperElement.getNamespaceURI());
    } else {
        av0.visit("name", "");
    }
    av0.visitEnd();

    // add constructor
    MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null);
    mv.visitCode();
    Label lbegin = createLabel();
    mv.visitLabel(lbegin);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
    mv.visitInsn(Opcodes.RETURN);
    Label lend = createLabel();
    mv.visitLabel(lend);
    mv.visitLocalVariable("this", "L" + classFileName + ";", null, lbegin, lend, 0);
    mv.visitMaxs(1, 1);
    mv.visitEnd();

    for (MessagePartInfo mpi : messageInfo.getMessageParts()) {
        generateMessagePart(cw, mpi, method, classFileName);
    }

    cw.visitEnd();

    Class<?> clz = loadClass(className, method.getDeclaringClass(), cw.toByteArray());
    wrapperPart.setTypeClass(clz);
    wrapperBeans.add(clz);
}
 
Example 19
Source File: JavaClass.java    From cxf with Apache License 2.0 4 votes vote down vote up
private String getSetterParamName(String fieldName) {
    return "new" + StringUtils.capitalize(fieldName);
}
 
Example 20
Source File: SpringServiceBuilderFactory.java    From cxf with Apache License 2.0 2 votes vote down vote up
/**
 * Convert a parameter value to the name of a bean we'd use for a data binding.
 *
 * @param databindingName
 * @return
 */
public static String databindingNameToBeanName(String databindingName) {
    return StringUtils.capitalize(databindingName.toLowerCase()) + ToolConstants.DATABIND_BEAN_NAME_SUFFIX;
}