Java Code Examples for org.apache.xerces.xs.XSNamedMap#getLength()

The following examples show how to use org.apache.xerces.xs.XSNamedMap#getLength() . 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: XmlTypeToJsonSchemaConverter.java    From iaf with Apache License 2.0 6 votes vote down vote up
public JsonObject getDefinitions() {
	JsonObjectBuilder definitionsBuilder = Json.createObjectBuilder();
	for (XSModel model:models) {
		XSNamedMap elements = model.getComponents(XSConstants.ELEMENT_DECLARATION);
		for (int i=0; i<elements.getLength(); i++) {
			XSElementDeclaration elementDecl = (XSElementDeclaration)elements.item(i);
			handleElementDeclaration(definitionsBuilder, elementDecl, false, false);
		}
		XSNamedMap types = model.getComponents(XSConstants.TYPE_DEFINITION);
		for (int i=0; i<types.getLength(); i++) {
			XSTypeDefinition typeDefinition = (XSTypeDefinition)types.item(i);
			String typeNamespace = typeDefinition.getNamespace();
			if (typeNamespace==null || !typeDefinition.getNamespace().equals(XML_SCHEMA_NS)) {
				definitionsBuilder.add(typeDefinition.getName(), getDefinition(typeDefinition, false));
			}
		}
	}
	return definitionsBuilder.build();
}
 
Example 2
Source File: ToXml.java    From iaf with Apache License 2.0 6 votes vote down vote up
public Set<XSElementDeclaration> findElementDeclarationsForName(String namespace, String name) {
	Set<XSElementDeclaration> result=new LinkedHashSet<XSElementDeclaration>();
	if (schemaInformation==null) {
		log.warn("No SchemaInformation specified, cannot find namespaces for ["+namespace+"]:["+name+"]");
		return null;
	}
	for (XSModel model:schemaInformation) {
		XSNamedMap components = model.getComponents(XSConstants.ELEMENT_DECLARATION);
		for (int i=0;i<components.getLength();i++) {
			XSElementDeclaration item=(XSElementDeclaration)components.item(i);
			if ((namespace==null || namespace.equals(item.getNamespace())) && (name==null || name.equals(item.getName()))) {
				if (log.isTraceEnabled()) log.trace("name ["+item.getName()+"] found in namespace ["+item.getNamespace()+"]");
				result.add(item);
			}
		}
	}
	return result;
}
 
Example 3
Source File: CMXSDDocument.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Collection<CMElementDeclaration> getElements() {
	if (elements == null) {
		elements = new ArrayList<>();
		XSNamedMap map = model.getComponents(XSConstants.ELEMENT_DECLARATION);
		for (int j = 0; j < map.getLength(); j++) {
			XSElementDeclaration elementDeclaration = (XSElementDeclaration) map.item(j);
			collectElement(elementDeclaration, elements);
		}
	}
	return elements;
}
 
Example 4
Source File: SentinelXsdDumpMetadata.java    From DataHubSystem with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * @param args
 */
public static void main(String[] args)
{
   if (!args[0].equals("--dump"))
   {
      // Activates the resolver for Drb
      try
      {
         DrbFactoryResolver.setMetadataResolver (
               new DrbCortexMetadataResolver (
            DrbCortexModel.getDefaultModel ()));
      }
      catch (IOException e)
      {
         System.err.println ("Resolver cannot be handled.");
      }
      process(args[0]);
   }
   else
   {
   System.out.println("declare function local:deduplicate($list) {");
   System.out.println("  if (fn:empty($list)) then ()");
   System.out.println("  else");
   System.out.println("    let $head := $list[1],");
   System.out.println("      $tail := $list[position() > 1]");
   System.out.println("    return");
   System.out
         .println("      if (fn:exists($tail[ . = $head ])) then " +
               "local:deduplicate($tail)");
   System.out.println("      else ($head, local:deduplicate($tail))");
   System.out.println("};");
   System.out.println();
   System.out.println("declare function local:values($list) {");
   System.out
         .println("  fn:string-join(local:deduplicate(" +
               "fn:data($list)), ' ')");
   System.out.println("};");
   System.out.println();

   System.out.println("let $doc := !!!! GIVE PATH HERE !!!!");
   System.out.println("return\n(\n");

   /**
    * Open XML Schema
    */
   final XSLoader loader = new XMLSchemaLoader();

   final XSModel model = loader.loadURI(args[1]);

   XSNamedMap map = model.getComponents(XSConstants.ELEMENT_DECLARATION);

   if (map != null)
   {
      for (int j = 0; j < map.getLength(); j++)
      {
         dumpElement("", (XSElementDeclaration) map.item(j));
      }
   }

   System.out.println("\n) ^--- REMOVE LAST COMMA !!!");
   }
}