View Javadoc
1 /* 2 * $Header: /cvsroot/ebxmlrr/jaxr/src/com/sun/xml/registry/ebxml/infomodel/ExtensibleObjectImpl.java,v 1.16 2003/09/13 19:43:54 farrukh_najmi Exp $ 3 * 4 * 5 */ 6 7 package com.sun.xml.registry.ebxml.infomodel; 8 9 import com.sun.xml.registry.ebxml.*; 10 11 import javax.xml.registry.*; 12 import javax.xml.registry.infomodel.*; 13 import java.util.*; 14 15 import com.sun.xml.registry.ebxml.util.I18nUtil; 16 17 import org.oasis.ebxml.registry.bindings.rim.RegistryObjectType; 18 import org.oasis.ebxml.registry.bindings.rim.SlotType1; 19 20 /*** 21 * Class Declaration for Class1 22 * @author <a href="mailto:Farrukh.Najmi@Sun.COM">Farrukh S. Najmi</a> 23 */ 24 public abstract class ExtensibleObjectImpl implements ExtensibleObject 25 { 26 // I18n support for all infomodel classes 27 protected static final I18nUtil i18nUtil = I18nUtil.getInstance(); 28 29 private TreeMap slots = new TreeMap(); 30 31 protected LifeCycleManagerImpl lcm = null; 32 33 //State variable 34 private boolean _new = false; //Object is unsaved and has never been committed to registry 35 private boolean modified = false; //Object has been modified in memory and not yet committed to registry 36 private boolean loaded = false; //Object has not been fully loaded from registry 37 38 39 ExtensibleObjectImpl(LifeCycleManagerImpl lcm) { 40 this.lcm = lcm; 41 _new = true; 42 } 43 44 ExtensibleObjectImpl(LifeCycleManagerImpl lcm, RegistryObjectType ebObject) 45 throws JAXRException 46 { 47 this(lcm); 48 _new = false; 49 50 SlotType1[] ebSlots = ebObject.getSlot(); 51 for (int i = 0; i < ebSlots.length; i++) { 52 internalAddSlot(new SlotImpl(lcm, ebSlots[i])); 53 } 54 } 55 56 protected BusinessQueryManager getBusinessQueryManager() throws JAXRException { 57 return lcm.getRegistryService().getBusinessQueryManager(); 58 } 59 60 protected DeclarativeQueryManager getDeclarativeQueryManager() throws JAXRException { 61 return lcm.getRegistryService().getDeclarativeQueryManager(); 62 } 63 64 /*** 65 * Implementation private 66 */ 67 public boolean isNew() { 68 return _new; 69 } 70 71 /*** 72 * Implementation private 73 */ 74 public void setNew(boolean _new) { 75 this._new = _new; 76 } 77 78 /*** 79 * Implementation private 80 */ 81 public boolean isModified() { 82 return modified; 83 } 84 85 /*** 86 * Implementation private 87 */ 88 public void setModified(boolean modified) { 89 this.modified = modified; 90 } 91 92 boolean isLoaded() { 93 return loaded; 94 } 95 96 protected void setLoaded(boolean loaded) { 97 this.loaded = loaded; 98 } 99 100 private void internalAddSlot(Slot slot) throws JAXRException { 101 if (slot != null) { 102 String slotName = slot.getName(); 103 if (!slots.keySet().contains(slotName)) { 104 105 // CHECK THIS! This will set modified to true!!! 106 //Check if slot already been added 107 //If already added then there could be a name conflict 108 //So remove before re-adding 109 if (!slots.entrySet().contains(slot)) { 110 removeSlot(slot.getName()); 111 } 112 113 ((SlotImpl)slot).setParent(this); 114 slots.put(slotName, slot); 115 } else { 116 Object objs[] = {slotName}; 117 throw new JAXRException(i18nUtil.getMessage("slot.name.duplicate", objs)); 118 } 119 } 120 } 121 122 public void addSlot(Slot slot) throws JAXRException { 123 internalAddSlot(slot); 124 setModified(true); 125 } 126 127 public void addSlots(Collection _slots) throws JAXRException { 128 //??Issue that if an error is encountered in adding slots 129 //than Slots would have been added partially. 130 //Need to compensate for that in case of exception half way thru 131 Iterator iter = _slots.iterator(); 132 while (iter.hasNext()) { 133 Object obj = (SlotImpl)iter.next(); 134 if (!(obj instanceof SlotImpl)) { 135 throw new InvalidRequestException("Expected SlotImpl, got " + obj); 136 } 137 SlotImpl slot = (SlotImpl)obj; 138 addSlot(slot); 139 } 140 } 141 142 public void removeSlot(String slotName) throws JAXRException { 143 Object removed = slots.remove(slotName); 144 if (removed != null) { 145 removeSlotInternal((SlotImpl)removed); 146 } 147 } 148 149 private void removeSlotInternal(SlotImpl slot) throws JAXRException { 150 slot.setParent(null); 151 setModified(true); 152 } 153 154 public void removeSlots(Collection slotNames) throws JAXRException { 155 Iterator iter = slotNames.iterator(); 156 while (iter.hasNext()) { 157 String slotName = (String)iter.next(); 158 removeSlot(slotName); 159 } 160 } 161 162 //??Add to JAXR 2.0 163 public void removeAllSlots() throws JAXRException { 164 TreeMap _slots = (TreeMap)slots.clone(); 165 Iterator iter = _slots.values().iterator(); 166 while (iter.hasNext()) { 167 SlotImpl slot = (SlotImpl)iter.next(); 168 169 //Must avoid case where a name change in SLot could prevent 170 //normal removeSlot to not work. 171 //String slotName = slot.getName(); 172 //removeSlot(slotName); 173 removeSlotInternal(slot); 174 } 175 slots = new TreeMap(); 176 } 177 178 public Slot getSlot(String slotName) throws JAXRException { 179 return (Slot)slots.get(slotName); 180 } 181 182 public Collection getSlots() throws JAXRException { 183 return ((TreeMap)(slots.clone())).values(); 184 } 185 186 //??Add to JAXR 2.0 187 public void setSlots(Collection slots) throws JAXRException { 188 removeAllSlots(); 189 addSlots(slots); 190 } 191 192 protected void setBindingObject(org.oasis.ebxml.registry.bindings.rim.RegistryObjectType ebObject) throws JAXRException { 193 Iterator iter = getSlots().iterator(); 194 while (iter.hasNext()) { 195 SlotImpl slot = (SlotImpl)iter.next(); 196 org.oasis.ebxml.registry.bindings.rim.Slot ebSlot = 197 new org.oasis.ebxml.registry.bindings.rim.Slot(); 198 slot.setBindingObject(ebSlot); 199 ebObject.addSlot(ebSlot); 200 } 201 202 } 203 204 public void getComposedObjects(HashSet composedObjects) 205 throws JAXRException 206 { 207 composedObjects.addAll(slots.values()); 208 } 209 }

This page was automatically generated by Maven