protected int javifyTypeEntryName()

in axis-codegen/src/main/java/org/apache/axis/wsdl/toJava/JavaGeneratorFactory.java [524:698]


    protected int javifyTypeEntryName(SymbolTable symbolTable, TypeEntry entry, HashMap anonQNames, int uniqueNum) {
        TypeEntry tEntry = entry;
        String dims = tEntry.getDimensions();
        TypeEntry refType = tEntry.getRefType();
        while (refType != null) {
            tEntry = refType;
            dims += tEntry.getDimensions();
            refType = tEntry.getRefType();
        }

        TypeEntry te = tEntry;
        while (te != null) {
            TypeEntry base = SchemaUtils.getBaseType(te, symbolTable);
            if (base == null)
                break;

            uniqueNum = javifyTypeEntryName(symbolTable, base, anonQNames, uniqueNum);

            if (Utils.getEnumerationBaseAndValues(te.getNode(), symbolTable) == null
                    &&SchemaUtils.getComplexElementExtensionBase(te.getNode(), symbolTable) == null
					&& te.getContainedAttributes() == null) {
                if(!SchemaUtils.isSimpleTypeWithUnion(te.getNode())) {
                    if (base.isSimpleType()) {
                        // Case 1:
                        // <simpleType name="mySimpleStringType">
                        //   <restriction base="xs:string">
                        //   </restriction>
                        // </simpleType>
                        te.setSimpleType(true);
                        te.setName(base.getName());
                        te.setRefType(base);
                    }
    
                    if (base.isBaseType()) {
                        // Case 2:
                        // <simpleType name="FooString">
                        //   <restriction base="foo:mySimpleStringType">
                        //   </restriction>
                        // </simpleType>
                        te.setBaseType(true);
                        te.setName(base.getName());
                        te.setRefType(base);
                    }
                }
            }

            if (!te.isSimpleType())
                break;

            te = base;
        }

        // Need to javify the ref'd TypeEntry if it was not
        // already processed
        if (tEntry.getName() == null) {
            boolean processed = false;	// true if the java name is already determined
            // Get the QName of the ref'd TypeEntry, which
            // is will be used to javify the name
            QName typeQName = tEntry.getQName();

            // In case of <xsd:list itemType="...">,
            // set typeQName to the value of the itemType attribute.
            QName itemType = SchemaUtils.getListItemType(tEntry.getNode());
            if (itemType != null) {
                // Get the typeEntry so we know the absolute base type
                TypeEntry itemEntry = symbolTable.getTypeEntry(itemType, false);
		// TODO - If the itemEntry is not found, we need to throw
		// an exception.  "Item is referenced, but not defined"
                javifyTypeEntryName(symbolTable, itemEntry, anonQNames, uniqueNum);
                // Grab the referenced type, If it's there.
                TypeEntry refedEntry = itemEntry.getRefType();
                QName baseName = refedEntry == null ? itemEntry.getQName() : 
                        refedEntry.getQName();
                typeQName = new QName(baseName.getNamespaceURI(),
                                        baseName.getLocalPart() + "[]");
            }
            
            if (emitter.isDeploy()) {				
                Class class1 = (Class) emitter.getQName2ClassMap().get(typeQName);				
				if (class1 != null && !class1.isArray()) {                    
                    tEntry.setName(getJavaClassName(class1));
                    processed = true;
                }                            
            }
            
            if (!processed) {
	            if ((typeQName.getLocalPart().
	                    indexOf(SymbolTable.ANON_TOKEN) < 0)) {
	                // Normal Case: The ref'd type is not anonymous
	                // Simply construct the java name from
	                // the qName
	                tEntry.setName(emitter.getJavaName(typeQName));
	            } else {
	                // This is an anonymous type name.
	                // Axis uses '>' as a nesting token to generate
	                // unique qnames for anonymous types.
	                // Only consider the localName after the last '>'
	                // when generating the java name
	                // String localName = typeQName.getLocalPart();
	                // localName =
	                // localName.substring(
	                // localName.lastIndexOf(
	                // SymbolTable.ANON_TOKEN)+1);
	                // typeQName = new QName(typeQName.getNamespaceURI(),
	                // localName);
	                String localName = typeQName.getLocalPart();
	
	                // Check to see if this is an anonymous type,
	                // if it is, replace Axis' ANON_TOKEN with
	                // an underscore to make sure we don't run
	                // into name collisions with similarly named
	                // non-anonymous types
	                StringBuffer sb = new StringBuffer(localName);
	                int aidx;
	
	                while ((aidx = sb.toString().indexOf(SymbolTable.ANON_TOKEN)) > -1) {
	                    sb.replace(aidx, aidx + SymbolTable.ANON_TOKEN.length(), "");
	                    char c = sb.charAt(aidx);
	                    if (Character.isLetter(c) && Character.isLowerCase(c)) {
	                        sb.setCharAt(aidx, Character.toUpperCase(c));
	                    }
	                }
	                        
	                localName = sb.toString();
	                typeQName = new QName(typeQName.getNamespaceURI(),
	                        localName);
	
	                if (emitter.isTypeCollisionProtection() &&
	                        !emitter.getNamespaceExcludes().contains(new NamespaceSelector(typeQName.getNamespaceURI()))) {
	                    // If there is already an existing type,
	                    // there will be a collision.
	                    // If there is an existing anon type,
	                    // there will be a  collision.
	                    // In both cases, mangle the name.
	                    if (symbolTable.getType(typeQName) != null ||
	                            anonQNames.get(typeQName) != null) {
	                        localName += "Type" + uniqueNum++;
	                        typeQName =
	                            new QName(typeQName.getNamespaceURI(),
	                                      localName);
	                    }
	                    
	                    anonQNames.put(typeQName, typeQName);
	                }
	
	                // Now set the name with the constructed qname
	                tEntry.setName(emitter.getJavaName(typeQName));
	            }
            }   // if (!processed)
        
            Vector elements = tEntry.getContainedElements();
            if (elements != null) {
                for (int i = 0; i < elements.size(); i++) {
                    ElementDecl elem = (ElementDecl) elements.get(i);
                    String varName = emitter.getJavaVariableName(typeQName, elem.getQName(), true);
                    elem.setName(varName);
                }
            }
            
            Vector attributes = tEntry.getContainedAttributes();
            if (attributes != null) {
                for (int i = 0; i < attributes.size(); i++) {
                    ContainedAttribute attr = (ContainedAttribute) attributes.get(i);
                    String varName = emitter.getJavaVariableName(typeQName, attr.getQName(), false);
                    attr.setName(varName);
                }
            }
        }

        // Set the entry with the same name as the ref'd entry
        // but add the appropriate amount of dimensions
        entry.setName(tEntry.getName() + dims);

        return uniqueNum;
    }