com.sun.codemodel.internal.JDefinedClass Java Examples

The following examples show how to use com.sun.codemodel.internal.JDefinedClass. 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: BindInfo.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/** Gets the xjc:superClass customization if it's turned on. */
public JClass getSuperClass() {
    Element sc = DOMUtil.getElement(dom,XJC_NS,"superClass");
    if (sc == null) return null;

    JDefinedClass c;

    try {
        String v = DOMUtil.getAttribute(sc,"name");
        if(v==null)     return null;
        c = codeModel._class(v);
        c.hide();
    } catch (JClassAlreadyExistsException e) {
        c = e.getExistingClass();
    }

    return c;
}
 
Example #2
Source File: BIConversion.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public TypeUse getTypeUse(XSSimpleType owner) {
    if(typeUse!=null)
        return typeUse;

    JCodeModel cm = getCodeModel();

    JDefinedClass a;
    try {
        a = cm._class(adapter);
        a.hide();   // we assume this is given by the user
        a._extends(cm.ref(XmlAdapter.class).narrow(String.class).narrow(
                cm.ref(type)));
    } catch (JClassAlreadyExistsException e) {
        a = e.getExistingClass();
    }

    // TODO: it's not correct to say that it adapts from String,
    // but OTOH I don't think we can compute that.
    typeUse = TypeUseFactory.adapt(
            CBuiltinLeafInfo.STRING,
            new CAdapter(a));

    return typeUse;
}
 
Example #3
Source File: SourceLocationAddOn.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public boolean run(
    Outline outline,
    Options opt,
    ErrorHandler errorHandler ) {

    for( ClassOutline ci : outline.getClasses() ) {
        JDefinedClass impl = ci.implClass;
        if (ci.getSuperClass() == null) {
            JVar $loc = impl.field(JMod.PROTECTED, Locator.class, fieldName);
            $loc.annotate(XmlLocation.class);
            $loc.annotate(XmlTransient.class);

            impl._implements(Locatable.class);

            impl.method(JMod.PUBLIC, Locator.class, "sourceLocation").body()._return($loc);

            JMethod setter = impl.method(JMod.PUBLIC, Void.TYPE, "setSourceLocation");
            JVar $newLoc = setter.param(Locator.class, "newLocator");
            setter.body().assign($loc, $newLoc);
        }
    }

    return true;
}
 
Example #4
Source File: WebServiceWrapperGenerator.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private void writeMember(JDefinedClass cls, TypeMirror paramType,
                         String paramName) {

    if (cls == null)
        return;

    String accessorName =BindingHelper.mangleNameToPropertyName(paramName);
    String getterPrefix = paramType.toString().equals("boolean")? "is" : "get";
    JType propType = getType(paramType);
    JMethod m = cls.method(JMod.PUBLIC, propType, getterPrefix+ accessorName);
    JDocComment methodDoc = m.javadoc();
    JCommentPart ret = methodDoc.addReturn();
    ret.add("returns "+propType.name());
    JBlock body = m.body();
    body._return( JExpr._this().ref(paramName) );

    m = cls.method(JMod.PUBLIC, cm.VOID, "set"+accessorName);
    JVar param = m.param(propType, paramName);
    methodDoc = m.javadoc();
    JCommentPart part = methodDoc.addParam(paramName);
    part.add("the value for the "+ paramName+" property");
    body = m.body();
    body.assign( JExpr._this().ref(paramName), param );
}
 
Example #5
Source File: BeanGenerator.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Generates the minimum {@link JDefinedClass} skeleton
 * without filling in its body.
 */
private ClassOutlineImpl generateClassDef(CClassInfo bean) {
    ImplStructureStrategy.Result r = model.strategy.createClasses(this, bean);
    JClass implRef;

    if (bean.getUserSpecifiedImplClass() != null) {
        // create a place holder for a user-specified class.
        JDefinedClass usr;
        try {
            usr = codeModel._class(bean.getUserSpecifiedImplClass());
            // but hide that file so that it won't be generated.
            usr.hide();
        } catch (JClassAlreadyExistsException e) {
            // it's OK for this to collide.
            usr = e.getExistingClass();
        }
        usr._extends(r.implementation);
        implRef = usr;
    } else {
        implRef = r.implementation;
    }

    return new ClassOutlineImpl(this, bean, r.exposed, r.implementation, implRef);
}
 
Example #6
Source File: BeanGenerator.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Generates the minimum {@link JDefinedClass} skeleton
 * without filling in its body.
 */
private ClassOutlineImpl generateClassDef(CClassInfo bean) {
    ImplStructureStrategy.Result r = model.strategy.createClasses(this, bean);
    JClass implRef;

    if (bean.getUserSpecifiedImplClass() != null) {
        // create a place holder for a user-specified class.
        JDefinedClass usr;
        try {
            usr = codeModel._class(bean.getUserSpecifiedImplClass());
            // but hide that file so that it won't be generated.
            usr.hide();
        } catch (JClassAlreadyExistsException e) {
            // it's OK for this to collide.
            usr = e.getExistingClass();
        }
        usr._extends(r.implementation);
        implRef = usr;
    } else {
        implRef = r.implementation;
    }

    return new ClassOutlineImpl(this, bean, r.exposed, r.implementation, implRef);
}
 
Example #7
Source File: SourceLocationAddOn.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public boolean run(
    Outline outline,
    Options opt,
    ErrorHandler errorHandler ) {

    for( ClassOutline ci : outline.getClasses() ) {
        JDefinedClass impl = ci.implClass;
        if (ci.getSuperClass() == null) {
            JVar $loc = impl.field(JMod.PROTECTED, Locator.class, fieldName);
            $loc.annotate(XmlLocation.class);
            $loc.annotate(XmlTransient.class);

            impl._implements(Locatable.class);

            impl.method(JMod.PUBLIC, Locator.class, "sourceLocation").body()._return($loc);

            JMethod setter = impl.method(JMod.PUBLIC, Void.TYPE, "setSourceLocation");
            JVar $newLoc = setter.param(Locator.class, "newLocator");
            setter.body().assign($loc, $newLoc);
        }
    }

    return true;
}
 
Example #8
Source File: WebServiceWrapperGenerator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private void writeMember(JDefinedClass cls, TypeMirror paramType,
                         String paramName) {

    if (cls == null)
        return;

    String accessorName =BindingHelper.mangleNameToPropertyName(paramName);
    String getterPrefix = paramType.toString().equals("boolean")? "is" : "get";
    JType propType = getType(paramType);
    JMethod m = cls.method(JMod.PUBLIC, propType, getterPrefix+ accessorName);
    JDocComment methodDoc = m.javadoc();
    JCommentPart ret = methodDoc.addReturn();
    ret.add("returns "+propType.name());
    JBlock body = m.body();
    body._return( JExpr._this().ref(paramName) );

    m = cls.method(JMod.PUBLIC, cm.VOID, "set"+accessorName);
    JVar param = m.param(propType, paramName);
    methodDoc = m.javadoc();
    JCommentPart part = methodDoc.addParam(paramName);
    part.add("the value for the "+ paramName+" property");
    body = m.body();
    body.assign( JExpr._this().ref(paramName), param );
}
 
Example #9
Source File: BindInfo.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/** Gets the xjc:superClass customization if it's turned on. */
public JClass getSuperClass() {
    Element sc = DOMUtil.getElement(dom,XJC_NS,"superClass");
    if (sc == null) return null;

    JDefinedClass c;

    try {
        String v = DOMUtil.getAttribute(sc,"name");
        if(v==null)     return null;
        c = codeModel._class(v);
        c.hide();
    } catch (JClassAlreadyExistsException e) {
        c = e.getExistingClass();
    }

    return c;
}
 
Example #10
Source File: ServiceGenerator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private void writeGetPort(Port port, JType retType, JDefinedClass cls) {
    JMethod m = cls.method(JMod.PUBLIC, retType, port.getPortGetter());
    JDocComment methodDoc = m.javadoc();
    if (port.getJavaDoc() != null) {
        methodDoc.add(port.getJavaDoc());
    }
    JCommentPart ret = methodDoc.addReturn();
    JCommentPart paramDoc = methodDoc.addParam("features");
    paramDoc.append("A list of ");
    paramDoc.append("{@link " + WebServiceFeature.class.getName() + "}");
    paramDoc.append("to configure on the proxy.  Supported features not in the <code>features</code> parameter will have their default values.");
    ret.add("returns " + retType.name());
    m.varParam(WebServiceFeature.class, "features");
    JBlock body = m.body();
    StringBuilder statement = new StringBuilder("return ");
    statement.append("super.getPort(new QName(\"").append(port.getName().getNamespaceURI()).append("\", \"").append(port.getName().getLocalPart()).append("\"), ");
    statement.append(retType.name());
    statement.append(".class, features);");
    body.directStatement(statement.toString());
    writeWebEndpoint(port, m);
}
 
Example #11
Source File: BIConversion.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public TypeUse getTypeUse(XSSimpleType owner) {
    if(typeUse!=null)
        return typeUse;

    JCodeModel cm = getCodeModel();

    JDefinedClass a;
    try {
        a = cm._class(adapter);
        a.hide();   // we assume this is given by the user
        a._extends(cm.ref(XmlAdapter.class).narrow(String.class).narrow(
                cm.ref(type)));
    } catch (JClassAlreadyExistsException e) {
        a = e.getExistingClass();
    }

    // TODO: it's not correct to say that it adapts from String,
    // but OTOH I don't think we can compute that.
    typeUse = TypeUseFactory.adapt(
            CBuiltinLeafInfo.STRING,
            new CAdapter(a));

    return typeUse;
}
 
Example #12
Source File: BindInfo.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/** Gets the xjc:superClass customization if it's turned on. */
public JClass getSuperClass() {
    Element sc = DOMUtil.getElement(dom,XJC_NS,"superClass");
    if (sc == null) return null;

    JDefinedClass c;

    try {
        String v = DOMUtil.getAttribute(sc,"name");
        if(v==null)     return null;
        c = codeModel._class(v);
        c.hide();
    } catch (JClassAlreadyExistsException e) {
        c = e.getExistingClass();
    }

    return c;
}
 
Example #13
Source File: BindInfo.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/** Gets the xjc:superClass customization if it's turned on. */
public JClass getSuperClass() {
    Element sc = DOMUtil.getElement(dom,XJC_NS,"superClass");
    if (sc == null) return null;

    JDefinedClass c;

    try {
        String v = DOMUtil.getAttribute(sc,"name");
        if(v==null)     return null;
        c = codeModel._class(v);
        c.hide();
    } catch (JClassAlreadyExistsException e) {
        c = e.getExistingClass();
    }

    return c;
}
 
Example #14
Source File: BIGlobalBinding.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
JDefinedClass getClazz(ClassType t) {
    if (clazz != null) return clazz;
    try {
        JCodeModel codeModel = Ring.get(JCodeModel.class);
        clazz = codeModel._class(name, t);
        clazz.hide();
        return clazz;
    } catch (JClassAlreadyExistsException e) {
        return e.getExistingClass();
    }
}
 
Example #15
Source File: WebServiceWrapperGenerator.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private void writeXmlTypeDeclaration(JDefinedClass cls, String typeName, String namespaceUri,
                                     Collection<MemberInfo> members) {
    if (cls == null)
        return;
    JAnnotationUse xmlTypeAnn = cls.annotate(cm.ref(XmlType.class));
    xmlTypeAnn.param("name", typeName);
    xmlTypeAnn.param("namespace", namespaceUri);
    if (members.size() > 1) {
        JAnnotationArrayMember paramArray = xmlTypeAnn.paramArray("propOrder");
        for (MemberInfo memInfo : members) {
            paramArray.param(memInfo.getParamName());
        }
    }
}
 
Example #16
Source File: GeneratorBase.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
protected JDefinedClass getClass(String className, ClassType type) throws JClassAlreadyExistsException {
    JDefinedClass cls;
    try {
        cls = cm._class(className, type);
    } catch (JClassAlreadyExistsException e){
        cls = cm._getClass(className);
        if (cls == null) {
            throw e;
        }
    }
    return cls;
}
 
Example #17
Source File: ServiceGenerator.java    From openjdk-jdk8u-backup 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: CodeModelClassFactory.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a dummy class to recover from an error.
 *
 * We won't generate the code, so the client will never see this class
 * getting generated.
 */
private JDefinedClass createDummyClass(JClassContainer parent) {
    try {
        return parent._class("$$$garbage$$$"+(ticketMaster++));
    } catch( JClassAlreadyExistsException ee ) {
        return ee.getExistingClass();
    }
}
 
Example #19
Source File: BIGlobalBinding.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
JDefinedClass getClazz(ClassType t) {
    if (clazz != null) return clazz;
    try {
        JCodeModel codeModel = Ring.get(JCodeModel.class);
        clazz = codeModel._class(name, t);
        clazz.hide();
        return clazz;
    } catch (JClassAlreadyExistsException e) {
        return e.getExistingClass();
    }
}
 
Example #20
Source File: SignatureWriter.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private void dumpChildren( JClassContainer cont ) throws IOException {
    Iterator itr = cont.classes();
    while(itr.hasNext()) {
        JDefinedClass cls = (JDefinedClass)itr.next();
        ClassOutline ci = classSet.get(cls);
        if(ci!=null)
            dump(ci);
    }
}
 
Example #21
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 #22
Source File: WebServiceWrapperGenerator.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private void writeXmlTypeDeclaration(JDefinedClass cls, String typeName, String namespaceUri,
                                     Collection<MemberInfo> members) {
    if (cls == null)
        return;
    JAnnotationUse xmlTypeAnn = cls.annotate(cm.ref(XmlType.class));
    xmlTypeAnn.param("name", typeName);
    xmlTypeAnn.param("namespace", namespaceUri);
    if (members.size() > 1) {
        JAnnotationArrayMember paramArray = xmlTypeAnn.paramArray("propOrder");
        for (MemberInfo memInfo : members) {
            paramArray.param(memInfo.getParamName());
        }
    }
}
 
Example #23
Source File: WebServiceWrapperGenerator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void writeXmlTypeDeclaration(JDefinedClass cls, String typeName, String namespaceUri,
                                     Collection<MemberInfo> members) {
    if (cls == null)
        return;
    JAnnotationUse xmlTypeAnn = cls.annotate(cm.ref(XmlType.class));
    xmlTypeAnn.param("name", typeName);
    xmlTypeAnn.param("namespace", namespaceUri);
    if (members.size() > 1) {
        JAnnotationArrayMember paramArray = xmlTypeAnn.paramArray("propOrder");
        for (MemberInfo memInfo : members) {
            paramArray.param(memInfo.getParamName());
        }
    }
}
 
Example #24
Source File: CodeModelClassFactory.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a dummy class to recover from an error.
 *
 * We won't generate the code, so the client will never see this class
 * getting generated.
 */
private JDefinedClass createDummyClass(JClassContainer parent) {
    try {
        return parent._class("$$$garbage$$$"+(ticketMaster++));
    } catch( JClassAlreadyExistsException ee ) {
        return ee.getExistingClass();
    }
}
 
Example #25
Source File: SignatureWriter.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private void dumpChildren( JClassContainer cont ) throws IOException {
    Iterator itr = cont.classes();
    while(itr.hasNext()) {
        JDefinedClass cls = (JDefinedClass)itr.next();
        ClassOutline ci = classSet.get(cls);
        if(ci!=null)
            dump(ci);
    }
}
 
Example #26
Source File: TypeUtil.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static JClass pickOne(Set<JClass> s) {
    // we may have more than one candidates at this point.
    // any user-defined generated types should have
    // precedence over system-defined existing types.
    //
    // so try to return such a type if any.
    for (JClass c : s)
        if (c instanceof JDefinedClass)
            return c;

    // we can do more if we like. for example,
    // we can avoid types in the RI runtime.
    // but for now, just return the first one.
    return s.iterator().next();
}
 
Example #27
Source File: ServiceGenerator.java    From jdk8u60 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 #28
Source File: SignatureWriter.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private void dump( ClassOutline ci ) throws IOException {
    JDefinedClass cls = ci.implClass;

    StringBuilder buf = new StringBuilder();
    buf.append("interface ");
    buf.append(cls.name());

    boolean first=true;
    Iterator itr = cls._implements();
    while(itr.hasNext()) {
        if(first) {
            buf.append(" extends ");
            first=false;
        } else {
            buf.append(", ");
        }
        buf.append( printName((JClass)itr.next()) );
    }
    buf.append(" {");
    println(buf.toString());
    indent++;

    // dump the field
    for( FieldOutline fo : ci.getDeclaredFields() ) {
        String type = printName(fo.getRawType());
        println(type+' '+fo.getPropertyInfo().getName(true)+';');
    }

    dumpChildren(cls);

    indent--;
    println("}");
}
 
Example #29
Source File: ServiceGenerator.java    From hottub 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: SignatureWriter.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private void dumpChildren( JClassContainer cont ) throws IOException {
    Iterator itr = cont.classes();
    while(itr.hasNext()) {
        JDefinedClass cls = (JDefinedClass)itr.next();
        ClassOutline ci = classSet.get(cls);
        if(ci!=null)
            dump(ci);
    }
}