com.sun.codemodel.internal.JFieldVar Java Examples

The following examples show how to use com.sun.codemodel.internal.JFieldVar. 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: ObjectFactoryGeneratorImpl.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * return a JFieldVar that represents the QName field for the given information.
 *
 * if it doesn't exist, create a static field in the class and store a new JFieldVar.
 */
private JExpression getQNameInvocation(CElementInfo ei) {
    QName name = ei.getElementName();
    if(qnameMap.containsKey(name)) {
        return qnameMap.get(name);
    }

    if(qnameMap.size()>1024)
        // stop gap measure to avoid 'code too large' error in javac.
        return createQName(name);

    // [RESULT]
    // private static final QName _XYZ_NAME = new QName("uri", "local");
    JFieldVar qnameField = objectFactory.field(
        JMod.PRIVATE | JMod.STATIC | JMod.FINAL,
        QName.class,
        '_' + ei.getSqueezedName() + "_QNAME", createQName(name));

    qnameMap.put(name, qnameField);

    return qnameField;
}
 
Example #2
Source File: ObjectFactoryGeneratorImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * return a JFieldVar that represents the QName field for the given information.
 *
 * if it doesn't exist, create a static field in the class and store a new JFieldVar.
 */
private JExpression getQNameInvocation(CElementInfo ei) {
    QName name = ei.getElementName();
    if(qnameMap.containsKey(name)) {
        return qnameMap.get(name);
    }

    if(qnameMap.size()>1024)
        // stop gap measure to avoid 'code too large' error in javac.
        return createQName(name);

    // [RESULT]
    // private static final QName _XYZ_NAME = new QName("uri", "local");
    JFieldVar qnameField = objectFactory.field(
        JMod.PRIVATE | JMod.STATIC | JMod.FINAL,
        QName.class,
        '_' + ei.getSqueezedName() + "_QNAME", createQName(name));

    qnameMap.put(name, qnameField);

    return qnameField;
}
 
Example #3
Source File: ObjectFactoryGeneratorImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * return a JFieldVar that represents the QName field for the given information.
 *
 * if it doesn't exist, create a static field in the class and store a new JFieldVar.
 */
private JExpression getQNameInvocation(CElementInfo ei) {
    QName name = ei.getElementName();
    if(qnameMap.containsKey(name)) {
        return qnameMap.get(name);
    }

    if(qnameMap.size()>1024)
        // stop gap measure to avoid 'code too large' error in javac.
        return createQName(name);

    // [RESULT]
    // private static final QName _XYZ_NAME = new QName("uri", "local");
    JFieldVar qnameField = objectFactory.field(
        JMod.PRIVATE | JMod.STATIC | JMod.FINAL,
        QName.class,
        '_' + ei.getSqueezedName() + "_QNAME", createQName(name));

    qnameMap.put(name, qnameField);

    return qnameField;
}
 
Example #4
Source File: ObjectFactoryGeneratorImpl.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * return a JFieldVar that represents the QName field for the given information.
 *
 * if it doesn't exist, create a static field in the class and store a new JFieldVar.
 */
private JExpression getQNameInvocation(CElementInfo ei) {
    QName name = ei.getElementName();
    if(qnameMap.containsKey(name)) {
        return qnameMap.get(name);
    }

    if(qnameMap.size()>1024)
        // stop gap measure to avoid 'code too large' error in javac.
        return createQName(name);

    // [RESULT]
    // private static final QName _XYZ_NAME = new QName("uri", "local");
    JFieldVar qnameField = objectFactory.field(
        JMod.PRIVATE | JMod.STATIC | JMod.FINAL,
        QName.class,
        '_' + ei.getSqueezedName() + "_QNAME", createQName(name));

    qnameMap.put(name, qnameField);

    return qnameField;
}
 
Example #5
Source File: ObjectFactoryGeneratorImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * return a JFieldVar that represents the QName field for the given information.
 *
 * if it doesn't exist, create a static field in the class and store a new JFieldVar.
 */
private JExpression getQNameInvocation(CElementInfo ei) {
    QName name = ei.getElementName();
    if(qnameMap.containsKey(name)) {
        return qnameMap.get(name);
    }

    if(qnameMap.size()>1024)
        // stop gap measure to avoid 'code too large' error in javac.
        return createQName(name);

    // [RESULT]
    // private static final QName _XYZ_NAME = new QName("uri", "local");
    JFieldVar qnameField = objectFactory.field(
        JMod.PRIVATE | JMod.STATIC | JMod.FINAL,
        QName.class,
        '_' + ei.getSqueezedName() + "_QNAME", createQName(name));

    qnameMap.put(name, qnameField);

    return qnameField;
}
 
Example #6
Source File: ObjectFactoryGeneratorImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * return a JFieldVar that represents the QName field for the given information.
 *
 * if it doesn't exist, create a static field in the class and store a new JFieldVar.
 */
private JExpression getQNameInvocation(CElementInfo ei) {
    QName name = ei.getElementName();
    if(qnameMap.containsKey(name)) {
        return qnameMap.get(name);
    }

    if(qnameMap.size()>1024)
        // stop gap measure to avoid 'code too large' error in javac.
        return createQName(name);

    // [RESULT]
    // private static final QName _XYZ_NAME = new QName("uri", "local");
    JFieldVar qnameField = objectFactory.field(
        JMod.PRIVATE | JMod.STATIC | JMod.FINAL,
        QName.class,
        '_' + ei.getSqueezedName() + "_QNAME", createQName(name));

    qnameMap.put(name, qnameField);

    return qnameField;
}
 
Example #7
Source File: ServiceGenerator.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private void writeResourceWSDLLocation(String className, JDefinedClass cls, JFieldVar urlField, JFieldVar exField) {
    JBlock staticBlock = cls.init();
    staticBlock.assign(urlField, JExpr.dotclass(cm.ref(className)).invoke("getResource").arg(wsdlLocation));
    JVar exVar = staticBlock.decl(cm.ref(WebServiceException.class), "e", JExpr._null());
    JConditional ifBlock = staticBlock._if(urlField.eq(JExpr._null()));
    ifBlock._then().assign(exVar, JExpr._new(cm.ref(WebServiceException.class)).arg(
            "Cannot find "+JExpr.quotify('\'', wsdlLocation)+" wsdl. Place the resource correctly in the classpath."));
    staticBlock.assign(exField, exVar);
}
 
Example #8
Source File: PluginImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Adds "@Generated" to the classes, methods, and fields.
 */
private void augument(ClassOutline co) {
    annotate(co.implClass);
    for (JMethod m : co.implClass.methods())
        annotate(m);
    for (JFieldVar f : co.implClass.fields().values())
        annotate(f);
}
 
Example #9
Source File: ServiceGenerator.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private void writeAbsWSDLLocation(JDefinedClass cls, JFieldVar urlField, JFieldVar exField) {
    JBlock staticBlock = cls.init();
    JVar urlVar = staticBlock.decl(cm.ref(URL.class), "url", JExpr._null());
    JVar exVar = staticBlock.decl(cm.ref(WebServiceException.class), "e", JExpr._null());

    JTryBlock tryBlock = staticBlock._try();
    tryBlock.body().assign(urlVar, JExpr._new(cm.ref(URL.class)).arg(wsdlLocation));
    JCatchBlock catchBlock = tryBlock._catch(cm.ref(MalformedURLException.class));
    catchBlock.param("ex");
    catchBlock.body().assign(exVar, JExpr._new(cm.ref(WebServiceException.class)).arg(JExpr.ref("ex")));

    staticBlock.assign(urlField, urlVar);
    staticBlock.assign(exField, exVar);
}
 
Example #10
Source File: PluginImpl.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Adds "@Generated" to the classes, methods, and fields.
 */
private void augument(ClassOutline co) {
    annotate(co.implClass);
    for (JMethod m : co.implClass.methods())
        annotate(m);
    for (JFieldVar f : co.implClass.fields().values())
        annotate(f);
}
 
Example #11
Source File: ElementOutlineImpl.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
ElementOutlineImpl(BeanGenerator parent, CElementInfo ei) {
    super(ei,
          parent.getClassFactory().createClass(
                  parent.getContainer( ei.parent, Aspect.EXPOSED ), ei.shortName(), ei.getLocator() ));
    this.parent = parent;
    parent.elements.put(ei,this);

    JCodeModel cm = parent.getCodeModel();

    implClass._extends(
        cm.ref(JAXBElement.class).narrow(
            target.getContentInMemoryType().toType(parent,Aspect.EXPOSED).boxify()));

    if(ei.hasClass()) {
        JType implType = ei.getContentInMemoryType().toType(parent,Aspect.IMPLEMENTATION);
        JExpression declaredType = JExpr.cast(cm.ref(Class.class),implType.boxify().dotclass()); // why do we have to cast?
        JClass scope=null;
        if(ei.getScope()!=null)
            scope = parent.getClazz(ei.getScope()).implRef;
        JExpression scopeClass = scope==null?JExpr._null():scope.dotclass();
        JFieldVar valField = implClass.field(JMod.PROTECTED|JMod.FINAL|JMod.STATIC,QName.class,"NAME",createQName(cm,ei.getElementName()));

        // take this opportunity to generate a constructor in the element class
        JMethod cons = implClass.constructor(JMod.PUBLIC);
        cons.body().invoke("super")
            .arg(valField)
            .arg(declaredType)
            .arg(scopeClass)
            .arg(cons.param(implType,"value"));

        // generate no-arg constructor in the element class (bug #391; section 5.6.2 in JAXB spec 2.1)
        JMethod noArgCons = implClass.constructor(JMod.PUBLIC);
        noArgCons.body().invoke("super")
            .arg(valField)
            .arg(declaredType)
            .arg(scopeClass)
            .arg(JExpr._null());

    }
}
 
Example #12
Source File: BeanGenerator.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Generates an attribute wildcard property on a class.
 */
private void generateAttributeWildcard(ClassOutlineImpl cc) {
    String FIELD_NAME = "otherAttributes";
    String METHOD_SEED = model.getNameConverter().toClassName(FIELD_NAME);

    JClass mapType = codeModel.ref(Map.class).narrow(QName.class, String.class);
    JClass mapImpl = codeModel.ref(HashMap.class).narrow(QName.class, String.class);

    // [RESULT]
    // Map<QName,String> m = new HashMap<QName,String>();
    JFieldVar $ref = cc.implClass.field(JMod.PRIVATE,
            mapType, FIELD_NAME, JExpr._new(mapImpl));
    $ref.annotate2(XmlAnyAttributeWriter.class);

    MethodWriter writer = cc.createMethodWriter();

    JMethod $get = writer.declareMethod(mapType, "get" + METHOD_SEED);
    $get.javadoc().append(
            "Gets a map that contains attributes that aren't bound to any typed property on this class.\n\n"
            + "<p>\n"
            + "the map is keyed by the name of the attribute and \n"
            + "the value is the string value of the attribute.\n"
            + "\n"
            + "the map returned by this method is live, and you can add new attribute\n"
            + "by updating the map directly. Because of this design, there's no setter.\n");
    $get.javadoc().addReturn().append("always non-null");

    $get.body()._return($ref);
}
 
Example #13
Source File: ServiceGenerator.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private void writeClassLoaderBaseResourceWSDLLocation(String className, JDefinedClass cls, JFieldVar urlField, JFieldVar exField) {
    JBlock staticBlock = cls.init();
    JVar exVar = staticBlock.decl(cm.ref(WebServiceException.class), "e", JExpr._null());
    JVar urlVar = staticBlock.decl(cm.ref(URL.class), "url", JExpr._null());
    JTryBlock tryBlock = staticBlock._try();
    tryBlock.body().assign(urlVar, JExpr._new(cm.ref(URL.class)).arg(JExpr.dotclass(cm.ref(className)).invoke("getResource").arg(".")).arg(wsdlLocation));
    JCatchBlock catchBlock = tryBlock._catch(cm.ref(MalformedURLException.class));
    JVar murlVar = catchBlock.param("murl");
    catchBlock.body().assign(exVar, JExpr._new(cm.ref(WebServiceException.class)).arg(murlVar));
    staticBlock.assign(urlField, urlVar);
    staticBlock.assign(exField, exVar);
}
 
Example #14
Source File: ServiceGenerator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void writeClassLoaderBaseResourceWSDLLocation(String className, JDefinedClass cls, JFieldVar urlField, JFieldVar exField) {
    JBlock staticBlock = cls.init();
    JVar exVar = staticBlock.decl(cm.ref(WebServiceException.class), "e", JExpr._null());
    JVar urlVar = staticBlock.decl(cm.ref(URL.class), "url", JExpr._null());
    JTryBlock tryBlock = staticBlock._try();
    tryBlock.body().assign(urlVar, JExpr._new(cm.ref(URL.class)).arg(JExpr.dotclass(cm.ref(className)).invoke("getResource").arg(".")).arg(wsdlLocation));
    JCatchBlock catchBlock = tryBlock._catch(cm.ref(MalformedURLException.class));
    JVar murlVar = catchBlock.param("murl");
    catchBlock.body().assign(exVar, JExpr._new(cm.ref(WebServiceException.class)).arg(murlVar));
    staticBlock.assign(urlField, urlVar);
    staticBlock.assign(exField, exVar);
}
 
Example #15
Source File: ServiceGenerator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void writeAbsWSDLLocation(JDefinedClass cls, JFieldVar urlField, JFieldVar exField) {
    JBlock staticBlock = cls.init();
    JVar urlVar = staticBlock.decl(cm.ref(URL.class), "url", JExpr._null());
    JVar exVar = staticBlock.decl(cm.ref(WebServiceException.class), "e", JExpr._null());

    JTryBlock tryBlock = staticBlock._try();
    tryBlock.body().assign(urlVar, JExpr._new(cm.ref(URL.class)).arg(wsdlLocation));
    JCatchBlock catchBlock = tryBlock._catch(cm.ref(MalformedURLException.class));
    catchBlock.param("ex");
    catchBlock.body().assign(exVar, JExpr._new(cm.ref(WebServiceException.class)).arg(JExpr.ref("ex")));

    staticBlock.assign(urlField, urlVar);
    staticBlock.assign(exField, exVar);
}
 
Example #16
Source File: ServiceGenerator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void writeResourceWSDLLocation(String className, JDefinedClass cls, JFieldVar urlField, JFieldVar exField) {
    JBlock staticBlock = cls.init();
    staticBlock.assign(urlField, JExpr.dotclass(cm.ref(className)).invoke("getResource").arg(wsdlLocation));
    JVar exVar = staticBlock.decl(cm.ref(WebServiceException.class), "e", JExpr._null());
    JConditional ifBlock = staticBlock._if(urlField.eq(JExpr._null()));
    ifBlock._then().assign(exVar, JExpr._new(cm.ref(WebServiceException.class)).arg(
            "Cannot find "+JExpr.quotify('\'', wsdlLocation)+" wsdl. Place the resource correctly in the classpath."));
    staticBlock.assign(exField, exVar);
}
 
Example #17
Source File: ServiceGenerator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void writeClassLoaderResourceWSDLLocation(String className, JDefinedClass cls, JFieldVar urlField, JFieldVar exField) {
    JBlock staticBlock = cls.init();
    staticBlock.assign(urlField, JExpr.dotclass(cm.ref(className)).invoke("getClassLoader").invoke("getResource").arg(wsdlLocation));
    JVar exVar = staticBlock.decl(cm.ref(WebServiceException.class), "e", JExpr._null());
    JConditional ifBlock = staticBlock._if(urlField.eq(JExpr._null()));
    ifBlock._then().assign(exVar, JExpr._new(cm.ref(WebServiceException.class)).arg(
            "Cannot find "+JExpr.quotify('\'', wsdlLocation)+" wsdl. Place the resource correctly in the classpath."));
    staticBlock.assign(exField, exVar);
}
 
Example #18
Source File: ElementOutlineImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
ElementOutlineImpl(BeanGenerator parent, CElementInfo ei) {
    super(ei,
          parent.getClassFactory().createClass(
                  parent.getContainer( ei.parent, Aspect.EXPOSED ), ei.shortName(), ei.getLocator() ));
    this.parent = parent;
    parent.elements.put(ei,this);

    JCodeModel cm = parent.getCodeModel();

    implClass._extends(
        cm.ref(JAXBElement.class).narrow(
            target.getContentInMemoryType().toType(parent,Aspect.EXPOSED).boxify()));

    if(ei.hasClass()) {
        JType implType = ei.getContentInMemoryType().toType(parent,Aspect.IMPLEMENTATION);
        JExpression declaredType = JExpr.cast(cm.ref(Class.class),implType.boxify().dotclass()); // why do we have to cast?
        JClass scope=null;
        if(ei.getScope()!=null)
            scope = parent.getClazz(ei.getScope()).implRef;
        JExpression scopeClass = scope==null?JExpr._null():scope.dotclass();
        JFieldVar valField = implClass.field(JMod.PROTECTED|JMod.FINAL|JMod.STATIC,QName.class,"NAME",createQName(cm,ei.getElementName()));

        // take this opportunity to generate a constructor in the element class
        JMethod cons = implClass.constructor(JMod.PUBLIC);
        cons.body().invoke("super")
            .arg(valField)
            .arg(declaredType)
            .arg(scopeClass)
            .arg(cons.param(implType,"value"));

        // generate no-arg constructor in the element class (bug #391; section 5.6.2 in JAXB spec 2.1)
        JMethod noArgCons = implClass.constructor(JMod.PUBLIC);
        noArgCons.body().invoke("super")
            .arg(valField)
            .arg(declaredType)
            .arg(scopeClass)
            .arg(JExpr._null());

    }
}
 
Example #19
Source File: ServiceGenerator.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private void writeClassLoaderResourceWSDLLocation(String className, JDefinedClass cls, JFieldVar urlField, JFieldVar exField) {
    JBlock staticBlock = cls.init();
    staticBlock.assign(urlField, JExpr.dotclass(cm.ref(className)).invoke("getClassLoader").invoke("getResource").arg(wsdlLocation));
    JVar exVar = staticBlock.decl(cm.ref(WebServiceException.class), "e", JExpr._null());
    JConditional ifBlock = staticBlock._if(urlField.eq(JExpr._null()));
    ifBlock._then().assign(exVar, JExpr._new(cm.ref(WebServiceException.class)).arg(
            "Cannot find "+JExpr.quotify('\'', wsdlLocation)+" wsdl. Place the resource correctly in the classpath."));
    staticBlock.assign(exField, exVar);
}
 
Example #20
Source File: ServiceGenerator.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private void writeAbsWSDLLocation(JDefinedClass cls, JFieldVar urlField, JFieldVar exField) {
    JBlock staticBlock = cls.init();
    JVar urlVar = staticBlock.decl(cm.ref(URL.class), "url", JExpr._null());
    JVar exVar = staticBlock.decl(cm.ref(WebServiceException.class), "e", JExpr._null());

    JTryBlock tryBlock = staticBlock._try();
    tryBlock.body().assign(urlVar, JExpr._new(cm.ref(URL.class)).arg(wsdlLocation));
    JCatchBlock catchBlock = tryBlock._catch(cm.ref(MalformedURLException.class));
    catchBlock.param("ex");
    catchBlock.body().assign(exVar, JExpr._new(cm.ref(WebServiceException.class)).arg(JExpr.ref("ex")));

    staticBlock.assign(urlField, urlVar);
    staticBlock.assign(exField, exVar);
}
 
Example #21
Source File: ElementOutlineImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
ElementOutlineImpl(BeanGenerator parent, CElementInfo ei) {
    super(ei,
          parent.getClassFactory().createClass(
                  parent.getContainer( ei.parent, Aspect.EXPOSED ), ei.shortName(), ei.getLocator() ));
    this.parent = parent;
    parent.elements.put(ei,this);

    JCodeModel cm = parent.getCodeModel();

    implClass._extends(
        cm.ref(JAXBElement.class).narrow(
            target.getContentInMemoryType().toType(parent,Aspect.EXPOSED).boxify()));

    if(ei.hasClass()) {
        JType implType = ei.getContentInMemoryType().toType(parent,Aspect.IMPLEMENTATION);
        JExpression declaredType = JExpr.cast(cm.ref(Class.class),implType.boxify().dotclass()); // why do we have to cast?
        JClass scope=null;
        if(ei.getScope()!=null)
            scope = parent.getClazz(ei.getScope()).implRef;
        JExpression scopeClass = scope==null?JExpr._null():scope.dotclass();
        JFieldVar valField = implClass.field(JMod.PROTECTED|JMod.FINAL|JMod.STATIC,QName.class,"NAME",createQName(cm,ei.getElementName()));

        // take this opportunity to generate a constructor in the element class
        JMethod cons = implClass.constructor(JMod.PUBLIC);
        cons.body().invoke("super")
            .arg(valField)
            .arg(declaredType)
            .arg(scopeClass)
            .arg(cons.param(implType,"value"));

        // generate no-arg constructor in the element class (bug #391; section 5.6.2 in JAXB spec 2.1)
        JMethod noArgCons = implClass.constructor(JMod.PUBLIC);
        noArgCons.body().invoke("super")
            .arg(valField)
            .arg(declaredType)
            .arg(scopeClass)
            .arg(JExpr._null());

    }
}
 
Example #22
Source File: BeanGenerator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Generates an attribute wildcard property on a class.
 */
private void generateAttributeWildcard(ClassOutlineImpl cc) {
    String FIELD_NAME = "otherAttributes";
    String METHOD_SEED = model.getNameConverter().toClassName(FIELD_NAME);

    JClass mapType = codeModel.ref(Map.class).narrow(QName.class, String.class);
    JClass mapImpl = codeModel.ref(HashMap.class).narrow(QName.class, String.class);

    // [RESULT]
    // Map<QName,String> m = new HashMap<QName,String>();
    JFieldVar $ref = cc.implClass.field(JMod.PRIVATE,
            mapType, FIELD_NAME, JExpr._new(mapImpl));
    $ref.annotate2(XmlAnyAttributeWriter.class);

    MethodWriter writer = cc.createMethodWriter();

    JMethod $get = writer.declareMethod(mapType, "get" + METHOD_SEED);
    $get.javadoc().append(
            "Gets a map that contains attributes that aren't bound to any typed property on this class.\n\n"
            + "<p>\n"
            + "the map is keyed by the name of the attribute and \n"
            + "the value is the string value of the attribute.\n"
            + "\n"
            + "the map returned by this method is live, and you can add new attribute\n"
            + "by updating the map directly. Because of this design, there's no setter.\n");
    $get.javadoc().addReturn().append("always non-null");

    $get.body()._return($ref);
}
 
Example #23
Source File: PluginImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Adds "@Generated" to the classes, methods, and fields.
 */
private void augument(ClassOutline co) {
    annotate(co.implClass);
    for (JMethod m : co.implClass.methods())
        annotate(m);
    for (JFieldVar f : co.implClass.fields().values())
        annotate(f);
}
 
Example #24
Source File: ElementOutlineImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
ElementOutlineImpl(BeanGenerator parent, CElementInfo ei) {
    super(ei,
          parent.getClassFactory().createClass(
                  parent.getContainer( ei.parent, Aspect.EXPOSED ), ei.shortName(), ei.getLocator() ));
    this.parent = parent;
    parent.elements.put(ei,this);

    JCodeModel cm = parent.getCodeModel();

    implClass._extends(
        cm.ref(JAXBElement.class).narrow(
            target.getContentInMemoryType().toType(parent,Aspect.EXPOSED).boxify()));

    if(ei.hasClass()) {
        JType implType = ei.getContentInMemoryType().toType(parent,Aspect.IMPLEMENTATION);
        JExpression declaredType = JExpr.cast(cm.ref(Class.class),implType.boxify().dotclass()); // why do we have to cast?
        JClass scope=null;
        if(ei.getScope()!=null)
            scope = parent.getClazz(ei.getScope()).implRef;
        JExpression scopeClass = scope==null?JExpr._null():scope.dotclass();
        JFieldVar valField = implClass.field(JMod.PROTECTED|JMod.FINAL|JMod.STATIC,QName.class,"NAME",createQName(cm,ei.getElementName()));

        // take this opportunity to generate a constructor in the element class
        JMethod cons = implClass.constructor(JMod.PUBLIC);
        cons.body().invoke("super")
            .arg(valField)
            .arg(declaredType)
            .arg(scopeClass)
            .arg(cons.param(implType,"value"));

        // generate no-arg constructor in the element class (bug #391; section 5.6.2 in JAXB spec 2.1)
        JMethod noArgCons = implClass.constructor(JMod.PUBLIC);
        noArgCons.body().invoke("super")
            .arg(valField)
            .arg(declaredType)
            .arg(scopeClass)
            .arg(JExpr._null());

    }
}
 
Example #25
Source File: BeanGenerator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Generates an attribute wildcard property on a class.
 */
private void generateAttributeWildcard(ClassOutlineImpl cc) {
    String FIELD_NAME = "otherAttributes";
    String METHOD_SEED = model.getNameConverter().toClassName(FIELD_NAME);

    JClass mapType = codeModel.ref(Map.class).narrow(QName.class, String.class);
    JClass mapImpl = codeModel.ref(HashMap.class).narrow(QName.class, String.class);

    // [RESULT]
    // Map<QName,String> m = new HashMap<QName,String>();
    JFieldVar $ref = cc.implClass.field(JMod.PRIVATE,
            mapType, FIELD_NAME, JExpr._new(mapImpl));
    $ref.annotate2(XmlAnyAttributeWriter.class);

    MethodWriter writer = cc.createMethodWriter();

    JMethod $get = writer.declareMethod(mapType, "get" + METHOD_SEED);
    $get.javadoc().append(
            "Gets a map that contains attributes that aren't bound to any typed property on this class.\n\n"
            + "<p>\n"
            + "the map is keyed by the name of the attribute and \n"
            + "the value is the string value of the attribute.\n"
            + "\n"
            + "the map returned by this method is live, and you can add new attribute\n"
            + "by updating the map directly. Because of this design, there's no setter.\n");
    $get.javadoc().addReturn().append("always non-null");

    $get.body()._return($ref);
}
 
Example #26
Source File: ServiceGenerator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private void writeClassLoaderBaseResourceWSDLLocation(String className, JDefinedClass cls, JFieldVar urlField, JFieldVar exField) {
    JBlock staticBlock = cls.init();
    JVar exVar = staticBlock.decl(cm.ref(WebServiceException.class), "e", JExpr._null());
    JVar urlVar = staticBlock.decl(cm.ref(URL.class), "url", JExpr._null());
    JTryBlock tryBlock = staticBlock._try();
    tryBlock.body().assign(urlVar, JExpr._new(cm.ref(URL.class)).arg(JExpr.dotclass(cm.ref(className)).invoke("getResource").arg(".")).arg(wsdlLocation));
    JCatchBlock catchBlock = tryBlock._catch(cm.ref(MalformedURLException.class));
    JVar murlVar = catchBlock.param("murl");
    catchBlock.body().assign(exVar, JExpr._new(cm.ref(WebServiceException.class)).arg(murlVar));
    staticBlock.assign(urlField, urlVar);
    staticBlock.assign(exField, exVar);
}
 
Example #27
Source File: PluginImpl.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Adds "@Generated" to the classes, methods, and fields.
 */
private void augument(ClassOutline co) {
    annotate(co.implClass);
    for (JMethod m : co.implClass.methods())
        annotate(m);
    for (JFieldVar f : co.implClass.fields().values())
        annotate(f);
}
 
Example #28
Source File: ServiceGenerator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private void writeResourceWSDLLocation(String className, JDefinedClass cls, JFieldVar urlField, JFieldVar exField) {
    JBlock staticBlock = cls.init();
    staticBlock.assign(urlField, JExpr.dotclass(cm.ref(className)).invoke("getResource").arg(wsdlLocation));
    JVar exVar = staticBlock.decl(cm.ref(WebServiceException.class), "e", JExpr._null());
    JConditional ifBlock = staticBlock._if(urlField.eq(JExpr._null()));
    ifBlock._then().assign(exVar, JExpr._new(cm.ref(WebServiceException.class)).arg(
            "Cannot find "+JExpr.quotify('\'', wsdlLocation)+" wsdl. Place the resource correctly in the classpath."));
    staticBlock.assign(exField, exVar);
}
 
Example #29
Source File: ServiceGenerator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private void writeAbsWSDLLocation(JDefinedClass cls, JFieldVar urlField, JFieldVar exField) {
    JBlock staticBlock = cls.init();
    JVar urlVar = staticBlock.decl(cm.ref(URL.class), "url", JExpr._null());
    JVar exVar = staticBlock.decl(cm.ref(WebServiceException.class), "e", JExpr._null());

    JTryBlock tryBlock = staticBlock._try();
    tryBlock.body().assign(urlVar, JExpr._new(cm.ref(URL.class)).arg(wsdlLocation));
    JCatchBlock catchBlock = tryBlock._catch(cm.ref(MalformedURLException.class));
    catchBlock.param("ex");
    catchBlock.body().assign(exVar, JExpr._new(cm.ref(WebServiceException.class)).arg(JExpr.ref("ex")));

    staticBlock.assign(urlField, urlVar);
    staticBlock.assign(exField, exVar);
}
 
Example #30
Source File: ServiceGenerator.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private void writeAbsWSDLLocation(JDefinedClass cls, JFieldVar urlField, JFieldVar exField) {
    JBlock staticBlock = cls.init();
    JVar urlVar = staticBlock.decl(cm.ref(URL.class), "url", JExpr._null());
    JVar exVar = staticBlock.decl(cm.ref(WebServiceException.class), "e", JExpr._null());

    JTryBlock tryBlock = staticBlock._try();
    tryBlock.body().assign(urlVar, JExpr._new(cm.ref(URL.class)).arg(wsdlLocation));
    JCatchBlock catchBlock = tryBlock._catch(cm.ref(MalformedURLException.class));
    catchBlock.param("ex");
    catchBlock.body().assign(exVar, JExpr._new(cm.ref(WebServiceException.class)).arg(JExpr.ref("ex")));

    staticBlock.assign(urlField, urlVar);
    staticBlock.assign(exField, exVar);
}