com.sun.xml.xsom.XSAttributeUse Java Examples

The following examples show how to use com.sun.xml.xsom.XSAttributeUse. 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: ComplexTypeImpl.java    From jolie with GNU Lesser General Public License v2.1 6 votes vote down vote up
public Iterator<XSAttributeUse> iterateAttributeUses() {
    
    XSComplexType baseType = getBaseType().asComplexType();
    
    if( baseType==null )    return super.iterateAttributeUses();
    
    return new Iterators.Union<XSAttributeUse>(
        new Iterators.Filter<XSAttributeUse>(baseType.iterateAttributeUses()) {
            protected boolean matches(XSAttributeUse value) {
                XSAttributeDecl u = value.getDecl();
                UName n = new UName(u.getTargetNamespace(),u.getName());
                return !prohibitedAtts.contains(n);
            }
        },
        super.iterateAttributeUses() );
}
 
Example #2
Source File: XmlFormBuilder.java    From dynaform with Artistic License 2.0 6 votes vote down vote up
public XmlForm attributeUse(XSAttributeUse use) {
  boolean required = use.isRequired();
  
  if (log.isDebugEnabled())
    log.debug("Attribute Use: " + use +
        ", Required: " + required);
  
  XSAttributeDecl decl = use.getDecl();

  XmlForm xmlForm = decl.apply(this);

  if (required) {
    Form form = xmlForm.getForm();
    if (form instanceof FormElement<?>)
      ((FormElement<?>) form).setRequired(true);
  }
  
  return xmlForm;
}
 
Example #3
Source File: SchemaWriter.java    From citygml4j with Apache License 2.0 6 votes vote down vote up
public void attributeUse( XSAttributeUse use ) {
	XSAttributeDecl decl = use.getDecl();

	String additionalAtts="";

	if(use.isRequired())
		additionalAtts += " use=\"required\"";
	if(use.getFixedValue()!=null && use.getDecl().getFixedValue()==null)
		additionalAtts += " fixed=\""+use.getFixedValue()+'\"';
	if(use.getDefaultValue()!=null && use.getDecl().getDefaultValue()==null)
		additionalAtts += " default=\""+use.getDefaultValue()+'\"';

	if(decl.isLocal()) {
		// this is anonymous attribute use
		dump(decl,additionalAtts);
	} else {
		// reference to a global one
		println(MessageFormat.format("<attribute ref=\"'{'{0}'}'{1}{2}\"/>",
				decl.getTargetNamespace(), decl.getName(), additionalAtts));
	}
}
 
Example #4
Source File: SchemaWriter.java    From citygml4j with Apache License 2.0 6 votes vote down vote up
public void attGroupDecl( XSAttGroupDecl decl ) {
	Iterator<?> itr;

	println(MessageFormat.format("<attributeGroup name=\"{0}\">", decl.getName()));
	indent++;

	// TODO: wildcard

	itr = decl.iterateAttGroups();
	while(itr.hasNext())
		dumpRef( (XSAttGroupDecl)itr.next() );

	itr = decl.iterateDeclaredAttributeUses();
	while(itr.hasNext())
		attributeUse( (XSAttributeUse)itr.next() );

	indent--;
	println("</attributeGroup>");
}
 
Example #5
Source File: JumbuneSchemaWriter.java    From jumbune with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void attributeUse( XSAttributeUse use ) {
    XSAttributeDecl decl = use.getDecl();

    String additionalAtts="";

    if(use.isRequired())
        additionalAtts += " use=\"required\"";
    if(use.getFixedValue()!=null && use.getDecl().getFixedValue()==null)
        additionalAtts += " fixed=\""+use.getFixedValue()+'\"';
    if(use.getDefaultValue()!=null && use.getDecl().getDefaultValue()==null)
        additionalAtts += " default=\""+use.getDefaultValue()+'\"';

    if(decl.isLocal()) {
        // this is anonymous attribute use
        dump(decl,additionalAtts);
    } else {
        // reference to a global one
        println(MessageFormat.format("<attribute ref=\"{0}{1}\"{2}/>",
            decl.getTargetNamespace(), decl.getName(), additionalAtts));
    }
}
 
Example #6
Source File: JumbuneSchemaWriter.java    From jumbune with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void attGroupDecl( XSAttGroupDecl decl ) {
    Iterator<?> itr;

    println(MessageFormat.format("<attGroup name=\"{0}\">", decl.getName()));
    indent++;
    
    // TODO: wildcard
    
    itr = decl.iterateAttGroups();
    while(itr.hasNext())
        dumpRef( (XSAttGroupDecl)itr.next() );

    itr = decl.iterateDeclaredAttributeUses();
    while(itr.hasNext())
        attributeUse( (XSAttributeUse)itr.next() );

    indent--;
    println("</attGroup>");
}
 
Example #7
Source File: ComplexTypeImpl.java    From jolie with GNU Lesser General Public License v2.1 6 votes vote down vote up
public XSAttributeUse getAttributeUse( String nsURI, String localName ) {
    UName name = new UName(nsURI,localName);
    
    if(prohibitedAtts.contains(name))       return null;
    
    XSAttributeUse o = attributes.get(name);
    
    
    if(o==null) {
        Iterator<XSAttGroupDecl> itr = iterateAttGroups();
        while(itr.hasNext() && o==null)
            o = itr.next().getAttributeUse(nsURI,localName);
    }
    
    if(o==null) {
        XSType base = getBaseType();
        if(base.asComplexType()!=null)
            o = base.asComplexType().getAttributeUse(nsURI,localName);
    }
    
    return o;
}
 
Example #8
Source File: SchemaWriter.java    From jolie with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void attributeUse( XSAttributeUse use ) {
    XSAttributeDecl decl = use.getDecl();

    String additionalAtts="";

    if(use.isRequired())
        additionalAtts += " use=\"required\"";
    if(use.getFixedValue()!=null && use.getDecl().getFixedValue()==null)
        additionalAtts += " fixed=\""+use.getFixedValue()+'\"';
    if(use.getDefaultValue()!=null && use.getDecl().getDefaultValue()==null)
        additionalAtts += " default=\""+use.getDefaultValue()+'\"';

    if(decl.isLocal()) {
        // this is anonymous attribute use
        dump(decl,additionalAtts);
    } else {
        // reference to a global one
        println(MessageFormat.format("<attribute ref=\"'{'{0}'}'{1}{2}\"/>",
            new Object[]{ decl.getTargetNamespace(), decl.getName(),
                additionalAtts }));
    }
}
 
Example #9
Source File: SchemaWriter.java    From jolie with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void attGroupDecl( XSAttGroupDecl decl ) {
    Iterator itr;

    println(MessageFormat.format("<attGroup name=\"{0}\">",
        new Object[]{ decl.getName() }));
    indent++;
    
    // TODO: wildcard
    
    itr = decl.iterateAttGroups();
    while(itr.hasNext())
        dumpRef( (XSAttGroupDecl)itr.next() );

    itr = decl.iterateDeclaredAttributeUses();
    while(itr.hasNext())
        attributeUse( (XSAttributeUse)itr.next() );

    indent--;
    println("</attGroup>");
}
 
Example #10
Source File: SchemaTreeTraverser.java    From jolie with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void attGroupDecl(XSAttGroupDecl decl) {
    SchemaTreeNode newNode = new SchemaTreeNode("Attribute group \""
            + decl.getName() + "\"", decl.getLocator());
    this.currNode.add(newNode);
    this.currNode = newNode;

    Iterator itr;

    itr = decl.iterateAttGroups();
    while (itr.hasNext()) {
        dumpRef((XSAttGroupDecl) itr.next());
    }

    itr = decl.iterateDeclaredAttributeUses();
    while (itr.hasNext()) {
        attributeUse((XSAttributeUse) itr.next());
    }

    this.currNode = (SchemaTreeNode) this.currNode.getParent();
}
 
Example #11
Source File: XJCCMInfoFactory.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private XSAttributeUse getAttributeUse(CAttributePropertyInfo propertyInfo) {
	final XSComponent schemaComponent = propertyInfo.getSchemaComponent();
	if (schemaComponent instanceof XSAttributeUse) {
		return (XSAttributeUse) schemaComponent;
	} else {
		return null;
	}
}
 
Example #12
Source File: SchemaWalker.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
public void complexType(XSComplexType type) {
	if (shouldWalk && visited.add(type.getContentType())) {
		type.getContentType().visit(this);
		for (XSAttributeUse u : type.getAttributeUses())
			if (shouldWalk && visited.add(u))
				attributeUse(u);
	}
}
 
Example #13
Source File: MetaPlugin.java    From jaxb2-rich-contract-plugin with MIT License 5 votes vote down vote up
private String getConstantName(final FieldOutline fieldOutline) {
	final XSComponent schemaComponent = fieldOutline.getPropertyInfo().getSchemaComponent();
	if (!this.fixedAttributeAsConstantProperty) return null;
	if (schemaComponent instanceof XSAttributeDecl) {
		return ((XSAttributeDecl)schemaComponent).getFixedValue() != null ? fieldOutline.parent().parent().getModel().getNameConverter().toConstantName(((XSAttributeDecl)schemaComponent).getName()) : null;
	} else {
		return schemaComponent instanceof XSAttributeUse && ((XSAttributeUse)schemaComponent).getFixedValue() != null ? fieldOutline.parent().parent().getModel().getNameConverter().toConstantName(((XSAttributeUse)schemaComponent).getDecl().getName()) : null;
	}
}
 
Example #14
Source File: GroupInterfaceGenerator.java    From jaxb2-rich-contract-plugin with MIT License 5 votes vote down vote up
private List<PropertyUse> findAttributeDecls(final XSAttGroupDecl attGroupDecl) {
	final List<PropertyUse> attributeDecls = new ArrayList<>();
	for (final XSAttributeUse child : attGroupDecl.getDeclaredAttributeUses()) {
		attributeDecls.add(new PropertyUse(child));
	}
	return attributeDecls;
}
 
Example #15
Source File: JumbuneSchemaWriter.java    From jumbune with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void dumpComplexTypeAttribute( XSComplexType type ) {
    Iterator<?> itr;

    itr = type.iterateAttGroups();
    while(itr.hasNext())
        dumpRef( (XSAttGroupDecl)itr.next() );

    itr = type.iterateDeclaredAttributeUses();
    while(itr.hasNext())
        attributeUse( (XSAttributeUse)itr.next() );

    XSWildcard awc = type.getAttributeWildcard();
    if(awc!=null)
        wildcard("anyAttribute",awc,"");
}
 
Example #16
Source File: XJCCMInfoFactory.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected NamespaceContext getDefaultValueNamespaceContext(
		CAttributePropertyInfo propertyInfo) {
	final XSAttributeUse attributeUse = getAttributeUse(propertyInfo);
	if (attributeUse != null) {
		final XmlString defaultValue = attributeUse.getDefaultValue();
		if (defaultValue != null) {
			return new NamespaceContextAdapter(defaultValue);
		}
	}
	return null;

}
 
Example #17
Source File: XJCCMInfoFactory.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected String getDefaultValue(CAttributePropertyInfo propertyInfo) {

		final XSAttributeUse attributeUse = getAttributeUse(propertyInfo);
		if (attributeUse != null) {
			final XmlString defaultValue = attributeUse.getDefaultValue();
			if (defaultValue != null) {
				return defaultValue.value;
			}
		}
		return null;
	}
 
Example #18
Source File: XmlUtils.java    From jolie with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void _valueToDocument( Value value, Element element, Document doc, XSType type ) {
	addForcedAttribute( value, element );
	if( type.isSimpleType() ) {
		element.appendChild( doc.createTextNode( value.strValue() ) );
	} else if( type.isComplexType() ) {
		String name;
		Value currValue;
		XSComplexType complexType = type.asComplexType();

		// Iterate over attributes
		Collection< ? extends XSAttributeUse > attributeUses = complexType.getAttributeUses();
		for( XSAttributeUse attrUse : attributeUses ) {
			name = attrUse.getDecl().getName();
			if( (currValue = getAttributeOrNull( value, name )) != null ) {
				element.setAttribute( name, currValue.strValue() );
			}
		}

		XSContentType contentType = complexType.getContentType();
		XSParticle particle = contentType.asParticle();
		if( contentType.asSimpleType() != null ) {
			element.appendChild( doc.createTextNode( value.strValue() ) );
		} else if( particle != null ) {
			XSTerm term = particle.getTerm();
			XSModelGroupDecl modelGroupDecl;
			XSModelGroup modelGroup = null;
			if( (modelGroupDecl = term.asModelGroupDecl()) != null ) {
				modelGroup = modelGroupDecl.getModelGroup();
			} else if( term.isModelGroup() ) {
				modelGroup = term.asModelGroup();
			}
			if( modelGroup != null ) {
				_valueToDocument( value, element, doc, modelGroup );
			}
		}
	}
}
 
Example #19
Source File: Axis.java    From jolie with GNU Lesser General Public License v2.1 5 votes vote down vote up
private Iterator<XSAttributeDecl> attributeHolder(final XSAttContainer atts) {
    // TODO: check spec. is this correct?
    return new Iterators.Adapter<XSAttributeDecl,XSAttributeUse>(atts.iterateAttributeUses()) {
        protected XSAttributeDecl filter(XSAttributeUse u) {
            return u.getDecl();
        }
    };
}
 
Example #20
Source File: SchemaWriter.java    From jolie with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void dumpComplexTypeAttribute( XSComplexType type ) {
    Iterator itr;

    itr = type.iterateAttGroups();
    while(itr.hasNext())
        dumpRef( (XSAttGroupDecl)itr.next() );

    itr = type.iterateDeclaredAttributeUses();
    while(itr.hasNext())
        attributeUse( (XSAttributeUse)itr.next() );
}
 
Example #21
Source File: SchemaTreeTraverser.java    From jolie with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Creates node for complex type.
 *
 * @param type Complex type.
 */
private void dumpComplexTypeAttribute(XSComplexType type) {
    Iterator itr;

    itr = type.iterateAttGroups();
    while (itr.hasNext()) {
        dumpRef((XSAttGroupDecl) itr.next());
    }

    itr = type.iterateDeclaredAttributeUses();
    while (itr.hasNext()) {
        attributeUse((XSAttributeUse) itr.next());
    }
}
 
Example #22
Source File: AttributesHolder.java    From jolie with GNU Lesser General Public License v2.1 5 votes vote down vote up
public List<XSAttributeUse> getAttributeUses() {
    // TODO: this is fairly inefficient
    List<XSAttributeUse> v = new ArrayList<XSAttributeUse>();
    v.addAll(attributes.values());
    for( XSAttGroupDecl agd : getAttGroups() )
        v.addAll(agd.getAttributeUses());
    return v;
}
 
Example #23
Source File: SchemaTreeTraverser.java    From jolie with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void attributeUse(XSAttributeUse use) {
    XSAttributeDecl decl = use.getDecl();

    String additionalAtts = "";

    if (use.isRequired()) {
        additionalAtts += " use=\"required\"";
    }
    if (use.getFixedValue() != null
            && use.getDecl().getFixedValue() == null) {
        additionalAtts += " fixed=\"" + use.getFixedValue() + "\"";
    }
    if (use.getDefaultValue() != null
            && use.getDecl().getDefaultValue() == null) {
        additionalAtts += " default=\"" + use.getDefaultValue() + "\"";
    }

    if (decl.isLocal()) {
        // this is anonymous attribute use
        dump(decl, additionalAtts);
    }
    else {
        // reference to a global one
        String str = MessageFormat.format(
                "Attribute ref \"'{'{0}'}'{1}{2}\"", new Object[]{
                    decl.getTargetNamespace(), decl.getName(),
                    additionalAtts});
        SchemaTreeNode newNode = new SchemaTreeNode(str, decl.getLocator());
        this.currNode.add(newNode);
    }
}
 
Example #24
Source File: SchemaWriter.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
private void dumpComplexTypeAttribute( XSComplexType type ) {
	Iterator<?> itr;

	itr = type.iterateAttGroups();
	while(itr.hasNext())
		dumpRef( (XSAttGroupDecl)itr.next() );

	itr = type.iterateDeclaredAttributeUses();
	while(itr.hasNext())
		attributeUse( (XSAttributeUse)itr.next() );

	XSWildcard awc = type.getAttributeWildcard();
	if(awc!=null)
		wildcard("anyAttribute",awc,"");
}
 
Example #25
Source File: XmlFormBuilder.java    From dynaform with Artistic License 2.0 5 votes vote down vote up
private void attributes(List<Form> forms,
    Map<String, TextWriter> attrWriters,
    Map<String, TextHandler> attrReaders,
    Collection<? extends XSAttributeUse> attrs) {
  
  for (XSAttributeUse use : attrs) {
    XmlForm xmlForm = use.apply(this);
    if (xmlForm != null) {
      XSAttributeDecl attr = use.getDecl();
      String name = attr.getName();

      Form form = xmlForm.getForm();
      if (form != null)
        forms.add(form);

      XmlWriter writer = xmlForm.getWriter();
      if (writer instanceof TextXmlWriter) {
        TextWriter textWriter = ((TextXmlWriter) writer).getWriter();
        attrWriters.put(name, textWriter);
      }
      
      XmlReader reader = xmlForm.getReader();
      TextHandler handler = null;
      if (reader instanceof TextXmlReader) {
        TextXmlReader textXmlReader = (TextXmlReader) reader;
        handler = textXmlReader.getHandler();
      } else if (reader != null)
        throw new IllegalStateException("XmlReader " + reader + " cannot be assigned to an XML attribtue, TextXmlReader expected");
      if (handler != null)
        attrReaders.put(name, handler);
    }
  }
}
 
Example #26
Source File: AttGroupDeclImpl.java    From jolie with GNU Lesser General Public License v2.1 5 votes vote down vote up
public XSAttributeUse getAttributeUse( String nsURI, String localName ) {
    UName name = new UName(nsURI,localName);
    XSAttributeUse o=null;
    
    Iterator<XSAttGroupDecl> itr = iterateAttGroups();
    while(itr.hasNext() && o==null)
        o = itr.next().getAttributeUse(nsURI,localName);
    
    if(o==null)     o = attributes.get(name);
    
    return o;
}
 
Example #27
Source File: ParticleMultiplicityCounter.java    From jsonix-schema-compiler with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public Multiplicity attributeUse(XSAttributeUse use) {
	return use.isRequired() ? Multiplicity.ONE : Multiplicity.OPTIONAL;
}
 
Example #28
Source File: GroupInterfaceGenerator.java    From jaxb2-rich-contract-plugin with MIT License 4 votes vote down vote up
@Override
public Boolean attributeUse(final XSAttributeUse use) {
	return use.getFixedValue() != null || use.getDecl().getFixedValue() != null;
}
 
Example #29
Source File: GroupInterfaceGenerator.java    From jaxb2-rich-contract-plugin with MIT License 4 votes vote down vote up
@Override
public String attributeUse(final XSAttributeUse use) {
	String customName = getCustomPropertyName(use);
	customName = customName == null ? getCustomPropertyName(use.getDecl()) : customName;
	return customName == null ? GroupInterfaceGenerator.this.pluginContext.outline.getModel().getNameConverter().toPropertyName(use.getDecl().getName()) : customName;
}
 
Example #30
Source File: MetaPlugin.java    From jaxb2-rich-contract-plugin with MIT License 4 votes vote down vote up
@Override
public QName attributeUse(final XSAttributeUse use) {
	return new QName(use.getDecl().getTargetNamespace(), use.getDecl().getName());
}