private SimpleHash buildType(ComplexType ft) { // create a variable "attributes" which his a list of all the // attributes, but at the same time, is a map keyed by name Map<String, Object> attributeMap = new LinkedHashMap<String, Object>(); Collection<PropertyDescriptor> descriptors = ft.getDescriptors(); for (Iterator<PropertyDescriptor> it = descriptors.iterator(); it.hasNext(); ) { PropertyDescriptor descr = it.next(); Map<String, Object> attribute = new HashMap<String, Object>(); attribute.put("name", descr.getName().getLocalPart()); attribute.put("namespace", getNamespace(descr.getName())); attribute.put("prefix", getPrefix(descr.getName())); attribute.put("type", descr.getType().getBinding().getName()); attribute.put( "isGeometry", Boolean.valueOf(Geometry.class.isAssignableFrom(descr.getType().getBinding()))); attributeMap.put(descr.getName().toString(), attribute); } // build up the result, feature type is represented by its name an // attributes SimpleHash map = new SimpleHash(); map.put("attributes", new SequenceMapModel(attributeMap, this)); map.put("name", ft.getName().getLocalPart()); map.put("namespace", getNamespace(ft.getName())); map.put("prefix", getPrefix(ft.getName())); return map; }
entrySet = new LinkedHashSet<MapEntry>(); final ComplexType featureType = feature.getType(); PropertyDescriptor attributeDescr = featureType.getDescriptor(attributeName); Property property = feature.getProperty(attributeName); List<AttributeDescriptor> substitutionGroup = (List<AttributeDescriptor>) attributeDescr.getUserData().get("substitutionGroup"); if (substitutionGroup != null) { Iterator<AttributeDescriptor> it = substitutionGroup.iterator(); while (property == null && it.hasNext()) { property = feature.getProperty(it.next().getName()); entrySet.add(new MapEntry<Object, Object>("name", attributeName.getLocalPart())); entrySet.add( new MapEntry<Object, Object>("namespace", getNamespace(attributeName))); entrySet.add(new MapEntry<Object, Object>("prefix", getPrefix(attributeName))); Geometry.class.isAssignableFrom(attributeDescr.getType().getBinding()); entrySet.add( new MapEntry<Object, Object>("isGeometry", Boolean.valueOf(isGeometry)));
AttributeDescriptor node = (AttributeDescriptor) itr.next(); if (node.getName() == null) { if (node.getType().getName().getLocalPart().equals(name)) { return node; if (node.getName().getLocalPart().equals(name)) { return node; AttributeType superType = schema.getSuper(); if (superType instanceof ComplexType) { return node((ComplexType) superType, name);
/** * Return true if name is the name of a descriptor of the type or of an ancestor type. * * @param type type to test * @param name name of descriptor * @return true if the type or an ancestor has a descriptor of this name */ private boolean isValidDescriptor(ComplexType type, Name name) { if (type.getDescriptor(name) != null) { return true; } else if (type.getSuper() instanceof ComplexType) { return isValidDescriptor((ComplexType) type.getSuper(), name); } else { return false; } }
/** * Returns the set of all descriptors of a complex type, including from supertypes. * * @param type The type, non null. * @return The list of all descriptors. */ public static List<PropertyDescriptor> descriptors(ComplexType type) { // get list of descriptors from types and all supertypes List<PropertyDescriptor> children = new ArrayList<PropertyDescriptor>(); ComplexType loopType = type; while (loopType != null) { children.addAll(loopType.getDescriptors()); loopType = loopType.getSuper() instanceof ComplexType ? (ComplexType) loopType.getSuper() : null; } return children; }
Name name = type.getName(); String isIdentified = type.isIdentified() ? "true" : "false"; .getLocalPart().toUpperCase() + "_TYPE"; if (cType.getDescriptors().isEmpty()) { for (PropertyDescriptor pd : cType.getDescriptors()) { if ( !(pd instanceof AttributeDescriptor) ) { continue; AttributeType adType = ad.getType(); if (ad.getName().getNamespaceURI() == null) { adName = "new NameImpl(\"" + ad.getName().getLocalPart() + "\")"; PropertyType pdType = pd.getType(); String pdTypeName = pdType.getName().getLocalPart().toUpperCase() + "_TYPE"; if (ns2import.containsKey(pdType.getName().getNamespaceURI())) { String importClassName = (String) ns2import.get(pdType.getName().getNamespaceURI()); pdTypeName = importClassName + "." + pdTypeName; String pdName = "new NameImpl(\"" + pd.getName().getNamespaceURI() + "\",\"" + pd.getName().getLocalPart() + "\")";
definition.setName(type.getName().getLocalPart()); definition.setDerivationMethod(XSDDerivationMethod.EXTENSION_LITERAL); for (PropertyDescriptor descriptor : type.getDescriptors()) { if (skip.contains(attributeDescriptor.getLocalName())) { continue; attribute.setName(attributeDescriptor.getLocalName()); attribute.setNillable(attributeDescriptor.isNillable()); Name name = attributeDescriptor.getType().getName(); if (!anyName.equals(name)) { AttributeType attributeType = attributeDescriptor.getType(); if (xsd.resolveTypeDefinition(name.getNamespaceURI(), name.getLocalPart()) == null) { Class<?> binding = attributeType.getBinding(); Entry<Name, AttributeType> entry = searchSchemas(binding); if (entry == null) {
if (_parentType.getName().equals(XSSchema.ANYTYPE_TYPE.getName()) && targetDescriptor != null) { if (actualDescriptor instanceof GeometryDescriptor) { if (Geometry.class.isAssignableFrom(targetNodeType.getBinding())) { if (!(targetNodeType instanceof GeometryType)) { targetNodeType = Collection properties = parentType.getDescriptors(); for (Iterator it = properties.iterator(); it.hasNext(); ) { PropertyDescriptor desc = (PropertyDescriptor) it.next(); Name name = desc.getName(); currStep + " is not a valid location path for type " + parentType.getName() + ". " + currStep + currStep.getName().getNamespaceURI() + ", " + parentType.getName().getLocalPart() + " properties: " + parentAtts);
if (type == null) return; namespace = type.getName().getNamespaceURI(); name = type.getName().getLocalPart(); description = type.getDescription(); isAbstract = type.isAbstract(); restrictions = null; AttributeType aType = (AttributeType) type; binding = aType.getBinding(); isIdentified = aType.isIdentified(); superType = aType.getSuper(); properties.addAll(cType.getDescriptors());
CoordinateReferenceSystem crs) { if (descriptor.getUserData().get("substitutionGroup") != null) { descriptor.getUserData().put("substitutionGroup", substitutionGroup); Collection<PropertyDescriptor> children = complexType.getDescriptors(); if (desc.getName().getLocalPart().equals(element.getName()) && desc.getName() .getNamespaceURI() .equals(element.getTargetNamespace())) { childDesc = desc;
/** * Test that this class can be loaded. */ public static void main(String[] args) { Schema schema = new GSSSchema(); for (Entry<Name, AttributeType> entry : new TreeMap<Name, AttributeType>(schema).entrySet()) { System.out.println("Type: " + entry.getValue().getName()); System.out.println(" Super type: " + entry.getValue().getSuper().getName()); if (entry.getValue() instanceof ComplexType) { for (PropertyDescriptor descriptor : ((ComplexType) entry.getValue()) .getDescriptors()) { System.out.println(" Property descriptor: " + descriptor.getName()); System.out.println(" Property type: " + descriptor.getType().getName()); } } } }
private void assertPropertyNamesAndTypeNames( ComplexType parentType, Map expectedPropertiesAndTypes) throws Exception { for (Iterator it = expectedPropertiesAndTypes.entrySet().iterator(); it.hasNext(); ) { Map.Entry entry = (Entry) it.next(); Name dName = (Name) entry.getKey(); Name expectedDescriptorTypeName = (Name) entry.getValue(); AttributeDescriptor d = (AttributeDescriptor) Types.descriptor(parentType, dName); assertNotNull("Descriptor " + dName + " not found for type " + parentType.getName(), d); AttributeType type; try { type = (AttributeType) d.getType(); } catch (Exception e) { LOGGER.log( Level.SEVERE, "type not parsed for " + ((AttributeDescriptor) d).getName(), e); throw e; } assertNotNull(type); Name actualTypeName = type.getName(); assertNotNull(actualTypeName); assertNotNull(type.getBinding()); if (expectedDescriptorTypeName != null) { assertEquals( "type mismatch for property " + dName, expectedDescriptorTypeName, actualTypeName); } } }
Assert.assertTrue(type instanceof FeatureType); Assert.assertFalse(type instanceof SimpleFeatureType); Assert.assertEquals(typeName, type.getName()); Assert.assertTrue( type.getUserData().get(XSDTypeDefinition.class) instanceof XSDComplexTypeDefinition); Assert.assertEquals(typeName, wq_plus_Type.getSuper().getName()); Assert.assertNotNull(wq_plus_Type.getDescriptors()); Assert.assertEquals( AttributeDescriptor wqPlusDescriptor = typeRegistry.getDescriptor(name, null); Assert.assertNotNull(wqPlusDescriptor); Assert.assertEquals(name, wqPlusDescriptor.getName()); Assert.assertSame(wq_plus_Type, wqPlusDescriptor.getType()); Assert.assertTrue( wqPlusDescriptor.getUserData().get(XSDElementDeclaration.class) instanceof XSDElementDeclaration); Assert.assertEquals(typeName, measurementType.getName()); Assert.assertTrue(measurementType.isIdentified()); Assert.assertFalse(measurementType.isAbstract()); Assert.assertEquals(2, measurementType.getDescriptors().size());
public Object getImmediateNode() { // first try regular way PropertyType pt = descriptor.getType(); if (pt instanceof ComplexType) { ComplexType ct = (ComplexType) pt; PropertyDescriptor ad = ct.getDescriptor("@" + name.getLocalPart()); if (ad != null) { return ad; } } XSDElementDeclaration decl = (XSDElementDeclaration) descriptor.getUserData().get(XSDElementDeclaration.class); Iterator it = Schemas.getAttributeDeclarations(decl).iterator(); while (it.hasNext()) { XSDAttributeDeclaration attDecl = ((XSDAttributeDeclaration) it.next()); if (attDecl.getURI() .equals( (name.getNamespaceURI() == null ? "" : name.getNamespaceURI()) + "#" + name.getLocalPart())) { return name; } } return null; }
Assert.assertTrue(type.getClass().getName(), type instanceof ComplexType); Assert.assertTrue( type.getUserData().get(XSDTypeDefinition.class) instanceof XSDComplexTypeDefinition); String local = ft.getName().getLocalPart(); String uri = ft.getName().getNamespaceURI(); Assert.assertEquals("simpleFeatureType", local); Assert.assertEquals(NS_URI, uri);
public String[] getPropertyNames(java.lang.Object o) { AttributeType att = (AttributeType) o; String[] propNames = null; if (att instanceof ComplexType) { ComplexType complexType = (ComplexType) att; List/*<AttributeDescriptor>*/ childTypes = new ArrayList(complexType.getDescriptors()); propNames = new String[childTypes.size()]; for (int i = 0; i < propNames.length; i++) { propNames[i] = ((AttributeDescriptor)childTypes.get(i)) .getName().getLocalPart(); } } return propNames; }
PropertyDescriptor descriptor = complexType.getDescriptor(currentTagName); if (descriptor != null) { PropertyType type = descriptor.getType(); attributeBuilder.setType((AttributeType) type); if (type.getBinding() == Collection.class && Types.isSimpleContentType(type)) { if (value != null || descriptor.isNillable()) { // add Object convertedValue = ff.literal(value) .evaluate(value, simpleContentType.getBinding());
/** * Returns the set of descriptors matching the given local name within the given type. * * @param type The type, non null. * @param name The name, non null. * @return The list of descriptors named 'name', or an empty list if none such match. */ public static List /* <PropertyDescriptor> */ descriptors(ComplexType type, String name) { if (name == null) return Collections.EMPTY_LIST; List match = new ArrayList(); for (Iterator itr = type.getDescriptors().iterator(); itr.hasNext(); ) { PropertyDescriptor descriptor = (PropertyDescriptor) itr.next(); String localPart = descriptor.getName().getLocalPart(); if (name.equals(localPart)) { match.add(descriptor); } } // only look up in the super type if the descriptor is not found // as a direct child definition if (match.size() == 0) { AttributeType superType = type.getSuper(); if (superType instanceof ComplexType) { List superDescriptors = descriptors((ComplexType) superType, name); match.addAll(superDescriptors); } } return match; }
public Set entrySet() { if (entrySet == null) { entrySet = new LinkedHashSet<MapEntry>(); final Collection<PropertyDescriptor> types = feature.getType().getDescriptors(); Name attName; Map attributesMap; for (Iterator<PropertyDescriptor> iterator = types.iterator(); iterator.hasNext(); ) { attName = iterator.next().getName(); attributesMap = new AttributeMap(attName, feature); entrySet.add( new MapEntry<Object, Object>(attName.getLocalPart(), attributesMap)); } } return entrySet; } }
public NonFeatureTypeProxy(final ComplexType type, final FeatureTypeMapping mapping, Collection<PropertyDescriptor> schema) { super(type.getName(), null); subject = type; AttributeDescriptor originalTarget = mapping.getTargetFeature(); int maxOccurs = originalTarget.getMaxOccurs(); int minOccurs = originalTarget.getMinOccurs(); boolean nillable = originalTarget.isNillable(); Object defaultValue = originalTarget.getDefaultValue(); Name name = originalTarget.getName(); // create a new descriptor with the wrapped type and set it to the mapping ComplexFeatureTypeFactoryImpl typeFactory = new ComplexFeatureTypeFactoryImpl(); AttributeDescriptor descriptor = typeFactory.createAttributeDescriptor(this, name, minOccurs, maxOccurs, nillable, defaultValue); descriptor.getUserData().putAll(originalTarget.getUserData()); mapping.setTargetFeature(descriptor); this.descriptors = schema; }