Java Code Examples for org.apache.xerces.xs.XSElementDeclaration#getName()

The following examples show how to use org.apache.xerces.xs.XSElementDeclaration#getName() . 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: Tree2Xml.java    From iaf with Apache License 2.0 6 votes vote down vote up
@Override
public final String getText(XSElementDeclaration elementDeclaration, N node) {
	String nodeName=elementDeclaration.getName();
	Object text;
	if (log.isTraceEnabled()) log.trace("getText() node ["+nodeName+"] currently parsed element ["+getContext().getLocalName()+"]");
	if (sp!=null && (text=sp.getOverride(getContext()))!=null) {
		if (log.isTraceEnabled()) log.trace("getText() node ["+nodeName+"] override found ["+text+"]");
		if (text instanceof String) {
			return (String)text;
		}
		return text.toString();
	}
	String result=getNodeText(elementDeclaration, node);
	if (sp!=null && StringUtils.isEmpty(result) && (text=sp.getDefault(getContext()))!=null) {
		if (log.isTraceEnabled()) log.trace("getText() node ["+nodeName+"] default found ["+text+"]");
		if (text instanceof String) {
			result = (String)text;
		}
		result = text.toString();
	}
	if (log.isTraceEnabled()) log.trace("getText() node ["+nodeName+"] returning value ["+result+"]");
	return result;
}
 
Example 2
Source File: Properties2Xml.java    From iaf with Apache License 2.0 6 votes vote down vote up
@Override
	public Iterable<String> getChildrenByName(String node, XSElementDeclaration childElementDeclaration) throws SAXException {
		String name = childElementDeclaration.getName();
		List<String> result=new LinkedList<String>();
		if (data.containsKey(name)) {
			String value=data.get(name);
			result.addAll(Arrays.asList(value.split(valueSeparator)));
			if (log.isDebugEnabled()) {
				String elems="";
				for (String elem:result) {
					elems+=", ["+elem+"]";
				}
				log.debug("getChildrenByName returning: "+elems.substring(1));
			}
			return result;
		}
//		for (int i=1;data.containsKey(name+indexSeparator+i);i++) {
//			result.add(data.get(name+indexSeparator+i));
//		}
		return result;
	}
 
Example 3
Source File: XmlAligner.java    From iaf with Apache License 2.0 6 votes vote down vote up
protected void collectChildElements(XSParticle particle, Set<String> elementNames) {
	if (particle==null) {
		log.warn("collectChildElements() particle is null, is this a problem?");	
		return;
	}
	XSTerm term = particle.getTerm();
	if (term==null) {
		throw new IllegalStateException("collectChildElements particle.term is null");
	} 
	if (term instanceof XSModelGroup) {
		XSModelGroup modelGroup = (XSModelGroup)term;
		XSObjectList particles = modelGroup.getParticles();
		for (int i=0;i<particles.getLength();i++) {
			XSParticle childParticle = (XSParticle)particles.item(i);
			collectChildElements(childParticle, elementNames);
		}
		return;
	} 
	if (term instanceof XSElementDeclaration) {
		XSElementDeclaration elementDeclaration=(XSElementDeclaration)term;
		String elementName=elementDeclaration.getName();
		if (log.isTraceEnabled()) log.trace("collectChildElements() ElementDeclaration name ["+elementName+"]");
		elementNames.add(elementName);
	}
	return;
}
 
Example 4
Source File: DomTreeAligner.java    From iaf with Apache License 2.0 5 votes vote down vote up
@Override
public Iterable<Node> getNodeChildrenByName(Node node, XSElementDeclaration childElementDeclaration) throws SAXException {
	String name=childElementDeclaration.getName();
	if (log.isTraceEnabled()) log.trace("getChildrenByName() node ["+node+"] name ["+name+"]");
	List<Node> children = new LinkedList<Node>();
	for (Node cur=node.getFirstChild();cur!=null;cur=cur.getNextSibling()) {
		if (cur.getNodeType()==Node.ELEMENT_NODE && name.equals(getNodeName(cur))) {
			if (log.isTraceEnabled()) log.trace("getChildrenByName() node ["+node+"] added node ["+getNodeName(cur)+"]");
			children.add(cur);
		}
	}
	return children;
}
 
Example 5
Source File: Json2Xml.java    From iaf with Apache License 2.0 5 votes vote down vote up
@Override
public Iterable<JsonValue> getNodeChildrenByName(JsonValue node, XSElementDeclaration childElementDeclaration) throws SAXException {
	String name=childElementDeclaration.getName();
	if (log.isTraceEnabled()) log.trace("getChildrenByName() childname ["+name+"] isParentOfSingleMultipleOccurringChildElement ["+isParentOfSingleMultipleOccurringChildElement()+"] isMultipleOccuringChildElement ["+isMultipleOccurringChildElement(name)+"] node ["+node+"]");
	try {
		if (!(node instanceof JsonObject)) {
			if (log.isTraceEnabled()) log.trace("getChildrenByName() parent node is not a JsonObject, but a ["+node.getClass().getName()+"]");
			return null;
		} 
		JsonObject o = (JsonObject)node;
		if (!o.containsKey(name)) {
			if (log.isTraceEnabled()) log.trace("getChildrenByName() no children named ["+name+"] node ["+node+"]");
			return null;
		} 
		JsonValue child = o.get(name);
		List<JsonValue> result = new LinkedList<JsonValue>(); 
		if (child instanceof JsonArray) {
			if (log.isTraceEnabled()) log.trace("getChildrenByName() child named ["+name+"] is a JsonArray, current node insertElementContainerElements ["+insertElementContainerElements+"]");
			// if it could be necessary to insert elementContainers, we cannot return them as a list of individual elements now, because then the containing element would be duplicated
			// we also cannot use the isSingleMultipleOccurringChildElement, because it is not valid yet
			if (!isMultipleOccurringChildElement(name)) {
				if (insertElementContainerElements || !strictSyntax) { 
					result.add(child);
					if (log.isTraceEnabled()) log.trace("getChildrenByName() singleMultipleOccurringChildElement ["+name+"] returning array node (insertElementContainerElements=true)");
				} else {
					throw new SAXException(MSG_EXPECTED_SINGLE_ELEMENT+" ["+name+"]");
				}
			} else {
				if (log.isTraceEnabled()) log.trace("getChildrenByName() childname ["+name+"] returning elements of array node (insertElementContainerElements=false or not singleMultipleOccurringChildElement)");
				result.addAll((JsonArray)child);
			}
			return result;
		}
		result.add(child);
		if (log.isTraceEnabled()) log.trace("getChildrenByName() name ["+name+"] returning ["+child+"]");
		return result;
	} catch (JsonException e) {
		throw new SAXException(e);
	}
}
 
Example 6
Source File: Json2Xml.java    From iaf with Apache License 2.0 5 votes vote down vote up
@Override
protected void processChildElement(JsonValue node, String name, XSElementDeclaration childElementDeclaration, boolean mandatory, Set<String> processedChildren) throws SAXException {
	String childElementName=childElementDeclaration.getName();
	if  (node instanceof JsonArray) {
		if (log.isTraceEnabled()) log.trace("Json2Xml.processChildElement() node is JsonArray, handling each of the elements as a ["+name+"]");
		JsonArray ja=(JsonArray)node;
		for (JsonValue child:ja) {
			handleElement(childElementDeclaration, child);
		}
		// mark that we have processed the arrayElement containers
		processedChildren.add(childElementName);
		return;
	}
	super.processChildElement(node, name, childElementDeclaration, mandatory, processedChildren);
}
 
Example 7
Source File: Tree2Xml.java    From iaf with Apache License 2.0 5 votes vote down vote up
@Override
public final Iterable<N> getChildrenByName(N node, XSElementDeclaration childElementDeclaration) throws SAXException {
	String childName=childElementDeclaration.getName();
	Iterable<N> children = getNodeChildrenByName(node, childElementDeclaration);
	if (children==null && sp!=null && sp.hasSubstitutionsFor(getContext(), childName)) {
		List<N> result=new LinkedList<N>();
		result.add(node);
		return result;
	}
	return children;
}
 
Example 8
Source File: XmlTypeToJsonSchemaConverter.java    From iaf with Apache License 2.0 5 votes vote down vote up
private void handleElementDeclaration(JsonObjectBuilder builder, XSElementDeclaration elementDeclaration, boolean multiOccurring, boolean shouldCreateReferences){	
	String elementName=elementDeclaration.getName();
	//if (log.isTraceEnabled()) log.trace("XSElementDeclaration name ["+elementName+"]");
	if (log.isTraceEnabled()) log.trace("XSElementDeclaration element ["+elementName+"]["+ToStringBuilder.reflectionToString(elementDeclaration,ToStringStyle.MULTI_LINE_STYLE)+"]");

	XSTypeDefinition elementTypeDefinition = elementDeclaration.getTypeDefinition();
	JsonStructure definition;
	if (elementTypeDefinition.getAnonymous() || XML_SCHEMA_NS.equals(elementTypeDefinition.getNamespace())) {
		definition =getDefinition(elementTypeDefinition, shouldCreateReferences);
	} else {
		definition = Json.createObjectBuilder().add("$ref",definitionsPath+elementTypeDefinition.getName()).build();
	}
	if (elementDeclaration.getNillable()) {
		definition=nillable(definition);
	}
	if (multiOccurring) {
		JsonObjectBuilder arrayBuilder = Json.createObjectBuilder();
		arrayBuilder.add("type", "array");
		arrayBuilder.add("items", definition);

		builder.add(elementName, arrayBuilder.build());
	} else {
		if (definition!=null) {
			builder.add(elementName, definition);
		}
	}
	
}
 
Example 9
Source File: ToXml.java    From iaf with Apache License 2.0 5 votes vote down vote up
protected void processChildElement(N node, String parentName, XSElementDeclaration childElementDeclaration, boolean mandatory, Set<String> processedChildren) throws SAXException {
		String childElementName = childElementDeclaration.getName(); 
		if (log.isTraceEnabled()) log.trace("To2Xml.processChildElement() parent name ["+parentName+"] childElementName ["+childElementName+"]");
		Iterable<N> childNodes = getChildrenByName(node,childElementDeclaration);
		boolean childSeen=false;
		if (childNodes!=null) {
			childSeen=true;
			int i=0;
			for (N childNode:childNodes) {
				i++;
				handleElement(childElementDeclaration,childNode);
			}
			if (log.isTraceEnabled()) log.trace("processed ["+i+"] children found by name ["+childElementName+"] in ["+parentName+"]");
			if (i==0 && isDeepSearch() && childElementDeclaration.getTypeDefinition().getTypeCategory()!=XSTypeDefinition.SIMPLE_TYPE) {
				if (log.isTraceEnabled()) log.trace("no children processed, and deepSearch, not a simple type therefore handle node ["+childElementName+"] in ["+parentName+"]");
				handleElement(childElementDeclaration,node);
				childSeen=true;
			}
		} else {
			if (log.isTraceEnabled()) log.trace("no children found by name ["+childElementName+"] in ["+parentName+"]");
			if (isDeepSearch() && childElementDeclaration.getTypeDefinition().getTypeCategory()!=XSTypeDefinition.SIMPLE_TYPE) {
				if (log.isTraceEnabled()) log.trace("no children found, and deepSearch, not a simple type therefore handle node ["+childElementName+"] in ["+parentName+"]");
				handleElement(childElementDeclaration,node);
				childSeen=true;
			}
		}
		if (childSeen) {
			if (processedChildren.contains(childElementName)) {
				throw new IllegalStateException("child element ["+childElementName+"] already processed for node ["+parentName+"]");
			}
			processedChildren.add(childElementName);
		}
//		if (!childSeen && mandatory && isAutoInsertMandatory()) {
//			if (log.isDebugEnabled()) log.debug("inserting mandatory element ["+childElementName+"]");
//			handleElement(childElementDeclaration,node); // insert node when minOccurs > 0, and no node is present
//		}
	}
 
Example 10
Source File: SentinelXsdDumpMetadata.java    From DataHubSystem with GNU Affero General Public License v3.0 4 votes vote down vote up
private static void dumpElement(String path, XSElementDeclaration element)
   {
      String output_path = "" + path + "/" + element.getName();

      XSTypeDefinition type = element.getTypeDefinition();

      if (type.getName().endsWith("Array"))
      {
//         System.err.println(element.getName() + " - " + type.getName()
//            + " SKIPPED !");
         return;
      }

      if (((type.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE)
            || ((XSComplexTypeDefinition) type)
            .getContentType() == XSComplexTypeDefinition.CONTENTTYPE_SIMPLE))
      {
         if (includesBaseType(type, "string")
               || includesBaseType(type, "integer")
               || includesBaseType(type, "boolean"))
         {
//            System.out.println("         <metadata name=\"" +
// element.getName() + "\" type=\"text/plain\" category=\"\">");
//            System.out.println("            " +
// indexedName(element.getName())
//               + " { local:values($doc" + output_path + ") }");
//            System.out.println("         </metadata>,");

            System.out.println("         local:getMetadata('" +
                  element.getName() + "', '" +
                  indexedName(element.getName()) + "',");
            System.out.println("            $doc" + output_path + "),");
         }
      }
      else
      {
         dumpParticle(output_path,
               ((XSComplexTypeDefinition)type).getParticle());
      }

   }
 
Example 11
Source File: XmlTypeToJsonSchemaConverter.java    From iaf with Apache License 2.0 4 votes vote down vote up
private void buildObject(JsonObjectBuilder builder, XSObjectList particles, XSObjectList attributeUses, String textAttribute, XSTypeDefinition baseType){
	builder.add("type", "object");
	builder.add("additionalProperties", false);
	JsonObjectBuilder propertiesBuilder = Json.createObjectBuilder();
	List<String> requiredProperties = new ArrayList<String>();

	if (attributeUses!=null) {
		for (int i=0; i< attributeUses.getLength(); i++) {
			XSAttributeUse attributeUse = (XSAttributeUse)attributeUses.get(i);
			XSAttributeDeclaration attributeDecl = attributeUse.getAttrDeclaration();
			propertiesBuilder.add(attributePrefix+attributeDecl.getName(), getDefinition(attributeDecl.getTypeDefinition(), true));
		}
	}
	if (textAttribute!=null && ((attributeUses!=null && attributeUses.getLength()>0) || (particles!=null && particles.getLength()>0))) {
		JsonObject elementType = baseType!=null ? getDefinition(baseType, true) : Json.createObjectBuilder().add("type", "string").build();
		propertiesBuilder.add(textAttribute, elementType);
	}
	if (particles!=null) {
		for (int i=0;i<particles.getLength();i++) {
			XSParticle childParticle = (XSParticle)particles.item(i);
			if (log.isTraceEnabled()) log.trace("childParticle ["+i+"]["+ToStringBuilder.reflectionToString(childParticle,ToStringStyle.MULTI_LINE_STYLE)+"]");
		
			XSTerm childTerm = childParticle.getTerm();
			if (childTerm instanceof XSElementDeclaration) {
				XSElementDeclaration elementDeclaration = (XSElementDeclaration) childTerm;
				String elementName = elementDeclaration.getName();

				if(elementName != null && childParticle.getMinOccurs() != 0){
					requiredProperties.add(elementName);
				}
			}
			
			handleParticle(propertiesBuilder, childParticle, null, true);
		}
	}
	builder.add("properties", propertiesBuilder.build());
	if(requiredProperties.size() > 0){
		JsonArrayBuilder requiredPropertiesBuilder = Json.createArrayBuilder();
		for (String requiredProperty : requiredProperties) {
			requiredPropertiesBuilder.add(requiredProperty);
		}
		builder.add("required", requiredPropertiesBuilder.build());
	}
}
 
Example 12
Source File: ToXml.java    From iaf with Apache License 2.0 4 votes vote down vote up
public void handleElement(XSElementDeclaration elementDeclaration, N node) throws SAXException {
		String name = elementDeclaration.getName();
		String elementNamespace=elementDeclaration.getNamespace();
		String qname=getQName(elementNamespace, name);
		if (log.isTraceEnabled()) log.trace("handleNode() name ["+name+"] elementNamespace ["+elementNamespace+"]");
		newLine();
		AttributesImpl attributes=new AttributesImpl();
		Map<String,String> nodeAttributes = getAttributes(elementDeclaration, node);
		if (log.isTraceEnabled()) log.trace("node ["+name+"] search for attributeDeclaration");
		XSTypeDefinition typeDefinition=elementDeclaration.getTypeDefinition();
		XSObjectList attributeUses=getAttributeUses(typeDefinition);
		if (attributeUses==null || attributeUses.getLength()==0) {
			if (nodeAttributes!=null && nodeAttributes.size()>0) {
				log.warn("node ["+name+"] found ["+nodeAttributes.size()+"] attributes, but no declared AttributeUses");
			} else {
				if (log.isTraceEnabled()) log.trace("node ["+name+"] no attributeUses, no attributes");
			}
		} else {
			if (nodeAttributes==null || nodeAttributes.isEmpty()) {
				log.warn("node ["+name+"] declared ["+attributeUses.getLength()+"] attributes, but no attributes found");
			} else {
				for (int i=0;i<attributeUses.getLength(); i++) {
					XSAttributeUse attributeUse=(XSAttributeUse)attributeUses.item(i);
					XSAttributeDeclaration attributeDeclaration=attributeUse.getAttrDeclaration();
					//XSSimpleTypeDefinition attTypeDefinition=attributeDeclaration.getTypeDefinition();
					//if (log.isTraceEnabled()) log.trace("node ["+name+"] attTypeDefinition ["+ToStringBuilder.reflectionToString(attTypeDefinition)+"]");
					String attName=attributeDeclaration.getName();
					if (nodeAttributes.containsKey(attName)) {
						String value=nodeAttributes.remove(attName);
						String uri=attributeDeclaration.getNamespace();
						String attqname=getQName(uri,attName);
						String type=null;
						if (log.isTraceEnabled()) log.trace("node ["+name+"] adding attribute ["+attName+"] value ["+value+"]");
						attributes.addAttribute(uri, attName, attqname, type, value);
					}
				}
			}
		}
		if (isNil(elementDeclaration, node)) {
			validatorHandler.startPrefixMapping(XSI_PREFIX_MAPPING, XML_SCHEMA_INSTANCE_NAMESPACE);
			attributes.addAttribute(XML_SCHEMA_INSTANCE_NAMESPACE, XML_SCHEMA_NIL_ATTRIBUTE, XSI_PREFIX_MAPPING+":"+XML_SCHEMA_NIL_ATTRIBUTE, "xs:boolean", "true");
			validatorHandler.startElement(elementNamespace, name, qname, attributes);
			validatorHandler.endElement(elementNamespace, name, qname);
			validatorHandler.endPrefixMapping(XSI_PREFIX_MAPPING);
		} else {
			validatorHandler.startElement(elementNamespace, name, qname, attributes);
			handleElementContents(elementDeclaration, node);
			validatorHandler.endElement(elementNamespace, name, qname);
		}
//		if (createdPrefix!=null) {
//			validatorHandler.endPrefixMapping(createdPrefix);
//		}
	}