Java Code Examples for com.sun.codemodel.JPackage#addResourceFile()
The following examples show how to use
com.sun.codemodel.JPackage#addResourceFile() .
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: CodeModelUtils.java From jaxb2-basics with BSD 2-Clause "Simplified" License | 6 votes |
/** * Returns a property file (created if necessary). * * @param thePackage * package to create property file * @param name * property file name. * @return Property file. */ public static JPropertyFile getOrCreatePropertyFile(JPackage thePackage, String name) { JPropertyFile propertyFile = null; for (Iterator<JResourceFile> iterator = thePackage.propertyFiles(); iterator .hasNext() && (null == propertyFile);) { final JResourceFile resourceFile = (JResourceFile) iterator.next(); if (resourceFile instanceof JPropertyFile && name.equals(resourceFile.name())) { propertyFile = (JPropertyFile) resourceFile; } } if (null == propertyFile) { propertyFile = new JPropertyFile(name); thePackage.addResourceFile(propertyFile); } return propertyFile; }
Example 2
Source File: CodeModelProgramWriter.java From jsonix-schema-compiler with BSD 2-Clause "Simplified" License | 6 votes |
@Override public void writeProgram(Module<NType, NClass> module, JSProgram program, Output output) { try { final JPackage _package = codeModel._package(output .getOutputPackageName()); _package.addResourceFile(createTextFile(output.getFileName(), program)); } catch (IOException ioex) { try { errorHandler.error(new SAXParseException(MessageFormat.format( "Could not create the code for the module [{0}].", module.getName()), null, ioex)); } catch (SAXException ignored) { } } }
Example 3
Source File: CodeModelJsonStructureWriter.java From jsonix-schema-compiler with BSD 2-Clause "Simplified" License | 6 votes |
@Override public void writeJsonStructure(Module<NType, NClass> module, JsonStructure structure, String fileName) { try { final JPackage _package = codeModel._package(""); _package.addResourceFile(createTextFile(fileName, structure)); } catch (IOException ioex) { try { errorHandler.error(new SAXParseException(MessageFormat.format( "Could not create the code for the module [{0}].", module.getName()), null, ioex)); } catch (SAXException ignored) { } } }
Example 4
Source File: AvroSchemagenPlugin.java From Avro-Schema-Generator with Apache License 2.0 | 6 votes |
private void outputSchema(JPackage avroPackage, List<NamedAvroType> types) { // set up the correct format for leading zeros (ensures proper order in filesystem) StringBuilder digits = new StringBuilder(); for (int i=0; i < Integer.toString(types.size()).length(); ++i) { digits.append("0"); } DecimalFormat format = new java.text.DecimalFormat(digits.toString()); AtomicInteger counter = new AtomicInteger(1); for (NamedAvroType type : types) { String id = format.format(counter.getAndIncrement()); JTextFile avroSchema = new JTextFile("avroSchema-"+ id +"_"+ type.name +".txt"); avroSchema.setContents(getJson(type)); avroPackage.addResourceFile(avroSchema); } }
Example 5
Source File: PluginContext.java From jaxb2-rich-contract-plugin with MIT License | 4 votes |
public void writeSourceFile(final Class<?> classToBeWritten) { final String resourcePath = "/" + classToBeWritten.getName().replace('.', '/') + ".java"; final JPackage jPackage = this.outline.getCodeModel()._package(classToBeWritten.getPackage().getName()); final JStaticJavaFile javaFile = new JStaticJavaFile(jPackage, classToBeWritten.getSimpleName(), classToBeWritten, null); jPackage.addResourceFile(javaFile); }
Example 6
Source File: PersistenceMarshaller.java From hyperjaxb3 with BSD 2-Clause "Simplified" License | 3 votes |
public void marshallPersistence(JCodeModel codeModel, Persistence persistence) throws Exception { // final JPackage defaultPackage = codeModel._package(""); final JPackage metaInfPackage = codeModel._package("META-INF"); final JTextFile persistenceXmlFile = new JTextFile("persistence.xml"); metaInfPackage.addResourceFile(persistenceXmlFile); final Writer writer = new StringWriter(); getMarshaller().marshal(persistence, writer); persistenceXmlFile.setContents(writer.toString()); }