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);
  }