Example #1
0
  /** Adds the methods we override from. {@link org.exolab.castor.xml.XMLClassDescriptor} */
  private void addXMLClassDescriptorOverrides() {
    JMethod method;
    JSourceCode jsc;
    // -- create getNameSpacePrefix method
    method =
        new JMethod(
            "getNameSpacePrefix",
            SGTypes.String,
            "the namespace prefix to use when marshaling as XML.");

    if (_config.useJava50()) {
      method.addAnnotation(new JAnnotation(new JAnnotationType("Override")));
    }

    jsc = method.getSourceCode();
    jsc.add("return nsPrefix;");
    addMethod(method);

    // -- create getNameSpaceURI method
    method =
        new JMethod(
            "getNameSpaceURI",
            SGTypes.String,
            "the namespace URI used when marshaling and unmarshaling as XML.");

    if (_config.useJava50()) {
      method.addAnnotation(new JAnnotation(new JAnnotationType("Override")));
    }

    jsc = method.getSourceCode();
    jsc.add("return nsURI;");
    addMethod(method);

    // -- create getValidator method
    method =
        new JMethod(
            "getValidator",
            TYPE_VALIDATOR_CLASS,
            "a specific validator for the class described" + " by this ClassDescriptor.");

    if (_config.useJava50()) {
      method.addAnnotation(new JAnnotation(new JAnnotationType("Override")));
    }

    jsc = method.getSourceCode();
    jsc.add("return this;");
    addMethod(method);

    // -- create getXMLName method
    method =
        new JMethod("getXMLName", SGTypes.String, "the XML Name for the Class being described.");

    if (_config.useJava50()) {
      method.addAnnotation(new JAnnotation(new JAnnotationType("Override")));
    }

    jsc = method.getSourceCode();
    jsc.add("return xmlName;");
    addMethod(method);
  }
Example #2
0
  /**
   * Adds the methods we override from. {@link org.exolab.castor.mapping.ClassDescriptor}
   *
   * @param extended true if we extend another class and thus need to call super()
   */
  private void addClassDescriptorOverrides(final boolean extended) {
    JSourceCode jsc;

    // -- create getAccessMode method
    JClass amClass = new JClass(MAPPING_ACCESS_MODE);
    JMethod getAccessMode =
        new JMethod("getAccessMode", amClass, "the access mode specified for this class.");

    if (_config.useJava50()) {
      getAccessMode.addAnnotation(new JAnnotation(new JAnnotationType("Override")));
    }

    jsc = getAccessMode.getSourceCode();
    jsc.add("return null;");
    addMethod(getAccessMode);

    // -- create getIdentity method
    JMethod getIdentity =
        new JMethod(
            "getIdentity",
            FIELD_DESCRIPTOR_CLASS,
            "the identity field, null if this class has no identity.");

    if (_config.useJava50()) {
      getIdentity.addAnnotation(new JAnnotation(new JAnnotationType("Override")));
    }

    jsc = getIdentity.getSourceCode();
    if (extended) {
      jsc.add("if (identity == null) {");
      jsc.indent();
      jsc.add("return super.getIdentity();");
      jsc.unindent();
      jsc.add("}");
    }
    jsc.add("return identity;");

    // --don't add the type to the import list
    addMethod(getIdentity, false);

    // -- create getJavaClass method
    JMethod getJavaClass =
        new JMethod(
            "getJavaClass", SGTypes.Class, "the Java class represented by this descriptor.");

    if (_config.useJava50()) {
      getJavaClass.addAnnotation(new JAnnotation(new JAnnotationType("Override")));
    }

    jsc = getJavaClass.getSourceCode();
    jsc.add("return ");
    jsc.append(classType(_type));
    jsc.append(";");

    // --don't add the type to the import list
    addMethod(getJavaClass, false);
  }
Example #3
0
  /**
   * Creates a new EnumerationFactory for the builder configuration given.
   *
   * @param config the current BuilderConfiguration instance.
   * @param groupNaming The group naming scheme to be used.
   * @param sourceGenerator the calling source generator.
   */
  public EnumerationFactory(
      final BuilderConfiguration config,
      final GroupNaming groupNaming,
      final SourceGenerator sourceGenerator) {
    super(config, null, groupNaming, sourceGenerator);
    _typeConversion = new TypeConversion(getConfig());

    // TODO[WG]: add code to read in max. value from builder property file
    _maxEnumerationsPerClass = config.getMaximumNumberOfConstants();
  } // -- SourceFactory
Example #4
0
  /** Initializes this DescriptorJClass with the required methods. */
  private void init() {
    // Make sure that the Descriptor is extended XMLClassDescriptor even when
    // the user has specified a super class for all the generated classes
    String superClass = null;
    if (_config != null) {
      superClass = _config.getProperty(BuilderConfiguration.Property.SUPER_CLASS, null);
    }

    boolean extended = false;

    if (_type.getSuperClassQualifiedName() == null
        || _type.getSuperClassQualifiedName().equals(superClass)) {
      setSuperClass(XMLCLASS_DESCRIPTOR_IMPL);
    } else {
      if (_type.getSuperClass() == null) {
        setSuperClass(null);
      } else {
        extended = true;
        setSuperClass(getSuperClassName());
      }
    }
    superClass = null;

    if (_type.getPackageName() != null && _type.getPackageName().length() > 0) {
      addImport(_type.getName());
      if (extended) {
        if (_type.getSuperClass() != null) {
          addImport(getSuperClassName());
        }
      }
    }

    addField(new JField(JType.BOOLEAN, "elementDefinition"));

    addField(new JField(SGTypes.String, "nsPrefix"));
    addField(new JField(SGTypes.String, "nsURI"));
    addField(new JField(SGTypes.String, "xmlName"));
    // -- if there is a super class, the identity field must remain
    // -- the same than the one in the super class
    addField(new JField(XML_FIELD_DESCRIPTOR_CLASS, "identity"));

    // -- create default constructor
    addDefaultConstructor(extended);

    // jsc.add("Class[] emptyClassArgs = new Class[0];");
    // jsc.add("Class[] classArgs = new Class[1];");

    // ---------------------------------------------/
    // - Methods Defined by XMLClassDescriptorImpl -/
    // ---------------------------------------------/

    addXMLClassDescriptorImplOverrides();

    // -----------------------------------------/
    // - Methods Defined by XMLClassDescriptor -/
    // -----------------------------------------/

    addXMLClassDescriptorOverrides();

    // --------------------------------------/
    // - Methods defined by ClassDescriptor -/
    // --------------------------------------/

    addClassDescriptorOverrides(extended);
  } // -- createSource