/* * Claudia Project * http://claudia.morfeo-project.org * * (C) Copyright 2010 Telefonica Investigacion y Desarrollo * S.A.Unipersonal (Telefonica I+D) * * See CREDITS file for info about members and contributors. * * This program is free software; you can redistribute it and/or modify * it under the terms of the Affero GNU General Public License (AGPL) as * published by the Free Software Foundation; either version 3 of the License, * or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the Affero GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * If you want to use this software an plan to distribute a * proprietary application in any way, and you are not licensing and * distributing your source code under AGPL, you probably need to * purchase a commercial license of the product. Please contact * claudia-support@lists.morfeo-project.org for more information. */ package com.telefonica.claudia.slm.deployment; import java.util.HashSet; import java.util.Set; import javax.persistence.Basic; import javax.persistence.CascadeType; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.OneToMany; import javax.persistence.OneToOne; import com.telefonica.claudia.slm.naming.DirectoryEntry; import com.telefonica.claudia.slm.naming.FQN; import com.telefonica.claudia.slm.naming.ReservoirDirectory; @Entity public class Customer implements DirectoryEntry { @Id @GeneratedValue public long internalId; @Basic private String customerName = null; @OneToOne(cascade=CascadeType.ALL) private FQN customerFQN = null; @OneToMany(mappedBy="customer", cascade=CascadeType.ALL) private Set<ServiceApplication> services = new HashSet<ServiceApplication>(); public Customer() {} public Customer(String customerName) { if(customerName == null) throw new IllegalArgumentException("Customer name cannot be null"); this.customerName = customerName; } public String getCustomerName(){ return customerName; } public Set<ServiceApplication> getServices() { return services; } public void registerService(ServiceApplication service) { if(service == null) throw new IllegalArgumentException("Cannot register null service"); if(!service.getCustomer().equals(this)) throw new IllegalArgumentException("Trying to register Service " + service + " on a different customer " + this); services.add(service); } public boolean isServiceRegistered(ServiceApplication service) { return services.contains(service); } public void unregisterService(ServiceApplication service) { services.remove(service); customerFQN.removeChild(service.getFQN()); } public FQN getFQN(){ if(customerFQN == null) customerFQN = ReservoirDirectory.getInstance().buildFQN(this); return customerFQN; } @Override public String toString() { return getFQN().toString(); } @Override public int hashCode() { return getFQN().hashCode(); } @Override public boolean equals(Object object) { if(object == null) return false; if(!(object instanceof Customer)) return false; return ((Customer)object).getFQN().equals(getFQN()); } }