Java Code Examples for org.apache.xerces.xs.XSTypeDefinition#SIMPLE_TYPE

The following examples show how to use org.apache.xerces.xs.XSTypeDefinition#SIMPLE_TYPE . 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: CMXSDAttributeDeclaration.java    From lemminx with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Returns list of xs:annotation from the element declaration or type
 * declaration.
 * 
 * @return list of xs:annotation from the element declaration or type
 *         declaration.
 */
private XSObjectList getAnnotations() {
	// Try get xs:annotation from the element declaration
	XSAttributeDeclaration attributeDeclaration = getAttrDeclaration();
	XSObjectList annotation = attributeDeclaration.getAnnotations();
	
	if (annotation != null && annotation.getLength() > 0) {
		return annotation;
	}
	// Try get xs:annotation from the type of element declaration
	XSTypeDefinition typeDefinition = attributeDeclaration.getTypeDefinition();
	if (typeDefinition == null) {
		return null;
	}
	if (typeDefinition.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) {
		return ((XSComplexTypeDecl) typeDefinition).getAnnotations();
	} else if (typeDefinition.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) {
		return ((XSSimpleTypeDecl) typeDefinition).getAnnotations();
	}
	return null;
}
 
Example 2
Source File: CMXSDElementDeclaration.java    From lemminx with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Returns list of xs:annotation from the element declaration or type
 * declaration.
 * 
 * @return list of xs:annotation from the element declaration or type
 *         declaration.
 */
private XSObjectList getAnnotations() {
	// Try get xs:annotation from the element declaration
	XSObjectList annotation = elementDeclaration.getAnnotations();
	if (annotation != null && annotation.getLength() > 0) {
		return annotation;
	}
	// Try get xs:annotation from the type of element declaration
	XSTypeDefinition typeDefinition = elementDeclaration.getTypeDefinition();
	if (typeDefinition == null) {
		return null;
	}
	if (typeDefinition.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) {
		return ((XSComplexTypeDecl) typeDefinition).getAnnotations();
	} else if (typeDefinition.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) {
		return ((XSSimpleTypeDecl) typeDefinition).getAnnotations();
	}
	return null;
}
 
Example 3
Source File: CMXSDAttributeDeclaration.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns list of xs:annotation from the element declaration or type
 * declaration.
 * 
 * Indicated by:
 * https://msdn.microsoft.com/en-us/library/ms256143(v=vs.110).aspx
 * xs:attribute tags have content of either an xs:annotation or xs:simpleType
 * 
 * @return list of xs:annotation from the element declaration or type
 *         declaration.
 */
private XSObjectList getValueAnnotations() {
	// Try get xs:annotation from the element declaration
	XSAttributeDeclaration attributeDeclaration = getAttrDeclaration();
	XSSimpleTypeDefinition simpleTypeDefinition = attributeDeclaration.getTypeDefinition();
	XSSimpleTypeDecl simpleTypeDecl;
	

	XSObjectList annotation = null; // The XSD tag that holds the documentation tag

	if(simpleTypeDefinition instanceof XSSimpleTypeDecl) {
		simpleTypeDecl = (XSSimpleTypeDecl) simpleTypeDefinition;
		XSObjectList multiFacets = simpleTypeDecl.getMultiValueFacets();
		if(!multiFacets.isEmpty()) {
			XSMultiValueFacet facet = (XSMultiValueFacet) multiFacets.get(0);
			multiFacets = facet.getAnnotations();
			Object[] annotationArray = multiFacets.toArray();
			if(!onlyContainsNull(annotationArray)) { // if multiValueFacets has annotations
				annotation = simpleTypeDecl.getMultiValueFacets();
			}
		}
	}
	if(annotation == null){ // There was no specific documentation for the value, so use the general attribute documentation
		annotation = attributeDeclaration.getAnnotations();
	}
	if (annotation != null && annotation.getLength() > 0) {
		return annotation;
	}
	// Try get xs:annotation from the type of element declaration
	XSTypeDefinition typeDefinition = attributeDeclaration.getTypeDefinition();
	if (typeDefinition == null) {
		return null;
	}
	if (typeDefinition.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) {
		return ((XSComplexTypeDecl) typeDefinition).getAnnotations();
	} else if (typeDefinition.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) {
		return ((XSSimpleTypeDecl) typeDefinition).getAnnotations();
	}
	return null;
}
 
Example 4
Source File: CMXSDElementDeclaration.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
private void collectAttributesDeclaration(XSElementDeclaration elementDecl,
		Collection<CMAttributeDeclaration> attributes) {
	XSTypeDefinition typeDefinition = elementDecl.getTypeDefinition();
	switch (typeDefinition.getTypeCategory()) {
	case XSTypeDefinition.SIMPLE_TYPE:
		// TODO...
		break;
	case XSTypeDefinition.COMPLEX_TYPE:
		collectAttributesDeclaration((XSComplexTypeDefinition) typeDefinition, attributes);
		break;
	}
}
 
Example 5
Source File: CMXSDElementDeclaration.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
private void collectElementsDeclaration(XSElementDeclaration elementDecl,
		Collection<CMElementDeclaration> elements) {
	XSTypeDefinition typeDefinition = elementDecl.getTypeDefinition();
	switch (typeDefinition.getTypeCategory()) {
	case XSTypeDefinition.SIMPLE_TYPE:
		// TODO...
		break;
	case XSTypeDefinition.COMPLEX_TYPE:
		collectElementsDeclaration((XSComplexTypeDefinition) typeDefinition, elements);
		break;
	}
}
 
Example 6
Source File: XmlTypeToJsonSchemaConverter.java    From iaf with Apache License 2.0 5 votes vote down vote up
public JsonObject getDefinition(XSTypeDefinition typeDefinition, boolean shouldCreateReferences) {
	JsonObjectBuilder builder = Json.createObjectBuilder();

	switch (typeDefinition.getTypeCategory()) {
	case XSTypeDefinition.COMPLEX_TYPE:
		XSComplexTypeDefinition complexTypeDefinition = (XSComplexTypeDefinition)typeDefinition;
		switch (complexTypeDefinition.getContentType()) {
		case XSComplexTypeDefinition.CONTENTTYPE_EMPTY:
			if (log.isTraceEnabled()) log.trace("getDefinition complexTypeDefinition.contentType is Empty, no child elements");
			break;
		case XSComplexTypeDefinition.CONTENTTYPE_SIMPLE:
			if (log.isTraceEnabled()) log.trace("getDefinition complexTypeDefinition.contentType is Simple, no child elements (only characters)");
			handleComplexTypeDefinitionOfSimpleContentType(complexTypeDefinition, shouldCreateReferences, builder);
			break;
		case XSComplexTypeDefinition.CONTENTTYPE_ELEMENT:
			if (log.isTraceEnabled()) log.trace("getDefinition complexTypeDefinition.contentType is Element, complexTypeDefinition ["+ToStringBuilder.reflectionToString(complexTypeDefinition,ToStringStyle.MULTI_LINE_STYLE)+"]");
			handleComplexTypeDefinitionOfElementContentType(complexTypeDefinition, shouldCreateReferences, builder);
			break;
		case XSComplexTypeDefinition.CONTENTTYPE_MIXED:
			if (log.isTraceEnabled()) log.trace("getDefinition complexTypeDefinition.contentType is Mixed");
			handleComplexTypeDefinitionOfSimpleContentType(complexTypeDefinition, shouldCreateReferences, builder);
			break;
		default:
			throw new IllegalStateException("getDefinition complexTypeDefinition.contentType is not Empty,Simple,Element or Mixed, but ["+complexTypeDefinition.getContentType()+"]");
		}
		if (log.isTraceEnabled()) log.trace(ToStringBuilder.reflectionToString(complexTypeDefinition,ToStringStyle.MULTI_LINE_STYLE));
		break;
	case XSTypeDefinition.SIMPLE_TYPE:
		handleSimpleTypeDefinition(typeDefinition, builder);
		break;
	default:
		throw new IllegalStateException("getDefinition typeDefinition.typeCategory is not Complex or Simple, but ["+typeDefinition.getTypeCategory()+"]");
	}
	return builder.build();
}
 
Example 7
Source File: JsonElementContainer.java    From iaf with Apache License 2.0 5 votes vote down vote up
public JsonElementContainer(String name, boolean xmlArrayContainer, boolean repeatedElement, boolean skipArrayElementContainers, String attributePrefix, String mixedContentLabel, XSTypeDefinition typeDefinition) {
	this.name=name;
	this.xmlArrayContainer=xmlArrayContainer;
	this.repeatedElement=repeatedElement;
	this.skipArrayElementContainers=skipArrayElementContainers;
	this.attributePrefix=attributePrefix;
	this.mixedContentLabel=mixedContentLabel;
	if (typeDefinition!=null) {
		switch(typeDefinition.getTypeCategory()) {
		case XSTypeDefinition.SIMPLE_TYPE:
			setType(ScalarType.findType(((XSSimpleType)typeDefinition)));
			break;
		case XSTypeDefinition.COMPLEX_TYPE:
			XSComplexTypeDefinition complexTypeDefinition=(XSComplexTypeDefinition)typeDefinition;
			switch (complexTypeDefinition.getContentType()) {
			case XSComplexTypeDefinition.CONTENTTYPE_EMPTY:
				if (log.isTraceEnabled()) log.trace("JsonElementContainer complexTypeDefinition.contentType is Empty, no child elements");
				break;
			case XSComplexTypeDefinition.CONTENTTYPE_SIMPLE:
				if (log.isTraceEnabled()) log.trace("JsonElementContainer complexTypeDefinition.contentType is Simple, no child elements (only characters)");
				setType(ScalarType.findType((XSSimpleType)complexTypeDefinition.getBaseType()));
				break;
			case XSComplexTypeDefinition.CONTENTTYPE_ELEMENT:
				if (log.isTraceEnabled()) log.trace("JsonElementContainer complexTypeDefinition.contentType is Element");
				break;
			case XSComplexTypeDefinition.CONTENTTYPE_MIXED:
				if (log.isTraceEnabled()) log.trace("JsonElementContainer complexTypeDefinition.contentType is Mixed");
				break;
			}
		}
	}
}
 
Example 8
Source File: ToXml.java    From iaf with Apache License 2.0 5 votes vote down vote up
public void handleElementContents(XSElementDeclaration elementDeclaration, N node) throws SAXException {
	XSTypeDefinition typeDefinition = elementDeclaration.getTypeDefinition();
	if (typeDefinition==null) {
		log.warn("handleElementContents typeDefinition is null");
		handleSimpleTypedElement(elementDeclaration, null, node);
		return;
	}
	switch (typeDefinition.getTypeCategory()) {
	case XSTypeDefinition.SIMPLE_TYPE:
		if (log.isTraceEnabled()) log.trace("handleElementContents typeDefinition.typeCategory is SimpleType, no child elements");
		handleSimpleTypedElement(elementDeclaration, (XSSimpleTypeDefinition)typeDefinition, node);
		return;
	case XSTypeDefinition.COMPLEX_TYPE:
		XSComplexTypeDefinition complexTypeDefinition=(XSComplexTypeDefinition)typeDefinition;
		switch (complexTypeDefinition.getContentType()) {
		case XSComplexTypeDefinition.CONTENTTYPE_EMPTY:
			if (log.isTraceEnabled()) log.trace("handleElementContents complexTypeDefinition.contentType is Empty, no child elements");
			return;
		case XSComplexTypeDefinition.CONTENTTYPE_SIMPLE:
			if (log.isTraceEnabled()) log.trace("handleElementContents complexTypeDefinition.contentType is Simple, no child elements (only characters)");
			handleSimpleTypedElement(elementDeclaration, null, node);
			return;
		case XSComplexTypeDefinition.CONTENTTYPE_ELEMENT:
		case XSComplexTypeDefinition.CONTENTTYPE_MIXED:
			handleComplexTypedElement(elementDeclaration,node);
			return;
		default:
			throw new IllegalStateException("handleElementContents complexTypeDefinition.contentType is not Empty,Simple,Element or Mixed, but ["+complexTypeDefinition.getContentType()+"]");
		}
	default:
		throw new IllegalStateException("handleElementContents typeDefinition.typeCategory is not SimpleType or ComplexType, but ["+typeDefinition.getTypeCategory()+"] class ["+typeDefinition.getClass().getName()+"]");
	}
}
 
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: ToXml.java    From iaf with Apache License 2.0 4 votes vote down vote up
public List<XSParticle> getBestChildElementPath(XSElementDeclaration elementDeclaration, N node, boolean silent) throws SAXException {
		XSTypeDefinition typeDefinition = elementDeclaration.getTypeDefinition();
		if (typeDefinition==null) {
			log.warn("getBestChildElementPath typeDefinition is null");
			return null;
		}
		switch (typeDefinition.getTypeCategory()) {
		case XSTypeDefinition.SIMPLE_TYPE:
			if (log.isTraceEnabled()) log.trace("getBestChildElementPath typeDefinition.typeCategory is SimpleType, no child elements");
			return null;
		case XSTypeDefinition.COMPLEX_TYPE:
			XSComplexTypeDefinition complexTypeDefinition=(XSComplexTypeDefinition)typeDefinition;
			switch (complexTypeDefinition.getContentType()) {
			case XSComplexTypeDefinition.CONTENTTYPE_EMPTY:
				if (log.isTraceEnabled()) log.trace("getBestChildElementPath complexTypeDefinition.contentType is Empty, no child elements");
				return null;
			case XSComplexTypeDefinition.CONTENTTYPE_SIMPLE:
				if (log.isTraceEnabled()) log.trace("getBestChildElementPath complexTypeDefinition.contentType is Simple, no child elements (only characters)");
				return null;
			case XSComplexTypeDefinition.CONTENTTYPE_ELEMENT:
			case XSComplexTypeDefinition.CONTENTTYPE_MIXED:
				XSParticle particle = complexTypeDefinition.getParticle();
				if (particle==null) {
					throw new IllegalStateException("getBestChildElementPath complexTypeDefinition.particle is null for Element or Mixed contentType");
//					log.warn("typeDefinition particle is null, is this a problem?");
//					return null;
				} 
				if (log.isTraceEnabled()) log.trace("typeDefinition particle ["+ToStringBuilder.reflectionToString(particle,ToStringStyle.MULTI_LINE_STYLE)+"]");
				List<XSParticle> result=new LinkedList<XSParticle>();
				List<String> failureReasons=new LinkedList<String>();
				if (getBestMatchingElementPath(elementDeclaration, node, particle, result, failureReasons)) {
					return result;
				}
				String msg="Cannot find path:";
				for (String reason:failureReasons) {
					msg+='\n'+reason;
				}
				if (!silent) {
					handleError(msg);
				}
				return null;
			default:
				throw new IllegalStateException("getBestChildElementPath complexTypeDefinition.contentType is not Empty,Simple,Element or Mixed, but ["+complexTypeDefinition.getContentType()+"]");
			}
		default:
			throw new IllegalStateException("getBestChildElementPath typeDefinition.typeCategory is not SimpleType or ComplexType, but ["+typeDefinition.getTypeCategory()+"] class ["+typeDefinition.getClass().getName()+"]");
		}
	}