📄 bindingdefinition.java
字号:
mb.appendLoadConstant((String)m_namespaceUris.get(i)); mb.appendAASTORE(); } mb.appendPutField(uris); } // create and fill array of namespace prefixes if (m_isOutput) { mb.appendLoadLocal(0); mb.appendLoadConstant(m_namespacePrefixes.size()); mb.appendCreateArray("java.lang.String"); for (int i = 0; i < m_namespacePrefixes.size(); i++) { mb.appendDUP(); mb.appendLoadConstant(i); mb.appendLoadConstant((String)m_namespacePrefixes.get(i)); mb.appendAASTORE(); } mb.appendPutField(prefs); } // create and fill arrays of globally mapped element names and URIs mb.appendLoadLocal(0); mb.appendLoadConstant(count); mb.appendCreateArray("java.lang.String"); for (int i = 0; i < count; i++) { String cname = (String)s_mappedClasses.get(i); IMapping map = m_activeContext.getMappingAtLevel(cname); if (map != null) { NameDefinition ndef = map.getName(); if (ndef != null) { mb.appendDUP(); mb.appendLoadConstant(i); ndef.genPushName(mb); mb.appendAASTORE(); } } } mb.appendPutField(gnames); mb.appendLoadLocal(0); mb.appendLoadConstant(count); mb.appendCreateArray("java.lang.String"); for (int i = 0; i < count; i++) { String cname = (String)s_mappedClasses.get(i); IMapping map = m_activeContext.getMappingAtLevel(cname); if (map != null) { NameDefinition ndef = map.getName(); if (ndef != null) { mb.appendDUP(); mb.appendLoadConstant(i); ndef.genPushUri(mb); mb.appendAASTORE(); } } } mb.appendPutField(guris); // create and fill array of class names with unique IDs (null if none) mb.appendLoadLocal(0); if (m_uniqueIds != null && m_uniqueIds.size() > 0) { mb.appendLoadConstant(m_uniqueIds.size()); mb.appendCreateArray("java.lang.String"); for (int i = 0; i < m_uniqueIds.size(); i++) { mb.appendDUP(); mb.appendLoadConstant(i); mb.appendLoadConstant((String)m_uniqueIds.get(i)); mb.appendAASTORE(); } } else { mb.appendACONST_NULL(); } mb.appendPutField(idnames); // get class names for types (abstract non-base mappings) ArrayList tnames = new ArrayList(); if (m_isForceClasses) { for (int i = 0; i < count; i++) { String cname = (String)s_mappedClasses.get(i); IMapping map = m_activeContext.getMappingAtLevel(cname); if (map != null && map.isAbstract() && !map.isBase()) { String tname = map.getTypeName(); if (tname == null) { tname = cname; } tnames.add(tname); } } } // check if map needed for types ClassItem tmap = null; if (tnames.size() >= TYPEMAP_MINIMUM_SIZE) { // create field for map tmap = cf.addPrivateField(STRINGINT_MAPTYPE, TYPEMAP_NAME); // initialize with appropriate size mb.appendLoadLocal(0); mb.appendCreateNew(STRINGINT_MAPTYPE); mb.appendDUP(); mb.appendLoadConstant(tnames.size()); mb.appendCallInit(STRINGINT_MAPTYPE, STRINGINTINIT_SIGNATURE); // add all values to map for (int i = 0; i < tnames.size(); i++) { int index = s_mappedClasses.find(tnames.get(i)); if (index >= 0) { mb.appendDUP(); mb.appendLoadConstant((String)tnames.get(i)); mb.appendLoadConstant(index); mb.appendCallVirtual(STRINGINTADD_METHOD, STRINGINTADD_SIGNATURE); mb.appendPOP(); } } mb.appendPutField(tmap); } // finish with return from constructor mb.appendReturn(); mb.codeComplete(false); mb.addMethod(); // add the public marshalling context construction method mb = new ExceptionMethodBuilder(CREATEMARSHAL_METHODNAME, ClassItem.typeFromName(MARSHALCONTEXT_INTERFACE), new Type[0], cf, Constants.ACC_PUBLIC); if (m_isOutput) { // construct and return marshaller instance mb.appendCreateNew(MARSHALCONTEXT_IMPLEMENTATION); mb.appendDUP(); mb.appendLoadLocal(0); mb.appendGetField(classes); mb.appendLoadLocal(0); mb.appendGetField(marshs); mb.appendLoadLocal(0); mb.appendGetField(uris); mb.appendLoadLocal(0); mb.appendCallInit(MARSHALCONTEXT_IMPLEMENTATION, MARSHALCONTEXTINIT_SIGNATURE); mb.appendReturn(MARSHALCONTEXT_IMPLEMENTATION); } else { // throw exception for unsupported operation mb.appendCreateNew(UNSUPPORTED_EXCEPTION_CLASS); mb.appendDUP(); mb.appendLoadConstant ("Binding is input only - cannot create unmarshaller"); mb.appendCallInit(UNSUPPORTED_EXCEPTION_CLASS, MethodBuilder.EXCEPTION_CONSTRUCTOR_SIGNATURE1); mb.appendThrow(); } mb.codeComplete(false); mb.addMethod(); // add the public unmarshalling context construction method mb = new ExceptionMethodBuilder(CREATEUNMARSHAL_METHODNAME, ClassItem.typeFromName(UNMARSHALCONTEXT_INTERFACE), new Type[0], cf, Constants.ACC_PUBLIC); if (m_isInput) { // construct and return unmarshaller instance mb.appendCreateNew(UNMARSHALCONTEXT_IMPLEMENTATION); mb.appendDUP(); mb.appendLoadConstant(mcnt); mb.appendLoadLocal(0); mb.appendGetField(umarshs); mb.appendLoadLocal(0); mb.appendGetField(guris); mb.appendLoadLocal(0); mb.appendGetField(gnames); mb.appendLoadLocal(0); mb.appendGetField(idnames); mb.appendLoadLocal(0); mb.appendCallInit(UNMARSHALCONTEXT_IMPLEMENTATION, UNMARSHALCONTEXTINIT_SIGNATURE); mb.appendReturn(UNMARSHALCONTEXT_IMPLEMENTATION); } else { // throw exception for unsupported operation mb.appendCreateNew(UNSUPPORTED_EXCEPTION_CLASS); mb.appendDUP(); mb.appendLoadConstant ("Binding is output only - cannot create marshaller"); mb.appendCallInit(UNSUPPORTED_EXCEPTION_CLASS, MethodBuilder.EXCEPTION_CONSTRUCTOR_SIGNATURE1); mb.appendThrow(); } mb.codeComplete(false); mb.addMethod(); // add the compiler version access method mb = new ExceptionMethodBuilder(GETVERSION_METHODNAME, Type.INT, new Type[0], cf, Constants.ACC_PUBLIC); mb.appendLoadConstant(IBindingFactory.CURRENT_VERSION_NUMBER); mb.appendReturn("int"); mb.codeComplete(false); mb.addMethod(); // add the compiler distribution access method mb = new ExceptionMethodBuilder(GETDISTRIB_METHODNAME, Type.STRING, new Type[0], cf, Constants.ACC_PUBLIC); mb.appendLoadConstant(CURRENT_VERSION_NAME); mb.appendReturn(Type.STRING); mb.codeComplete(false); mb.addMethod(); // add the defined namespace URI array access method Type satype = new ArrayType(Type.STRING, 1); mb = new ExceptionMethodBuilder(GETDEFINEDNSS_METHODNAME, satype, new Type[0], cf, Constants.ACC_PUBLIC); mb.appendLoadLocal(0); mb.appendGetField(uris); mb.appendReturn(satype); mb.codeComplete(false); mb.addMethod(); // add the defined namespace prefixes array access method mb = new ExceptionMethodBuilder(GETDEFINEDPREFS_METHODNAME, satype, new Type[0], cf, Constants.ACC_PUBLIC); mb.appendLoadLocal(0); mb.appendGetField(prefs); mb.appendReturn(satype); mb.codeComplete(false); mb.addMethod(); // add the class name array access method mb = new ExceptionMethodBuilder(GETCLASSES_METHODNAME, satype, new Type[0], cf, Constants.ACC_PUBLIC); mb.appendLoadLocal(0); mb.appendGetField(classes); mb.appendReturn(satype); mb.codeComplete(false); mb.addMethod(); // add the element namespace URI array access method mb = new ExceptionMethodBuilder(GETELEMENTNSS_METHODNAME, satype, new Type[0], cf, Constants.ACC_PUBLIC); mb.appendLoadLocal(0); mb.appendGetField(guris); mb.appendReturn(satype); mb.codeComplete(false); mb.addMethod(); // add the element name array access method mb = new ExceptionMethodBuilder(GETELEMENTNAMES_METHODNAME, satype, new Type[0], cf, Constants.ACC_PUBLIC); mb.appendLoadLocal(0); mb.appendGetField(gnames); mb.appendReturn(satype); mb.codeComplete(false); mb.addMethod(); // add the type mapping index lookup method mb = new ExceptionMethodBuilder(GETTYPEINDEX_METHODNAME, Type.INT, new Type[] { Type.STRING }, cf, Constants.ACC_PUBLIC); if (tnames.size() > 0) { if (tmap == null) { // generate in-line compares for mapping for (int i = 0; i < tnames.size(); i++) { int index = s_mappedClasses.find(tnames.get(i)); if (index >= 0) { mb.appendLoadLocal(1); mb.appendLoadConstant((String)tnames.get(i)); mb.appendCallVirtual("java.lang.String.equals", "(Ljava/lang/Object;)Z"); BranchWrapper onfail = mb.appendIFEQ(this); mb.appendLoadConstant(index); mb.appendReturn(Type.INT); mb.targetNext(onfail); } } mb.appendLoadConstant(-1); } else { // use map constructed in initializer mb.appendLoadLocal(0); mb.appendGetField(tmap); mb.appendLoadLocal(1); mb.appendCallVirtual(STRINGINTGET_METHOD, STRINGINTGET_SIGNATURE); } } else { // no types to handle, just always return failure mb.appendLoadConstant(-1); } mb.appendReturn(Type.INT); mb.codeComplete(false); mb.addMethod(); // finish with instance creation method mb = new ExceptionMethodBuilder(GETINST_METHODNAME, ClassItem.typeFromName(FACTORY_INTERFACE), new Type[0], cf, (short)(Constants.ACC_PUBLIC | Constants.ACC_STATIC)); mb.appendGetStatic(inst); BranchWrapper ifdone = mb.appendIFNONNULL(this); mb.appendCreateNew(cf.getName()); mb.appendDUP(); mb.appendCallInit(cf.getName(), "()V"); mb.appendPutStatic(inst); mb.targetNext(ifdone); mb.appendGetStatic(inst); mb.appendReturn(FACTORY_INTERFACE); mb.codeComplete(false); mb.addMethod(); // add factory class to generated registry cf = MungedClass.getUniqueSupportClass(cf); String link = name; if (!name.equals(cf.getName())) { link = cf.getName() + '=' + name; } // record the binding factory in each top-level mapped class ArrayList maps = m_activeContext.getMappings(); for (int i = 0; i < maps.size(); i++) { IMapping map = (IMapping)maps.get(i); if (map instanceof MappingBase) { BoundClass bound = ((MappingBase)map).getBoundClass(); if (bound.getClassFile().isModifiable()) { bound.addFactory(link); } } } } /** * Get indexed binding. * * @param index number of binding to be returned * @return binding at the specified index */ public static BindingDefinition getBinding(int index) { return (BindingDefinition)s_bindings.get(index); } /** * Discard cached information and reset in preparation for a new binding * run. */ public static void reset() { s_bindings = new ArrayList(); s_mappedClasses = new ArrayMap(); } // // IContainer interface method definitions public boolean isContentOrdered() { return true; } public boolean hasNamespaces() { return false; } public BindingDefinition getBindingRoot() { return this; } public DefinitionContext getDefinitionContext() { return m_activeContext; } // DEBUG private static byte[] s_blanks = " ".getBytes(); public static void indent(int depth) { if (depth < s_blanks.length) { System.out.write(s_blanks, 0, depth); } else { System.out.print(s_blanks); } } public void print() { System.out.println("binding " + m_name + ":"); m_activeContext.print(1); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -