Java源码示例:com.sun.tools.internal.xjc.outline.Outline

示例1
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;
}
 
示例2
public boolean run(Outline model, Options opt, ErrorHandler errorHandler) {
    for( ClassOutline co : model.getClasses() ) {
        CPluginCustomization c = co.target.getCustomizations().find(Const.NS,"code");
        if(c==null)
            continue;   // no customization --- nothing to inject here

        c.markAsAcknowledged();
        // TODO: ideally you should validate this DOM element to make sure
        // that there's no typo/etc. JAXP 1.3 can do this very easily.
        String codeFragment = DOMUtils.getElementText(c.element);

        // inject the specified code fragment into the implementation class.
        co.implClass.direct(codeFragment);
    }

    return true;
}
 
示例3
public JExpression createConstant(Outline outline, XmlString lexical) {
    if(isCollection())  return null;

    if(adapter==null)     return coreType.createConstant(outline, lexical);

    // [RESULT] new Adapter().unmarshal(CONSTANT);
    JExpression cons = coreType.createConstant(outline, lexical);
    Class<? extends XmlAdapter> atype = adapter.getAdapterIfKnown();

    // try to run the adapter now rather than later.
    if(cons instanceof JStringLiteral && atype!=null) {
        JStringLiteral scons = (JStringLiteral) cons;
        XmlAdapter a = ClassFactory.create(atype);
        try {
            Object value = a.unmarshal(scons.str);
            if(value instanceof String) {
                return JExpr.lit((String)value);
            }
        } catch (Exception e) {
            // assume that we can't eagerly bind this
        }
    }

    return JExpr._new(adapter.getAdapterClass(outline)).invoke("unmarshal").arg(cons);
}
 
示例4
public JExpression createConstant(Outline outline, XmlString lexical) {
    if(isCollection())  return null;

    if(adapter==null)     return coreType.createConstant(outline, lexical);

    // [RESULT] new Adapter().unmarshal(CONSTANT);
    JExpression cons = coreType.createConstant(outline, lexical);
    Class<? extends XmlAdapter> atype = adapter.getAdapterIfKnown();

    // try to run the adapter now rather than later.
    if(cons instanceof JStringLiteral && atype!=null) {
        JStringLiteral scons = (JStringLiteral) cons;
        XmlAdapter a = ClassFactory.create(atype);
        try {
            Object value = a.unmarshal(scons.str);
            if(value instanceof String) {
                return JExpr.lit((String)value);
            }
        } catch (Exception e) {
            // assume that we can't eagerly bind this
        }
    }

    return JExpr._new(adapter.getAdapterClass(outline)).invoke("unmarshal").arg(cons);
}
 
示例5
/**
 * Generates the minimum {@link JDefinedClass} skeleton
 * without filling in its body.
 */
private EnumOutline generateEnumDef(CEnumLeafInfo e) {
    JDefinedClass type;

    type = getClassFactory().createClass(
            getContainer(e.parent, EXPOSED), e.shortName, e.getLocator(), ClassType.ENUM);
    type.javadoc().append(e.javadoc);

    return new EnumOutline(e, type) {

        @Override
        public
        @NotNull
        Outline parent() {
            return BeanGenerator.this;
        }
    };
}
 
示例6
/**
 * Generates the minimum {@link JDefinedClass} skeleton
 * without filling in its body.
 */
private EnumOutline generateEnumDef(CEnumLeafInfo e) {
    JDefinedClass type;

    type = getClassFactory().createClass(
            getContainer(e.parent, EXPOSED), e.shortName, e.getLocator(), ClassType.ENUM);
    type.javadoc().append(e.javadoc);

    return new EnumOutline(e, type) {

        @Override
        public
        @NotNull
        Outline parent() {
            return BeanGenerator.this;
        }
    };
}
 
示例7
/**
 * Generates the minimum {@link JDefinedClass} skeleton
 * without filling in its body.
 */
private EnumOutline generateEnumDef(CEnumLeafInfo e) {
    JDefinedClass type;

    type = getClassFactory().createClass(
            getContainer(e.parent, EXPOSED), e.shortName, e.getLocator(), ClassType.ENUM);
    type.javadoc().append(e.javadoc);

    return new EnumOutline(e, type) {

        @Override
        public
        @NotNull
        Outline parent() {
            return BeanGenerator.this;
        }
    };
}
 
示例8
/**
 * Generates the minimum {@link JDefinedClass} skeleton
 * without filling in its body.
 */
private EnumOutline generateEnumDef(CEnumLeafInfo e) {
    JDefinedClass type;

    type = getClassFactory().createClass(
            getContainer(e.parent, EXPOSED), e.shortName, e.getLocator(), ClassType.ENUM);
    type.javadoc().append(e.javadoc);

    return new EnumOutline(e, type) {

        @Override
        public
        @NotNull
        Outline parent() {
            return BeanGenerator.this;
        }
    };
}
 
示例9
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;
}
 
示例10
static NClass getRef( final Class<? extends XmlAdapter> adapter, boolean copy ) {
    if(copy) {
        // TODO: this is a hack. the code generation should be defered until
        // the backend. (right now constant generation happens in the front-end)
        return new EagerNClass(adapter) {
            @Override
            public JClass toType(Outline o, Aspect aspect) {
                return o.addRuntime(adapter);
            }
            public String fullName() {
                // TODO: implement this method later
                throw new UnsupportedOperationException();
            }
        };
    } else {
        return NavigatorImpl.theInstance.ref(adapter);
    }
}
 
示例11
public JExpression createConstant(Outline outline, XmlString lexical) {
    if(isCollection())  return null;

    if(adapter==null)     return coreType.createConstant(outline, lexical);

    // [RESULT] new Adapter().unmarshal(CONSTANT);
    JExpression cons = coreType.createConstant(outline, lexical);
    Class<? extends XmlAdapter> atype = adapter.getAdapterIfKnown();

    // try to run the adapter now rather than later.
    if(cons instanceof JStringLiteral && atype!=null) {
        JStringLiteral scons = (JStringLiteral) cons;
        XmlAdapter a = ClassFactory.create(atype);
        try {
            Object value = a.unmarshal(scons.str);
            if(value instanceof String) {
                return JExpr.lit((String)value);
            }
        } catch (Exception e) {
            // assume that we can't eagerly bind this
        }
    }

    return JExpr._new(adapter.getAdapterClass(outline)).invoke("unmarshal").arg(cons);
}
 
示例12
private SignatureWriter( Outline model, Writer out ) {
    this.out = out;
    this.classes = model.getClasses();

    for( ClassOutline ci : classes )
        classSet.put( ci.ref, ci );
}
 
示例13
/**
 * Creates a new {@link CDefaultValue} that computes the default value
 * by applying a lexical representation to a {@link TypeUse}.
 */
public static CDefaultValue create(final TypeUse typeUse, final XmlString defaultValue) {
    return new CDefaultValue() {
        public JExpression compute(Outline outline) {
            return typeUse.createConstant(outline,defaultValue);
        }
    };
}
 
示例14
public JExpression createConstant(Outline outline, XmlString lexical) {
    QName qn = DatatypeConverter.parseQName(lexical.value,new NamespaceContextAdapter(lexical));
    return JExpr._new(outline.getCodeModel().ref(QName.class))
        .arg(qn.getNamespaceURI())
        .arg(qn.getLocalPart())
        .arg(qn.getPrefix());
}
 
示例15
JAXBModelImpl(Outline outline) {
    this.model = outline.getModel();
    this.outline = outline;

    for (CClassInfo ci : model.beans().values()) {
        if(!ci.isElement())
            continue;
        byXmlName.put(ci.getElementName(),new BeanMappingImpl(this,ci));
    }
    for (CElementInfo ei : model.getElementMappings(null).values()) {
        byXmlName.put(ei.getElementName(),new ElementMappingImpl(this,ei));
    }
}
 
示例16
public JExpression createConstant(Outline outline, XmlString literal) {
    // correctly identifying which constant it maps to is hard, so
    // here I'm cheating
    JClass type = toType(outline,Aspect.EXPOSED);
    for (CEnumConstant mem : members) {
        if(mem.getLexicalValue().equals(literal.value))
            return type.staticRef(mem.getName());
    }
    return null;
}
 
示例17
/**
 * Creates a new {@link CDefaultValue} that computes the default value
 * by applying a lexical representation to a {@link TypeUse}.
 */
public static CDefaultValue create(final TypeUse typeUse, final XmlString defaultValue) {
    return new CDefaultValue() {
        public JExpression compute(Outline outline) {
            return typeUse.createConstant(outline,defaultValue);
        }
    };
}
 
示例18
public JExpression createConstant(Outline outline, XmlString lexical) {
    QName qn = DatatypeConverter.parseQName(lexical.value,new NamespaceContextAdapter(lexical));
    return JExpr._new(outline.getCodeModel().ref(QName.class))
        .arg(qn.getNamespaceURI())
        .arg(qn.getLocalPart())
        .arg(qn.getPrefix());
}
 
示例19
public JExpression createConstant(Outline outline, XmlString lexical) {
    QName qn = DatatypeConverter.parseQName(lexical.value,new NamespaceContextAdapter(lexical));
    return JExpr._new(outline.getCodeModel().ref(QName.class))
        .arg(qn.getNamespaceURI())
        .arg(qn.getLocalPart())
        .arg(qn.getPrefix());
}
 
示例20
public JExpression createConstant(Outline outline, XmlString lexical) {
    QName qn = DatatypeConverter.parseQName(lexical.value,new NamespaceContextAdapter(lexical));
    return JExpr._new(outline.getCodeModel().ref(QName.class))
        .arg(qn.getNamespaceURI())
        .arg(qn.getLocalPart())
        .arg(qn.getPrefix());
}
 
示例21
public JExpression createConstant(Outline outline, XmlString literal) {
    // correctly identifying which constant it maps to is hard, so
    // here I'm cheating
    JClass type = toType(outline,Aspect.EXPOSED);
    for (CEnumConstant mem : members) {
        if(mem.getLexicalValue().equals(literal.value))
            return type.staticRef(mem.getName());
    }
    return null;
}
 
示例22
public JExpression createConstant(Outline outline, XmlString lexical) {
    QName qn = DatatypeConverter.parseQName(lexical.value,new NamespaceContextAdapter(lexical));
    return JExpr._new(outline.getCodeModel().ref(QName.class))
        .arg(qn.getNamespaceURI())
        .arg(qn.getLocalPart())
        .arg(qn.getPrefix());
}
 
示例23
/**
 * Creates a new {@link CDefaultValue} that computes the default value
 * by applying a lexical representation to a {@link TypeUse}.
 */
public static CDefaultValue create(final TypeUse typeUse, final XmlString defaultValue) {
    return new CDefaultValue() {
        public JExpression compute(Outline outline) {
            return typeUse.createConstant(outline,defaultValue);
        }
    };
}
 
示例24
public JExpression createConstant(Outline outline, XmlString lexical) {
    return null;
}
 
示例25
public JType toType(Outline o, Aspect aspect) {
    return o.getCodeModel().ref(Element.class);
}
 
示例26
protected final Outline outline() {
    return core.parent().parent();
}
 
示例27
public static void write( Outline model, Writer out )
    throws IOException {

    new SignatureWriter(model,out).dump();
}
 
示例28
public JClass toType(Outline o, Aspect aspect) {
    return clazz;
}
 
示例29
public JExpression createConstant(Outline outline, XmlString lexical) {
    return JExpr.lit(DatatypeConverter.parseBoolean(lexical.value));
}
 
示例30
protected final Outline outline() {
    return core.parent().parent();
}