264 // this codepath.
265 return (CClass)_bindToClass(t,referer,cannotBeDelayed);
266 }
267
268 public TypeUse bindToType( XSType t, XSComponent referer ) {
269 if(t instanceof XSSimpleType) {
270 return Ring.get(SimpleTypeBuilder.class).build((XSSimpleType)t);
271 } else
272 return (CNonElement)_bindToClass(t,referer,false);
273 }
274
275 /**
276 * The real meat of the "bindToType" code.
277 *
278 * @param cannotBeDelayed
279 * if the binding of the body of the class cannot be defered
280 * and needs to be done immediately. If the flag is false,
281 * the binding of the body will be done later, to avoid
282 * cyclic binding problem.
283 * @param referer
284 * The component that refers to <tt>sc</tt>. This can be null,
285 * if figuring out the referer is too hard, in which case
286 * the error message might be less user friendly.
287 */
288 // TODO: consider getting rid of "cannotBeDelayed"
289 CTypeInfo _bindToClass( @NotNull XSComponent sc, XSComponent referer, boolean cannotBeDelayed ) {
290 // check if this class is already built.
291 if(!bindMap.containsKey(sc)) {
292 // craete a bind task
293
294 // if this is a global declaration, make sure they will be generated
295 // under a package.
296 boolean isGlobal = false;
297 if( sc instanceof XSDeclaration ) {
298 isGlobal = ((XSDeclaration)sc).isGlobal();
299 if( isGlobal )
300 pushClassScope( new CClassInfoParent.Package(
301 getPackage(((XSDeclaration)sc).getTargetNamespace())) );
302 }
303
304 // otherwise check if this component should become a class.
406 append(bean,jdoc);
407
408 // then schema fragment
409 StringWriter out = new StringWriter();
410 out.write("<pre>\n");
411 SchemaWriter sw = new SchemaWriter(new JavadocEscapeWriter(out));
412 sc.visit(sw);
413 out.write("</pre>");
414 append(bean,out.toString());
415 }
416
417 private void append(CClassInfo bean, String doc) {
418 if(bean.javadoc==null)
419 bean.javadoc = doc+'\n';
420 else
421 bean.javadoc += '\n'+doc+'\n';
422 }
423
424
425 /**
426 * Set of package names that are tested (set of <code>String</code>s.)
427 *
428 * This set is used to avoid duplicating "incorrect package name"
429 * errors.
430 */
431 private static Set<String> checkedPackageNames = new HashSet<String>();
432
433 /**
434 * Gets the Java package to which classes from
435 * this namespace should go.
436 *
437 * <p>
438 * Usually, the getOuterClass method should be used
439 * to determine where to put a class.
440 */
441 public JPackage getPackage(String targetNamespace) {
442 XSSchema s = Ring.get(XSSchemaSet.class).getSchema(targetNamespace);
443
444 BISchemaBinding sb =
445 builder.getBindInfo(s).get(BISchemaBinding.class);
446 if(sb!=null) sb.markAsAcknowledged();
|
264 // this codepath.
265 return (CClass)_bindToClass(t,referer,cannotBeDelayed);
266 }
267
268 public TypeUse bindToType( XSType t, XSComponent referer ) {
269 if(t instanceof XSSimpleType) {
270 return Ring.get(SimpleTypeBuilder.class).build((XSSimpleType)t);
271 } else
272 return (CNonElement)_bindToClass(t,referer,false);
273 }
274
275 /**
276 * The real meat of the "bindToType" code.
277 *
278 * @param cannotBeDelayed
279 * if the binding of the body of the class cannot be defered
280 * and needs to be done immediately. If the flag is false,
281 * the binding of the body will be done later, to avoid
282 * cyclic binding problem.
283 * @param referer
284 * The component that refers to {@code sc}. This can be null,
285 * if figuring out the referer is too hard, in which case
286 * the error message might be less user friendly.
287 */
288 // TODO: consider getting rid of "cannotBeDelayed"
289 CTypeInfo _bindToClass( @NotNull XSComponent sc, XSComponent referer, boolean cannotBeDelayed ) {
290 // check if this class is already built.
291 if(!bindMap.containsKey(sc)) {
292 // craete a bind task
293
294 // if this is a global declaration, make sure they will be generated
295 // under a package.
296 boolean isGlobal = false;
297 if( sc instanceof XSDeclaration ) {
298 isGlobal = ((XSDeclaration)sc).isGlobal();
299 if( isGlobal )
300 pushClassScope( new CClassInfoParent.Package(
301 getPackage(((XSDeclaration)sc).getTargetNamespace())) );
302 }
303
304 // otherwise check if this component should become a class.
406 append(bean,jdoc);
407
408 // then schema fragment
409 StringWriter out = new StringWriter();
410 out.write("<pre>\n");
411 SchemaWriter sw = new SchemaWriter(new JavadocEscapeWriter(out));
412 sc.visit(sw);
413 out.write("</pre>");
414 append(bean,out.toString());
415 }
416
417 private void append(CClassInfo bean, String doc) {
418 if(bean.javadoc==null)
419 bean.javadoc = doc+'\n';
420 else
421 bean.javadoc += '\n'+doc+'\n';
422 }
423
424
425 /**
426 * Set of package names that are tested (set of {@code String}s.)
427 *
428 * This set is used to avoid duplicating "incorrect package name"
429 * errors.
430 */
431 private static Set<String> checkedPackageNames = new HashSet<String>();
432
433 /**
434 * Gets the Java package to which classes from
435 * this namespace should go.
436 *
437 * <p>
438 * Usually, the getOuterClass method should be used
439 * to determine where to put a class.
440 */
441 public JPackage getPackage(String targetNamespace) {
442 XSSchema s = Ring.get(XSSchemaSet.class).getSchema(targetNamespace);
443
444 BISchemaBinding sb =
445 builder.getBindInfo(s).get(BISchemaBinding.class);
446 if(sb!=null) sb.markAsAcknowledged();
|