Examples of UnmarshallingContext


Examples of org.jibx.runtime.impl.UnmarshallingContext

   * @see org.jibx.runtime.IUnmarshaller#unmarshal(java.lang.Object, org.jibx.runtime.IUnmarshallingContext)
   */
  public Object unmarshal(Object obj, IUnmarshallingContext ictx) throws JiBXException {

    // make sure we're at the appropriate start tag
    UnmarshallingContext ctx = (UnmarshallingContext) ictx;
    if (!ctx.isAt(uri, name)) {
      ctx.throwStartTagNameError(uri, name);
    }

    // create new hashmap if needed
    OverlapBehaviorInfo overlapBehaviorInfo = (OverlapBehaviorInfo) obj;
    if (overlapBehaviorInfo == null) {
      overlapBehaviorInfo = new OverlapBehaviorInfo();
    }

    // process all entries present in document
    ctx.parsePastStartTag(uri, name);
    boolean found = false;
    for (OverlapBehaviorInfoInner inner : OverlapBehaviorInfoInner.values()) {
      if (ctx.parseIfStartTag(uri, inner.name())) {
        found = true;
        overlapBehaviorInfo.setOverlapBehavior(inner);
        ctx.parsePastEndTag(uri, inner.name());
        break;
      }
    }
    if (!found) {
      ctx.throwStartTagException("Unrecognized inner element");
    }
    ctx.parsePastEndTag(uri, name);
    return overlapBehaviorInfo;
  }
View Full Code Here

Examples of org.jibx.runtime.impl.UnmarshallingContext

    public Container getSharedLayout() throws Exception {
        String path = "war:/conf/portal/portal/sharedlayout.xml";
        String out = IOUtil.getStreamContentAsString(confManager_.getInputStream(path));
        ByteArrayInputStream is = new ByteArrayInputStream(out.getBytes("UTF-8"));
        IBindingFactory bfact = BindingDirectory.getFactory(Container.class);
        UnmarshallingContext uctx = (UnmarshallingContext) bfact.createUnmarshallingContext();
        uctx.setDocument(is, null, "UTF-8", false);
        Container container = (Container) uctx.unmarshalElement();
        generateStorageName(container);
        return container;
    }
View Full Code Here

Examples of org.jibx.runtime.impl.UnmarshallingContext

   {
      String path = "war:/conf/portal/portal/sharedlayout.xml";
      String out = IOUtil.getStreamContentAsString(confManager_.getInputStream(path));
      ByteArrayInputStream is = new ByteArrayInputStream(out.getBytes("UTF-8"));
      IBindingFactory bfact = BindingDirectory.getFactory(Container.class);
      UnmarshallingContext uctx = (UnmarshallingContext)bfact.createUnmarshallingContext();
      uctx.setDocument(is, null, "UTF-8", false);
      Container container = (Container)uctx.unmarshalElement();
      generateStorageName(container);
      return container;
   }
View Full Code Here

Examples of org.jibx.runtime.impl.UnmarshallingContext

   }

   @SuppressWarnings("unchecked")
   public Object unmarshal(Object obj, IUnmarshallingContext ictx) throws JiBXException
   {
      UnmarshallingContext ctx = (UnmarshallingContext)ictx;
      if (!ctx.isAt(marshalURI, marshallName))
         ctx.throwStartTagNameError(marshalURI, marshallName);

      int size = ctx.attributeInt(marshalURI, SIZE_ATTRIBUTE_NAME, DEFAULT_SIZE);
      Properties map = (Properties)obj;
      if (map == null)
         map = new Properties(size);

      ctx.parsePastStartTag(marshalURI, marshallName);
      while (ctx.isAt(marshalURI, ENTRY_ELEMENT_NAME))
      {
         Object key = ctx.attributeText(marshalURI, KEY_ATTRIBUTE_NAME, null);
         ctx.next();
         Object value = ctx.getText();
         map.put(key.toString(), value.toString());
         ctx.parsePastEndTag(marshalURI, ENTRY_ELEMENT_NAME);
      }
      ctx.parsePastEndTag(marshalURI, marshallName);
      return map;
   }
View Full Code Here

Examples of org.jibx.runtime.impl.UnmarshallingContext

      return ctx.isAt(m_uri, m_name);
   }

   public Object unmarshal(Object obj, IUnmarshallingContext ictx) throws JiBXException
   {
      UnmarshallingContext ctx = (UnmarshallingContext)ictx;
      if (!ctx.isAt(m_uri, m_name))
      {
         ctx.throwStartTagNameError(m_uri, m_name);
      }

      //
      if (obj != null)
      {
         throw new AssertionError("That should not happen");
      }

      // Id
      String id = optionalAttribute(ctx, "id");

      //
      ctx.parsePastStartTag(m_uri, m_name);

      //
      Application<Portlet> app;
      if ("application".equals(m_name))
      {
         String instanceId = ctx.parseElementText(m_uri, "instance-id");
         instanceId = NewPortalConfigListener.fixInstanceIdOwnerName(instanceId);
         int i0 = instanceId.indexOf("#");
         int i1 = instanceId.indexOf(":/", i0 + 1);
         String ownerType = instanceId.substring(0, i0);
         String ownerId = instanceId.substring(i0 + 1, i1);
         String persistenceid = instanceId.substring(i1 + 2);
         String[] persistenceChunks = split("/", persistenceid);
         TransientApplicationState<Portlet> state;
         if (persistenceChunks.length == 2)
         {
            state = new TransientApplicationState<Portlet>(
               persistenceChunks[0] + "/" +  persistenceChunks[1],
               null,
               ownerType,
               ownerId,
               null);
         }
         else
         {
            state = new TransientApplicationState<Portlet>(
               persistenceChunks[0] + "/" +  persistenceChunks[1],
               null,
               ownerType,
               ownerId,
               persistenceChunks[2]);
         }
         app = Application.createPortletApplication();
         app.setState(state);
      }
      else
      {
         ctx.parsePastStartTag(m_uri, "portlet");
         String applicationName = ctx.parseElementText(m_uri, "application-ref");
         String portletName = ctx.parseElementText(m_uri, "portlet-ref");
         TransientApplicationState<Portlet> state;
         if (ctx.isAt(m_uri, "preferences"))
         {
            PortletBuilder builder = new PortletBuilder();
            ctx.parsePastStartTag(m_uri, "preferences");
            while (ctx.isAt(m_uri, "preference"))
            {
               Preference value = (Preference)ctx.unmarshalElement();
               builder.add(value.getName(), value.getValues(), value.isReadOnly());
            }
            ctx.parsePastEndTag(m_uri, "preferences");
            state = new TransientApplicationState<Portlet>(applicationName + "/" + portletName, builder.build());
         }
         else
         {
            state = new TransientApplicationState<Portlet>(applicationName + "/" + portletName, null);
         }
         app = Application.createPortletApplication();
         app.setState(state);
         ctx.parsePastEndTag(m_uri, "portlet");
      }

      //
      nextOptionalTag(ctx, "application-type");
      String theme = nextOptionalTag(ctx, "theme");
      String title = nextOptionalTag(ctx, "title");
      String accessPermissions = nextOptionalTag(ctx, "access-permissions");
      boolean showInfoBar = nextOptionalBooleanTag(ctx, "show-info-bar", true);
      boolean showApplicationState = nextOptionalBooleanTag(ctx, "show-application-state", true);
      boolean showApplicationMode = nextOptionalBooleanTag(ctx, "show-application-mode", true);
      String description = nextOptionalTag(ctx, "description");
      String icon = nextOptionalTag(ctx, "icon");
      String width = nextOptionalTag(ctx, "width");
      String height = nextOptionalTag(ctx, "height");

      //
      Properties properties = null;
      if (ctx.isAt(m_uri, "properties"))
      {
         properties = (Properties)ctx.unmarshalElement();
      }

      //
      ctx.parsePastEndTag(m_uri, m_name);

      //
      app.setId(id);
      app.setTheme(theme);
      app.setTitle(title);
View Full Code Here

Examples of org.jibx.runtime.impl.UnmarshallingContext

      return ctx.isAt(m_uri, m_name);
   }

   public Object unmarshal(Object obj, IUnmarshallingContext ictx) throws JiBXException
   {
      UnmarshallingContext ctx = (UnmarshallingContext)ictx;
      if (!ctx.isAt(m_uri, m_name))
      {
         ctx.throwStartTagNameError(m_uri, m_name);
      }

      //
      if (obj != null)
      {
         throw new AssertionError("That should not happen");
      }

      //
      PortletBuilder builder = new PortletBuilder();

      //
      ctx.parsePastStartTag(m_uri, m_name);
      while (ctx.isAt(m_uri, "preference"))
      {
         Preference value = (Preference)ctx.unmarshalElement();
         builder.add(value.getName(), value.getValues(), value.isReadOnly());
      }
      ctx.parsePastEndTag(m_uri, m_name);

      //
      return builder.build();
   }
View Full Code Here

Examples of org.jibx.runtime.impl.UnmarshallingContext

   private <T> T fromXML(String ownerType, String owner, String xml, Class<T> clazz) throws Exception
   {
      ByteArrayInputStream is = new ByteArrayInputStream(xml.getBytes("UTF-8"));
      IBindingFactory bfact = BindingDirectory.getFactory(clazz);
      UnmarshallingContext uctx = (UnmarshallingContext)bfact.createUnmarshallingContext();
      uctx.setDocument(is, null, "UTF-8", false);
      T o = clazz.cast(uctx.unmarshalElement());
      if (o instanceof PageNavigation)
      {
         PageNavigation nav = (PageNavigation)o;
         nav.setOwnerType(ownerType);
         nav.setOwnerId(owner);
View Full Code Here

Examples of org.jibx.runtime.impl.UnmarshallingContext

    public static <T> UnmarshalledObject<T> unmarshall(Class<T> type, byte[] bytes) throws Exception {
        ByteArrayInputStream baos = new ByteArrayInputStream(bytes);

        //
        IBindingFactory bfact = BindingDirectory.getFactory(type);
        UnmarshallingContext uctx = (UnmarshallingContext) bfact.createUnmarshallingContext();
        uctx.setDocument(baos, null, "UTF-8", false);
        T obj = type.cast(uctx.unmarshalElement());

        // Find out version
        XMLInputFactory factory = XMLInputFactory.newInstance();
        baos.reset();
        XMLStreamReader reader = factory.createXMLStreamReader(baos);
View Full Code Here

Examples of org.jibx.runtime.impl.UnmarshallingContext

        return ctx.isAt(marshalURI, marshallName);
    }

    @SuppressWarnings("unchecked")
    public Object unmarshal(Object obj, IUnmarshallingContext ictx) throws JiBXException {
        UnmarshallingContext ctx = (UnmarshallingContext) ictx;
        if (!ctx.isAt(marshalURI, marshallName))
            ctx.throwStartTagNameError(marshalURI, marshallName);

        int size = ctx.attributeInt(marshalURI, SIZE_ATTRIBUTE_NAME, DEFAULT_SIZE);
        Properties map = (Properties) obj;
        if (map == null)
            map = new Properties(size);

        ctx.parsePastStartTag(marshalURI, marshallName);
        while (ctx.isAt(marshalURI, ENTRY_ELEMENT_NAME)) {
            Object key = ctx.attributeText(marshalURI, KEY_ATTRIBUTE_NAME, null);
            ctx.next();
            Object value = ctx.getText();
            map.put(key.toString(), value.toString());
            ctx.parsePastEndTag(marshalURI, ENTRY_ELEMENT_NAME);
        }
        ctx.parsePastEndTag(marshalURI, marshallName);
        return map;
    }
View Full Code Here

Examples of org.jibx.runtime.impl.UnmarshallingContext

    }

    private static final Pattern RFC1766_PATTERN = Pattern.compile("^([a-zA-Z]{2})(?:-([a-zA-Z]{2}))?$");

    public Object unmarshal(Object o, IUnmarshallingContext ictx) throws JiBXException {
        UnmarshallingContext ctx = (UnmarshallingContext) ictx;
        if (!ctx.isAt(marshalURI, marshallName)) {
            ctx.throwStartTagNameError(marshalURI, marshallName);
        }
        int count = ctx.getAttributeCount();
        Locale lang = null;
        for (int i = 0; i < count; i++) {
            String attrName = ctx.getAttributeName(i);
            if (attrName.equals("xml:lang")) {
                String attrValue = ctx.getAttributeValue(i).trim();
                Matcher matcher = RFC1766_PATTERN.matcher(attrValue);
                if (matcher.matches()) {
                    String langISO = matcher.group(1);
                    String countryISO = matcher.group(2);
                    if (countryISO == null) {
                        lang = new Locale(langISO.toLowerCase());
                    } else {
                        lang = new Locale(langISO.toLowerCase(), countryISO.toLowerCase());
                    }
                } else {
                    throw new JiBXParseException("The attribute xml:lang " + attrValue
                            + " does not represent a valid language as defined by RFC 1766", attrValue);
                }
                break;
            }
        }
        ctx.parsePastStartTag(marshalURI, marshallName);
        String value = ctx.getText();
        ctx.parsePastEndTag(marshalURI, marshallName);
        return new LocalizedString(value, lang);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.