Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*     */ package com.sun.xml.bind.v2.runtime.reflect;
  /*     */ 
  /*     */ import com.sun.istack.NotNull;
  /*     */ import com.sun.istack.Nullable;
  /*     */ import com.sun.istack.SAXException2;
  /*     */ import com.sun.xml.bind.WhiteSpaceProcessor;
  /*     */ import com.sun.xml.bind.api.AccessorException;
  /*     */ import com.sun.xml.bind.v2.model.core.ID;
 /*     */ import com.sun.xml.bind.v2.runtime.Name;
 /*     */ import com.sun.xml.bind.v2.runtime.Transducer;
 /*     */ import java.io.IOException;
 /*     */ import java.util.concurrent.Callable;
 /*     */ import javax.xml.bind.JAXBException;
 /*     */ import javax.xml.stream.XMLStreamException;
 /*     */ import org.xml.sax.SAXException;
 /*     */ 
 /*     */ public abstract class TransducedAccessor<BeanT>
 /*     */ {
 /*     */   public boolean useNamespace()
 /*     */   {
 /*  89 */     return false;
 /*     */   }
 /*     */ 
 /*     */   public void declareNamespace(BeanT oXMLSerializer w)
 /*     */     throws AccessorExceptionSAXException
 /*     */   {
 /*     */   }
 /*     */ 
 /*     */   @Nullable
 /*     */   public abstract CharSequence print(@NotNull BeanT paramBeanT)
 /*     */     throws AccessorExceptionSAXException;
 /*     */ 
 /*     */   public abstract void parse(BeanT paramBeanTCharSequence paramCharSequence)
 /*     */     throws AccessorExceptionSAXException;
 /*     */ 
 /*     */   public abstract boolean hasValue(BeanT paramBeanT)
 /*     */     throws AccessorException;
 /*     */ 
 /*     */   public static <T> TransducedAccessor<T> get(JAXBContextImpl contextRuntimeNonElementRef ref)
 /*     */   {
 /* 153 */     Transducer xducer = RuntimeModelBuilder.createTransducer(ref);
 /* 154 */     RuntimePropertyInfo prop = ref.getSource();
 /*     */ 
 /* 156 */     if (prop.isCollection()) {
 /* 157 */       return new ListTransducedAccessorImpl(xducer, prop.getAccessor(), Lister.create(Navigator.REFLECTION.erasure(prop.getRawType()), prop.id(), prop.getAdapter()));
 /*     */     }
 /*     */ 
 /* 162 */     if (prop.id() == ID.IDREF) {
 /* 163 */       return new IDREFTransducedAccessorImpl(prop.getAccessor());
 /*     */     }
 /* 165 */     if ((xducer.isDefault()) && (!context.fastBoot)) {
 /* 166 */       TransducedAccessor xa = OptimizedTransducedAccessorFactory.get(prop);
 /* 167 */       if (xa != nullreturn xa;
 /*     */     }
 /*     */ 
 /* 170 */     if (xducer.useNamespace()) {
 /* 171 */       return new CompositeContextDependentTransducedAccessorImpl(context, xducer, prop.getAccessor());
 /*     */     }
 /* 173 */     return new CompositeTransducedAccessorImpl(context, xducer, prop.getAccessor());
 /*     */   }
 /*     */ 
 /*     */   public abstract void writeLeafElement(XMLSerializer paramXMLSerializerName paramName, BeanT paramBeanTString paramString)
 /*     */     throws SAXExceptionAccessorExceptionIOExceptionXMLStreamException;
 /*     */ 
 /*     */   public abstract void writeText(XMLSerializer paramXMLSerializer, BeanT paramBeanTString paramString)
 /*     */     throws AccessorExceptionSAXExceptionIOExceptionXMLStreamException;
 /*     */ 
 /*     */   private static final class IDREFTransducedAccessorImpl<BeanT, TargetT> extends DefaultTransducedAccessor<BeanT>
 /*     */   {
 /*     */     private final Accessor<BeanT, TargetT> acc;
 /*     */     private final Class<TargetT> targetType;
 /*     */ 
 /*     */     public IDREFTransducedAccessorImpl(Accessor<BeanT, TargetT> acc)
 /*     */     {
 /* 274 */       this.acc = acc;
 /* 275 */       this.targetType = acc.getValueType();
 /*     */     }
 /*     */ 
 /*     */     public String print(BeanT beanthrows AccessorExceptionSAXException {
 /* 279 */       Object target = this.acc.get(bean);
 /* 280 */       if (target == nullreturn null;
 /*     */ 
 /* 282 */       XMLSerializer w = XMLSerializer.getInstance();
 /*     */       try {
 /* 284 */         String id = w.grammar.getBeanInfo(target, true).getId(target, w);
 /* 285 */         if (id == null)
/* 286 */           w.errorMissingId(target);
/* 287 */         return id;
/*     */       } catch (JAXBException e) {
/* 289 */         w.reportError(null, e);
/* 290 */       }return null;
/*     */     }
/*     */ 
/*     */     private void assign(BeanT bean, TargetT tUnmarshallingContext contextthrows AccessorException
/*     */     {
/* 295 */       if (!this.targetType.isInstance(t))
/* 296 */         context.handleError(Messages.UNASSIGNABLE_TYPE.format(new Object[] { this.targetType, t.getClass() }));
/*     */       else
/* 298 */         this.acc.set(bean, t);
/*     */     }
/*     */ 
/*     */     public void parse(BeanT beanCharSequence lexicalthrows AccessorExceptionSAXException {
/* 302 */       String idref = WhiteSpaceProcessor.trim(lexical).toString();
/* 303 */       UnmarshallingContext context = UnmarshallingContext.getInstance();
/*     */ 
/* 305 */       Callable callable = context.getObjectFromId(idref, this.acc.valueType);
/* 306 */       if (callable == null)
/*     */       {
/* 308 */         context.errorUnresolvedIDREF(bean, idref, context.getLocator());
/* 309 */         return;
/*     */       }
/*     */       Object t;
/*     */       try {
/* 314 */         t = callable.call();
/*     */       } catch (SAXException e) {
/* 316 */         throw e;
/*     */       } catch (RuntimeException e) {
/* 318 */         throw e;
/*     */       } catch (Exception e) {
/* 320 */         throw new SAXException2(e);
/*     */       }
/* 322 */       if (t != null) {
/* 323 */         assign(bean, t, context);
/*     */       }
/*     */       else {
/* 326 */         LocatorEx loc = new LocatorEx.Snapshot(context.getLocator());
/* 327 */         context.addPatcher(new Patcher(callable, context, bean, idref, loc) {
/*     */           public void run() throws SAXException {
/*     */             try {
/* 330 */               Object t = this.val$callable.call();
/* 331 */               if (t == null)
/* 332 */                 this.val$context.errorUnresolvedIDREF(this.val$bean, this.val$idref, this.val$loc);
/*     */               else
/* 334 */                 TransducedAccessor.IDREFTransducedAccessorImpl.this.assign(this.val$bean, t, this.val$context);
/*     */             }
/*     */             catch (AccessorException e) {
/* 337 */               this.val$context.handleError(e);
/*     */             } catch (SAXException e) {
/* 339 */               throw e;
/*     */             } catch (RuntimeException e) {
/* 341 */               throw e;
/*     */             } catch (Exception e) {
/* 343 */               throw new SAXException2(e);
/*     */             }
/*     */           } } );
/*     */       }
/*     */     }
/*     */ 
/*     */     public boolean hasValue(BeanT beanthrows AccessorException {
/* 351 */       return this.acc.get(bean) != null;
/*     */     }
/*     */   }
/*     */ 
/*     */   static class CompositeTransducedAccessorImpl<BeanT, ValueT> extends TransducedAccessor<BeanT>
/*     */   {
/*     */     protected final Transducer<ValueT> xducer;
/*     */     protected final Accessor<BeanT, ValueT> acc;
/*     */ 
/*     */     public CompositeTransducedAccessorImpl(JAXBContextImpl contextTransducer<ValueT> xducerAccessor<BeanT, ValueT> acc)
/*     */     {
/* 230 */       this.xducer = xducer;
/* 231 */       this.acc = acc.optimize(context);
/*     */     }
/*     */ 
/*     */     public CharSequence print(BeanT beanthrows AccessorException {
/* 235 */       Object o = this.acc.get(bean);
/* 236 */       if (o == nullreturn null;
/* 237 */       return this.xducer.print(o);
/*     */     }
/*     */ 
/*     */     public void parse(BeanT beanCharSequence lexicalthrows AccessorExceptionSAXException {
/* 241 */       this.acc.set(bean, this.xducer.parse(lexical));
/*     */     }
/*     */ 
/*     */     public boolean hasValue(BeanT beanthrows AccessorException {
/* 245 */       return this.acc.getUnadapted(bean) != null;
/*     */     }
/*     */ 
/*     */     public void writeLeafElement(XMLSerializer wName tagName, BeanT oString fieldNamethrows SAXExceptionAccessorExceptionIOExceptionXMLStreamException
/*     */     {
/* 250 */       this.xducer.writeLeafElement(w, tagName, this.acc.get(o), fieldName);
/*     */     }
/*     */ 
/*     */     public void writeText(XMLSerializer w, BeanT oString fieldNamethrows AccessorExceptionSAXExceptionIOExceptionXMLStreamException
/*     */     {
/* 255 */       this.xducer.writeText(w, this.acc.get(o), fieldName);
/*     */     }
/*     */   }
/*     */ 
/*     */   static class CompositeContextDependentTransducedAccessorImpl<BeanT, ValueT> extends TransducedAccessor.CompositeTransducedAccessorImpl<BeanT, ValueT>
/*     */   {
/*     */     public CompositeContextDependentTransducedAccessorImpl(JAXBContextImpl contextTransducer<ValueT> xducerAccessor<BeanT, ValueT> acc)
/*     */     {
/* 195 */       super(xducer, acc);
/* 196 */       assert (xducer.useNamespace());
/*     */     }
/*     */ 
/*     */     public boolean useNamespace() {
/* 200 */       return true;
/*     */     }
/*     */ 
/*     */     public void declareNamespace(BeanT beanXMLSerializer wthrows AccessorException {
/* 204 */       Object o = this.acc.get(bean);
/* 205 */       if (o != null)
/* 206 */         this.xducer.declareNamespace(o, w);
/*     */     }
/*     */ 
/*     */     public void writeLeafElement(XMLSerializer wName tagName, BeanT oString fieldNamethrows SAXExceptionAccessorExceptionIOExceptionXMLStreamException
/*     */     {
/* 211 */       w.startElement(tagName, null);
/* 212 */       declareNamespace(o, w);
/* 213 */       w.endNamespaceDecls(null);
/* 214 */       w.endAttributes();
/* 215 */       this.xducer.writeText(w, this.acc.get(o), fieldName);
/* 216 */       w.endElement();
/*     */     }
/*     */   }
/*     */ }
/* Location:           /home/mnovotny/projects/EMBEDDED_JBOSS_BETA3_COMMUNITY/embedded/output/lib/embedded-jboss/lib/thirdparty-all.jar
 * Qualified Name:     com.sun.xml.bind.v2.runtime.reflect.TransducedAccessor
 * JD-Core Version:    0.6.0
 */
New to GrepCode? Check out our FAQ X