Package javax.jcr

Examples of javax.jcr.PropertyIterator


    @Override
    public Object[] getIds() {
        Collection<String> ids = new ArrayList<String>();
        if(node != null) {
            try {
                PropertyIterator pit = node.getProperties();
                while (pit.hasNext()) {
                    ids.add(pit.nextProperty().getName());
                }
            } catch (RepositoryException e) {
                //do nothing, just do not list properties
            }
            try {
View Full Code Here


    public PropertyIterator getProperties() {
        return new MockPropertyIterator(properties.values().iterator());
    }

    public PropertyIterator getProperties(String namePattern) throws RepositoryException {
        PropertyIterator iterator = getProperties();
        List<Property> properties = new ArrayList<Property>();

        while (iterator.hasNext()) {
            Property p = iterator.nextProperty();
            String name = p.getName();
            if (ChildrenCollectorFilter.matches(name, namePattern)) {
                properties.add(p);
            }
        }
View Full Code Here

     * @throws IllegalArgumentException if a repository exception occurs
     */
    void readFully() {
        if (!fullyRead) {
            try {
                final PropertyIterator pi = node.getProperties();
                while (pi.hasNext()) {
                    final Property prop = pi.nextProperty();
                    this.cacheProperty(prop);
                }
                fullyRead = true;
            } catch (final RepositoryException re) {
                throw new IllegalArgumentException(re);
View Full Code Here

     * @throws IllegalArgumentException if a repository exception occurs
     */
    void readFully() {
        if (!fullyRead) {
            try {
                final PropertyIterator pi = node.getProperties();
                while (pi.hasNext()) {
                    final Property prop = pi.nextProperty();
                    this.cacheProperty(prop);
                }
                fullyRead = true;
            } catch (final RepositoryException re) {
                throw new IllegalArgumentException(re);
View Full Code Here

    /**
     * Load this preferences from a node.
     */
    @SuppressWarnings("unchecked")
    protected void readPreferences(PreferencesImpl prefs, Session session, Node node) throws RepositoryException {
        final PropertyIterator iterator = node.getProperties();
        while ( iterator.hasNext() ) {
            final Property prop = iterator.nextProperty();
            if ( prop.getName().startsWith(this.namespacePrefixSep) ) {
                prefs.getProperties().put(prop.getName(), prop.getString());
            }
        }
    }
View Full Code Here

      try {
        Session session = getSession();
        Node node = session.getNode(getPath());
        HashMap<String, Object> map = new HashMap<String, Object>();

        PropertyIterator properties = node.getProperties();
        while (properties.hasNext()) {
          Property p = properties.nextProperty();
          if (p.getType() == PropertyType.BOOLEAN) {
            map.put(p.getName(), p.getBoolean());
          } else if (p.getType() == PropertyType.STRING) {
            map.put(p.getName(), p.getString());
          } else if (p.getType() == PropertyType.DATE) {
            map.put(p.getName(), p.getDate().getTime());
          } else if (p.getType() == PropertyType.NAME) {
            map.put(p.getName(), p.getName());
          } else {
            throw new RuntimeException(
                "Unsupported property type: " + p.getType());
          }
        }
        ValueMap valueMap = new ValueMapDecorator(map);
        return (AdapterType) valueMap;
      } catch (Exception e) {
        e.printStackTrace();
        return null;
      }
    } else if (type.equals(ModifiableValueMap.class)) {
      return (AdapterType) new ModifiableValueMap() {

        public Collection<Object> values() {
          throw new UnsupportedOperationException();
        }

        public int size() {
          throw new UnsupportedOperationException();
        }

        public Object remove(Object arg0) {
          Session session = getSession();
          try{
            final Node node = session.getNode(getPath());
            final Property p = node.getProperty(String.valueOf(arg0));
            if (p!=null) {
              p.remove();
            }
            // this is not according to the spec - but OK for tests since
            // the return value is never used
                return null;
          } catch(PathNotFoundException pnfe) {
            // perfectly fine
            return null;
          } catch(RepositoryException e) {
            throw new RuntimeException(e);
          }
        }

        public void putAll(Map<? extends String, ? extends Object> arg0) {
          throw new UnsupportedOperationException();
        }

        public Object put(String arg0, Object arg1) {
          Session session = getSession();
          try{
            final Node node = session.getNode(getPath());
            Object result = null;
            if (node.hasProperty(arg0)) {
              final Property previous = node.getProperty(arg0);
              if (previous==null) {
                // null
              } else if (previous.getType() == PropertyType.STRING) {
                result = previous.getString();
              } else if (previous.getType() == PropertyType.DATE) {
                result = previous.getDate();
              } else if (previous.getType() == PropertyType.BOOLEAN) {
                result = previous.getBoolean();
              } else {
                throw new UnsupportedOperationException();
              }
            }
            if (arg1 instanceof String) {
              node.setProperty(arg0, (String)arg1);
            } else if (arg1 instanceof Long) {
              node.setProperty(arg0, (Long)arg1);
            } else if (arg1 instanceof Calendar) {
              node.setProperty(arg0, (Calendar)arg1);
            } else if (arg1 instanceof Boolean) {
              node.setProperty(arg0, (Boolean)arg1);
            } else {
              throw new UnsupportedOperationException();
            }
            return result;
          } catch(RepositoryException e) {
            throw new RuntimeException(e);
          }
        }

        public Set<String> keySet() {
          Session session = getSession();
          try {
            final Node node = session.getNode(getPath());
            final PropertyIterator pi = node.getProperties();
            final Set<String> result = new HashSet<String>();
            while(pi.hasNext()) {
              final Property p = pi.nextProperty();
              result.add(p.getName());
            }
            return result;
          } catch (RepositoryException e) {
            throw new RuntimeException(e);
View Full Code Here

            try {
                Session session = getSession();
                Node node = session.getNode(getPath());
                HashMap<String, Object> map = new HashMap<String, Object>();

                PropertyIterator properties = node.getProperties();
                while (properties.hasNext()) {
                    Property p = properties.nextProperty();
                    List valuesList;
                    if (p.isMultiple()) {
                        switch (p.getType()) {
                            case PropertyType.STRING:
                                valuesList = new ArrayList<String>();
                                for (Value v : p.getValues()) {
                                    valuesList.add(v.getString());
                                }
                                map.put(p.getName(), valuesList.toArray());
                                break;
                            case PropertyType.NAME:
                                valuesList = new ArrayList<String>();
                                for (Value v : p.getValues()) {
                                    valuesList.add(v.getString());
                                }
                                map.put(p.getName(), valuesList.toArray());
                                break;
                        }
                    } else if (p.getType() == PropertyType.BOOLEAN) {
                        map.put(p.getName(), p.getBoolean());
                    } else if (p.getType() == PropertyType.STRING) {
                        map.put(p.getName(), p.getString());
                    } else if (p.getType() == PropertyType.DATE) {
                        map.put(p.getName(), p.getDate().getTime());
                    } else if (p.getType() == PropertyType.NAME) {
                        map.put(p.getName(), p.getName());
                    } else {
                        throw new RuntimeException(
                                "Unsupported property type: " + p.getType());
                    }
                }
                ValueMap valueMap = new ValueMapDecorator(map);
                return (AdapterType) valueMap;
            } catch (Exception e) {
                e.printStackTrace();
                return null;
            }
        } else if (type.equals(ModifiableValueMap.class)) {
            return (AdapterType) new ModifiableValueMap() {

                public Collection<Object> values() {
                    throw new UnsupportedOperationException();
                }

                public int size() {
                    throw new UnsupportedOperationException();
                }

                public Object remove(Object arg0) {
                    throw new UnsupportedOperationException();
                }

                public void putAll(Map<? extends String, ? extends Object> arg0) {
                    throw new UnsupportedOperationException();
                }

                public Object put(String arg0, Object arg1) {
                    Session session = getSession();
                    try {
                        final Node node = session.getNode(getPath());
                        Object result = null;
                        if (node.hasProperty(arg0)) {
                            final Property previous = node.getProperty(arg0);
                            if (previous == null) {
                                // null
                            } else if (previous.getType() == PropertyType.STRING) {
                                result = previous.getString();
                            } else if (previous.getType() == PropertyType.DATE) {
                                result = previous.getDate();
                            } else if (previous.getType() == PropertyType.BOOLEAN) {
                                result = previous.getBoolean();
                            } else {
                                throw new UnsupportedOperationException();
                            }
                        }
                        if (arg1 instanceof String) {
                            node.setProperty(arg0, (String) arg1);
                        } else if (arg1 instanceof Calendar) {
                            node.setProperty(arg0, (Calendar) arg1);
                        } else if (arg1 instanceof Boolean) {
                            node.setProperty(arg0, (Boolean) arg1);
                        } else {
                            throw new UnsupportedOperationException();
                        }
                        return result;
                    } catch (RepositoryException e) {
                        throw new RuntimeException(e);
                    }
                }

                public Set<String> keySet() {
                    Session session = getSession();
                    try {
                        final Node node = session.getNode(getPath());
                        final PropertyIterator pi = node.getProperties();
                        final Set<String> result = new HashSet<String>();
                        while (pi.hasNext()) {
                            final Property p = pi.nextProperty();
                            result.add(p.getName());
                        }
                        return result;
                    } catch (RepositoryException e) {
                        throw new RuntimeException(e);
View Full Code Here

        return result;
    }

    /** Load properties of n into d */
    protected void loadProperties(Dictionary<String, Object> d, Node n) throws RepositoryException {
        final PropertyIterator pi = n.getProperties();
        while(pi.hasNext()) {
            final Property p = pi.nextProperty();
            final String name = p.getName();

            // ignore jcr: and similar properties
            if(name.contains(":")) {
                continue;
View Full Code Here

                exchange.getOut().setBody(node.getIdentifier());
                session.save();
            } else if (JcrConstants.JCR_GET_BY_ID.equals(operation)) {
                Node node = session.getNodeByIdentifier(exchange.getIn()
                        .getMandatoryBody(String.class));
                PropertyIterator properties = node.getProperties();
                while (properties.hasNext()) {
                    Property property = properties.nextProperty();
                    Class<?> aClass = classForJCRType(property);
                    Object value;
                    if (property.isMultiple()) {
                        value = converter.convertTo(aClass, exchange, property.getValues());
                    } else {
View Full Code Here

       
        MockControl nodeCtrl = MockControl.createNiceControl(Node.class);
        Node node = (Node) nodeCtrl.getMock();

        MockControl iteratorCtrl = MockControl.createControl(PropertyIterator.class);
        PropertyIterator iterator = (PropertyIterator) iteratorCtrl.getMock();
       
        MockControl iterCtrl = MockControl.createControl(NodeIterator.class);
        NodeIterator iter = (NodeIterator) iterCtrl.getMock();
       
        nodeCtrl.expectAndReturn(node.getPath(), "path");
        nodeCtrl.expectAndReturn(node.getProperties(), iterator);
        iteratorCtrl.expectAndReturn(iterator.hasNext(), false);
        nodeCtrl.expectAndReturn(node.getNodes(), iter);
        iterCtrl.expectAndReturn(iter.hasNext(), false);
       
        sessionControl.expectAndReturn(session.getRootNode(), node);
       
View Full Code Here

TOP

Related Classes of javax.jcr.PropertyIterator

Copyright © 2018 www.massapicom. 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.