org.citygml4j.model.module.ModuleContext Java Examples

The following examples show how to use org.citygml4j.model.module.ModuleContext. 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: XMLQueryView.java    From importer-exporter with Apache License 2.0 6 votes vote down vote up
private void setEmptyQuery() {
    Query query = new Query();
    query.setFeatureTypeFilter(new FeatureTypeFilter());
    query.setAppearanceFilter(new AppearanceFilter());
    query.setCounterFilter(new CounterFilter());
    query.setLodFilter(new LodFilter());
    query.setProjectionFilter(new ProjectionFilter());
    query.setSelectionFilter(new SelectionFilter());
    query.setSorting(new Sorting());
    query.setTiling(new Tiling());

    CityGMLNamespaceContext namespaceContext = new CityGMLNamespaceContext();
    namespaceContext.setPrefixes(new ModuleContext(CityGMLVersion.v2_0_0));
    namespaceContext.setDefaultNamespace(ConfigUtil.CITYDB_CONFIG_NAMESPACE_URI);

    xmlText.setText(marshalQuery(query, namespaceContext));
}
 
Example #2
Source File: CityGMLWriterFactory.java    From importer-exporter with Apache License 2.0 6 votes vote down vote up
private Map<String, Namespace> getNamespaces(ModuleContext moduleContext) {
	Map<String, Namespace> namespaces = cityGMLOptions.isSetNamespaces() ? new LinkedHashMap<>(cityGMLOptions.getNamespaces()) : new LinkedHashMap<>();
	for (Module module : moduleContext.getModules()) {
		Namespace namespace = namespaces.get(module.getNamespaceURI());
		if (namespace == null) {
			namespace = new Namespace();
			namespace.setURI(module.getNamespaceURI());
			namespace.setSchemaLocation(module.getSchemaLocation());
			namespace.setPrefix(module.getType() != CityGMLModuleType.CORE ? module.getNamespacePrefix() : XMLConstants.DEFAULT_NS_PREFIX);
		}

		namespaces.put(namespace.getURI(), namespace);
	}

	return namespaces;
}
 
Example #3
Source File: JAXBOutputFactory.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
public CityGMLWriter createCityGMLWriter(OutputStream outputStream, String encoding, ModuleContext moduleContext) throws CityGMLWriteException {
	try {
		return new JAXBSimpleWriter(
				new SAXWriter(outputStream, encoding), 
				this, 
				moduleContext);
	} catch (IOException e) {
		throw new CityGMLWriteException("Caused by: ", e);
	}
}
 
Example #4
Source File: XMLQueryView.java    From importer-exporter with Apache License 2.0 5 votes vote down vote up
private String wrapQuery(String query) {
    StringBuilder wrapper = new StringBuilder("<wrapper xmlns=\"")
            .append(ConfigUtil.CITYDB_CONFIG_NAMESPACE_URI).append("\" ");

    ModuleContext context = new ModuleContext(CityGMLVersion.v2_0_0);
    for (Module module : context.getModules()) {
        wrapper.append("xmlns:").append(module.getNamespacePrefix()).append("=\"")
                .append(module.getNamespaceURI()).append("\" ");
    }

    wrapper.append(">\n").append(query).append("</wrapper>");

    return wrapper.toString();
}
 
Example #5
Source File: JAXBModelWriter.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
public JAXBModelWriter(SAXWriter writer, 
		JAXBOutputFactory factory, 
		ModuleContext moduleContext) throws CityGMLWriteException {
	super(writer, factory, moduleContext);

	initModuleCtx = new ModuleContext(moduleContext);
}
 
Example #6
Source File: ConfigNamespaceFilter.java    From importer-exporter with Apache License 2.0 5 votes vote down vote up
public ConfigNamespaceFilter(XMLReader reader) {
	super(reader);
	prefixToUri = new HashMap<>();
	uriToPrefix = new HashMap<>();

	// bind default CityGML and ADE namespaces
	ModuleContext modules = new ModuleContext(CityGMLVersion.DEFAULT);
	for (Module module : modules.getModules())
		bindNamespace(module.getNamespacePrefix(), module.getNamespaceURI());

	// bind 3DCityDB ADE namespace
	bindNamespace("citydb", "http://www.3dcitydb.org/citygml-ade/3.0/citygml/2.0");
}
 
Example #7
Source File: JAXBOutputFactory.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
public JAXBOutputFactory(CityGMLBuilder builder, ModuleContext moduleContext, SchemaHandler schemaHandler) {
	this.builder = builder;
	this.schemaHandler = schemaHandler;
	this.moduleContext = moduleContext;

	gmlIdManager = DefaultGMLIdManager.getInstance();
	featureWriteMode = FeatureWriteMode.NO_SPLIT;
	excludes = new HashSet<>();
	keepInlineAppearance = true;
	splitCopy = true;
}
 
Example #8
Source File: JAXBOutputFactory.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
public CityGMLWriter createCityGMLWriter(File file, ModuleContext moduleContext) throws CityGMLWriteException {
	try {
		createParentDirectories(file.toPath());
		return new JAXBSimpleWriter(
				new SAXWriter(new OutputStreamWriter(new FileOutputStream(file))), 
				this, 
				moduleContext);
	} catch (IOException e) {
		throw new CityGMLWriteException("Caused by: ", e);
	}
}
 
Example #9
Source File: JAXBOutputFactory.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
public CityGMLWriter createCityGMLWriter(File file, String encoding, ModuleContext moduleContext) throws CityGMLWriteException {
	try {
		createParentDirectories(file.toPath());
		return new JAXBSimpleWriter(
				new SAXWriter(new OutputStreamWriter(new FileOutputStream(file), encoding)), 
				this, 
				moduleContext);
	} catch (IOException e) {
		throw new CityGMLWriteException("Caused by: ", e);
	}
}
 
Example #10
Source File: JAXBOutputFactory.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
public CityGMLWriter createCityGMLWriter(OutputStream outputStream, ModuleContext moduleContext) throws CityGMLWriteException {
	try {
		return new JAXBSimpleWriter(
				new SAXWriter(outputStream), 
				this, 
				moduleContext);
	} catch (IOException e) {
		throw new CityGMLWriteException("Caused by: ", e);
	}
}
 
Example #11
Source File: JAXBModelWriter.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
public JAXBModelWriter(SAXWriter writer, 
		JAXBOutputFactory factory, 
		ModuleContext moduleContext, 
		CityModelInfo cityModelInfo) throws CityGMLWriteException {
	this(writer, factory, moduleContext);		
	this.cityModelInfo = cityModelInfo;
}
 
Example #12
Source File: JAXBOutputFactory.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
public CityGMLWriter createCityGMLWriter(StreamResult streamResult, String encoding, ModuleContext moduleContext) throws CityGMLWriteException {
	try {
		return new JAXBSimpleWriter(
				new SAXWriter(streamResult, encoding), 
				this, 
				moduleContext);
	} catch (IOException e) {
		throw new CityGMLWriteException("Caused by: ", e);
	}
}
 
Example #13
Source File: JAXBOutputFactory.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
public CityGMLWriter createCityGMLWriter(Writer writer, ModuleContext moduleContext) throws CityGMLWriteException {
	try {
		return new JAXBSimpleWriter(
				new SAXWriter(writer), 
				this, 
				moduleContext);
	} catch (IOException e) {
		throw new CityGMLWriteException("Caused by: ", e);
	}
}
 
Example #14
Source File: JAXBOutputFactory.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
public CityModelWriter createCityModelWriter(File file, String encoding, ModuleContext moduleContext) throws CityGMLWriteException {
	try {
		createParentDirectories(file.toPath());
		return new JAXBModelWriter(
				new SAXWriter(new OutputStreamWriter(new FileOutputStream(file), encoding)), 
				this, 
				moduleContext);
	} catch (IOException e) {
		throw new CityGMLWriteException("Caused by: ", e);
	}
}
 
Example #15
Source File: WritingCityGML.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
private static void setContext(AbstractCityGMLWriter writer, 
		ModuleContext moduleContext, 
		FeatureWriteMode writeMode,
		boolean splitOnCopy) {
	writer.setPrefixes(moduleContext);
	writer.setPrefix("noise", "http://www.citygml.org/ade/noise_de/2.0");
	writer.setDefaultNamespace(moduleContext.getModule(CityGMLModuleType.CORE));
	writer.setSchemaLocation("http://www.citygml.org/ade/noise_de/2.0", "../datasets/schemas/CityGML-NoiseADE-2_0_0.xsd");
	writer.setIndentString("  ");
	writer.setHeaderComment("written by citygml4j", 
			"using a CityGMLWriter instance", 
			"Split mode: " + writeMode, 
			"Split on copy: " + splitOnCopy);
}
 
Example #16
Source File: JAXBMarshaller.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
public JAXBMarshaller(CityGMLBuilder builder, ModuleContext moduleContext) {
	this.builder = builder;
	this.moduleContext = moduleContext;

	citygml = new CityGMLMarshaller(this);
	gml = new GMLMarshaller(this);
	xal = new XALMarshaller();
	ade = new ADEMarshaller(this);
	
	try {
		dataTypeFactory = DatatypeFactory.newInstance();
	} catch (DatatypeConfigurationException e) {
		throw new RuntimeException("Failed to create DatatypeFactory.", e);
	}
}
 
Example #17
Source File: AbstractJAXBWriter.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
public void setSchemaLocations(ModuleContext moduleContext) {
	for (CityGMLModule module : moduleContext.getCityGMLModules()) {
		if (module instanceof CoreModule)
			continue;

		setSchemaLocation(module);
	}

	for (ADEModule adeModule : moduleContext.getADEModules())
		setSchemaLocation(adeModule);
}
 
Example #18
Source File: AbstractJAXBWriter.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public AbstractJAXBWriter(SAXWriter writer, JAXBOutputFactory factory, ModuleContext moduleContext) throws CityGMLWriteException {
	this.writer = writer;

	jaxbMarshaller = factory.builder.createJAXBMarshaller(new ModuleContext(moduleContext));
	jaxbContext = factory.builder.getJAXBContext();
	schemaHandler = factory.getSchemaHandler();
	transformerChainFactory = factory.getTransformerChainFactory();

	featureWriteMode = (FeatureWriteMode)factory.getProperty(CityGMLOutputFactory.FEATURE_WRITE_MODE);
	useValidation = (Boolean)factory.getProperty(CityGMLOutputFactory.USE_VALIDATION);

	if (featureWriteMode == FeatureWriteMode.SPLIT_PER_COLLECTION_MEMBER) {
		featureSplitter = new FeatureSplitter()
				.setSchemaHandler(schemaHandler)
				.setGMLIdManager(factory.getGMLIdManager())
				.setSplitMode(FeatureSplitMode.SPLIT_PER_COLLECTION_MEMBER)
				.keepInlineAppearance((Boolean)factory.getProperty(CityGMLOutputFactory.KEEP_INLINE_APPEARANCE))
				.splitCopy((Boolean)factory.getProperty(CityGMLOutputFactory.SPLIT_COPY))
				.exclude((Set<Class<? extends CityGML>>)factory.getProperty(CityGMLOutputFactory.EXCLUDE_FROM_SPLITTING));
	}

	if (useValidation) {
		if (schemaHandler == null) {
			try {
				schemaHandler = factory.builder.getDefaultSchemaHandler();
			} catch (CityGMLBuilderException e) {
				throw new CityGMLWriteException("Caused by: ", e);
			}
		}

		validationSchemaHandler = new ValidationSchemaHandler(schemaHandler);
		validationEventHandler = factory.getValidationEventHandler();
	}		
}
 
Example #19
Source File: JAXBOutputFactory.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
public CityModelWriter createCityModelWriter(Writer writer, ModuleContext moduleContext) throws CityGMLWriteException {
	try {
		return new JAXBModelWriter(
				new SAXWriter(writer), 
				this, 
				moduleContext);
	} catch (IOException e) {
		throw new CityGMLWriteException("Caused by: ", e);
	}
}
 
Example #20
Source File: JAXBOutputFactory.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
public CityModelWriter createCityModelWriter(StreamResult streamResult, String encoding, ModuleContext moduleContext) throws CityGMLWriteException {
	try {
		return new JAXBModelWriter(
				new SAXWriter(streamResult, encoding), 
				this, 
				moduleContext);
	} catch (IOException e) {
		throw new CityGMLWriteException("Caused by: ", e);
	}
}
 
Example #21
Source File: JAXBOutputFactory.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
public CityModelWriter createCityModelWriter(OutputStream outputStream, String encoding, ModuleContext moduleContext) throws CityGMLWriteException {
	try {
		return new JAXBModelWriter(
				new SAXWriter(outputStream, encoding), 
				this, 
				moduleContext);
	} catch (IOException e) {
		throw new CityGMLWriteException("Caused by: ", e);
	}
}
 
Example #22
Source File: JAXBOutputFactory.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
public CityModelWriter createCityModelWriter(OutputStream outputStream, ModuleContext moduleContext) throws CityGMLWriteException {
	try {
		return new JAXBModelWriter(
				new SAXWriter(outputStream), 
				this, 
				moduleContext);
	} catch (IOException e) {
		throw new CityGMLWriteException("Caused by: ", e);
	}
}
 
Example #23
Source File: JAXBOutputFactory.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
public CityModelWriter createCityModelWriter(File file, ModuleContext moduleContext) throws CityGMLWriteException {
	try {
		createParentDirectories(file.toPath());
		return new JAXBModelWriter(
				new SAXWriter(new OutputStreamWriter(new FileOutputStream(file))), 
				this, 
				moduleContext);
	} catch (IOException e) {
		throw new CityGMLWriteException("Caused by: ", e);
	}
}
 
Example #24
Source File: AbstractJAXBWriter.java    From citygml4j with Apache License 2.0 4 votes vote down vote up
public void setModuleContext(ModuleContext moduleContext) {
	jaxbMarshaller.setModuleContext(moduleContext);
}
 
Example #25
Source File: JAXBOutputFactory.java    From citygml4j with Apache License 2.0 4 votes vote down vote up
public JAXBOutputFactory(CityGMLBuilder builder, ModuleContext moduleContext) {
	this(builder, moduleContext, null);
}
 
Example #26
Source File: JAXBOutputFactory.java    From citygml4j with Apache License 2.0 4 votes vote down vote up
public JAXBOutputFactory(CityGMLBuilder builder, SchemaHandler schemaHandler) {
	this(builder, new ModuleContext(), schemaHandler);
}
 
Example #27
Source File: CityGMLMarshaller.java    From citygml4j with Apache License 2.0 4 votes vote down vote up
private CityGMLModule getCityGMLModule(Object src) {

		if (src instanceof ModelObject) {
			ModuleContext moduleContext = jaxb.getModuleContext();

			if (src instanceof AppearanceModuleComponent)
				return (AppearanceModule)moduleContext.getModule(CityGMLModuleType.APPEARANCE);
			else if (src instanceof BridgeModuleComponent)
				return (BridgeModule)moduleContext.getModule(CityGMLModuleType.BRIDGE);
			else if (src instanceof BuildingModuleComponent)
				return (BuildingModule)moduleContext.getModule(CityGMLModuleType.BUILDING);
			else if (src instanceof CityFurnitureModuleComponent)
				return (CityFurnitureModule)moduleContext.getModule(CityGMLModuleType.CITY_FURNITURE);
			else if (src instanceof CityObjectGroupModuleComponent)
				return (CityObjectGroupModule)moduleContext.getModule(CityGMLModuleType.CITY_OBJECT_GROUP);
			else if (src instanceof GenericsModuleComponent)
				return (GenericsModule)moduleContext.getModule(CityGMLModuleType.GENERICS);
			else if (src instanceof LandUseModuleComponent)
				return (LandUseModule)moduleContext.getModule(CityGMLModuleType.LAND_USE);
			else if (src instanceof ReliefModuleComponent)
				return (ReliefModule)moduleContext.getModule(CityGMLModuleType.RELIEF);
			else if (src instanceof TexturedSurfaceModuleComponent)
				return (TexturedSurfaceModule)moduleContext.getModule(CityGMLModuleType.TEXTURED_SURFACE);
			else if (src instanceof TransportationModuleComponent)
				return (TransportationModule)moduleContext.getModule(CityGMLModuleType.TRANSPORTATION);
			else if (src instanceof TunnelModuleComponent)
				return (TunnelModule)moduleContext.getModule(CityGMLModuleType.TUNNEL);
			else if (src instanceof VegetationModuleComponent)
				return (VegetationModule)moduleContext.getModule(CityGMLModuleType.VEGETATION);
			else if (src instanceof WaterBodyModuleComponent)
				return (WaterBodyModule)moduleContext.getModule(CityGMLModuleType.WATER_BODY);
			else
				return (CoreModule)moduleContext.getModule(CityGMLModuleType.CORE);		
		}

		else if (src != null) {
			moduleMatcher.reset(src.getClass().getPackage().getName());

			if (moduleMatcher.matches()) {
				String moduleString = moduleMatcher.group(1);
				if (moduleString == null)
					moduleString = "core";

				CityGMLModuleVersion version = moduleMatcher.group(2).equals("_2") ? CityGMLModuleVersion.v2_0_0 : CityGMLModuleVersion.v1_0_0;
				for (CityGMLModule module : Modules.getCityGMLModules()) {
					if (module.getVersion() == version && module.getType().toString().toLowerCase().equals(moduleString))
						return module;
				}	
			}		
		}

		return null;
	}
 
Example #28
Source File: AbstractJAXBWriter.java    From citygml4j with Apache License 2.0 4 votes vote down vote up
public void setPrefixes(ModuleContext moduleContext) {
	for (Module module : moduleContext.getModules())
		setPrefix(module);
}
 
Example #29
Source File: CityGMLNamespaceContext.java    From citygml4j with Apache License 2.0 4 votes vote down vote up
public void setPrefixes(ModuleContext moduleContext) {
	for (Module module : moduleContext.getModules())
		setPrefix(module);
}
 
Example #30
Source File: JAXBOutputFactory.java    From citygml4j with Apache License 2.0 4 votes vote down vote up
public void setCityGMLVersion(CityGMLVersion version) {
	if (version == null)
		throw new IllegalArgumentException("CityGML version may not be null.");

	moduleContext = new ModuleContext(version);
}