public XPsviGmlPropertyDefinition(GmlSchemaParser model, XSParticle particle) { this.model = model; this.particle = particle; XSTerm term = particle.getTerm(); if ((term instanceof XSElementDeclaration)) this.element = ((XSElementDeclaration) term); else { throw new IllegalArgumentException( "A property can only be created from an element particle"); } this.type = this.element.getTypeDefinition(); }
private void addChildElementDecls( final XSParticle particle, final List<XSTerm> propDecls ) { if ( particle != null ) { final XSTerm term = particle.getTerm(); if ( term instanceof XSModelGroup ) { final XSObjectList particles = ( (XSModelGroup) term ).getParticles(); for ( int i = 0; i < particles.getLength(); i++ ) { addChildElementDecls( (XSParticle) particles.item( i ), propDecls ); } } else if ( term instanceof XSWildcard || term instanceof XSElementDeclaration ) { propDecls.add( term ); } else { throw new RuntimeException( "Unhandled term type: " + term.getClass() ); } } }
private List<XSParticle> getAllElementParticles( XSParticle particle ) { List<XSParticle> particles = new ArrayList<XSParticle>(); XSTerm xsTerm = particle.getTerm(); switch ( xsTerm.getType() ) { case XSConstants.ELEMENT_DECLARATION: particles.add( particle ); break; case XSConstants.MODEL_GROUP: XSModelGroup group = (XSModelGroup) xsTerm; for ( Iterator<XSParticle> itr = group.getParticles().iterator(); itr.hasNext(); ) { XSParticle xsParticle = itr.next(); particles.addAll( getAllElementParticles( xsParticle ) ); } break; default: // ignore wildcard term } return particles; }
private void getPropertyDecls( XSParticle particle, List<XSElementDeclaration> propertyDecls ) { if ( particle != null ) { XSTerm term = particle.getTerm(); if ( term instanceof XSElementDeclaration ) { propertyDecls.add( (XSElementDeclaration) term ); } else if ( term instanceof XSModelGroup ) { XSObjectList particles = ( (XSModelGroup) term ).getParticles(); for ( int i = 0; i < particles.getLength(); i++ ) { getPropertyDecls( (XSParticle) particles.item( i ), propertyDecls ); } } else { LOG.warn( "Unhandled term type: " + term.getClass() ); } } }
private Pair<XSElementDeclaration, Boolean> getTargetElement( Pair<XSElementDeclaration, Boolean> context, QName elName, int num ) { XSTypeDefinition typeDef = context.getFirst().getTypeDefinition(); if ( !( typeDef instanceof XSComplexTypeDefinition ) ) { throw new IllegalArgumentException( "XPath refers to a simple type definition." ); } XSParticle particle = ( (XSComplexTypeDefinition) typeDef ).getParticle(); if ( particle == null ) { throw new IllegalArgumentException( "XPath refers to an empty type definition." ); } return getTargetElementTerm( new Pair<XSTerm, Boolean>( particle.getTerm(), null ), elName, num ); }
private void expandRelatedParticleComponents(XSParticle component, Vector componentList, String namespace, Hashtable dependencies) { XSTerm term = component.getTerm(); switch (term.getType()) { case XSConstants.ELEMENT_DECLARATION : addRelatedElement((XSElementDeclaration) term, componentList, namespace, dependencies); break; case XSConstants.MODEL_GROUP : expandRelatedModelGroupComponents((XSModelGroup) term, componentList, namespace, dependencies); break; default: break; } }
private XSParticle getEnclosingParticle( XSElementDeclaration elDecl ) { XSComplexTypeDefinition enclosingDef = elDecl.getEnclosingCTDefinition(); if ( enclosingDef != null ) { List<XSParticle> particles = getAllElementParticles( enclosingDef.getParticle() ); for ( XSParticle xp : particles ) { XSTerm term = xp.getTerm(); if ( term.getType() == ELEMENT_DECLARATION ) { XSElementDeclaration currentElDecl = (XSElementDeclaration) term; if ( elDecl.equals( currentElDecl ) ) { return xp; } } } } return null; }
private void setProperties(List properties, XSParticle particle) { XSTerm term = particle.getTerm(); if ((term instanceof XSElementDeclaration)) { properties .add(new XPsviGmlPropertyDefinition(this.model, particle)); } else if ((term instanceof XSModelGroup)) { XSModelGroup modelGroup = (XSModelGroup) term; XSObjectList particles = modelGroup.getParticles(); for (int i = 0; i < particles.getLength(); i++) setProperties(properties, (XSParticle) particles.item(i)); } }
private boolean isGroupTypeWithMultipleOccurs(XSParticle particle) { if (particle == null) return false; XSTerm term = particle.getTerm(); if (term.getType() != XSConstants.MODEL_GROUP) return false; XSModelGroup group = (XSModelGroup) term; final short compositor = group.getCompositor(); switch(compositor) { case XSModelGroup.COMPOSITOR_CHOICE: case XSModelGroup.COMPOSITOR_SEQUENCE: return particle.getMaxOccurs() > 1 || particle.getMaxOccursUnbounded(); default: return false; } }
private List<Schema.Field> createFields(XSComplexTypeDefinition type) { final Map<String, Schema.Field> fields = new LinkedHashMap<>(); XSObjectList attrUses = type.getAttributeUses(); for (int i = 0; i < attrUses.getLength(); i++) { XSAttributeUse attrUse = (XSAttributeUse) attrUses.item(i); XSAttributeDeclaration attrDecl = attrUse.getAttrDeclaration(); boolean optional = !attrUse.getRequired(); Schema.Field field = createField(fields.values(), attrDecl, attrDecl.getTypeDefinition(), optional, false); fields.put(field.getProp(Source.SOURCE), field); } XSParticle particle = type.getParticle(); if (particle == null) return new ArrayList<>(fields.values()); XSTerm term = particle.getTerm(); if (term.getType() != XSConstants.MODEL_GROUP) throw new ConverterException("Unsupported term type " + term.getType()); XSModelGroup group = (XSModelGroup) term; createGroupFields(group, fields, false); return new ArrayList<>(fields.values()); }
public static XSElementDeclaration unwrapArrayType(XSTypeDefinition xst) { if (xst instanceof XSComplexTypeDefinition == false) return null; XSComplexTypeDefinition xc = (XSComplexTypeDefinition)xst; if (xc.getContentType() == XSComplexTypeDefinition.CONTENTTYPE_EMPTY) return null; XSParticle xsp = xc.getParticle(); if (xsp == null) return null; XSTerm xsterm = xsp.getTerm(); if (xsterm instanceof XSModelGroup == false) return null; XSModelGroup xm = (XSModelGroup)xsterm; XSObjectList xo = xm.getParticles(); if (xo.getLength() != 1) return null; XSParticle xp = (XSParticle)xo.item(0); XSTerm term = xp.getTerm(); if ((xp.getMaxOccursUnbounded() || xp.getMaxOccurs() > 1) == false || term instanceof XSElementDeclaration == false) return null; return (XSElementDeclaration)term; }
private GmlPropertyDefinition getProperty(XSParticle particle, String propertyNamespaceUri, String propertyLocalName) { XSTerm term = particle.getTerm(); if ((term instanceof XSElementDeclaration)) { if ((term.getNamespace().equals(propertyNamespaceUri)) && (term.getName().equals(propertyLocalName))) return new XPsviGmlPropertyDefinition(this.model, particle); } else if ((term instanceof XSModelGroup)) { XSModelGroup modelGroup = (XSModelGroup) term; XSObjectList particles = modelGroup.getParticles(); for (int i = 0; i < particles.getLength(); i++) { GmlPropertyDefinition property = getProperty( (XSParticle) particles.item(i), propertyNamespaceUri, propertyLocalName); if (property != null) { return property; } } } return null; }
private void setPropertyNames(List properties, XSElementDeclaration element, XSParticle particle) { XSTerm term = particle.getTerm(); if ((term instanceof XSElementDeclaration)) { XSElementDeclaration propertyElement = (XSElementDeclaration) term; String namespaceUri = propertyElement.getNamespace(); String localName = propertyElement.getName(); properties.add(new QName(namespaceUri, localName)); } else if ((term instanceof XSModelGroup)) { XSModelGroup modelGroup = (XSModelGroup) term; XSObjectList particles = modelGroup.getParticles(); for (int i = 0; i < particles.getLength(); i++) setPropertyNames(properties, element, (XSParticle) particles.item(i)); } }
private void analyzeParticle(XSParticle particle, String parentName, String namespace) { // Is this right, can a particle be null? if (particle == null) return; XSTerm term = particle.getTerm(); // Is this right, can a term be null? if (term == null) return; switch (term.getType()) { case XSConstants.MODEL_GROUP: XSModelGroup group = (XSModelGroup)term; XSObjectList list = group.getParticles(); for (int i = 0; i < list.getLength(); i++) analyzeParticle((XSParticle)list.item(i), parentName, namespace); break; case XSConstants.ELEMENT_DECLARATION: XSElementDeclaration decl = (XSElementDeclaration)term; analyzeElement(decl, parentName, namespace, new Integer(particle.getMinOccurs()), new Integer(particle.getMaxOccurs())); } }
private void setPropertyNames(List properties, XSElementDeclaration element, XSParticle particle) { XSTerm term = particle.getTerm(); if ((term instanceof XSElementDeclaration)) { XSElementDeclaration propertyElement = (XSElementDeclaration) term; String namespaceUri = propertyElement.getNamespace(); String localName = propertyElement.getName(); properties.add(new QName(namespaceUri, localName)); } else if ((term instanceof XSModelGroup)) { XSModelGroup modelGroup = (XSModelGroup) term; XSObjectList particles = modelGroup.getParticles(); for (int i = 0; i < particles.getLength(); i++) setPropertyNames(properties, element, (XSParticle) particles.item(i)); } }
private boolean containsOnlyProperties(XSElementDeclaration featureElement, XSParticle particle) { boolean containsOnlyProperties = true; XSTerm term = particle.getTerm(); if ((term instanceof XSElementDeclaration)) { if (!validateProperty(featureElement, (XSElementDeclaration) term)) containsOnlyProperties = false; } else if ((term instanceof XSModelGroup)) { XSModelGroup modelGroup = (XSModelGroup) term; XSObjectList particles = modelGroup.getParticles(); for (int i = 0; i < particles.getLength(); i++) { if (!containsOnlyProperties(featureElement, (XSParticle) particles.item(i))) { containsOnlyProperties = false; } } } return containsOnlyProperties; }
private void addBaseTypeParts(XSTypeDefinition baseType, List<XSParticle> xsparts) { if (baseType == null) throw MESSAGES.illegalNullArgumentInSchemaMapping("baseType"); if (XSTypeDefinition.COMPLEX_TYPE == baseType.getTypeCategory()) { XSTypeDefinition btype = baseType.getBaseType(); if (btype != null) addBaseTypeParts(btype, xsparts); //Recurse //Just add the particles from this basetype as a ModelGroup sequence XSParticle part = ((XSComplexTypeDefinition)baseType).getParticle(); XSTerm term = part.getTerm(); if (term instanceof XSModelGroup) { JBossXSParticle p = new JBossXSParticle(); p.setTerm(term); xsparts.add(p); } } }
private void setSimpleTypeProperties(List properties, XSElementDeclaration element, XSParticle particle) { XSTerm term = particle.getTerm(); if ((term instanceof XSElementDeclaration)) { XSElementDeclaration propertyElement = (XSElementDeclaration) term; if ((propertyElement.getTypeDefinition() instanceof XSSimpleTypeDefinition)) { String namespaceUri = propertyElement.getNamespace(); String localName = propertyElement.getName(); properties.add(new QName(namespaceUri, localName)); } } else if ((term instanceof XSModelGroup)) { XSModelGroup modelGroup = (XSModelGroup) term; XSObjectList particles = modelGroup.getParticles(); for (int i = 0; i < particles.getLength(); i++) setSimpleTypeProperties(properties, element, (XSParticle) particles.item(i)); } }
private void setMandatoryPropertyNames(List properties, XSElementDeclaration element, XSParticle particle) { if (particle.getMinOccurs() > 0) { XSTerm term = particle.getTerm(); if ((term instanceof XSElementDeclaration)) { XSElementDeclaration propertyElement = (XSElementDeclaration) term; String namespaceUri = propertyElement.getNamespace(); String localName = propertyElement.getName(); properties.add(new QName(namespaceUri, localName)); } else if ((term instanceof XSModelGroup)) { XSModelGroup modelGroup = (XSModelGroup) term; XSObjectList particles = modelGroup.getParticles(); for (int i = 0; i < particles.getLength(); i++) setMandatoryPropertyNames(properties, element, (XSParticle) particles.item(i)); } } }
private boolean marshalModelGroup(XSParticle particle, boolean declareNs) { XSModelGroup modelGroup = (XSModelGroup)particle.getTerm(); boolean marshalled; switch(modelGroup.getCompositor()) { case XSModelGroup.COMPOSITOR_ALL: marshalled = marshalModelGroupAll(modelGroup.getParticles(), declareNs); break; case XSModelGroup.COMPOSITOR_CHOICE: marshalled = marshalModelGroupChoice(modelGroup.getParticles(), declareNs); break; case XSModelGroup.COMPOSITOR_SEQUENCE: marshalled = marshalModelGroupSequence(modelGroup.getParticles(), declareNs); break; default: throw new IllegalStateException("Unexpected compsitor: " + modelGroup.getCompositor()); } return marshalled; }