/** * Encode the provided SimpleFeatureType into an XSD file, using a target namespace * * <p>When encoding the simpleFeatureType: * * <ul> * <li>target prefix/namespace can be provided by prefix and namespace parameters. This is the * default for the entire XSD document. * <li>simpleFeatureType.geName().getNamespaceURI() is used for the simpleFeatureType itself, * providing simpleFeatureType.getUserData().get("prefix") is defined * </ul> * * @param simpleFeatureType To be encoded as an XSD document * @param prefix Prefix to use for for target namespace * @param namespace Target namespace */ public void encode(OutputStream out, SimpleFeatureType simpleFeatureType) throws IOException { XSDSchema xsd = xsd(simpleFeatureType); XSDResourceImpl.serialize(out, xsd.getElement(), encoding.name()); }
protected XSDParticle createXSDElementReference() { List list = xsdModelGroup.getSchema().getElementDeclarations(); XSDElementDeclaration referencedElement = null; if (list.size() > 0) { referencedElement = (XSDElementDeclaration)list.get(0); } else { referencedElement = createGlobalXSDElementDeclaration(); Text textNode = xsdSchema.getDocument().createTextNode("\n"); //$NON-NLS-1$ xsdSchema.getElement().appendChild(textNode); xsdSchema.getContents().add(referencedElement); } XSDElementDeclaration element = XSDFactory.eINSTANCE.createXSDElementDeclaration(); element.setResolvedElementDeclaration(referencedElement); XSDParticle particle = XSDFactory.eINSTANCE.createXSDParticle(); particle.setContent(element); addedXSDConcreteComponent = element; return particle; }
/** * Assigns diagnostics to a schema. * @param xsdSchema the schema. * @param xsdDiagnostics the {@link XSDDiagnostic}s. */ protected static void assignDiagnostics(XSDSchema xsdSchema, Collection<XSDDiagnostic> xsdDiagnostics) { if (!xsdDiagnostics.isEmpty()) { xsdSchema.getDiagnostics().addAll(xsdDiagnostics); for (XSDDiagnostic xsdDiagnostic : xsdDiagnostics) { xsdDiagnostic.getComponents().add(xsdSchema); if (xsdSchema.getElement() != null) { xsdDiagnostic.setNode(xsdSchema.getElement()); } } } }
/** * Assigns diagnostics to a schema. * @param xsdSchema the schema. * @param xsdDiagnostics the {@link XSDDiagnostic}s. */ protected static void assignDiagnostics(XSDSchema xsdSchema, Collection<XSDDiagnostic> xsdDiagnostics) { if (!xsdDiagnostics.isEmpty()) { xsdSchema.getDiagnostics().addAll(xsdDiagnostics); for (XSDDiagnostic xsdDiagnostic : xsdDiagnostics) { xsdDiagnostic.getComponents().add(xsdSchema); if (xsdSchema.getElement() != null) { xsdDiagnostic.setNode(xsdSchema.getElement()); } } } }
public void updateMapAfterDelete(XSDImport deletedNode) { String ns = deletedNode.getNamespace(); if (ns != null) { String prefix = getPrefix(ns, false); if (prefix != null) { prefix = prefix.trim(); } String xmlnsAttr = (prefix == "") ? "xmlns" : "xmlns:" + prefix; if (prefix == "") { prefix = null; } if (xsdSchema != null) { Map map = xsdSchema.getQNamePrefixToNamespaceMap(); map.remove(prefix); Element schemaElement = xsdSchema.getElement(); schemaElement.removeAttribute(xmlnsAttr); } } }
@Override public EObject getEObject(String uriFragment) { // Do ID-based lookup. // if (!uriFragment.startsWith("/")) { Element theElement = getSchema().getElement(); if (theElement != null) { // Navigate out through the elements. // Element resultElement = theElement.getOwnerDocument().getElementById(uriFragment); List<Element> parents = new ArrayList<Element>(); for (Node parent = resultElement; parent != null; parent = parent.getParentNode()) { if (parent.getNodeType() == Node.ELEMENT_NODE) { parents.add((Element)parent); } } return ((org.eclipse.xsd.impl.XSDSchemaImpl)getSchema()).getBestConcreteComponent(parents); } } return super.getEObject(uriFragment); }
@Override public EObject getEObject(String uriFragment) { // Do ID-based lookup. // if (!uriFragment.startsWith("/")) { Element theElement = getSchema().getElement(); if (theElement != null) { // Navigate out through the elements. // Element resultElement = theElement.getOwnerDocument().getElementById(uriFragment); List<Element> parents = new ArrayList<Element>(); for (Node parent = resultElement; parent != null; parent = parent.getParentNode()) { if (parent.getNodeType() == Node.ELEMENT_NODE) { parents.add((Element)parent); } } return ((org.eclipse.xsd.impl.XSDSchemaImpl)getSchema()).getBestConcreteComponent(parents); } } return super.getEObject(uriFragment); }
public void execute() { try { super.execute(); // Add this after if we don't have a DOM Node yet beginRecording(xsdSchema.getElement()); XSDImport xsdImport = XSDFactory.eINSTANCE.createXSDImport(); xsdSchema.getContents().add(findNextPositionToInsert(), xsdImport); addedXSDConcreteComponent = xsdImport; formatChild(xsdSchema.getElement()); } finally { endRecording(); } } }
public void doWidgetSelected(SelectionEvent e) { if (e.widget == editButton) { XSDEditNamespacesAction nsAction = new XSDEditNamespacesAction(XSDEditorPlugin.getXSDString("_UI_ACTION_EDIT_NAMESPACES"), xsdSchema.getElement(), null, xsdSchema); //$NON-NLS-1$ nsAction.run(); refresh(); } }
/** Create a namespace prefix if needed, other wise retrieve * a predefined namespace prefix * @return */ private String handleNamespacePrefices() { Element schemaElement = component.getSchema().getElement(); String prefix = null; // If target namespace of the attribute already exists List namespacePrefices = manager.getNamespaceInfoList(schemaElement); for (int i = 0; i < namespacePrefices.size(); i++){ NamespaceInfo info = (NamespaceInfo) namespacePrefices.get(i); if ( info.uri.equals(attribute.getTargetNamespace())) { prefix = info.prefix; } } // Create unquie namespace prefix if ( prefix == null){ prefix = createUniquePrefix(component); } NamespaceInfo info = new NamespaceInfo(attribute.getTargetNamespace(), prefix, ""); //$NON-NLS-1$ List infoList = new ArrayList(1); infoList.add(info); manager.addNamespaceInfo(schemaElement, infoList, false); return prefix; }
public void execute() { super.execute(); try { // Add this after if we don't have a DOM Node yet beginRecording(xsdSchema.getElement()); XSDRedefine xsdRedefine = XSDFactory.eINSTANCE.createXSDRedefine(); xsdRedefine.setSchemaLocation(""); //$NON-NLS-1$ xsdSchema.getContents().add(findNextPositionToInsert(), xsdRedefine); addedXSDConcreteComponent = xsdRedefine; formatChild(xsdSchema.getElement()); } finally { endRecording(); } }
public void execute() { try { super.execute(); // Add this after if we don't have a DOM Node yet beginRecording(xsdSchema.getElement()); XSDInclude xsdInclude = XSDFactory.eINSTANCE.createXSDInclude(); xsdInclude.setSchemaLocation(""); //$NON-NLS-1$ xsdSchema.getContents().add(findNextPositionToInsert(), xsdInclude); addedXSDConcreteComponent = xsdInclude; formatChild(xsdSchema.getElement()); } finally { endRecording(); } } }
protected XSDAttributeDeclaration createGlobalXSDAttributeDeclaration(XSDSchema xsdSchema) { ensureSchemaElement(xsdSchema); XSDAttributeDeclaration attribute = XSDFactory.eINSTANCE.createXSDAttributeDeclaration(); attribute.setTypeDefinition(xsdSchema.getSchemaForSchema().resolveSimpleTypeDefinition("string")); //$NON-NLS-1$ attribute.setName(XSDCommonUIUtils.createUniqueElementName("NewAttribute", xsdSchema.getAttributeDeclarations())); //$NON-NLS-1$ Text textNode = xsdSchema.getDocument().createTextNode("\n"); //$NON-NLS-1$ xsdSchema.getElement().appendChild(textNode); xsdSchema.getContents().add(attribute); return attribute; }
protected void addExtensionNode() { XSDAnnotation xsdAnnotation = XSDCommonUIUtils.getInputXSDAnnotation(component, true); XSDSchema schema= xsdAnnotation.getSchema(); Element schemaElement = schema.getElement(); if (xsdAnnotation.getApplicationInformation().size() == 0) { appInfo = xsdAnnotation.createApplicationInformation(null); xsdAnnotation.getElement().appendChild(appInfo); List appInfos = xsdAnnotation.getApplicationInformation(); appInfos.add(appInfo); } else { // use the first appInfo appInfo = (Element)xsdAnnotation.getApplicationInformation().get(0); } if (appInfo != null) { Document doc = appInfo.getOwnerDocument(); String prefix = addToNamespaceTable(schemaElement); newElement = doc.createElementNS(extensionsSchemaSpec.getNamespaceURI(), element.getName()); newElement.setPrefix(prefix); appInfo.appendChild(newElement); xsdAnnotation.updateElement(); } }
protected void doSave(Writer writer, Map<?, ?> options) throws IOException { XSDSchema xsdSchema = getSchema(); if (xsdSchema != null) { Document document = xsdSchema.getDocument(); if (document == null) { xsdSchema.updateDocument(); document = xsdSchema.getDocument(); } if (xsdSchema.getElement() == null) { xsdSchema.updateElement(); } doSerialize(writer, document, options); } }
protected void doWrite( FeatureTypeInfo[] featureTypeInfos, OutputStream output, Operation describeFeatureType) throws IOException { // create the schema Object request = describeFeatureType.getParameters()[0]; DescribeFeatureTypeRequest req = DescribeFeatureTypeRequest.adapt(request); XSDSchema schema = schemaBuilder.build(featureTypeInfos, req.getBaseURL()); // serialize schema.updateElement(); final String encoding = gs.getSettings().getCharset(); XSDResourceImpl.serialize(output, schema.getElement(), encoding); }
protected void doSave(Writer writer, Map<?, ?> options) throws IOException { XSDSchema xsdSchema = getSchema(); if (xsdSchema != null) { Document document = xsdSchema.getDocument(); if (document == null) { xsdSchema.updateDocument(); document = xsdSchema.getDocument(); } if (xsdSchema.getElement() == null) { xsdSchema.updateElement(); } doSerialize(writer, document, options); } }
protected XSDModelGroupDefinition createXSDModelGroupDefinition() { XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory(); XSDModelGroupDefinition def = factory.createXSDModelGroupDefinition(); List list = parent.getSchema().getModelGroupDefinitions(); String newName = XSDCommonUIUtils.createUniqueElementName("ModelGroupDefinition", list); //$NON-NLS-1$ def.setName(newName); XSDModelGroup modelGroup = createModelGroup(); def.setModelGroup(modelGroup); Text textNode = parent.getSchema().getDocument().createTextNode("\n"); //$NON-NLS-1$ parent.getSchema().getElement().appendChild(textNode); parent.getSchema().getContents().add(def); formatChild(def.getElement()); return def; }
@Override protected void doSave(OutputStream os, Map<?, ?> options) throws IOException { if (os instanceof URIConverter.WriteableOutputStream) { doSave(((URIConverter.WriteableOutputStream)os).asWriter(), options); } else { XSDSchema xsdSchema = getSchema(); if (xsdSchema != null) { Document document = xsdSchema.getDocument(); if (document == null) { xsdSchema.updateDocument(); document = xsdSchema.getDocument(); } if (xsdSchema.getElement() == null) { xsdSchema.updateElement(); } doSerialize(os, document, options); } } }
@Override protected void doSave(OutputStream os, Map<?, ?> options) throws IOException { if (os instanceof URIConverter.WriteableOutputStream) { doSave(((URIConverter.WriteableOutputStream)os).asWriter(), options); } else { XSDSchema xsdSchema = getSchema(); if (xsdSchema != null) { Document document = xsdSchema.getDocument(); if (document == null) { xsdSchema.updateDocument(); document = xsdSchema.getDocument(); } if (xsdSchema.getElement() == null) { xsdSchema.updateElement(); } doSerialize(os, document, options); } } }