com.sun.xml.internal.bind.api.AccessorException Java Examples

The following examples show how to use com.sun.xml.internal.bind.api.AccessorException. 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: Scope.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Adds a new item to this packing scope.
 */
public void add( Accessor<BeanT,PropT> acc, Lister<BeanT,PropT,ItemT,PackT> lister, ItemT value) throws SAXException{
    try {
        if(!hasStarted()) {
            this.bean = (BeanT)context.getCurrentState().getTarget();
            this.acc = acc;
            this.lister = lister;
            this.pack = lister.startPacking(bean,acc);
        }

        lister.addToPack(pack,value);
    } catch (AccessorException e) {
        Loader.handleGenericException(e,true);
        // recover from this error by ignoring future items.
        this.lister = Lister.getErrorInstance();
        this.acc = Accessor.getErrorInstance();
    }
}
 
Example #2
Source File: SingleReferenceNodeProperty.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public void serializeBody(BeanT o, XMLSerializer w, Object outerPeer) throws SAXException, AccessorException, IOException, XMLStreamException {
    ValueT v = acc.get(o);
    if(v!=null) {
        try {
            JaxBeanInfo bi = w.grammar.getBeanInfo(v,true);
            if(bi.jaxbType==Object.class && domHandler!=null)
                // even if 'v' is a DOM node, it always derive from Object,
                // so the getBeanInfo returns BeanInfo for Object
                w.writeDom(v,domHandler,o,fieldName);
            else
                bi.serializeRoot(v,w);
        } catch (JAXBException e) {
            w.reportError(fieldName,e);
            // recover by ignoring this property
        }
    }
}
 
Example #3
Source File: Scope.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Starts the packing scope, without adding any item.
 *
 * This allows us to return an empty pack, thereby allowing the user
 * to distinguish empty array vs null array.
 */
public void start( Accessor<BeanT,PropT> acc, Lister<BeanT,PropT,ItemT,PackT> lister) throws SAXException{
    try {
        if(!hasStarted()) {
            this.bean = (BeanT)context.getCurrentState().getTarget();
            this.acc = acc;
            this.lister = lister;
            this.pack = lister.startPacking(bean,acc);
        }
    } catch (AccessorException e) {
        Loader.handleGenericException(e,true);
        // recover from this error by ignoring future items.
        this.lister = Lister.getErrorInstance();
        this.acc = Accessor.getErrorInstance();
    }
}
 
Example #4
Source File: ClassBeanInfoImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public void serializeBody(BeanT bean, XMLSerializer target) throws SAXException, IOException, XMLStreamException {
    if (superClazz != null) {
        superClazz.serializeBody(bean, target);
    }
    try {
        for (Property<BeanT> p : properties) {
            if (retainPropertyInfo) {
                target.currentProperty.set(p);
            }
            boolean isThereAnOverridingProperty = p.isHiddenByOverride();
            if (!isThereAnOverridingProperty || bean.getClass().equals(jaxbType)) {
                p.serializeBody(bean, target, null);
            } else if (isThereAnOverridingProperty) {
                // need to double check the override - it should be safe to do after the model has been created because it's targeted to override properties only
                Class beanClass = bean.getClass();
                if (Utils.REFLECTION_NAVIGATOR.getDeclaredField(beanClass, p.getFieldName()) == null) {
                    p.serializeBody(bean, target, null);
                }
            }
        }
    } catch (AccessorException e) {
        target.reportError(null, e);
    }
}
 
Example #5
Source File: ListTransducedAccessorImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public void declareNamespace(BeanT bean, XMLSerializer w) throws AccessorException, SAXException {
    ListT list = acc.get(bean);

    if(list!=null) {
       ListIterator<ItemT> itr = lister.iterator(list, w);

        while(itr.hasNext()) {
            try {
                ItemT item = itr.next();
                if (item != null) {
                    xducer.declareNamespace(item,w);
                }
            } catch (JAXBException e) {
                w.reportError(null,e);
            }
        }
    }
}
 
Example #6
Source File: ListTransducedAccessorImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private void processValue(BeanT bean, CharSequence s) throws AccessorException, SAXException {
    PackT pack = lister.startPacking(bean,acc);

    int idx = 0;
    int len = s.length();

    while(true) {
        int p = idx;
        while( p<len && !WhiteSpaceProcessor.isWhiteSpace(s.charAt(p)) )
            p++;

        CharSequence token = s.subSequence(idx,p);
        if (!token.equals(""))
            lister.addToPack(pack,xducer.parse(token));

        if(p==len)      break;  // done

        while( p<len && WhiteSpaceProcessor.isWhiteSpace(s.charAt(p)) )
            p++;
        if(p==len)      break;  // done

        idx = p;
    }

    lister.endPacking(pack,bean,acc);
}
 
Example #7
Source File: XsiNilLoader.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void onNil(UnmarshallingContext.State state) throws SAXException {
    try {
        acc.set(state.getPrev().getTarget(),null);
        state.getPrev().setNil(true);
    } catch (AccessorException e) {
        handleGenericException(e,true);
    }
}
 
Example #8
Source File: RuntimeEnumLeafInfoImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public T parse(CharSequence lexical) throws AccessorException, SAXException {
    // TODO: error handling

    B b = baseXducer.parse(lexical);

    if (tokenStringType) {
        b = (B) ((String)b).trim();
    }

    return parseMap.get(b);
}
 
Example #9
Source File: Accessor.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private AccessorException handleInvocationTargetException(InvocationTargetException e) {
    // don't block a problem in the user code
    Throwable t = e.getTargetException();
    if (t instanceof RuntimeException)
        throw (RuntimeException) t;
    if (t instanceof Error)
        throw (Error) t;

    // otherwise it's a checked exception.
    // I'm not sure how to handle this.
    // we can throw a checked exception from here,
    // but because get/set would be called from so many different places,
    // the handling would be tedious.
    return new AccessorException(t);
}
 
Example #10
Source File: SingleElementNodeProperty.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void serializeBody(BeanT o, XMLSerializer w, Object outerPeer) throws SAXException, AccessorException, IOException, XMLStreamException {
    ValueT v = acc.get(o);
    if (v!=null) {
        Class vtype = v.getClass();
        TagAndType tt=typeNames.get(vtype); // quick way that usually works

        if(tt==null) {// slow way that always works
            for (Map.Entry<Class,TagAndType> e : typeNames.entrySet()) {
                if(e.getKey().isAssignableFrom(vtype)) {
                    tt = e.getValue();
                    break;
                }
            }
        }

        boolean addNilDecl = (o instanceof JAXBElement) && ((JAXBElement)o).isNil();
        if(tt==null) {
            // actually this is an error, because the actual type was not a sub-type
            // of any of the types specified in the annotations,
            // but for the purpose of experimenting with simple type substitution,
            // it's convenient to marshal this anyway (for example so that classes
            // generated from simple types like String can be marshalled as expected.)
            w.startElement(typeNames.values().iterator().next().tagName,null);
            w.childAsXsiType(v,fieldName,w.grammar.getBeanInfo(Object.class), addNilDecl && nillable);
        } else {
            w.startElement(tt.tagName,null);
            w.childAsXsiType(v,fieldName,tt.beanInfo, addNilDecl && nillable);
        }
        w.endElement();
    } else if (nillable) {
        w.startElement(nullTagName,null);
        w.writeXsiNilTrue();
        w.endElement();
    }
}
 
Example #11
Source File: RawAccessorWrapper.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void set(Object bean, Object value) throws DatabindingException {
    try {
        accessor.set(bean, value);
    } catch (AccessorException e) {
        throw new DatabindingException(e);
    }
}
 
Example #12
Source File: RuntimeClassInfoImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public @NotNull CharSequence print(BeanT o) throws AccessorException {
    try {
        CharSequence value = xacc.print(o);
        if(value==null)
            throw new AccessorException(Messages.THERE_MUST_BE_VALUE_IN_XMLVALUE.format(o));
        return value;
    } catch (SAXException e) {
        throw new AccessorException(e);
    }
}
 
Example #13
Source File: SingleMapNodeProperty.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void leaveElement(State state, TagName ea) throws SAXException {
    super.leaveElement(state, ea);
    try {
        acc.set(target.get(), map.get());
        if (--depthCounter == 0) {
            target.remove();
            map.remove();
        }
    } catch (AccessorException ex) {
        handleGenericException(ex,true);
    }
}
 
Example #14
Source File: SingleMapNodeProperty.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void serializeBody(BeanT o, XMLSerializer w, Object outerPeer) throws SAXException, AccessorException, IOException, XMLStreamException {
    ValueT v = acc.get(o);
    if(v!=null) {
        bareStartTag(w,tagName,v);
        for( Map.Entry e : (Set<Map.Entry>)v.entrySet() ) {
            bareStartTag(w,entryTag,null);

            Object key = e.getKey();
            if(key!=null) {
                w.startElement(keyTag,key);
                w.childAsXsiType(key,fieldName,keyBeanInfo, false);
                w.endElement();
            }

            Object value = e.getValue();
            if(value!=null) {
                w.startElement(valueTag,value);
                w.childAsXsiType(value,fieldName,valueBeanInfo, false);
                w.endElement();
            }

            w.endElement();
        }
        w.endElement();
    } else
    if(nillable) {
        w.startElement(tagName,null);
        w.writeXsiNilTrue();
        w.endElement();
    }
}
 
Example #15
Source File: SingleElementLeafProperty.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void serializeBody(BeanT o, XMLSerializer w, Object outerPeer) throws SAXException, AccessorException, IOException, XMLStreamException {
    boolean hasValue = xacc.hasValue(o);

    Object obj = null;

    try {
        obj = acc.getUnadapted(o);
    } catch (AccessorException ae) {
        ; // noop
    }

    Class valueType = acc.getValueType();

    // check for different type than expected. If found, add xsi:type declaration
    if (xsiTypeNeeded(o, w, obj, valueType)) {
        w.startElement(tagName, outerPeer);
        w.childAsXsiType(obj, fieldName, w.grammar.getBeanInfo(valueType), false);
        w.endElement();
    } else {  // current type is expected
        if (hasValue) {
            xacc.writeLeafElement(w, tagName, o, fieldName);
        } else if (nillable) {
            w.startElement(tagName, null);
            w.writeXsiNilTrue();
            w.endElement();
        }
    }
}
 
Example #16
Source File: ElementBeanInfoImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void serializeBody(JAXBElement element, XMLSerializer target) throws SAXException, IOException, XMLStreamException {
    try {
        property.serializeBody(element,target,null);
    } catch (AccessorException x) {
        target.reportError(null,x);
    }
}
 
Example #17
Source File: LeafBeanInfoImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public final void serializeURIs(BeanT bean, XMLSerializer target) throws SAXException {
    // TODO: maybe we should create another LeafBeanInfoImpl class for
    // context-dependent xducers?
    if(xducer.useNamespace()) {
        try {
            xducer.declareNamespace(bean,target);
        } catch (AccessorException e) {
            target.reportError(null,e);
        }
    }
}
 
Example #18
Source File: TransducedAccessor.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void writeLeafElement(XMLSerializer w, Name tagName, BeanT o, String fieldName) throws SAXException, AccessorException, IOException, XMLStreamException {
    w.startElement(tagName,null);
    declareNamespace(o,w);
    w.endNamespaceDecls(null);
    w.endAttributes();
    xducer.writeText(w,acc.get(o),fieldName);
    w.endElement();
}
 
Example #19
Source File: MimeTypedTransducer.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void writeText(XMLSerializer w, V o, String fieldName) throws IOException, SAXException, XMLStreamException, AccessorException {
    MimeType old = w.setExpectedMimeType(expectedMimeType);
    try {
        core.writeText(w, o, fieldName);
    } finally {
        w.setExpectedMimeType(old);
    }
}
 
Example #20
Source File: MimeTypedTransducer.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void writeLeafElement(XMLSerializer w, Name tagName, V o, String fieldName) throws IOException, SAXException, XMLStreamException, AccessorException {
    MimeType old = w.setExpectedMimeType(expectedMimeType);
    try {
        core.writeLeafElement(w, tagName, o, fieldName);
    } finally {
        w.setExpectedMimeType(old);
    }
}
 
Example #21
Source File: LeafBeanInfoImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public final void serializeBody(BeanT bean, XMLSerializer w) throws SAXException, IOException, XMLStreamException {
    // most of the times leaves are printed as leaf element/attribute property,
    // so this code is only used for example when you have multiple XmlElement on a property
    // and some of them are leaves. Hence this doesn't need to be super-fast.
    try {
        xducer.writeText(w,bean,null);
    } catch (AccessorException e) {
        w.reportError(null,e);
    }
}
 
Example #22
Source File: ValueListBeanInfoImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public final void serializeURIs(Object array, XMLSerializer target) throws SAXException {
    if(xducer.useNamespace()) {
        int len = Array.getLength(array);
        for( int i=0; i<len; i++ )  {
            Object item = Array.get(array,i);
            try {
                xducer.declareNamespace(item,target);
            } catch (AccessorException e) {
                target.reportError("arrayItem",e);
            }
        }
    }
}
 
Example #23
Source File: Lister.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public T startPacking(BeanT bean, Accessor<BeanT, T> acc) throws AccessorException {
    T collection = acc.get(bean);
    if(collection==null) {
        collection = ClassFactory.create(implClass);
        if(!acc.isAdapted())
            acc.set(bean,collection);
    }
    collection.clear();
    return collection;
}
 
Example #24
Source File: ClassBeanInfoImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public boolean reset(BeanT bean, UnmarshallingContext context) throws SAXException {
    try {
        if(superClazz!=null)
            superClazz.reset(bean,context);
        for( Property<BeanT> p : properties )
            p.reset(bean);
        return true;
    } catch (AccessorException e) {
        context.handleError(e);
        return false;
    }
}
 
Example #25
Source File: ClassBeanInfoImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public String getId(BeanT bean, XMLSerializer target) throws SAXException {
    if(idProperty!=null) {
        try {
            return idProperty.getIdValue(bean);
        } catch (AccessorException e) {
            target.reportError(null,e);
        }
    }
    return null;
}
 
Example #26
Source File: SchemaTypeTransducer.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void writeText(XMLSerializer w, V o, String fieldName) throws IOException, SAXException, XMLStreamException, AccessorException {
    QName old = w.setSchemaType(schemaType);
    try {
        core.writeText(w,o,fieldName);
    } finally {
        w.setSchemaType(old);
    }
}
 
Example #27
Source File: SchemaTypeTransducer.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void writeLeafElement(XMLSerializer w, Name tagName, V o, String fieldName) throws IOException, SAXException, XMLStreamException, AccessorException {
    QName old = w.setSchemaType(schemaType);
    try {
        core.writeLeafElement(w, tagName, o, fieldName);
    } finally {
        w.setSchemaType(old);
    }
}
 
Example #28
Source File: UnmarshallingContext.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Ends the current packing scope.
 *
 * <p>
 * If any packing in progress will be finalized by this method.
 *
 * @param frameSize
 *      The same size that gets passed to the {@link #startScope(int)}
 *      method.
 */
public void endScope(int frameSize) throws SAXException {
    try {
        for( ; frameSize>0; frameSize--, scopeTop-- )
            scopes[scopeTop].finish();
    } catch (AccessorException e) {
        handleError(e);

        // the error might have left scopes in inconsistent state,
        // so replace them by fresh ones
        for( ; frameSize>0; frameSize-- )
            scopes[scopeTop--] = new Scope(this);
    }
}
 
Example #29
Source File: InlineBinaryTransducer.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void writeLeafElement(XMLSerializer w, Name tagName, V o, String fieldName) throws IOException, SAXException, XMLStreamException, AccessorException {
    boolean old = w.setInlineBinaryFlag(true);
    try {
        core.writeLeafElement(w, tagName, o, fieldName);
    } finally {
        w.setInlineBinaryFlag(old);
    }
}
 
Example #30
Source File: AdaptedLister.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void addToPack(PackT pack, OnWireItemT item) throws AccessorException {
    InMemItemT r;
    try {
        r = getAdapter().unmarshal(item);
    } catch (Exception e) {
        throw new AccessorException(e);
    }
    core.addToPack(pack,r);
}