/** * Factory method that performs validation. * <p> * Creates a Factory that will return a clone of the same prototype object * each time the factory is used. The prototype will be cloned using one of these * techniques (in order): * <ul> * <li>public clone method * <li>public copy constructor * <li>serialization clone * <ul> * * @param prototype the object to clone each time in the factory * @return the <code>prototype</code> factory * @throws IllegalArgumentException if the prototype is null * @throws IllegalArgumentException if the prototype cannot be cloned */ public static Factory getInstance(Object prototype) { if (prototype == null) { return ConstantFactory.NULL_INSTANCE; } try { java.lang.reflect.Method method = prototype.getClass().getMethod("clone", (java.lang.Class[])null); return new PrototypeCloneFactory(prototype, method); } catch (java.lang.NoSuchMethodException ex) { try { prototype.getClass().getConstructor(new java.lang.Class[] { prototype.getClass() }); return new InstantiateFactory( prototype.getClass(), new java.lang.Class[] { prototype.getClass() }, new Object[] { prototype }); } catch (java.lang.NoSuchMethodException ex2) { if (prototype is java.io.Serializable) { return new PrototypeSerializationFactory((java.io.Serializable)prototype); } } } throw new java.lang.IllegalArgumentException("The prototype must be cloneable via a public clone method"); }
public override bool equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } Contact other = (Contact) obj; if (uri == null) { if (other.uri != null) { return false; } } else if (!uri.equals(other.uri)) { return false; } if (!exists.equals(other.exists)) { return false; } return true; }
public override bool equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } TypingUser other = (TypingUser) obj; if (conversationUri == null) { if (other.conversationUri != null) { return false; } } else if (!conversationUri.equals(other.conversationUri)) { return false; } if (userUri == null) { if (other.userUri != null) { return false; } } else if (!userUri.equals(other.userUri)) { return false; } if (!exists.equals(other.exists)) { return false; } return true; }
public override bool Equals(Object anotherState) { if (this == anotherState) { return true; } if ((anotherState == null) || (this.getClass() != anotherState.getClass())) { return false; } GameState another = (GameState)anotherState; Set keySet1 = state.keySet(); Iterator i = keySet1.iterator(); Iterator j = another.state.keySet().iterator(); while (i.hasNext()) { String key = (String)i.next(); bool keymatched = false; bool valueMatched = false; while (j.hasNext()) { String key2 = (String)j.next(); if (key.Equals(key2)) { keymatched = true; if (state.get(key).Equals(another.state.get(key2))) { valueMatched = true; } break; } } if (!((keymatched) && valueMatched)) { return false; } } return true; }
public Iterator<?> getIterator(Object obj, JexlInfo info) { if (obj instanceof Iterator<?>) { return ((Iterator <?>) obj); } if (obj.getClass().isArray()) { return new ArrayIterator(obj); } if (obj instanceof Map<?, ?>) { return ((Map <?, ?>) obj).values().iterator(); } if (obj instanceof Enumeration<?>) { return new EnumerationIterator<Object>((Enumeration<Object>)obj); } if (obj instanceof Iterable<?>) { return ((Iterable <?>) obj).iterator(); } try { // look for an iterator() method to support the JDK5 Iterable // interface or any user tools/DTOs that want to work in // foreach without implementing the Collection interface AbstractExecutor.Method it = getMethodExecutor(obj, "iterator", null); if (it != null && Iterator.class.isAssignableFrom(it.getReturnType())) {
public bool Write(Type field, Object value, NodeMap node, Dictionary map) { if(field.Type != value.getClass()) { node.put(ELEMENT_NAME, value.getClass().getName()); } return false; }
public override bool equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } User other = (User) obj; if (avatarHash == null) { if (other.avatarHash != null) { return false; } } else if (!avatarHash.equals(other.avatarHash)) { return false; } if (currentStatus == null) { if (other.currentStatus != null) { return false; } } else if (!currentStatus.equals(other.currentStatus)) { return false; } if (dateOfBirth != (other.dateOfBirth)) { return false; } if (displayName == null) { if (other.displayName != null) { return false; } } else if (!displayName.equals(other.displayName)) { return false; } if (ecoid == null) { if (other.ecoid != null) { return false; } } else if (!ecoid.equals(other.ecoid)) { return false; } if (emailAddress == null) { if (other.emailAddress != null) { return false; } } else if (!emailAddress.equals(other.emailAddress)) { return false; } if (gender == null) { if (other.gender != null) { return false; } } else if (!gender.equals(other.gender)) { return false; } if (installedApps == null) { if (other.installedApps != null) { return false; } } else if (!installedApps.equals(other.installedApps)) { return false; } if (location == null) { if (other.location != null) { return false; } } else if (!location.equals(other.location)) { return false; } if (maxVcardSize != (other.maxVcardSize)) { return false; } if (nickname == null) { if (other.nickname != null) { return false; } } else if (!nickname.equals(other.nickname)) { return false; } if (nowPlayingMessage == null) { if (other.nowPlayingMessage != null) { return false; } } else if (!nowPlayingMessage.equals(other.nowPlayingMessage)) { return false; } if (personalMessage == null) { if (other.personalMessage != null) { return false; } } else if (!personalMessage.equals(other.personalMessage)) { return false; } if (personalMessageTimestamp != (other.personalMessageTimestamp)) { return false; } if (personalMessageTpaUri == null) { if (other.personalMessageTpaUri != null) { return false; } } else if (!personalMessageTpaUri.equals(other.personalMessageTpaUri)) { return false; } if (pin == null) { if (other.pin != null) { return false; } } else if (!pin.equals(other.pin)) { return false; } if (pins == null) { if (other.pins != null) { return false; } } else if (!pins.equals(other.pins)) { return false; } if (showBusy != (other.showBusy)) { return false; } if (showLocationTimezone != (other.showLocationTimezone)) { return false; } if (systemNotifications == null) { if (other.systemNotifications != null) { return false; } } else if (!systemNotifications.equals(other.systemNotifications)) { return false; } if (timezone == null) { if (other.timezone != null) { return false; } } else if (!timezone.equals(other.timezone)) { return false; } if (uri == null) { if (other.uri != null) { return false; } } else if (!uri.equals(other.uri)) { return false; } if (!exists.equals(other.exists)) { return false; } return true; }
/// <summary> /// This <c>write</c> method is used to convert the provided /// object to an XML element. This creates a child node from the /// given <c>OutputNode</c> object. Once this child element /// is created it is populated with the fields of the source object /// in accordance with the XML schema class. /// </summary> /// <param name="source"> /// this is the object to be serialized to XML /// </param> /// <param name="expect"> /// this is the class that is expected to be written /// </param> /// <param name="name"> /// this is the name of the root annotation used /// </param> public void Write(OutputNode node, Object source, Class expect, String name) { OutputNode child = node.getChild(name); Type type = GetType(expect); if(source != null) { Class actual = source.getClass(); if(!context.SetOverride(type, source, child)) { Converter convert = GetComposite(actual); Decorator decorator = GetDecorator(actual); decorator.decorate(child); convert.Write(child, source); } } child.commit(); }
/** * Gets the size of the collection/iterator specified. * <p> * This method can handles objects as follows * <ul> * <li>Collection - the collection size * <li>Map - the map size * <li>Array - the array size * <li>Iterator - the number of elements remaining in the iterator * <li>Enumeration - the number of elements remaining in the enumeration * </ul> * * @param object the object to get the size of * @return the size of the specified collection * @throws IllegalArgumentException thrown if object is not recognised or null * @since Commons Collections 3.1 */ public static int size(Object obj) { int total = 0; if (obj is java.util.Map<Object, Object>) { total = ((java.util.Map<Object, Object>)obj).size(); } else if (obj is java.util.Collection<Object>) { total = ((java.util.Collection<Object>)obj).size(); } else if (obj is Object[]) { total = ((Object[])obj).Length; } else if (obj is java.util.Iterator<Object>) { java.util.Iterator<Object> it = (java.util.Iterator<Object>)obj; while (it.hasNext()) { total++; it.next(); } } else if (obj is java.util.Enumeration<Object>) { java.util.Enumeration<Object> it = (java.util.Enumeration<Object>)obj; while (it.hasMoreElements()) { total++; it.nextElement(); } } else if (obj == null) { throw new java.lang.IllegalArgumentException("Unsupported object type: null"); } else { try { total = java.lang.reflect.Array.getLength(obj); } catch (java.lang.IllegalArgumentException ex) { throw new java.lang.IllegalArgumentException("Unsupported object type: " + obj.getClass().getName()); } } return total; }
/// <summary> /// This write method is used to write the text contact from the /// provided source object to the XML element. This takes the text /// value from the source object and writes it to the single contact /// marked with the <c>Text</c> annotation. If the value is /// null and the contact value is required an exception is thrown. /// </summary> /// <param name="source"> /// this is the source object to be serialized /// </param> /// <param name="node"> /// this is the XML element to write text value to /// </param> /// <param name="schema"> /// this is used to track the referenced elements /// </param> public void WriteText(OutputNode node, Object source, Schema schema) { Label label = schema.getText(); if(label != null) { Contact contact = label.getContact(); Object value = contact.Get(source); Class type = source.getClass(); if(value == null) { value = label.getEmpty(context); } if(value == null && label.isRequired()) { throw new TextException("Value for %s is null for %s", label, type); } WriteText(node, value, label); } }
/** * Returns the value of the field in the specified object as a {@code short} * . This reproduces the effect of {@code object.fieldName} * <p> * If this field is static, the object argument is ignored. * Otherwise, if the object is {@code null}, a NullPointerException is * thrown. If the object is not an instance of the declaring class of the * method, an IllegalArgumentException is thrown. * <p> * If this Field object is enforcing access control (see AccessibleObject) * and this field is not accessible from the current context, an * IllegalAccessException is thrown. * * @param object * the object to access * @return the field value * @throws NullPointerException * if the object is {@code null} and the field is non-static * @throws IllegalArgumentException * if the object is not compatible with the declaring class * @throws IllegalAccessException * if this field is not accessible */ public short getShort(Object objectJ) { Type type = objectJ.GetType (); System.Reflection.FieldInfo f = type.GetField (this.name); Object resultObj = f.GetValue (objectJ); if (resultObj is short) return ((short)resultObj); if (resultObj is java.lang.Short) return (((java.lang.Short)resultObj).shortValue()); throw new IllegalArgumentException ("Attempt to get int field " + objectJ.getClass().getName()+"."+this.getName() + " with illegal data type conversion to " + "short"); }
/** * Determines whether the supplied object was loaded by the given {@code ClassLoader}. * * @param theObject * the object to check. * @param theClassLoader * the {@code ClassLoader}. * @return {@code true} if the Object does belong to the {@code ClassLoader} * , {@code false} otherwise */ private static bool isClassFromClassLoader(Object theObject, java.lang.ClassLoader theClassLoader) { if ((theObject == null) || (theClassLoader == null)) { return false; } java.lang.Class objectClass = theObject.getClass(); try { java.lang.Class checkClass = java.lang.Class.forName(objectClass.getName(), true, theClassLoader); if (checkClass == objectClass) { return true; } } catch (Exception /*Throwable*/ t) { // Empty } return false; }
/** * Compares the specified object with this {@code BasicPermission} for * equality. Returns {@code true} if the specified object has the same class * and the two {@code Permissions}s have the same name. * <p/> * The {@link #implies(Permission)} method should be used for making access * control checks. * * @param obj * object to be compared for equality with this {@code * BasicPermission}. * @return {@code true} if the specified object is equal to this {@code * BasicPermission}, otherwise {@code false}. */ public override bool Equals(Object obj) { if (obj == this) { return true; } if (obj != null && obj.getClass() == this.getClass()) { return this.getName().equals(((Permission)obj).getName()); } return false; }
/// <summary> /// This <c>write</c> method is used to perform serialization of /// the given source object. Serialization is performed by appending /// elements and attributes from the source object to the provided XML /// element object. How the objects contacts are serialized is /// determined by the XML schema class that the source object is an /// instance of. If a required contact is null an exception is thrown. /// </summary> /// <param name="source"> /// this is the source object to be serialized /// </param> /// <param name="node"> /// the XML element the object is to be serialized to /// </param> public void Write(OutputNode node, Object source) { Class type = source.getClass(); Schema schema = context.GetSchema(type); Caller caller = schema.GetCaller(); try { if(schema.IsPrimitive()) { primitive.Write(node, source); } else { caller.persist(source); Write(node, source, schema); } } finally { caller.complete(source); } }
/// <summary> /// This method checks to see if there are any <c>Label</c> /// objects remaining in the provided map that are required. This is /// used when deserialization is performed to ensure the the XML /// element deserialized contains sufficient details to satisfy the /// XML schema class annotations. If there is a required label that /// remains it is reported within the exception thrown. /// </summary> /// <param name="map"> /// this is the map to check for remaining labels /// </param> /// <param name="source"> /// this is the object that has been deserialized /// </param> public void Validate(InputNode node, LabelMap map, Object source) { Position line = node.getPosition(); Class expect = type.Type; if(source != null) { expect = source.getClass(); } for(Label label : map) { if(label.isRequired() && revision.IsEqual()) { throw new ValueRequiredException("Unable to satisfy %s for %s at %s", label, expect, line); } Object value = label.getEmpty(context); if(value != null) { criteria.Set(label, value); } } }
/// <summary> /// This <c>read</c> method is used to perform deserialization /// of the provided node object using a delegate converter. This is /// typically another <c>Composite</c> converter, or if the /// node is an attribute a <c>Primitive</c> converter. When /// the delegate converter has completed the deserialized value is /// assigned to the contact. /// </summary> /// <param name="node"> /// this is the node that contains the contact value /// </param> /// <param name="source"> /// the type of the object that is being deserialized /// </param> /// <param name="label"> /// this is the label used to create the converter /// </param> public Object Read(InputNode node, Object source, Label label) { Object object = ReadObject(node, source, label); if(object == null) { Position line = node.getPosition(); Class expect = type.Type; if(source != null) { expect = source.getClass(); } if(label.isRequired() && revision.IsEqual()) { throw new ValueRequiredException("Empty value for %s in %s at %s", label, expect, line); } } else { if(object != label.getEmpty(context)) { criteria.Set(label, object); } } return object; }
/// <summary> /// This <c>readElement</c> method is used for deserialization /// of the provided node object using a delegate converter. This is /// typically another <c>Composite</c> converter, or if the /// node is an attribute a <c>Primitive</c> converter. When /// the delegate converter has completed the deserialized value is /// assigned to the contact. /// </summary> /// <param name="node"> /// this is the node that contains the contact value /// </param> /// <param name="source"> /// the type of the object that is being deserialized /// </param> /// <param name="map"> /// this is the map that contains the label objects /// </param> public void ReadElement(InputNode node, Object source, LabelMap map) { String name = node.GetName(); Label label = map.take(name); if(label == null) { label = criteria.Get(name); } if(label == null) { Position line = node.getPosition(); Class type = source.getClass(); if(map.IsStrict(context) && revision.IsEqual()) { throw new ElementException("Element '%s' does not have a match in %s at %s", name, type, line); } else { node.skip(); } } else { Read(node, source, label); } }
/// <summary> /// This <c>read</c> method performs deserialization of the XML /// schema class type by traversing the contacts and instantiating them /// using details from the provided XML element. Because this will /// convert a non-primitive value it delegates to other converters to /// perform deserialization of lists and primitives. /// <p> /// If any of the required contacts are not present within the provided /// XML element this will terminate deserialization and throw an /// exception. The annotation missing is reported in the exception. /// </summary> /// <param name="node"> /// the XML element contact values are deserialized from /// </param> /// <param name="source"> /// the object whose contacts are to be deserialized /// </param> /// <returns> /// this returns the fully deserialized object graph /// </returns> public Object Read(InputNode node, Object source) { Class type = source.getClass(); Schema schema = context.GetSchema(type); Caller caller = schema.GetCaller(); Read(node, source, schema); criteria.Commit(source); caller.Validate(source); caller.Commit(source); return ReadResolve(node, source, caller); }
public override bool Equals(Object o) { if (this == o) return true; if ((o == null) || (this.getClass() != o.getClass())) return false; NQueensBoard aBoard = (NQueensBoard)o; bool retVal = true; List<XYLocation> locs = getQueenPositions(); foreach (XYLocation loc in locs) { if (!(aBoard.queenExistsAt(loc))) retVal = false; } return retVal; }
/** * Returns the <code>index</code>-th value in <code>object</code>, throwing * <code>IndexOutOfBoundsException</code> if there is no such element or * <code>IllegalArgumentException</code> if <code>object</code> is not an * instance of one of the supported types. * <p> * The supported types, and associated semantics are: * <ul> * <li> Map -- the value returned is the <code>Map.Entry</code> in position * <code>index</code> in the map's <code>entrySet</code> iterator, * if there is such an entry.</li> * <li> List -- this method is equivalent to the list's get method.</li> * <li> Array -- the <code>index</code>-th array entry is returned, * if there is such an entry; otherwise an <code>IndexOutOfBoundsException</code> * is thrown.</li> * <li> Collection -- the value returned is the <code>index</code>-th object * returned by the collection's default iterator, if there is such an element.</li> * <li> Iterator or Enumeration -- the value returned is the * <code>index</code>-th object in the Iterator/Enumeration, if there * is such an element. The Iterator/Enumeration is advanced to * <code>index</code> (or to the end, if <code>index</code> exceeds the * number of entries) as a side effect of this method.</li> * </ul> * * @param object the object to get a value from * @param index the index to get * @return the object at the specified index * @throws IndexOutOfBoundsException if the index is invalid * @throws IllegalArgumentException if the object type is invalid */ public static Object get(Object obj, int index) { if (index < 0) { throw new java.lang.IndexOutOfBoundsException("Index cannot be negative: " + index); } if (obj is java.util.Map<Object, Object>) { java.util.Map<Object, Object> map = (java.util.Map<Object, Object>)obj; java.util.Iterator<Object> iterator = (java.util.Iterator<Object>)map.entrySet().iterator(); return get(iterator, index); } else if (obj is java.util.List<Object>) { return ((java.util.List<Object>)obj).get(index); } else if (obj is Object[]) { return ((Object[])obj)[index]; } else if (obj is java.util.Iterator<Object>) { java.util.Iterator<Object> it = (java.util.Iterator<Object>)obj; while (it.hasNext()) { index--; if (index == -1) { return it.next(); } else { it.next(); } } throw new java.lang.IndexOutOfBoundsException("Entry does not exist: " + index); } else if (obj is java.util.Collection<Object>) { java.util.Iterator<Object> iterator = ((java.util.Collection<Object>)obj).iterator(); return get(iterator, index); } else if (obj is java.util.Enumeration<Object>) { java.util.Enumeration<Object> it = (java.util.Enumeration<Object>)obj; while (it.hasMoreElements()) { index--; if (index == -1) { return it.nextElement(); } else { it.nextElement(); } } throw new java.lang.IndexOutOfBoundsException("Entry does not exist: " + index); } else if (obj == null) { throw new java.lang.IllegalArgumentException("Unsupported object type: null"); } else { try { return java.lang.reflect.Array.get(obj, index); } catch (java.lang.IllegalArgumentException ex) { throw new java.lang.IllegalArgumentException("Unsupported object type: " + obj.getClass().getName()); } } }
public override bool equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } Category other = (Category) obj; if (canDelete != (other.canDelete)) { return false; } if (id != (other.id)) { return false; } if (name == null) { if (other.name != null) { return false; } } else if (!name.equals(other.name)) { return false; } if (!exists.equals(other.exists)) { return false; } return true; }
/** * Checks if the specified collection/array/iterator is empty. * <p> * This method can handles objects as follows * <ul> * <li>Collection - via collection isEmpty * <li>Map - via map isEmpty * <li>Array - using array size * <li>Iterator - via hasNext * <li>Enumeration - via hasMoreElements * </ul> * <p> * Note: This method is named to avoid clashing with * {@link #isEmpty(Collection)}. * * @param object the object to get the size of, not null * @return true if empty * @throws IllegalArgumentException thrown if object is not recognised or null * @since Commons Collections 3.2 */ public static bool sizeIsEmpty(Object obj) { if (obj is java.util.Collection<Object>) { return ((java.util.Collection<Object>)obj).isEmpty(); } else if (obj is java.util.Map<Object, Object>) { return ((java.util.Map<Object, Object>)obj).isEmpty(); } else if (obj is Object[]) { return ((Object[])obj).Length == 0; } else if (obj is java.util.Iterator<Object>) { return ((java.util.Iterator<Object>)obj).hasNext() == false; } else if (obj is java.util.Enumeration<Object>) { return ((java.util.Enumeration<Object>)obj).hasMoreElements() == false; } else if (obj == null) { throw new java.lang.IllegalArgumentException("Unsupported object type: null"); } else { try { return java.lang.reflect.Array.getLength(obj) == 0; } catch (java.lang.IllegalArgumentException ex) { throw new java.lang.IllegalArgumentException("Unsupported object type: " + obj.getClass().getName()); } } }
/** * Creates and returns a new instance of the implementation described by * this {@code Service}. * * @param constructorParameter * the parameter that is used by the constructor, or {@code * null} if the implementation does not declare a constructor * parameter. * @return a new instance of the implementation described by this * {@code Service}. * @throws NoSuchAlgorithmException * if the instance could not be constructed. * @throws InvalidParameterException * if the implementation does not support the specified * {@code constructorParameter}. */ public Object newInstance(Object constructorParameter) { //throws NoSuchAlgorithmException { if (implementation == null || !className.equals(lastClassName)) { java.lang.ClassLoader cl = provider.getClass() .getClassLoader(); if (cl == null) { cl = java.lang.ClassLoader.getSystemClassLoader(); } try { implementation = java.lang.Class.forName(className, true, cl); } catch (Exception e) { return new NoSuchAlgorithmException( type + " " + algorithm + " implementation not found: " + e); } lastClassName = className; } java.lang.Class[] parameterTypes = new java.lang.Class[1]; if (constructorParameter != null && !supportsParameter(constructorParameter)) { throw new InvalidParameterException(type + ": service cannot use the parameter"); //$NON-NLS-1$ } Object[] initargs = { constructorParameter }; try { if (type.equalsIgnoreCase("CertStore")) { //$NON-NLS-1$ parameterTypes[0] = java.lang.Class .forName("java.security.cert.CertStoreParameters"); //$NON-NLS-1$ } else if (type.equalsIgnoreCase("Configuration")) { parameterTypes[0] = java.lang.Class .forName("javax.security.auth.login.Configuration$Parameters"); } if (parameterTypes[0] == null) { if (constructorParameter == null) { return implementation.newInstance(); } else { parameterTypes[0] = constructorParameter.getClass(); } } return implementation.getConstructor(parameterTypes) .newInstance(initargs); } catch (java.lang.Exception e) { throw new NoSuchAlgorithmException(type + " " + algorithm + " implementation not found: ", e); } }
/** * Returns the invocation handler of the specified proxy instance. * * @param proxy * the proxy instance * @return the invocation handler of the specified proxy instance * @throws IllegalArgumentException * if the supplied {@code proxy} is not a proxy object */ public static InvocationHandler getInvocationHandler(Object proxy) { //throws IllegalArgumentException { if (isProxyClass(proxy.getClass())) { return ((Proxy) proxy).h; } throw new IllegalArgumentException("not a proxy instance"); //$NON-NLS-1$ }
/// <summary> /// The <c>replace</c> method is used to replace an object /// before it is serialized. This is used so that an object can give /// a substitute to be written to the XML document in the event that /// the actual object is not suitable or desired for serialization. /// This acts as an equivalent to the Java Object Serialization /// <c>writeReplace</c> method for the object serialization. /// </summary> /// <param name="source"> /// this is the source object that is to be replaced /// </param> /// <returns> /// this returns the object to use as a replacement value /// </returns> public Object WriteReplace(Object source) { if(source != null) { Class type = source.getClass(); Caller caller = context.GetCaller(type); return caller.replace(source); } return source; }
/// <summary> /// All Java classes can get resources over method java.net.URL java.lang.Class.getResource(); /// </summary> /// <param name="t">an instance</param> /// <param name="name">named resource</param> /// <returns></returns> public static java.net.URL getResource(this System.Object t, String name) { return(t.getClass().getResource(name)); }
/// <summary> /// This <c>read</c> method will read the contents of the XML /// document from the provided source and populate the object with /// the values deserialized. This is used as a means of injecting an /// object with values deserialized from an XML document. If the /// XML source cannot be deserialized or there is a problem building /// the object graph an exception is thrown. /// </summary> /// <param name="node"> /// this is the node that is to be deserialized /// </param> /// <param name="value"> /// this is the value that is to be deserialized /// </param> /// <returns> /// an object deserialized from the XML element /// </returns> public Object Read(InputNode node, Object value) { Class type = value.getClass(); Composite factory = GetComposite(type); Object real = factory.Read(node, value); return Read(node, type, real); }
/// <summary> /// This is used to acquire a text value for the specified object. /// This will convert the object to a string using the transformer /// so that it can be deserialized from the generate XML document. /// However if the type is an <c>Enum</c> type then the text /// value is taken from <c>Enum.name</c> so it can later be /// deserialized easily using the enumeration class and name. /// </summary> /// <param name="source"> /// this is the object instance to get the value of /// </param> /// <returns> /// this returns a string representation of the object /// </returns> public String GetText(Object source) { Class type = source.getClass(); if(type.isEnum()) { Enum value = (Enum)source; return value.name(); } return support.write(source, type); }
/// <summary> /// This <c>write</c> method is used to convert the provided /// object to an XML element. This creates a child node from the /// given <c>OutputNode</c> object. Once this child element /// is created it is populated with the fields of the source object /// in accordance with the XML schema class. /// </summary> /// <param name="source"> /// this is the object to be serialized to XML /// </param> public void Write(OutputNode node, Object source) { Write(node, source, source.getClass()); }
public override bool Equals(Object o) { if (this == o) { return true; } if ((o == null) || (this.getClass() != o.getClass())) { return false; } EightPuzzleBoard aBoard = (EightPuzzleBoard) o; for (int i = 0; i < 8; i++) { if (this.getPositionOf(i) != aBoard.getPositionOf(i)) { return false; } } return true; }
/// <summary> /// This <c>write</c> method is used to convert the provided /// object to an XML element. This creates a child node from the /// given <c>OutputNode</c> object. Once this child element /// is created it is populated with the fields of the source object /// in accordance with the XML schema class. /// </summary> /// <param name="source"> /// this is the object to be serialized to XML /// </param> /// <param name="expect"> /// this is the class that is expected to be written /// </param> public void Write(OutputNode node, Object source, Class expect) { Class type = source.getClass(); String root = GetName(type); if(root == null) { throw new RootException("Root annotation required for %s", type); } Write(node, source, expect, root); }