@Override
  public void chown(final Account u, final String group) throws XMLDBException {
    final XmldbURI collUri = collection.getPathURI();

    try {
      executeWithBroker(
          new BrokerOperation<Void>() {
            @Override
            public Void withBroker(final DBBroker broker)
                throws XMLDBException, LockException, PermissionDeniedException, IOException,
                    EXistException, TriggerException, SyntaxException {
              return modifyCollection(
                  broker,
                  collUri,
                  new DatabaseItemModifier<org.exist.collections.Collection, Void>() {
                    @Override
                    public Void modify(org.exist.collections.Collection collection)
                        throws PermissionDeniedException, SyntaxException, LockException {
                      final Permission permission = collection.getPermissions();
                      permission.setOwner(u);
                      permission.setGroup(group);
                      return null;
                    }
                  });
            }
          });
    } catch (final Exception e) {
      throw new XMLDBException(
          ErrorCodes.VENDOR_ERROR,
          "Failed to modify permission on Collection '" + collUri.toString() + "'",
          e);
    }
  }
  @Override
  public Permission[] listCollectionPermissions() throws XMLDBException {

    final XmldbURI collectionUri = collection.getPathURI();
    try {
      return executeWithBroker(
          new BrokerOperation<Permission[]>() {
            @Override
            public Permission[] withBroker(final DBBroker broker)
                throws XMLDBException, LockException, PermissionDeniedException, IOException,
                    EXistException, TriggerException, SyntaxException {
              return readCollection(
                  broker,
                  collectionUri,
                  new DatabaseItemReader<org.exist.collections.Collection, Permission[]>() {
                    @Override
                    public Permission[] read(org.exist.collections.Collection collection)
                        throws XMLDBException, PermissionDeniedException {
                      if (!collection.getPermissions().validate(user, Permission.READ)) {
                        return new Permission[0];
                      }

                      final Permission perms[] =
                          new Permission[collection.getChildCollectionCount(broker)];
                      final Iterator<XmldbURI> itChildCollectionUri =
                          collection.collectionIterator(broker);
                      int i = 0;
                      while (itChildCollectionUri.hasNext()) {
                        final XmldbURI childCollectionUri =
                            collectionUri.append(itChildCollectionUri.next());
                        Permission childPermission =
                            readCollection(
                                broker,
                                childCollectionUri,
                                new DatabaseItemReader<
                                    org.exist.collections.Collection, Permission>() {
                                  @Override
                                  public Permission read(
                                      org.exist.collections.Collection childCollection) {
                                    return childCollection.getPermissions();
                                  }
                                });
                        perms[i++] = childPermission;
                      }

                      return perms;
                    }
                  });
            }
          });
    } catch (final Exception e) {
      throw new XMLDBException(ErrorCodes.VENDOR_ERROR, e.getMessage(), e);
    }
  }
Example #3
0
 public Icon getIcon() {
   return icon.getLocal();
 }
Example #4
0
 public Map<String, Icon> getIconMap() {
   if (icon == null) {
     icon = new LocalCollection<Icon>();
   }
   return icon.toMap();
 }
Example #5
0
  public static final Application _read(final XoXMLStreamReader reader, RuntimeContext context)
      throws Exception {

    // Check for xsi:nil
    if (reader.isXsiNil()) {
      return null;
    }

    if (context == null) {
      context = new RuntimeContext();
    }

    final Application application = new Application();
    context.beforeUnmarshal(application, LifecycleCallback.NONE);

    ArrayList<Text> descriptions = null;
    ArrayList<Text> displayNames = null;
    LocalCollection<Icon> icon = null;
    List<Module> module = null;
    List<SecurityRole> securityRole = null;
    KeyedCollection<String, EnvEntry> envEntry = null;
    KeyedCollection<String, EjbRef> ejbRef = null;
    KeyedCollection<String, EjbLocalRef> ejbLocalRef = null;
    KeyedCollection<String, ServiceRef> serviceRef = null;
    KeyedCollection<String, ResourceRef> resourceRef = null;
    KeyedCollection<String, ResourceEnvRef> resourceEnvRef = null;
    KeyedCollection<String, MessageDestinationRef> messageDestinationRef = null;
    KeyedCollection<String, PersistenceContextRef> persistenceContextRef = null;
    KeyedCollection<String, PersistenceUnitRef> persistenceUnitRef = null;
    KeyedCollection<String, MessageDestination> messageDestination = null;
    KeyedCollection<String, DataSource> dataSource = null;

    // Check xsi:type
    final QName xsiType = reader.getXsiType();
    if (xsiType != null) {
      if (("applicationType" != xsiType.getLocalPart())
          || ("http://java.sun.com/xml/ns/javaee" != xsiType.getNamespaceURI())) {
        return context.unexpectedXsiType(reader, Application.class);
      }
    }

    // Read attributes
    for (final Attribute attribute : reader.getAttributes()) {
      if (("version" == attribute.getLocalName())
          && (("" == attribute.getNamespace()) || (attribute.getNamespace() == null))) {
        // ATTRIBUTE: version
        application.version =
            Adapters.collapsedStringAdapterAdapter.unmarshal(attribute.getValue());
      } else if (("id" == attribute.getLocalName())
          && (("" == attribute.getNamespace()) || (attribute.getNamespace() == null))) {
        // ATTRIBUTE: id
        final String id = Adapters.collapsedStringAdapterAdapter.unmarshal(attribute.getValue());
        context.addXmlId(reader, id, application);
        application.id = id;
      } else if (XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI != attribute.getNamespace()) {
        context.unexpectedAttribute(attribute, new QName("", "version"), new QName("", "id"));
      }
    }

    // Read elements
    for (final XoXMLStreamReader elementReader : reader.getChildElements()) {
      if (("application-name" == elementReader.getLocalName())
          && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
        // ELEMENT: applicationName
        final String applicationNameRaw = elementReader.getElementAsString();

        final String applicationName;
        try {
          applicationName = Adapters.collapsedStringAdapterAdapter.unmarshal(applicationNameRaw);
        } catch (final Exception e) {
          context.xmlAdapterError(
              elementReader, CollapsedStringAdapter.class, String.class, String.class, e);
          continue;
        }

        application.applicationName = applicationName;
      } else if (("description" == elementReader.getLocalName())
          && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
        // ELEMENT: descriptions
        final Text descriptionsItem = readText(elementReader, context);
        if (descriptions == null) {
          descriptions = new ArrayList<Text>();
        }
        descriptions.add(descriptionsItem);
      } else if (("display-name" == elementReader.getLocalName())
          && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
        // ELEMENT: displayNames
        final Text displayNamesItem = readText(elementReader, context);
        if (displayNames == null) {
          displayNames = new ArrayList<Text>();
        }
        displayNames.add(displayNamesItem);
      } else if (("icon" == elementReader.getLocalName())
          && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
        // ELEMENT: icon
        final Icon iconItem = readIcon(elementReader, context);
        if (icon == null) {
          icon = application.icon;
          if (icon != null) {
            icon.clear();
          } else {
            icon = new LocalCollection<Icon>();
          }
        }
        icon.add(iconItem);
      } else if (("initialize-in-order" == elementReader.getLocalName())
          && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
        // ELEMENT: initializeInOrder
        final Boolean initializeInOrder =
            ("1".equals(elementReader.getElementAsString())
                || "true".equals(elementReader.getElementAsString()));
        application.initializeInOrder = initializeInOrder;
      } else if (("module" == elementReader.getLocalName())
          && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
        // ELEMENT: module
        final Module moduleItem = readModule(elementReader, context);
        if (module == null) {
          module = application.module;
          if (module != null) {
            module.clear();
          } else {
            module = new ArrayList<Module>();
          }
        }
        module.add(moduleItem);
      } else if (("security-role" == elementReader.getLocalName())
          && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
        // ELEMENT: securityRole
        final SecurityRole securityRoleItem = readSecurityRole(elementReader, context);
        if (securityRole == null) {
          securityRole = application.securityRole;
          if (securityRole != null) {
            securityRole.clear();
          } else {
            securityRole = new ArrayList<SecurityRole>();
          }
        }
        securityRole.add(securityRoleItem);
      } else if (("library-directory" == elementReader.getLocalName())
          && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
        // ELEMENT: libraryDirectory
        final String libraryDirectoryRaw = elementReader.getElementAsString();

        final String libraryDirectory;
        try {
          libraryDirectory = Adapters.collapsedStringAdapterAdapter.unmarshal(libraryDirectoryRaw);
        } catch (final Exception e) {
          context.xmlAdapterError(
              elementReader, CollapsedStringAdapter.class, String.class, String.class, e);
          continue;
        }

        application.libraryDirectory = libraryDirectory;
      } else if (("env-entry" == elementReader.getLocalName())
          && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
        // ELEMENT: envEntry
        final EnvEntry envEntryItem = readEnvEntry(elementReader, context);
        if (envEntry == null) {
          envEntry = application.envEntry;
          if (envEntry != null) {
            envEntry.clear();
          } else {
            envEntry = new KeyedCollection<String, EnvEntry>();
          }
        }
        envEntry.add(envEntryItem);
      } else if (("ejb-ref" == elementReader.getLocalName())
          && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
        // ELEMENT: ejbRef
        final EjbRef ejbRefItem = readEjbRef(elementReader, context);
        if (ejbRef == null) {
          ejbRef = application.ejbRef;
          if (ejbRef != null) {
            ejbRef.clear();
          } else {
            ejbRef = new KeyedCollection<String, EjbRef>();
          }
        }
        ejbRef.add(ejbRefItem);
      } else if (("ejb-local-ref" == elementReader.getLocalName())
          && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
        // ELEMENT: ejbLocalRef
        final EjbLocalRef ejbLocalRefItem = readEjbLocalRef(elementReader, context);
        if (ejbLocalRef == null) {
          ejbLocalRef = application.ejbLocalRef;
          if (ejbLocalRef != null) {
            ejbLocalRef.clear();
          } else {
            ejbLocalRef = new KeyedCollection<String, EjbLocalRef>();
          }
        }
        ejbLocalRef.add(ejbLocalRefItem);
      } else if (("service-ref" == elementReader.getLocalName())
          && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
        // ELEMENT: serviceRef
        final ServiceRef serviceRefItem = readServiceRef(elementReader, context);
        if (serviceRef == null) {
          serviceRef = application.serviceRef;
          if (serviceRef != null) {
            serviceRef.clear();
          } else {
            serviceRef = new KeyedCollection<String, ServiceRef>();
          }
        }
        serviceRef.add(serviceRefItem);
      } else if (("resource-ref" == elementReader.getLocalName())
          && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
        // ELEMENT: resourceRef
        final ResourceRef resourceRefItem = readResourceRef(elementReader, context);
        if (resourceRef == null) {
          resourceRef = application.resourceRef;
          if (resourceRef != null) {
            resourceRef.clear();
          } else {
            resourceRef = new KeyedCollection<String, ResourceRef>();
          }
        }
        resourceRef.add(resourceRefItem);
      } else if (("resource-env-ref" == elementReader.getLocalName())
          && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
        // ELEMENT: resourceEnvRef
        final ResourceEnvRef resourceEnvRefItem = readResourceEnvRef(elementReader, context);
        if (resourceEnvRef == null) {
          resourceEnvRef = application.resourceEnvRef;
          if (resourceEnvRef != null) {
            resourceEnvRef.clear();
          } else {
            resourceEnvRef = new KeyedCollection<String, ResourceEnvRef>();
          }
        }
        resourceEnvRef.add(resourceEnvRefItem);
      } else if (("message-destination-ref" == elementReader.getLocalName())
          && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
        // ELEMENT: messageDestinationRef
        final MessageDestinationRef messageDestinationRefItem =
            readMessageDestinationRef(elementReader, context);
        if (messageDestinationRef == null) {
          messageDestinationRef = application.messageDestinationRef;
          if (messageDestinationRef != null) {
            messageDestinationRef.clear();
          } else {
            messageDestinationRef = new KeyedCollection<String, MessageDestinationRef>();
          }
        }
        messageDestinationRef.add(messageDestinationRefItem);
      } else if (("persistence-context-ref" == elementReader.getLocalName())
          && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
        // ELEMENT: persistenceContextRef
        final PersistenceContextRef persistenceContextRefItem =
            readPersistenceContextRef(elementReader, context);
        if (persistenceContextRef == null) {
          persistenceContextRef = application.persistenceContextRef;
          if (persistenceContextRef != null) {
            persistenceContextRef.clear();
          } else {
            persistenceContextRef = new KeyedCollection<String, PersistenceContextRef>();
          }
        }
        persistenceContextRef.add(persistenceContextRefItem);
      } else if (("persistence-unit-ref" == elementReader.getLocalName())
          && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
        // ELEMENT: persistenceUnitRef
        final PersistenceUnitRef persistenceUnitRefItem =
            readPersistenceUnitRef(elementReader, context);
        if (persistenceUnitRef == null) {
          persistenceUnitRef = application.persistenceUnitRef;
          if (persistenceUnitRef != null) {
            persistenceUnitRef.clear();
          } else {
            persistenceUnitRef = new KeyedCollection<String, PersistenceUnitRef>();
          }
        }
        persistenceUnitRef.add(persistenceUnitRefItem);
      } else if (("message-destination" == elementReader.getLocalName())
          && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
        // ELEMENT: messageDestination
        final MessageDestination messageDestinationItem =
            readMessageDestination(elementReader, context);
        if (messageDestination == null) {
          messageDestination = application.messageDestination;
          if (messageDestination != null) {
            messageDestination.clear();
          } else {
            messageDestination = new KeyedCollection<String, MessageDestination>();
          }
        }
        messageDestination.add(messageDestinationItem);
      } else if (("data-source" == elementReader.getLocalName())
          && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
        // ELEMENT: dataSource
        final DataSource dataSourceItem = readDataSource(elementReader, context);
        if (dataSource == null) {
          dataSource = application.dataSource;
          if (dataSource != null) {
            dataSource.clear();
          } else {
            dataSource = new KeyedCollection<String, DataSource>();
          }
        }
        dataSource.add(dataSourceItem);
      } else {
        context.unexpectedElement(
            elementReader,
            new QName("http://java.sun.com/xml/ns/javaee", "application-name"),
            new QName("http://java.sun.com/xml/ns/javaee", "description"),
            new QName("http://java.sun.com/xml/ns/javaee", "display-name"),
            new QName("http://java.sun.com/xml/ns/javaee", "icon"),
            new QName("http://java.sun.com/xml/ns/javaee", "initialize-in-order"),
            new QName("http://java.sun.com/xml/ns/javaee", "module"),
            new QName("http://java.sun.com/xml/ns/javaee", "security-role"),
            new QName("http://java.sun.com/xml/ns/javaee", "library-directory"),
            new QName("http://java.sun.com/xml/ns/javaee", "env-entry"),
            new QName("http://java.sun.com/xml/ns/javaee", "ejb-ref"),
            new QName("http://java.sun.com/xml/ns/javaee", "ejb-local-ref"),
            new QName("http://java.sun.com/xml/ns/javaee", "service-ref"),
            new QName("http://java.sun.com/xml/ns/javaee", "resource-ref"),
            new QName("http://java.sun.com/xml/ns/javaee", "resource-env-ref"),
            new QName("http://java.sun.com/xml/ns/javaee", "message-destination-ref"),
            new QName("http://java.sun.com/xml/ns/javaee", "persistence-context-ref"),
            new QName("http://java.sun.com/xml/ns/javaee", "persistence-unit-ref"),
            new QName("http://java.sun.com/xml/ns/javaee", "message-destination"),
            new QName("http://java.sun.com/xml/ns/javaee", "data-source"));
      }
    }
    if (descriptions != null) {
      try {
        application.setDescriptions(descriptions.toArray(new Text[descriptions.size()]));
      } catch (final Exception e) {
        context.setterError(reader, Application.class, "setDescriptions", Text[].class, e);
      }
    }
    if (displayNames != null) {
      try {
        application.setDisplayNames(displayNames.toArray(new Text[displayNames.size()]));
      } catch (final Exception e) {
        context.setterError(reader, Application.class, "setDisplayNames", Text[].class, e);
      }
    }
    if (icon != null) {
      application.icon = icon;
    }
    if (module != null) {
      application.module = module;
    }
    if (securityRole != null) {
      application.securityRole = securityRole;
    }
    if (envEntry != null) {
      application.envEntry = envEntry;
    }
    if (ejbRef != null) {
      application.ejbRef = ejbRef;
    }
    if (ejbLocalRef != null) {
      application.ejbLocalRef = ejbLocalRef;
    }
    if (serviceRef != null) {
      application.serviceRef = serviceRef;
    }
    if (resourceRef != null) {
      application.resourceRef = resourceRef;
    }
    if (resourceEnvRef != null) {
      application.resourceEnvRef = resourceEnvRef;
    }
    if (messageDestinationRef != null) {
      application.messageDestinationRef = messageDestinationRef;
    }
    if (persistenceContextRef != null) {
      application.persistenceContextRef = persistenceContextRef;
    }
    if (persistenceUnitRef != null) {
      application.persistenceUnitRef = persistenceUnitRef;
    }
    if (messageDestination != null) {
      application.messageDestination = messageDestination;
    }
    if (dataSource != null) {
      application.dataSource = dataSource;
    }

    context.afterUnmarshal(application, LifecycleCallback.NONE);

    return application;
  }
Example #6
0
  public static final Listener _read(final XoXMLStreamReader reader, RuntimeContext context)
      throws Exception {

    // Check for xsi:nil
    if (reader.isXsiNil()) {
      return null;
    }

    if (context == null) {
      context = new RuntimeContext();
    }

    final Listener listener = new Listener();
    context.beforeUnmarshal(listener, LifecycleCallback.NONE);

    ArrayList<Text> descriptions = null;
    ArrayList<Text> displayNames = null;
    LocalCollection<Icon> icon = null;

    // Check xsi:type
    final QName xsiType = reader.getXsiType();
    if (xsiType != null) {
      if (("listenerType" != xsiType.getLocalPart())
          || ("http://java.sun.com/xml/ns/javaee" != xsiType.getNamespaceURI())) {
        return context.unexpectedXsiType(reader, Listener.class);
      }
    }

    // Read attributes
    for (final Attribute attribute : reader.getAttributes()) {
      if (("id" == attribute.getLocalName())
          && (("" == attribute.getNamespace()) || (attribute.getNamespace() == null))) {
        // ATTRIBUTE: id
        final String id = Adapters.collapsedStringAdapterAdapter.unmarshal(attribute.getValue());
        context.addXmlId(reader, id, listener);
        listener.id = id;
      } else if (XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI != attribute.getNamespace()) {
        context.unexpectedAttribute(attribute, new QName("", "id"));
      }
    }

    // Read elements
    for (final XoXMLStreamReader elementReader : reader.getChildElements()) {
      if (("description" == elementReader.getLocalName())
          && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
        // ELEMENT: descriptions
        final Text descriptionsItem = readText(elementReader, context);
        if (descriptions == null) {
          descriptions = new ArrayList<Text>();
        }
        descriptions.add(descriptionsItem);
      } else if (("display-name" == elementReader.getLocalName())
          && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
        // ELEMENT: displayNames
        final Text displayNamesItem = readText(elementReader, context);
        if (displayNames == null) {
          displayNames = new ArrayList<Text>();
        }
        displayNames.add(displayNamesItem);
      } else if (("icon" == elementReader.getLocalName())
          && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
        // ELEMENT: icon
        final Icon iconItem = readIcon(elementReader, context);
        if (icon == null) {
          icon = listener.icon;
          if (icon != null) {
            icon.clear();
          } else {
            icon = new LocalCollection<Icon>();
          }
        }
        icon.add(iconItem);
      } else if (("listener-class" == elementReader.getLocalName())
          && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
        // ELEMENT: listenerClass
        final String listenerClassRaw = elementReader.getElementAsString();

        final String listenerClass;
        try {
          listenerClass = Adapters.collapsedStringAdapterAdapter.unmarshal(listenerClassRaw);
        } catch (final Exception e) {
          context.xmlAdapterError(
              elementReader, CollapsedStringAdapter.class, String.class, String.class, e);
          continue;
        }

        listener.listenerClass = listenerClass;
      } else {
        context.unexpectedElement(
            elementReader,
            new QName("http://java.sun.com/xml/ns/javaee", "description"),
            new QName("http://java.sun.com/xml/ns/javaee", "display-name"),
            new QName("http://java.sun.com/xml/ns/javaee", "icon"),
            new QName("http://java.sun.com/xml/ns/javaee", "listener-class"));
      }
    }
    if (descriptions != null) {
      try {
        listener.setDescriptions(descriptions.toArray(new Text[descriptions.size()]));
      } catch (final Exception e) {
        context.setterError(reader, Listener.class, "setDescriptions", Text[].class, e);
      }
    }
    if (displayNames != null) {
      try {
        listener.setDisplayNames(displayNames.toArray(new Text[displayNames.size()]));
      } catch (final Exception e) {
        context.setterError(reader, Listener.class, "setDisplayNames", Text[].class, e);
      }
    }
    if (icon != null) {
      listener.icon = icon;
    }

    context.afterUnmarshal(listener, LifecycleCallback.NONE);

    return listener;
  }