com.sun.tools.xjc.model.Model类的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(12.5k)|赞(0)|评价(0)|浏览(146)

本文整理了Java中com.sun.tools.xjc.model.Model类的一些代码示例,展示了Model类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Model类的具体详情如下:
包路径:com.sun.tools.xjc.model.Model
类名称:Model

Model介绍

[英]Root of the object model that represents the code that needs to be generated.

A Model is a schema language neutral representation of the result of a schema parsing. The back-end then works against this model to turn this into a series of Java source code.
[中]表示需要生成的代码的对象模型的根。
模型是与模式语言无关的模式解析结果的表示。然后,后端针对该模型工作,将其转换为一系列Java源代码。

代码示例

代码示例来源:origin: Evolveum/midpoint

private void addComplexType(Outline outline, Map<String, JFieldVar> namespaceFields) {
  Set<Map.Entry<NClass, CClassInfo>> set = outline.getModel().beans().entrySet();
  for (Map.Entry<NClass, CClassInfo> entry : set) {
    ClassOutline classOutline = outline.getClazz(entry.getValue());
    QName qname = entry.getValue().getTypeName();
    if (qname == null) {
      continue;
    }
    JFieldVar namespaceField = namespaceFields.get(qname.getNamespaceURI());
    createQName(outline, classOutline.implClass, COMPLEX_TYPE_FIELD_NAME, qname, namespaceField, false, false);
  }
}

代码示例来源:origin: org.jvnet.jaxb2_commons/tools

public static CCustomizations getCustomizations(final Model model) {
  final CCustomizations main = new CCustomizations(model
      .getCustomizations());
  return main;
}

代码示例来源:origin: org.glassfish.metro/webservices-tools

private CClassInfo createDefaultClass() {
  String className = owner.model.getNameConverter().toClassName(name);
  QName tagName = new QName("",name);
  return new CClassInfo(owner.model,owner.getTargetPackage(),className,locator,null,tagName,null,null/*TODO*/);
}

代码示例来源:origin: sun-jaxb/jaxb-xjc

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

代码示例来源:origin: sun-jaxb/jaxb-xjc

/**
 * Returns all <i>used</i> JPackages.
 *
 * A JPackage is considered as "used" if a ClassItem or
 * a InterfaceItem resides in that package.
 *
 * This value is dynamically calculated every time because
 * one can freely remove ClassItem/InterfaceItem.
 *
 * @return
 *         Given the same input, the order of packages in the array
 *         is always the same regardless of the environment.
 */
public final JPackage[] getUsedPackages( Aspect aspect ) {
  Set<JPackage> s = new TreeSet<JPackage>();
  for( CClassInfo bean : model.beans().values() ) {
    JClassContainer cont = getContainer(bean.parent(),aspect);
    if(cont.isPackage())
      s.add( (JPackage)cont );
  }
  for( CElementInfo e : model.getElementMappings(null).values() ) {
    // at the first glance you might think we should be iterating all elements,
    // not just global ones, but if you think about it, local ones live inside
    // another class, so those packages are already enumerated when we were
    // walking over CClassInfos.
    s.add( e._package() );
  }
  return s.toArray(new JPackage[s.size()]);
}

代码示例来源:origin: org.glassfish.metro/webservices-tools

private void mapToClass(DElementPattern p) {
  NameClass nc = p.getName();
  if(nc.isOpen())
    return;   // infinite name. can't map to a class.
  Set<QName> names = nc.listNames();
  CClassInfo[] types = new CClassInfo[names.size()];
  int i=0;
  for( QName n : names ) {
    // TODO: read class names from customization
    String name = model.getNameConverter().toClassName(n.getLocalPart());
    bindQueue.put(
      types[i++] = new CClassInfo(model,pkg,name,p.getLocation(),null,n,null,null/*TODO*/),
      p.getChild() );
  }
  classes.put(p,types);
}

代码示例来源:origin: mklemm/jaxb2-rich-contract-plugin

public <T> T getCustomization(final Class<T> customizationClass, final Deque<CCustomizable> schemaComponents) {
  final QName qName = getQName(customizationClass);
  if (!schemaComponents.isEmpty()) {
    final CCustomizable schemaComponent = schemaComponents.pop();
    final CPluginCustomization pluginCustomization = schemaComponent.getCustomizations().find(qName.getNamespaceURI(), qName.getLocalPart());
    if (pluginCustomization == null) {
      return getCustomization(customizationClass, schemaComponents);
    } else {
      pluginCustomization.markAsAcknowledged();
      return JAXB.unmarshal(new DOMSource(pluginCustomization.element), customizationClass);
    }
  } else {
    final CPluginCustomization pluginCustomization = this.outline.getModel().getCustomizations().find(qName.getNamespaceURI(), qName.getLocalPart());
    if (pluginCustomization != null) {
      pluginCustomization.markAsAcknowledged();
      return JAXB.unmarshal(new DOMSource(pluginCustomization.element), customizationClass);
    } else {
      return null;
    }
  }
}

代码示例来源:origin: Evolveum/midpoint

private void addContainerName(Outline outline, Map<String, JFieldVar> namespaceFields) {
  Map<QName, List<QName>> complexTypeToElementName = null;
  Set<Map.Entry<NClass, CClassInfo>> set = outline.getModel().beans().entrySet();
  for (Map.Entry<NClass, CClassInfo> entry : set) {
    CClassInfo classInfo = entry.getValue();
    JFieldVar var = namespaceFields.get(qname.getNamespaceURI());
    JInvocation invocation = JExpr._new(CLASS_MAP.get(QName.class));
    if (var != null) {
      JClass schemaClass = outline.getModel().codeModel._getClass(StepSchemaConstants.SCHEMA_CONSTANTS_GENERATED_CLASS_NAME);
      invocation.arg(schemaClass.staticRef(var));
      invocation.arg(qname.getLocalPart());
    } else {
      invocation.arg(qname.getNamespaceURI());
      invocation.arg(qname.getLocalPart());

代码示例来源:origin: Evolveum/midpoint

for (CElementInfo elementInfo : outline.getModel().getAllElements()) {
  QName name = elementInfo.getElementName();
  XSComponent elementDecl;
    elementDecl = elementInfo.getSchemaComponent();
  } else {
    elementDecl = schemaSet.getElementDecl(name.getNamespaceURI(), name.getLocalPart());
          nameValue.generate(nameFormatter);
          if (("\""+name.getNamespaceURI()+"\"").equals(namespaceWriter.toString()) &&
              ("\""+name.getLocalPart()+"\"").equals(nameWriter.toString())) {
            print("*** Annotating method as @Raw: " + method.name());

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.jaxb-xjc

/**
 * Returns the "squeezed name" of this element.
 *
 * @see CClassInfo#getSqueezedName()
 */
@XmlElement
public String getSqueezedName() {
  if(squeezedName!=null)  return squeezedName;
  
  StringBuilder b = new StringBuilder();
  CClassInfo s = getScope();
  if(s!=null)
    b.append(s.getSqueezedName());
  if(className!=null)
    b.append(className);
  else
    b.append( model.getNameConverter().toClassName(tagName.getLocalPart()));
  return b.toString();
}

代码示例来源:origin: Evolveum/midpoint

@Override
public boolean run(Outline outline, Options opt, ErrorHandler errorHandler) throws Exception {
  Model model = outline.getModel();
  JDefinedClass schemaConstants = model.codeModel._class(SCHEMA_CONSTANTS_GENERATED_CLASS_NAME);
  Map<QName, CElementInfo> map = model.getElementMappings(null);
  Set<Map.Entry<QName, CElementInfo>> set = map.entrySet();
  for (Map.Entry<QName, CElementInfo> entry : set) {
    JFieldVar var = namespaceFields.get(field.getValue().getNamespaceURI());
    createQName(outline, schemaConstants, field.getFieldName(), field.getValue(), var, true, true);

代码示例来源:origin: Evolveum/midpoint

public static ClassOutline findClassOutline(Outline outline, QName type) {
  Set<Map.Entry<NClass, CClassInfo>> set = outline.getModel().beans().entrySet();
  for (Map.Entry<NClass, CClassInfo> entry : set) {
    ClassOutline classOutline = outline.getClazz(entry.getValue());
    QName qname = entry.getValue().getTypeName();
    if (!type.equals(qname)) {
      continue;
    }
    return classOutline;
  }
  throw new IllegalStateException("Object type class defined by qname '" + type + "' outline was not found.");
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.jaxb-xjc

for (CEnumLeafInfo p : model.enums().values()) {
  enums.put(p, generateEnumDef(p));
for (CClassInfo bean : model.beans().values()) {
  getClazz(bean);
JClass OBJECT = codeModel.ref(Object.class);
  CClassInfo superClass = cc.target.getBaseClass();
  if (superClass != null) {
    CClassRef refSuperClass = cc.target.getRefBaseClass();
    if (refSuperClass != null) {
      cc.implClass._extends(refSuperClass.toType(this, EXPOSED));
  CClassInfoParent base = cc.target.parent();
  if ((base != null) && (base instanceof CClassInfo)) {
    String pkg = base.getOwnerPackage().name();
for (CElementInfo ei : model.getAllElements()) {
  getPackageContext(ei._package()).objectFactoryGenerator().populate(ei);
  codeModel._prepareModuleInfo(model.options.getModuleName(), JAXB_PACKAGE);

代码示例来源:origin: com.legsem.legstar/legstar-jaxb-generator

packageName, tempXsdFile.getAbsolutePath() });
  Model model = ModelLoader.load(options, new JCodeModel(),
      errorReceiver);
  if (model.generateCode(options, errorReceiver) == null) {
    throw new Cob2JaxbGeneratorException(
        "JAXB-XJC failed to compile a schema");
  model.codeModel.build(targetFolder);
  tempXsdFile.deleteOnExit();
} catch (IOException e) {

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.jaxb-xjc

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

代码示例来源:origin: sun-jaxb/jaxb-xjc

for( CEnumLeafInfo p : model.enums().values() )
  enums.put( p, generateEnumDef(p) );
for( CClassInfo bean : model.beans().values() )
  getClazz(bean);
  p.calcDefaultValues();
JClass OBJECT = codeModel.ref(Object.class);
  CClassInfo superClass = cc.target.getBaseClass();
  if(superClass!=null) {
    CClassRef refSuperClass = cc.target.getRefBaseClass();
    if(refSuperClass!=null) {
      cc.implClass._extends(refSuperClass.toType(this,EXPOSED));
for( CElementInfo ei : model.getAllElements())
  getPackageContext(ei._package()).objectFactoryGenerator().populate(ei);

代码示例来源:origin: CodeFX-org/java-9-wtf

private void execute(String configuration) throws Exception {
  Options options = createOptions(configuration);
  Model model = ModelLoader.load(options, new JCodeModel(), ERROR_RECEIVER);
  Outline outline = model.generateCode(model.options, ERROR_RECEIVER);
  writeCode(outline);
}

代码示例来源:origin: net.sourceforge.ccxjc/cc-xjc-plugin

&& field.getPropertyInfo().getAdapter().customType != null )
typeInfo = field.parent().parent().getModel().getTypeInfo(
  field.getPropertyInfo().getAdapter().customType );
  tryCopy._catch( field.parent().parent().getCodeModel().ref( Exception.class ) );
  ref( AssertionError.class ) ).arg( e ) );

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.jaxb-xjc

/**
 * The whole type set can be later bound to a reference property,
 * in which case we need to generate additional code to wrap this
 * type reference into an element class.
 *
 * This method generates such an element class and returns it.
 */
protected void toElementRef(CReferencePropertyInfo prop) {
  CClassInfo scope = Ring.get(ClassSelector.class).getCurrentBean();
  Model model = Ring.get(Model.class);
  CCustomizations custs = Ring.get(BGMBuilder.class).getBindInfo(decl).toCustomizationList();
  if(target instanceof CClassInfo && Ring.get(BIGlobalBinding.class).isSimpleMode()) {
    CClassInfo bean = new CClassInfo(model,scope,
            model.getNameConverter().toClassName(decl.getName()),
            decl.getLocator(), null, BGMBuilder.getName(decl), decl,
            custs);
    bean.setBaseClass((CClassInfo)target);
    prop.getElements().add(bean);
  } else {
    CElementInfo e = new CElementInfo(model,BGMBuilder.getName(decl),scope,target,
        decl.getDefaultValue(), decl, custs, decl.getLocator());
    prop.getElements().add(e);
  }
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.jaxb-xjc

protected CPropertyInfo(String name, boolean collection, XSComponent source,
            CCustomizations customizations, Locator locator) {
  this.publicName = name;
  String n = null;
  Model m = Ring.get(Model.class);
  if (m != null) {
    n = m.getNameConverter().toVariableName(name);
  } else {
    n = NameConverter.standard.toVariableName(name);
  }
  
  if(!JJavaName.isJavaIdentifier(n))
    n = '_'+n;  // avoid colliding with the reserved names like 'abstract'.
  this.privateName = n;
  this.isCollection = collection;
  this.locator = locator;
  if(customizations==null)
    this.customizations = CCustomizations.EMPTY;
  else
    this.customizations = customizations;
  this.source = source;
}

相关文章