Java Code Examples for org.dom4j.Element.getQualifiedName()

The following are Jave code examples for showing how to use getQualifiedName() of the org.dom4j.Element class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: joai-project   File: CompositorGuard.java   View Source Code Vote up 6 votes
/**
 *  Gets the occurrencesCount attribute of the ChoiceGuard object
 *
 * @param  name  NOT YET DOCUMENTED
 * @return       The occurrencesCount value
 */
public final int getOccurrencesCount(String name) {
	prtln("\ngetOccurrencesCount for name: " + name);
	int cnt = 0;
	if (occurrences != null) {
		for (int i = 0; i < occurrences.size(); i++) {
			Occurrence o = (Occurrence) occurrences.get(i);

			if (o.elements != null) {
				for (Iterator elements = o.elements.iterator(); elements.hasNext(); ) {
					Element member = (Element) elements.next();
					String memberName = member.getQualifiedName();
					prtln("\t memberName: " + memberName);
					if (name.equals(memberName))
						cnt++;
				}
			}
		}
	}
	prtln("... getOccurrencesCount for " + name + " returning " + cnt + "\n");
	return cnt;
}
 
Example 2
Project: joai-project   File: SchemaHelper.java   View Source Code Vote up 6 votes
/**
 *  Gets the qualified element name of the repeatingComplexSingleton child of
 *  the node specified by the provided path, or an empty string if such a child
 *  does not exist.
 *
 * @param  xpath  NOT YET DOCUMENTED
 * @return        The repeatingComplexSingletonChildName value
 */
public String getRepeatingComplexSingletonChildName(String xpath) {
	String normalizedXPath = XPathUtils.normalizeXPath(xpath);
	Node instanceDocNode = getInstanceDocNode(normalizedXPath);
	if (instanceDocNode != null && instanceDocNode.getNodeType() == org.dom4j.Node.ELEMENT_NODE) {
		List children = ((Element) instanceDocNode).elements();
		if (children.size() == 1) {
			Element childElement = (Element) children.get(0);
			String childPath = childElement.getPath();
			SchemaNode schemaNode = getSchemaNode(childPath);
			if (schemaNode != null && schemaNode.getTypeDef().isComplexType() && isRepeatingElement(childPath))
				return childElement.getQualifiedName();
		}
	}
	return "";
}
 
Example 3
Project: joai-project   File: DocMap.java   View Source Code Vote up 6 votes
/**
 *  If the child is an substitution element, then return the Head Element's
 *  qualified name, otherwise just use the child's qualified name
 *
 * @param  parentPath  NOT YET DOCUMENTED
 * @param  element     NOT YET DOCUMENTED
 * @return             NOT YET DOCUMENTED
 */
private String resolveElementName(String parentPath, Element element) {

	String qualifiedName = element.getQualifiedName();
	if (schemaHelper == null)
		return qualifiedName;

	String xpath = parentPath + "/" + qualifiedName;
	SchemaNode schemaNode = schemaHelper.getSchemaNode(xpath);
	if (schemaNode == null) {
		// prtln ("\t schemaNode not found: returning " + qualifiedName);
		return qualifiedName;
	}

	if (schemaNode.getHeadElementName().length() > 0) {
		// prtln ("\t this HAS a head element" + Dom4jUtils.prettyPrint (element));
		return schemaNode.getHeadElementName();
	}
	else {
		// prtln ("this did not have a head element");
		return qualifiedName;
	}
}
 
Example 4
Project: joai-project   File: ChoiceGuard.java   View Source Code Vote up 5 votes
/**
 *  Returns a list of occurrence instances that can be used to determine
 *  whether an instance document element satisfies the occurrence constraints
 *  of the schema.<p>
 *  Walk down the buckets, when there is no room to add the current member,
 *  start an new occurrance. NOTE: the order in which we add members is 
 *  aribitrary - we just can't overfill any single member.<p>
 
 NOTE: this does not account for many of the children choice compositors can have:
 - choice
 - sequence
 - any
 - element
 - group
 *
 *@return                The occurrences value
 *@exception  Exception  NOT YET DOCUMENTED
 */
protected List getOccurrences() throws Exception {

	List occurrences = new ArrayList();
	Occurrence o = null;

	Iterator iMembers = this.instanceMembers.iterator();
	/* compositor.getLeafMemberNames(); */
	
	CompositorMember lastCM = null;
	
	while (iMembers.hasNext()) {
		Element memberElement = (Element) iMembers.next();
		String leafName = memberElement.getQualifiedName();
		
					
		// sanity check - must find a member for this child
		if (!compositor.getLeafMemberNames().contains(leafName)) {
			throw new Exception("Unexpected child element: \"" + leafName + "\"");
		}
		
		CompositorMember cm = compositor.getMember (leafName);
		if (cm == null)
			throw new Exception("Could not find CM for: \"" + leafName + "\"");
		
		
		if (cm != lastCM || o.getMemberCount (cm) == cm.maxOccurs) {
			// start a new occurrence
			o = new Occurrence(compositor);
			occurrences.add (o);
		}
		
		o.add (memberElement);
		lastCM = cm;
	}

	return occurrences;
}
 
Example 5
Project: joai-project   File: AllGuard.java   View Source Code Vote up 5 votes
/**
 *  Returns a list of occurrence instances that can be used to determine whether an instance document element
 *  satisfies the occurrence constraints of the schema.
 *
 * @return                The occurrences value
 * @exception  Exception  NOT YET DOCUMENTED
 */
protected List getOccurrences() throws Exception {
	prtln ("getOccurrences()");
	occurrenceCounter = new OccurrenceCounter();
	occurrences = new ArrayList();
	List membersSeen = new ArrayList();
	List elements = instanceMembers;

	// walk down the elements
	// we don't want to see any member twice, and no group should have more than one element
	Occurrence occurrence = null;
	if (elements.size() > 0) {
		occurrence = new Occurrence ();
		for (Iterator i = instanceMembers.iterator(); i.hasNext(); ) {
			Element element = (Element) i.next();
			// String name = element.getName();
			String name = element.getQualifiedName();
			if (compositor.getMember(name) == null || membersSeen.contains(name))
				throw new Exception ("Unexpected child element: \"" + name + "\"");
			
			membersSeen.add (name);
			occurrence.elements.add (element);
		}
		occurrences.add (occurrence);
	}
	prtln ("getOccurrences returning " + this.occurrences.size());
	return occurrences;
}
 
Example 6
Project: joai-project   File: SequenceGuard.java   View Source Code Vote up 4 votes
/**
 *  Returns a list of element CMBuckets (representing contiguous elements
 *  belonging to the same top-level (the children of the compositor element)
 *  member.<p>
 *
 *  E.g., if the top-level member is a sequence compositor, then as long as
 *  instanceElements belong to that compositor (i.e., they are in the set of
 *  leafMembersNames) we collect them in the same bucket.<p>
 *
 *  Each bucket instance keeps track of how many elements it contains. Later,
 *  the buckets list is split into Occurrences.
 *
 * @return                CMBuckets found in the instance document element to
 *      be tested
 * @exception  Exception  NOT YET DOCUMENTED
 */
private List getCMBuckets() throws Exception {

	// first pass - aggregate instanceElement children into buckets

	List buckets = new ArrayList();
	CompositorMember lastCM = null;
	CMBucket currentBucket = null;
	CompositorMember currentMember = null;

	for (Iterator i = instanceMembers.iterator(); i.hasNext(); ) {
		Element child = (Element) i.next();
		String name = child.getQualifiedName();
		// prtln ("compositorMemberName: " + name);
		// sanity check - must find a member for this child
		if (!compositor.getLeafMemberNames().contains(name)) {
			// prtln (" .. not found but maybe it's an any type");
			if (!compositor.hasAnyTypeMember())
				throw new Exception("Unexpected child element: \"" + name + "\"");
		}

		CompositorMember cm = resolveLeafNameToCM(name);

		if (cm == null) {
			throw new Exception("CompositorMember (cm) not found for \"" + name + "\"");
		}

		// create a new bucket if the cm has changed AND
		// the cmType has also changed.
		// -- new buckets NOT added for adjacent ELEMENT compositors
		if (cm != lastCM) {
			// we're looking at a different CompositorMember. Create a
			// new bucket UNLESS ...
			if (lastCM != null &&
				!lastCM.hasSubCompositor() &&
				!cm.hasSubCompositor()) {

				// do not create a new bucket for adjacent ELEMENTs

			}
			else {

				// prtln ("\t ** adding new bucket");
				currentBucket = new CMBucket(cm);
				buckets.add(currentBucket);
			}
			lastCM = cm;
		}
		currentBucket.add(child);
	}

	// prtln(buckets.size() + " buckets after FIRST pass ....");
	// printCMBuckets(buckets);
	return buckets;
}
 
Example 7
Project: joai-project   File: CollapseBeanInitializer.java   View Source Code Vote up 4 votes
/**
 *  Initialize children of the element specified by path - note: we must
 *  manually add indexing for repeating elements
 *
 *@param  path     xpath to element whose children are to be processed
 *@param  element  instance document element at path
 */
private void initializeChildren(String path, Element element) {
	prtln ("initializeChildren() " + path);
	SchemaNode parentNode = sh.getSchemaNode(path);

	/*
	 *  otherChildrenNames used to collect the member names that are NOT
	 *  present in the instance document
	 */
	List otherChildrenNames = new ArrayList();

	if (parentNode != null && parentNode.hasCompositor()) {
		otherChildrenNames.addAll(parentNode.getCompositor().getLeafMemberNames());
	}

	Iterator elementIter = element.elementIterator();
	String lastChildName = "";
	int index = -1;
	while (elementIter.hasNext()) {
		Element child = (Element) elementIter.next();
		String childName = child.getQualifiedName();
		String childPath = path + "/" + childName;

		if (!lastChildName.equals(childName)) {
			lastChildName = childName;
			index = 1;
		}

		otherChildrenNames.remove(childName);

		SchemaNode schemaNode = sh.getSchemaNode(childPath);
		if (schemaNode != null) {
			boolean doInitialize = true;
			GlobalDef typeDef = sh.getGlobalDef(schemaNode);
			if (typeDef == null) {
				doInitialize = true;
			} else if (typeDef.isComplexType()) {
				doInitialize = true;
			} else if (sh.isMultiSelect(schemaNode)) {
				doInitialize = true;
			}

			// duh - it is ALWAYS true!
			if (!doInitialize) {
				continue;
			}

			// for repeating items we have to add indexing to the path
			if (sh.isRepeatingElement(schemaNode)) {
				childPath += "[" + index++ + "]";
			}
		} else {
			prtlnErr("schemaNode not found at " + childPath);
		}
		// recurse with childPath
		initializePath(childPath);
	}

	// set displayState of otherChildren to open so their "add" controls will be available
	if (!otherChildrenNames.isEmpty()) {
		for (Iterator j = otherChildrenNames.iterator(); j.hasNext(); ) {
			String encodedPath = XPathUtils.encodeXPath(path + "/" + (String) j.next());
			this.openElement(encodedPath);
		}
	}
}
 
Example 8
Project: unitimes   File: LowercaseTableNames.java   View Source Code Vote up 4 votes
protected void writeElement(Element element) throws IOException {
    int size = element.nodeCount();
    String qualifiedName = element.getQualifiedName();

    writePrintln();
    indent();

    writer.write("<");
    writer.write(qualifiedName);

    boolean textOnly = true;

    for (int i = 0; i < size; i++) {
        Node node = element.node(i);
        if (node instanceof Element) {
            textOnly = false;
        } else if (node instanceof Comment) {
            textOnly = false;
        }
    }

    writeAttributes(element);

    lastOutputNodeType = Node.ELEMENT_NODE;

    if (size <= 0) {
        writeEmptyElementClose(qualifiedName);
    } else {
        writer.write(">");

        if (textOnly) {
            // we have at least one text node so lets assume
            // that its non-empty
            writeElementContent(element);
        } else {
        	if (element.attributeCount() > 3)
        		writePrintln();
            // we know it's not null or empty from above
            ++indentLevel;

            writeElementContent(element);

            --indentLevel;

            writePrintln();
            indent();
        }

        writer.write("</");
        writer.write(qualifiedName);
        writer.write(">");
    }
   	if (element.attributeCount() > 2 && indentLevel > 0)
   		writePrintln();

    lastOutputNodeType = Node.ELEMENT_NODE;
}