private void processSimpleType(SimpleType simpleType, SGStateInfo sInfo) { if (simpleType == null) return; String packageName = sInfo.packageName; //-- Right now the only time we actually //-- generate source for a simpletype is //-- when it's an enumeration //if (! (simpleType instanceof BuiltInType) ) { if (simpleType.hasFacet(Facet.ENUMERATION)) { ClassInfo classInfo = sInfo.resolve(simpleType); if (classInfo == null) { JClass jClass = sourceFactory.createSourceCode(simpleType, sInfo); processJClass(jClass, sInfo); } else { JClass jClass = classInfo.getJClass(); if (!sInfo.processed(jClass)) { processJClass(jClass, sInfo); } } } } //-- processSimpleType
/** * @param logging * @param origin origin source * @param ident unique identity for this cached source, used in filename * @param descr description of the source, used in logging * @param logging if true, log cache access * @return new source */ public ResourceModelSource createCachingSource( ResourceModelSource origin, String ident, String descr, SourceFactory.CacheType type, final boolean logging) { final File file = getResourceModelSourceFileCacheForType(ident); final ResourceModelSourceService nodesSourceService = getResourceModelSourceService(); final ResourceFormatGeneratorService resourceFormatGeneratorService = getResourceFormatGeneratorService(); final Properties fileSourceConfig = generateFileSourceConfigurationProperties( file.getAbsolutePath(), ResourceXMLFormatGenerator.SERVICE_PROVIDER_TYPE, false, false); try { ResourceModelSource fileSource = nodesSourceService.getSourceForConfiguration("file", fileSourceConfig); ResourceFormatGenerator generatorForFormat = resourceFormatGeneratorService.getGeneratorForFormat( ResourceXMLFormatGenerator.SERVICE_PROVIDER_TYPE); String ident1 = "[ResourceModelSource: " + descr + ", project: " + projectConfig.getName() + "]"; StoreExceptionHandler handler = new StoreExceptionHandler(ident); ResourceModelSourceCache cache = new FileResourceModelSourceCache(file, generatorForFormat, fileSource); if (logging) { cache = new LoggingResourceModelSourceCache(cache, ident1); } return SourceFactory.cachedSource(origin, ident1, handler, cache, type); } catch (UnsupportedFormatException | ExecutionServiceException e) { e.printStackTrace(); } return null; }
private void createClasses(Group group, SGStateInfo sInfo) { if (sInfo.verbose()) { System.out.print("Creating classes for group: "); System.out.println(group.getName()); if (group.getName() == null) { System.out.println("cannot create classes for unnamed nested groups"); return; } } JClass[] classes = sourceFactory.createSourceCode(group, sInfo); processContentModel(group, sInfo); for (int i = 0; i < classes.length; i++) processJClass(classes[i], sInfo); } //-- createClasses
/** * Processes the given ComplexType and creates all necessary class * to support it * @param complexType the ComplexType to process **/ private void processComplexType(ComplexType complexType, SGStateInfo sInfo) { if (complexType == null) return; ClassInfo classInfo = sInfo.resolve(complexType); if (classInfo == null) { //-- handle top-leve complextypes if (complexType.isTopLevel()) { JClass[] classes = sourceFactory.createSourceCode(complexType, sInfo); for (int i = 0; i < classes.length; i++) processJClass(classes[i], sInfo); } //-- process base complextype if necessary XMLType baseType= complexType.getBaseType(); if (baseType != null && baseType.getSchema() == complexType.getSchema()) { if (baseType.isComplexType()) processComplexType((ComplexType)baseType, sInfo); } //-- process AttributeDecl processAttributes(complexType, sInfo); //-- process ContentModel processContentModel(complexType, sInfo); } else { JClass jClass = classInfo.getJClass(); if (!sInfo.processed(jClass)) { //-- process AttributeDecl processAttributes(complexType, sInfo); //-- process ContentModel processContentModel(complexType, sInfo); processJClass(jClass, sInfo); } } } //-- processComplexType
private void createClasses(ElementDecl elementDecl, SGStateInfo sInfo) { //-- when mapping schema types, only interested in producing classes //-- for elements with anonymous complex types if (SourceGenerator.mappingSchemaType2Java()) if (elementDecl.isReference() || (elementDecl.getType()!=null && elementDecl.getType().getName()!=null)) return; if (sInfo.verbose()) { System.out.print("Creating classes for element: "); System.out.println(elementDecl.getName()); } //-- create classes for sub-elements if necessary XMLType xmlType = elementDecl.getType(); //-- No type definition if (xmlType == null) { System.out.print("Type not found for element: "); System.out.println(elementDecl.getName()); return; } //-- ComplexType else if (xmlType.isComplexType()) { JClass[] classes = sourceFactory.createSourceCode(elementDecl, sInfo); processComplexType((ComplexType)xmlType, sInfo); for (int i = 0; i < classes.length; i++) processJClass(classes[i], sInfo); } //-- SimpleType else { processSimpleType((SimpleType)xmlType, sInfo); } } //-- createClasses
private Generator<Object[]> createXLSSourceGenerator( ArrayTypeDescriptor arrayType, BeneratorContext context, String sourceName) { logger.debug("createXLSSourceGenerator({})", arrayType); boolean rowBased = (arrayType.isRowBased() != null ? arrayType.isRowBased() : true); String emptyMarker = arrayType.getEmptyMarker(); String nullMarker = arrayType.getNullMarker(); boolean formatted = isFormatted(arrayType); DataSourceProvider<Object[]> factory = new XLSArraySourceProvider( formatted, new ScriptConverterForObjects(context), emptyMarker, nullMarker, rowBased); Generator<Object[]> generator = SourceFactory.createRawSourceGenerator( arrayType.getNesting(), arrayType.getDataset(), sourceName, factory, Object[].class, context); generator = WrapperFactory.applyConverter(generator, new ArrayElementTypeConverter(arrayType)); return generator; }
private Generator<Object[]> createCSVSourceGenerator( ArrayTypeDescriptor arrayType, BeneratorContext context, String sourceName) { logger.debug("createCSVSourceGenerator({})", arrayType); String encoding = arrayType.getEncoding(); if (encoding == null) encoding = context.getDefaultEncoding(); char separator = DescriptorUtil.getSeparator(arrayType, context); boolean rowBased = (arrayType.isRowBased() != null ? arrayType.isRowBased() : true); DataSourceProvider<Object[]> factory = new CSVArraySourceProvider( arrayType.getName(), new ScriptConverterForStrings(context), rowBased, separator, encoding); Generator<Object[]> generator = SourceFactory.createRawSourceGenerator( arrayType.getNesting(), arrayType.getDataset(), sourceName, factory, Object[].class, context); return WrapperFactory.applyConverter(generator, new ArrayElementTypeConverter(arrayType)); }
/** * Sets whether or not to create the XML marshalling framework specific * methods (marshall, unmarshall, validate) in the generated classes. * By default, these methods are generated. * * @param createMarshall a boolean, when true indicates * to generated the marshalling framework methods * */ public void setTestable(boolean testable) { if (sourceFactory != null) sourceFactory.setTestable(testable); } //-- setTestable
/** * Sets whether or not to create the XML marshalling framework specific * methods (marshall, unmarshall, validate) in the generated classes. * By default, these methods are generated. * * @param createMarshalMethods a boolean, when true indicates * to generated the marshalling framework methods * */ public void setCreateMarshalMethods(boolean createMarshalMethods) { if (sourceFactory != null) sourceFactory.setCreateMarshalMethods(createMarshalMethods); } //-- setCreateMarshalMethods