src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/unmarshaller/UnmarshallingContext.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -196,24 +196,23 @@
      */
     public final class State {
         /**
          * Loader that owns this element.
          */
-        public Loader loader;
+        private Loader loader;
         /**
          * Once {@link #loader} is completed, this receiver
          * receives the result.
          */
-        public Receiver receiver;
-
-        public Intercepter intercepter;
+        private Receiver receiver;
 
+        private Intercepter intercepter;
 
         /**
          * Object being unmarshalled by this {@link #loader}.
          */
-        public Object target;
+        private Object target;
 
         /**
          * Hack for making JAXBElement unmarshalling work.
          *
          * <p>

@@ -238,11 +237,11 @@
          * Yes, I know this is a hack, and no, I'm not proud of it.
          *
          * @see ElementBeanInfoImpl.IntercepterLoader#startElement(State, TagName)
          * @see ElementBeanInfoImpl.IntercepterLoader#intercept(State, Object)
          */
-        public Object backup;
+        private Object backup;
 
         /**
          * Number of {@link UnmarshallingContext#nsBind}s declared thus far.
          * (The value of {@link UnmarshallingContext#nsLen} when this state is pushed.
          */

@@ -254,21 +253,26 @@
          * This should be set by either a parent {@link Loader} when
          * {@link Loader#childElement(State, TagName)} is called
          * or by a child {@link Loader} when
          * {@link Loader#startElement(State, TagName)} is called.
          */
-        public String elementDefaultValue;
+        private String elementDefaultValue;
 
         /**
          * {@link State} for the parent element
          *
          * {@link State} objects form a doubly linked list.
          */
-        public State prev;
+        private State prev;
         private State next;
 
-        public boolean nil = false;
+        private boolean nil = false;
+
+        /**
+         * specifies that we are working with mixed content
+         */
+        private boolean mixed = false;
 
         /**
          * Gets the context.
          */
         public UnmarshallingContext getContext() {

@@ -278,20 +282,22 @@
         @SuppressWarnings("LeakingThisInConstructor")
         private State(State prev) {
             this.prev = prev;
             if (prev!=null) {
                 prev.next = this;
+                if (prev.mixed) // parent is in mixed mode
+                    this.mixed = true;
             }
         }
 
         private void push() {
             if (logger.isLoggable(Level.FINEST)) {
                 logger.log(Level.FINEST, "State.push");
             }
             if (next==null) {
                 assert current == this;
-                allocateMoreStates();
+                next = new State(this);
             }
             nil = false;
             State n = next;
             n.numNsDecl = nsLen;
             current = n;

@@ -302,15 +308,75 @@
                 logger.log(Level.FINEST, "State.pop");
             }
             assert prev!=null;
             loader = null;
             nil = false;
+            mixed = false;
             receiver = null;
             intercepter = null;
             elementDefaultValue = null;
             target = null;
             current = prev;
+            next = null;
+        }
+
+        public boolean isMixed() {
+            return mixed;
+        }
+
+        public Object getTarget() {
+            return target;
+        }
+
+        public void setLoader(Loader loader) {
+            if (loader instanceof StructureLoader) // set mixed mode
+                mixed = !((StructureLoader)loader).getBeanInfo().hasElementOnlyContentModel();
+            this.loader = loader;
+        }
+
+        public void setReceiver(Receiver receiver) {
+            this.receiver = receiver;
+        }
+
+        public State getPrev() {
+            return prev;
+        }
+
+        public void setIntercepter(Intercepter intercepter) {
+            this.intercepter = intercepter;
+        }
+
+        public void setBackup(Object backup) {
+            this.backup = backup;
+        }
+
+        public void setTarget(Object target) {
+            this.target = target;
+        }
+
+        public Object getBackup() {
+            return backup;
+        }
+
+        public boolean isNil() {
+            return nil;
+        }
+
+        public void setNil(boolean nil) {
+            this.nil = nil;
+        }
+
+        public Loader getLoader() {
+            return loader;
+        }
+
+        public String getElementDefaultValue() {
+            return elementDefaultValue;
+        }
+
+        public void setElementDefaultValue(String elementDefaultValue) {
+            this.elementDefaultValue = elementDefaultValue;
         }
     }
 
     /**
      * Stub to the user-specified factory method.

@@ -346,11 +412,10 @@
      */
     public UnmarshallingContext( UnmarshallerImpl _parent, AssociationMap assoc) {
         this.parent = _parent;
         this.assoc = assoc;
         this.root = this.current = new State(null);
-        allocateMoreStates();
     }
 
     public void reset(InfosetScanner scanner,boolean isInplaceMode, JaxBeanInfo expectedType, IDResolver idResolver) {
         this.scanner = scanner;
         this.isInplaceMode = isInplaceMode;

@@ -393,27 +458,10 @@
         }
 
         return null;
     }
 
-    /**
-     * Allocates a few more {@link State}s.
-     *
-     * Allocating multiple {@link State}s at once allows those objects
-     * to be allocated near each other, which reduces the working set
-     * of CPU. It improves the chance the relevant data is in the cache.
-     */
-    private void allocateMoreStates() {
-        // this method should be used only when we run out of a state.
-        assert current.next==null;
-
-        State s = current;
-        for (int i=0; i<8; i++) {
-            s = new State(s);
-        }
-    }
-
     public void clearStates() {
         State last = current;
         while (last.next != null) last = last.next;
         while (last.prev != null) {
             last.loader = null;

@@ -513,20 +561,19 @@
         current.loader.startElement(current,tagName);
     }
 
     @Override
     public void text(CharSequence pcdata) throws SAXException {
-        State cur = current;
         pushCoordinator();
         try {
-            if(cur.elementDefaultValue!=null) {
-                if(pcdata.length()==0) {
+            if (current.elementDefaultValue != null) {
+                if (pcdata.length() == 0) {
                     // send the default value into the unmarshaller instead
-                    pcdata = cur.elementDefaultValue;
+                    pcdata = current.elementDefaultValue;
                 }
             }
-            cur.loader.text(cur,pcdata);
+            current.loader.text(current, pcdata);
         } finally {
             popCoordinator();
         }
     }