001/* 002 * (C) Copyright 2017 Nuxeo (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Funsho David 018 * 019 */ 020 021package org.nuxeo.directory.mongodb; 022 023import org.nuxeo.common.xmap.annotation.XNode; 024import org.nuxeo.common.xmap.annotation.XNodeList; 025import org.nuxeo.common.xmap.annotation.XObject; 026import org.nuxeo.ecm.directory.BaseDirectoryDescriptor; 027 028/** 029 * @since 9.1 030 */ 031@XObject("directory") 032public class MongoDBDirectoryDescriptor extends BaseDirectoryDescriptor { 033 034 @XNode("serverUrl") 035 public String serverUrl; 036 037 @XNode("databaseName") 038 public String databaseName; 039 040 @XNodeList(value = "references/reference", type = MongoDBReferenceDescriptor[].class, componentType = MongoDBReferenceDescriptor.class) 041 public MongoDBReferenceDescriptor[] mongodbReferences; 042 043 public String getServerUrl() { 044 return serverUrl; 045 } 046 047 public String getDatabaseName() { 048 return databaseName; 049 } 050 051 public MongoDBReferenceDescriptor[] getMongoDBReferences() { 052 return mongodbReferences; 053 } 054 055 @Override 056 public void merge(BaseDirectoryDescriptor other) { 057 super.merge(other); 058 if (other instanceof MongoDBDirectoryDescriptor) { 059 merge((MongoDBDirectoryDescriptor) other); 060 } 061 } 062 063 protected void merge(MongoDBDirectoryDescriptor other) { 064 if (other.serverUrl != null) { 065 serverUrl = other.serverUrl; 066 } 067 if (other.databaseName != null) { 068 databaseName = other.databaseName; 069 } 070 if (other.mongodbReferences != null && mongodbReferences.length != 0) { 071 mongodbReferences = other.mongodbReferences; 072 } 073 } 074 075 @Override 076 public MongoDBDirectoryDescriptor clone() { 077 MongoDBDirectoryDescriptor clone = (MongoDBDirectoryDescriptor) super.clone(); 078 if (mongodbReferences != null) { 079 clone.mongodbReferences = new MongoDBReferenceDescriptor[mongodbReferences.length]; 080 for (int i = 0; i < mongodbReferences.length; i++) { 081 clone.mongodbReferences[i] = mongodbReferences[i].clone(); 082 } 083 } 084 return clone; 085 } 086 087 @Override 088 public MongoDBDirectory newDirectory() { 089 return new MongoDBDirectory(this); 090 } 091 092}