com.sun.xml.xsom.XSElementDecl Java Examples

The following examples show how to use com.sun.xml.xsom.XSElementDecl. 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: XmlFormBuilder.java    From dynaform with Artistic License 2.0 6 votes vote down vote up
private XmlForm elementDeclSimple(XSElementDecl decl, XSSimpleType simpleType) {
  FormElement element = declSimple(simpleType, decl.getName(), decl.getDefaultValue(), decl.getFixedValue());
  if (element == null)
    return null;
  
  XmlWriter writer = new XmlElementWriter(decl.getName(), null,
      new TextXmlWriter(new FormElementWriter(element)));
  
  XmlReader reader = new XmlElementReader(decl.getName(), null,
      new TextXmlReader(new FormElementHandler(element)));
  
  if (ignoreWhitespace)
    reader = WhitespaceReader.appendTo(reader);

  return new XmlFormImpl(element, writer, reader);
}
 
Example #2
Source File: SchemaTreeTraverser.java    From jolie with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Creates node for element declaration with additional attributes.
 *
 * @param decl      Element declaration.
 * @param extraAtts Additional attributes.
 */
private void elementDecl(XSElementDecl decl, String extraAtts) {
    XSType type = decl.getType();

    // TODO: various other attributes

    String str = MessageFormat.format("Element name=\"{0}\"{1}{2}",
            new Object[]{
                decl.getName(),
                type.isLocal() ? "" : " type=\"{"
            + type.getTargetNamespace() + "}"
            + type.getName() + "\"", extraAtts});

    SchemaTreeNode newNode = new SchemaTreeNode(str, decl.getLocator());
    this.currNode.add(newNode);
    this.currNode = newNode;

    if (type.isLocal()) {
        if (type.isLocal()) {
            type.visit(this);
        }
    }

    this.currNode = (SchemaTreeNode) this.currNode.getParent();
}
 
Example #3
Source File: SchemaWriter.java    From jolie with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void elementDecl( XSElementDecl decl, String extraAtts ) {
    XSType type = decl.getType();
    
    // TODO: various other attributes 
    
    println(MessageFormat.format("<element name=\"{0}\"{1}{2}{3}>",
        new Object[]{
            decl.getName(),
            type.isLocal()?"":" type=\"{"+
                type.getTargetNamespace()+'}'+
                type.getName()+'\"',
            extraAtts,
            type.isLocal()?"":"/"
        }));

    if(type.isLocal()) {
        indent++;

        if(type.isLocal())  type.visit(this);

        indent--;
        println("</element>");
    }
}
 
Example #4
Source File: XsdToJolieConverterImpl.java    From jolie with GNU Lesser General Public License v2.1 6 votes vote down vote up
private TypeDefinition createSimpleType( XSType type, XSElementDecl element, Range range ) {
	checkType( type );
	TypeInlineDefinition right = new TypeInlineDefinition( PARSING_CONTEXT, element.getName().replace( "-", "_" ),
		XsdUtils.xsdToNativeType( type.getName() ), range );
	if( element.isNillable() ) {
		TypeInlineDefinition left =
			new TypeInlineDefinition( PARSING_CONTEXT, element.getName().replace( "-", "_" ),
				NativeType.VOID, range );
		return new TypeChoiceDefinition( PARSING_CONTEXT, element.getName().replace( "-", "_" ), range, left,
			right );
	} else {
		return right;
	}



}
 
Example #5
Source File: SoapProtocol.java    From jolie with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void groupProcessing(
	Value value,
	XSElementDecl xsDecl,
	SOAPElement element,
	SOAPEnvelope envelope,
	boolean first,
	XSModelGroup modelGroup,
	XSSchemaSet sSet,
	String messageNamespace )
	throws SOAPException {

	XSParticle[] children = modelGroup.getChildren();
	XSTerm currTerm;
	for( XSParticle child : children ) {
		currTerm = child.getTerm();
		if( currTerm.isModelGroup() ) {
			groupProcessing( value, xsDecl, element, envelope, first, currTerm.asModelGroup(), sSet,
				messageNamespace );
		} else {
			termProcessing( value, element, envelope, first, currTerm, child.getMaxOccurs(), sSet,
				messageNamespace );
		}
	}
}
 
Example #6
Source File: SchemaTreeTraverser.java    From jolie with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void schema(XSSchema s) {
    // QUICK HACK: don't print the built-in components
    if (s.getTargetNamespace().equals(Const.schemaNamespace)) {
        return;
    }

    SchemaTreeNode newNode = new SchemaTreeNode("Schema "
            + s.getLocator().getSystemId(), s.getLocator());
    this.currNode = newNode;
    this.model.addSchemaNode(newNode);

    for (XSAttGroupDecl groupDecl : s.getAttGroupDecls().values()) {
        attGroupDecl(groupDecl);
    }

    for (XSAttributeDecl attrDecl : s.getAttributeDecls().values()) {
        attributeDecl(attrDecl);
    }

    for (XSComplexType complexType : s.getComplexTypes().values()) {
        complexType(complexType);
    }

    for (XSElementDecl elementDecl : s.getElementDecls().values()) {
        elementDecl(elementDecl);
    }

    for (XSModelGroupDecl modelGroupDecl : s.getModelGroupDecls().values()) {
        modelGroupDecl(modelGroupDecl);
    }

    for (XSSimpleType simpleType : s.getSimpleTypes().values()) {
        simpleType(simpleType);
    }
}
 
Example #7
Source File: XsdToJolieConverterImpl.java    From jolie with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Emit an alert in case we find a "default" or "fixed" attribute
 */
private void checkDefaultAndFixed( XSElementDecl element ) {
	if( element.getDefaultValue() != null ) {
		log( Level.WARNING, WARNING_DEFAULT_ATTRIBUTE + " Element: " + element.getName() );
	}

	if( element.getFixedValue() != null ) {
		log( Level.WARNING, WARNING_FIXED_ATTRIBUTE + " Element: " + element.getName() );
	}

}
 
Example #8
Source File: SoapProtocol.java    From jolie with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void termProcessing( Value value, SOAPElement element, SOAPEnvelope envelope, boolean first,
	XSTerm currTerm, int getMaxOccur,
	XSSchemaSet sSet, String messageNamespace )
	throws SOAPException {
	Value currValue = value.clone();
	if( currTerm.isElementDecl() ) {
		ValueVector vec;
		XSElementDecl currElementDecl = currTerm.asElementDecl();
		String name = currElementDecl.getName();
		String prefix = (first) ? getPrefix( currElementDecl ) : getPrefixOrNull( currElementDecl );
		SOAPElement childElement;
		if( (vec = currValue.children().get( name )) != null ) {
			int k = 0;
			while( vec.size() > 0 && (getMaxOccur > k || getMaxOccur == XSParticle.UNBOUNDED) ) {
				if( prefix == null ) {
					childElement = element.addChildElement( name );
				} else {
					childElement = element.addChildElement( name, prefix );
				}
				Value v = vec.remove( 0 );
				valueToTypedSOAP(
					v,
					currElementDecl,
					childElement,
					envelope,
					false,
					sSet,
					messageNamespace );
				k++;
			}
		}
	}

}
 
Example #9
Source File: SchemaSetImpl.java    From jolie with GNU Lesser General Public License v2.1 5 votes vote down vote up
public Iterator<XSElementDecl> iterateElementDecls() {
    return new Iterators.Map<XSElementDecl,XSSchema>(iterateSchema()) {
        protected Iterator<XSElementDecl> apply(XSSchema u) {
            return u.iterateElementDecls();
        }
    };
}
 
Example #10
Source File: ElementDecl.java    From jolie with GNU Lesser General Public License v2.1 5 votes vote down vote up
public Set<? extends XSElementDecl> getSubstitutables() {
    if( substitutables==null ) {
        // if the field is null by the time this method
        // is called, it means this element is substitutable by itself only.
        substitutables = substitutablesView = Collections.singleton((XSElementDecl)this);
    }
    return substitutablesView;
}
 
Example #11
Source File: ElementDecl.java    From jolie with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected void addSubstitutable( ElementDecl decl ) {
    if( substitutables==null ) {
        substitutables = new HashSet<XSElementDecl>();
        substitutables.add(this);
        substitutablesView = Collections.unmodifiableSet(substitutables);
    }
    substitutables.add(decl);
}
 
Example #12
Source File: XmlFormBuilder.java    From dynaform with Artistic License 2.0 5 votes vote down vote up
private Map<String, XmlForm> parse(XSSchemaSet set) {
  Map<String, XmlForm> result = new HashMap<String, XmlForm>();
  
  /*
   * Accepts all element declarations in the Schema set
   */
  for (Iterator<XSElementDecl> elements = set.iterateElementDecls(); elements.hasNext();) {
    XSElementDecl decl = elements.next();
    XmlForm xmlForm = decl.apply(this);
    if (xmlForm != null)
      result.put(decl.getName(), xmlForm);
  }
  return result;
}
 
Example #13
Source File: Axis.java    From jolie with GNU Lesser General Public License v2.1 5 votes vote down vote up
public Iterator<XSComponent> elementDecl(XSElementDecl decl) {
    XSComplexType ct = decl.getType().asComplexType();
    if(ct==null)
        return empty();
    else {
        // also pick up model groups inside this complex type
        return new Iterators.Union<XSComponent>(singleton(ct),complexType(ct));
    }
}
 
Example #14
Source File: XmlFormBuilder.java    From dynaform with Artistic License 2.0 5 votes vote down vote up
public XmlForm elementDecl(XSElementDecl decl) {
  if (log.isDebugEnabled())
    log.debug("Element Declaration: " + decl);
    
  XSType type = decl.getType();
  
  if (type.isSimpleType())
    return elementDeclSimple(decl, type.asSimpleType());
  else
    return elementDeclComplex(decl, type.asComplexType());
}
 
Example #15
Source File: FindXSElementDeclVisitor.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void elementDecl(XSElementDecl decl) {
	final QName declName = StringUtils.isEmpty(decl.getTargetNamespace()) ? new QName(
			decl.getName()) : new QName(decl.getTargetNamespace(),
			decl.getName());
	if (this.name.equals(declName)) {
		this.elementDecl = decl;
	}
}
 
Example #16
Source File: XsdParser.java    From jumbune with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * @param schema
 */
public XsdParser(File schema) {
	this.schema = schema;

	globalelements = new HashSet<XSElementDecl>();
	childelements = new HashSet<XSElementDecl>();
}
 
Example #17
Source File: GroupInterfaceGenerator.java    From jaxb2-rich-contract-plugin with MIT License 5 votes vote down vote up
private static XSComplexType getTypeDefinition(final XSComponent xsTypeComponent) {
	if (xsTypeComponent instanceof XSAttContainer) {
		return (XSComplexType) xsTypeComponent;
	} else if (xsTypeComponent instanceof XSElementDecl) {
		return ((XSElementDecl) xsTypeComponent).getType().asComplexType();
	} else {
		return null;
	}
}
 
Example #18
Source File: GroupInterfaceGenerator.java    From jaxb2-rich-contract-plugin with MIT License 5 votes vote down vote up
private List<PropertyUse> findElementDecls(final XSModelGroupDecl modelGroup) {
	final List<PropertyUse> elementDecls = new ArrayList<>();
	for (final XSParticle child : modelGroup.getModelGroup()) {
		XSTerm term = child.getTerm();
		if (term instanceof XSElementDecl) {
			elementDecls.add(new PropertyUse(term));
		} else if (term instanceof XSModelGroupDecl && ((XSModelGroupDecl)term).getName().equals(modelGroup.getName())) {
			elementDecls.addAll(findElementDecls((XSModelGroupDecl)term));
		}
	}
	return elementDecls;
}
 
Example #19
Source File: MetaPlugin.java    From jaxb2-rich-contract-plugin with MIT License 5 votes vote down vote up
@Override
public QName elementDecl(final XSElementDecl decl) {
	if (decl.getType().getName() == null) {
		return new QName(decl.getType().getTargetNamespace(), "anononymousElementType");
	} else {
		return new QName(decl.getType().getTargetNamespace(), decl.getType().getName());
	}
}
 
Example #20
Source File: ElementDecl.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
public QName getRootSubsitutionGroup() {
	XSElementDecl tmp = element;
	XSElementDecl head = null;

	while ((tmp = tmp.getSubstAffiliation()) != null)
		head = tmp;

	return (head != null) ? new QName(head.getTargetNamespace(), head.getName()) : null;
}
 
Example #21
Source File: ElementDecl.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
public boolean substitutes(String namespaceURI, String localName) {
	XSElementDecl tmp = element;

	while ((tmp = tmp.getSubstAffiliation()) != null) {
		if (namespaceURI.equals(tmp.getTargetNamespace()) && 
				localName.equals(tmp.getName()))
			return true;
	}

	return false;
}
 
Example #22
Source File: ElementDecl.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
List<XSElementDecl> getChildElements() {
	final List<XSElementDecl> childs = new ArrayList<XSElementDecl>();
	SchemaWalker schemaWalker = new SchemaWalker() {

		@Override
		public void elementDecl(XSElementDecl child) {
			childs.add(child);
		}

	};

	element.getType().visit(schemaWalker);
	return childs;
}
 
Example #23
Source File: SchemaWriter.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
public void schema( XSSchema s ) {

		// QUICK HACK: don't print the built-in components
		if(s.getTargetNamespace().equals(Const.schemaNamespace))
			return;

		println(MessageFormat.format("<schema targetNamespace=\"{0}\">", s.getTargetNamespace()));
		indent++;

		Iterator<?> itr;

		itr = s.iterateAttGroupDecls();
		while(itr.hasNext())
			attGroupDecl( (XSAttGroupDecl)itr.next() );

		itr = s.iterateAttributeDecls();
		while(itr.hasNext())
			attributeDecl( (XSAttributeDecl)itr.next() );

		itr = s.iterateComplexTypes();
		while(itr.hasNext())
			complexType( (XSComplexType)itr.next() );

		itr = s.iterateElementDecls();
		while(itr.hasNext())
			elementDecl( (XSElementDecl)itr.next() );

		itr = s.iterateModelGroupDecls();
		while(itr.hasNext())
			modelGroupDecl( (XSModelGroupDecl)itr.next() );

		itr = s.iterateSimpleTypes();
		while(itr.hasNext())
			simpleType( (XSSimpleType)itr.next() );

		indent--;
		println("</schema>");
	}
 
Example #24
Source File: MetaPlugin.java    From jaxb2-rich-contract-plugin with MIT License 4 votes vote down vote up
@Override
public Boolean elementDecl(final XSElementDecl decl) {
	return false;
}
 
Example #25
Source File: CollectEnumerationValuesVisitor.java    From jsonix-schema-compiler with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void elementDecl(XSElementDecl decl) {
	decl.getType().visit(this);
}
 
Example #26
Source File: XSFunctionFilter.java    From jolie with GNU Lesser General Public License v2.1 4 votes vote down vote up
public T elementDecl(XSElementDecl decl) {
    return core.elementDecl(decl);
}
 
Example #27
Source File: MetaPlugin.java    From jaxb2-rich-contract-plugin with MIT License 4 votes vote down vote up
@Override
public QName elementDecl(final XSElementDecl decl) {
	return new QName(decl.getTargetNamespace(), decl.getName());
}
 
Example #28
Source File: NameGetter.java    From jolie with GNU Lesser General Public License v2.1 4 votes vote down vote up
public String elementDecl(XSElementDecl decl) {
    return localize("elementDecl");
}
 
Example #29
Source File: ComponentNameFunction.java    From jolie with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * @see com.sun.xml.xsom.visitor.XSTermFunction#elementDecl(XSElementDecl)
 */
public String elementDecl(XSElementDecl decl) {
    String name = decl.getName();
    if( name == null ) name = "";
    return name + " " + nameGetter.elementDecl( decl );
}
 
Example #30
Source File: JumbuneSchemaWriter.java    From jumbune with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void schema( XSSchema s) {
	
	if(this.elementsMap.size() != 0){

	StringBuffer sb = new StringBuffer();
     
     for(String prefix : uriMapping.keySet()){
    	 
    	 String uri = uriMapping.get(prefix);
    	 if(Const.schemaNamespace.equalsIgnoreCase(uri)) rootPrefix = prefix+":";
    	 sb.append("xmlns:"+prefix+"=\""+uri+"\" " );
    	 
     }
     
     if(!s.getTargetNamespace().isEmpty()){
    	 println(MessageFormat.format("<schema {0} targetNamespace=\"{1}\">",sb.toString(),s.getTargetNamespace()));
     }else{
    	 println(MessageFormat.format("<schema {0} >",sb.toString()));
     }
     
      indent++;

      Iterator<XSAttGroupDecl> itrAGD = s.iterateAttGroupDecls();
      while (itrAGD.hasNext()) {
    	  attGroupDecl(itrAGD.next());
      }

      Iterator<XSAttributeDecl> itrAD = s.iterateAttributeDecls();
      while(itrAD.hasNext()) {
    	  attributeDecl(itrAD.next());
      }

      Iterator<XSComplexType> itrCT = s.iterateComplexTypes();
      while(itrCT.hasNext()) {
    	  complexType(itrCT.next());
      }
      
      Iterator<XSElementDecl> itrED = s.iterateElementDecls();
      while(itrED.hasNext()) {
    	  elementDecl(itrED.next());
      } 
      
      Iterator<XSModelGroupDecl> itrMGD = s.iterateModelGroupDecls();
      while(itrMGD.hasNext()) {
    	  modelGroupDecl(itrMGD.next()); 
      }

      Iterator<XSSimpleType> itrST = s.iterateSimpleTypes();
      while(itrST.hasNext()) {
    	  simpleType(itrST.next());
      }

      indent--;
      println("</schema>");
	}
	//}

   
}