本文整理了Java中com.sun.codemodel.JPackage.addResourceFile()
方法的一些代码示例,展示了JPackage.addResourceFile()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JPackage.addResourceFile()
方法的具体详情如下:
包路径:com.sun.codemodel.JPackage
类名称:JPackage
方法名:addResourceFile
[英]Adds a new resource file to this package.
[中]将新资源文件添加到此包。
代码示例来源:origin: nokia/Avro-Schema-Generator
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);
}
}
代码示例来源:origin: mklemm/jaxb2-rich-contract-plugin
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);
}
代码示例来源:origin: sun-jaxb/jaxb-xjc
public JClass generateStaticClass(Class src, JPackage out) {
String shortName = getShortName(src.getName());
// some people didn't like our jars to contain files with .java extension,
// so when we build jars, we'' use ".java_". But when we run from the workspace,
// we want the original source code to be used, so we check both here.
// see bug 6211503.
URL res = src.getResource(shortName+".java");
if(res==null)
res = src.getResource(shortName+".java_");
if(res==null)
throw new InternalError("Unable to load source code of "+src.getName()+" as a resource");
JStaticJavaFile sjf = new JStaticJavaFile(out,shortName, res, null );
out.addResourceFile(sjf);
return sjf.getJClass();
}
代码示例来源:origin: org.jvnet.hyperjaxb3/hyperjaxb3-ejb-plugin
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());
}
}
代码示例来源:origin: highsource/hyperjaxb3
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());
}
}
代码示例来源:origin: org.hisrc.jsonix/jsonix-schema-compiler
@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) {
}
}
}
代码示例来源:origin: org.jvnet.jaxb2_commons/basic
@Override
public boolean run(Outline outline, Options opt, ErrorHandler errorHandler) {
for (final PackageOutline packageOutline : outline
.getAllPackageContexts()) {
final StringBuffer sb = new StringBuffer();
for (final ClassOutline classOutline : packageOutline.getClasses()) {
sb.append(CodeModelUtils.getLocalClassName(classOutline.ref));
sb.append("\n");
}
final JTextFile indexFile = new JTextFile("jaxb.index");
indexFile.setContents(sb.toString());
packageOutline._package().addResourceFile(indexFile);
}
return true;
}
}
代码示例来源:origin: apache/servicemix-bundles
public JClass generateStaticClass(Class src, JPackage out) {
JStaticJavaFile sjf = new JStaticJavaFile(out, getShortName(src), src, null);
out.addResourceFile(sjf);
return sjf.getJClass();
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.jaxb-xjc
public JClass generateStaticClass(Class src, JPackage out) {
JStaticJavaFile sjf = new JStaticJavaFile(out, getShortName(src), src, null);
out.addResourceFile(sjf);
return sjf.getJClass();
}
代码示例来源:origin: org.jvnet.hyperjaxb3/hyperjaxb3-tools
@Override
public boolean run(Outline outline, Options opt, ErrorHandler errorHandler) {
for (final PackageOutline packageOutline : outline
.getAllPackageContexts()) {
final StringBuffer sb = new StringBuffer();
for (final ClassOutline classOutline : packageOutline.getClasses()) {
sb.append(CodeModelUtils.getLocalClassName(classOutline.ref));
sb.append("\n");
}
final JTextFile indexFile = new JTextFile("jaxb.index");
indexFile.setContents(sb.toString());
packageOutline._package().addResourceFile(indexFile);
}
return true;
}
代码示例来源:origin: org.glassfish.metro/webservices-tools
public JClass generateStaticClass(Class src, JPackage out) {
JStaticJavaFile sjf = new JStaticJavaFile(out, getShortName(src), src, null);
out.addResourceFile(sjf);
return sjf.getJClass();
}
代码示例来源:origin: org.hisrc.jsonix/jsonix-schema-compiler
@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) {
}
}
}
代码示例来源:origin: com.cedarsoft.serialization.generator/common
@Nonnull
@Override
protected JExpression createExpectedExpression( @Nonnull JClass testClass, @Nonnull JClass domainType ) {
String resourceName = domainType.name() + "_1.0.0_1.xml";
JPackage testClassPackage = testClass._package();
if ( !testClassPackage.hasResourceFile( resourceName ) ) {
JTextFile resource = new JTextFile( resourceName );
resource.setContents( createSampleContent( domainType ) );
testClassPackage.addResourceFile( resource );
}
return testClass.dotclass().invoke( METHOD_GET_RESOURCE ).arg( resourceName );
}
代码示例来源:origin: com.cedarsoft.serialization.generator/common
@Nonnull
@Override
protected JExpression createExpectedExpression( @Nonnull JClass testClass, @Nonnull JClass domainType ) {
String resourceName = domainType.name() + "_1.0.0_1.json";
JPackage testClassPackage = testClass._package();
if ( !testClassPackage.hasResourceFile( resourceName ) ) {
JTextFile resource = new JTextFile( resourceName );
resource.setContents( createSampleContent( domainType ) );
testClassPackage.addResourceFile( resource );
}
return testClass.dotclass().invoke( METHOD_GET_RESOURCE ).arg( resourceName );
}
代码示例来源:origin: apache/servicemix-bundles
public PrivateObjectFactoryGenerator(BeanGenerator outline, Model model, JPackage targetPackage) {
super(outline, model, targetPackage.subPackage("impl"));
JPackage implPkg = targetPackage.subPackage("impl");
// put JAXBContextFactory into the impl package
JClass factory = outline.generateStaticClass(JAXBContextFactory.class,implPkg);
// and then put jaxb.properties to point to it
JPropertyFile jaxbProperties = new JPropertyFile("jaxb.properties");
targetPackage.addResourceFile(jaxbProperties);
jaxbProperties.add(
JAXBContext.JAXB_CONTEXT_FACTORY,
factory.fullName());
}
代码示例来源:origin: org.andromda.thirdparty.jaxb2_commons/jaxb-xjc
public PrivateObjectFactoryGenerator(BeanGenerator outline, Model model, JPackage targetPackage) {
super(outline, model, targetPackage.subPackage("impl"));
JPackage implPkg = targetPackage.subPackage("impl");
// put JAXBContextFactory into the impl package
JClass factory = outline.generateStaticClass(JAXBContextFactory.class,implPkg);
// and then put jaxb.properties to point to it
JPropertyFile jaxbProperties = new JPropertyFile("jaxb.properties");
targetPackage.addResourceFile(jaxbProperties);
jaxbProperties.add(
JAXBContext.JAXB_CONTEXT_FACTORY,
factory.fullName());
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.jaxb-xjc
public PrivateObjectFactoryGenerator(BeanGenerator outline, Model model, JPackage targetPackage) {
super(outline, model, targetPackage.subPackage("impl"));
JPackage implPkg = targetPackage.subPackage("impl");
// put JAXBContextFactory into the impl package
JClass factory = outline.generateStaticClass(JAXBContextFactory.class,implPkg);
// and then put jaxb.properties to point to it
JPropertyFile jaxbProperties = new JPropertyFile("jaxb.properties");
targetPackage.addResourceFile(jaxbProperties);
jaxbProperties.add(
JAXBContext.JAXB_CONTEXT_FACTORY,
factory.fullName());
}
代码示例来源:origin: org.glassfish.metro/webservices-tools
public PrivateObjectFactoryGenerator(BeanGenerator outline, Model model, JPackage targetPackage) {
super(outline, model, targetPackage.subPackage("impl"));
JPackage implPkg = targetPackage.subPackage("impl");
// put JAXBContextFactory into the impl package
JClass factory = outline.generateStaticClass(JAXBContextFactory.class,implPkg);
// and then put jaxb.properties to point to it
JPropertyFile jaxbProperties = new JPropertyFile("jaxb.properties");
targetPackage.addResourceFile(jaxbProperties);
jaxbProperties.add(
JAXBContext.JAXB_CONTEXT_FACTORY,
factory.fullName());
}
代码示例来源:origin: sun-jaxb/jaxb-xjc
public PrivateObjectFactoryGenerator(BeanGenerator outline, Model model, JPackage targetPackage) {
super(outline, model, targetPackage.subPackage("impl"));
JPackage implPkg = targetPackage.subPackage("impl");
// put JAXBContextFactory into the impl package
JClass factory = outline.generateStaticClass(JAXBContextFactory.class,implPkg);
// and then put jaxb.properties to point to it
JPropertyFile jaxbProperties = new JPropertyFile("jaxb.properties");
targetPackage.addResourceFile(jaxbProperties);
jaxbProperties.add(
JAXBContext.JAXB_CONTEXT_FACTORY,
factory.fullName());
}
代码示例来源:origin: apache/servicemix-bundles
/**
* Generates <code>package.html</code> if the customization
* says so.
*/
private void processPackageJavadoc( XSSchema s ) {
// look for the schema-wide customization
BISchemaBinding cust = getBindInfo(s).get(BISchemaBinding.class);
if(cust==null) return; // not present
cust.markAsAcknowledged();
if( cust.getJavadoc()==null ) return; // no javadoc customization
// produce a HTML file
JTextFile html = new JTextFile("package.html");
html.setContents(cust.getJavadoc());
getClassSelector().getPackage(s.getTargetNamespace()).addResourceFile(html);
}
内容来源于网络,如有侵权,请联系作者删除!