Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you 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 org.apache.cxf.tools.java2wsdl.processor.internal.jaxws;
 
 import java.util.Map;
 
 
 
 public final class FaultBean {
     private static final String[] EXCLUDED_GETTER = new String[] {"getCause",
                                                                   "getLocalizedMessage",
                                                                   "getStackTrace",
                                                                   "getSuppressed",
                                                                   "getClass"};
 
     public boolean faultBeanExists(final Class<?> exceptionClass) {
         String fb = getWebFaultBean(exceptionClass);
         if (!StringUtils.isEmpty(fb)) {
             try {
                 return AnnotationUtil.loadClass(fb,
                                                 exceptionClass.getClassLoader()) != null;
             } catch (Exception e) {
                 return false;
             }
         }
         return false
     }
     
     private String getWebFaultBean(final Class<?> exceptionClass) {
         WebFault fault = exceptionClass.getAnnotation(WebFault.class);
         if (fault == null) {
             return null;
         }
         return fault.faultBean();
     }
 
     private boolean isWebFaultAbsent(final Class<?> exceptionClass) {
         return StringUtils.isEmpty(getWebFaultBean(exceptionClass));
     }
     
     public WrapperBeanClass transform(final Class<?> exceptionClassfinal String defaultPackage) {
         WrapperBeanClass jClass = new WrapperBeanClass();
         if (isWebFaultAbsent(exceptionClass)) {
             jClass.setName(exceptionClass.getSimpleName() + "Bean");
             jClass.setPackageName(defaultPackage);
         } else {
             jClass.setFullClassName(getWebFaultBean(exceptionClass));
         }
 
         buildBeanFields(exceptionClassjClass);
         
         String pkg = PackageUtils.getPackageName(exceptionClass);
         if (pkg.length() > 0) {
             jClass.setElementName(new QName(URIParserUtil.getNamespace(pkg),
                                         exceptionClass.getSimpleName()));
         } else {
             jClass.setElementName(new QName(URIParserUtil.getNamespace(.),
                                         exceptionClass.getSimpleName()));
         }
         jClass.annotate(new WrapperBeanAnnotator(exceptionClass));
         
         return jClass;
     }
 
     private String getFieldName(final Method method) {
         String name = method.getName().substring(3);
         char chars[] = name.toCharArray();
         chars[0] = Character.toLowerCase(chars[0]);
        return new String(chars);
    }
    private boolean isIncludedGetter(final Method method) {
        return method.getName().startsWith("get")
            && !Arrays.asList().contains(method.getName());
    }
    
    private void buildBeanFields(final Class<?> exceptionClassfinal JavaClass jClass) {
        Map<StringJavaFieldfields = new TreeMap<StringJavaField>(); 
        
        for (Method method : exceptionClass.getMethods()) {
            if (isIncludedGetter(method)) {
                JavaField field = new JavaField(getFieldName(method),
                                                method.getReturnType().getName(),
                                                "");
                field.setOwner(jClass);
                fields.put(field.getName(), field);
            }
        }
        for (Map.Entry<StringJavaFieldent : fields.entrySet()) {
            jClass.addField(ent.getValue());
            jClass.appendGetter(ent.getValue());
            jClass.appendSetter(ent.getValue());
        }
    }
    
New to GrepCode? Check out our FAQ X