List of usage examples for java.io InvalidObjectException InvalidObjectException
public InvalidObjectException(String reason)
InvalidObjectException
. From source file:org.brocalc.domain.CurrencyAmount.java
private void readObject(ObjectInputStream ois) throws InvalidObjectException { throw new InvalidObjectException("Serialization Proxy required"); }
From source file:Main.java
/** * Converts a given object to a form encoded map * @param objName Name of the object// w ww . j a v a 2s . com * @param obj The object to convert into a map * @param objectMap The object map to populate * @param processed List of objects hashCodes that are already parsed * @throws InvalidObjectException */ private static void objectToMap(String objName, Object obj, Map<String, Object> objectMap, HashSet<Integer> processed) throws InvalidObjectException { //null values need not to be processed if (obj == null) return; //wrapper types are autoboxed, so reference checking is not needed if (!isWrapperType(obj.getClass())) { //avoid infinite recursion if (processed.contains(obj.hashCode())) return; processed.add(obj.hashCode()); } //process arrays if (obj instanceof Collection<?>) { //process array if ((objName == null) || (objName.isEmpty())) throw new InvalidObjectException("Object name cannot be empty"); Collection<?> array = (Collection<?>) obj; //append all elements in the array into a string int index = 0; for (Object element : array) { //load key value pair String key = String.format("%s[%d]", objName, index++); loadKeyValuePairForEncoding(key, element, objectMap, processed); } } else if (obj instanceof Map) { //process map Map<?, ?> map = (Map<?, ?>) obj; //append all elements in the array into a string for (Map.Entry<?, ?> pair : map.entrySet()) { String attribName = pair.getKey().toString(); String key = attribName; if ((objName != null) && (!objName.isEmpty())) { key = String.format("%s[%s]", objName, attribName); } loadKeyValuePairForEncoding(key, pair.getValue(), objectMap, processed); } } else { //process objects // invoke getter methods Method[] methods = obj.getClass().getMethods(); for (Method method : methods) { //is a getter? if ((method.getParameterTypes().length != 0) || (!method.getName().startsWith("get"))) continue; //get json attribute name Annotation getterAnnotation = method.getAnnotation(JsonGetter.class); if (getterAnnotation == null) continue; //load key name String attribName = ((JsonGetter) getterAnnotation).value(); String key = attribName; if ((objName != null) && (!objName.isEmpty())) { key = String.format("%s[%s]", objName, attribName); } try { //load key value pair Object value = method.invoke(obj); loadKeyValuePairForEncoding(key, value, objectMap, processed); } catch (Exception ex) { } } // load fields Field[] fields = obj.getClass().getFields(); for (Field field : fields) { //load key name String attribName = field.getName(); String key = attribName; if ((objName != null) && (!objName.isEmpty())) { key = String.format("%s[%s]", objName, attribName); } try { //load key value pair Object value = field.get(obj); loadKeyValuePairForEncoding(key, value, objectMap, processed); } catch (Exception ex) { } } } }
From source file:com.phoenixst.plexus.util.UnmodifiableGraph.java
private void readObject(ObjectInputStream in) throws ClassNotFoundException, IOException { in.defaultReadObject();/* w w w . j a v a 2s . c o m*/ if (delegate == null) { throw new InvalidObjectException("Wrapped Graph is null."); } initialize(); }
From source file:org.protempa.proposition.ProviderBasedLocalUniqueId.java
private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException { this.id = (String) s.readObject(); if (this.id == null) { throw new InvalidObjectException("Can't restore. Null id"); }//from w w w .j a v a 2 s. c o m this.numericalId = s.readInt(); }
From source file:org.asoem.greyfish.core.actions.GenericMovement.java
private void readObject(final ObjectInputStream stream) throws InvalidObjectException { throw new InvalidObjectException("Builder required"); }
From source file:org.wrml.runtime.format.application.schema.json.JsonSchemaFormatter.java
@SuppressWarnings("unchecked") @Override//from w w w. j a v a 2 s . c om public <M extends Model> M readModel(final InputStream in, final Keys rootModelKeys, final Dimensions rootModelDimensions) throws ModelReadingException, UnsupportedOperationException { final Context context = getContext(); final SchemaLoader schemaLoader = context.getSchemaLoader(); final URI uri = rootModelKeys.getValue(schemaLoader.getDocumentSchemaUri()); final URI schemaUri = rootModelDimensions.getSchemaUri(); if (!isApplicableTo(schemaUri)) { throw new UnsupportedOperationException(getClass().getSimpleName() + " can be used to read and write schemas only (" + schemaLoader.getSchemaSchemaUri() + ")"); } final JsonSchemaLoader jsonSchemaLoader = schemaLoader.getJsonSchemaLoader(); JsonSchema jsonSchema; Schema wrmlSchema = null; try { jsonSchema = jsonSchemaLoader.load(in, uri); wrmlSchema = schemaLoader.load(jsonSchema, schemaLoader.getDocumentSchemaUri()); if (wrmlSchema == null) { throw new InvalidObjectException("Unable to deserialize InputStream to Model"); } } catch (Exception e) { throw new ModelReadingException( getClass().getSimpleName() + " encounter an error while attempting to read a JSON Schema (" + uri + "). Message: " + e.getMessage(), null, this); } return (M) wrmlSchema; }
From source file:com.phoenixst.plexus.operations.Join.java
private void readObject(ObjectInputStream in) throws ClassNotFoundException, IOException { in.defaultReadObject();/*from w w w . ja v a 2 s .c o m*/ if (left == null) { throw new InvalidObjectException("Left operand is null."); } if (right == null) { throw new InvalidObjectException("Right operand is null."); } initialize(); }
From source file:com.phoenixst.plexus.examples.CompleteTree.java
private void readObject(ObjectInputStream in) throws ClassNotFoundException, IOException { in.defaultReadObject();/* w ww . j a va2 s. c om*/ if (height < 0) { throw new InvalidObjectException("A CompleteTree must have height at least 0: " + height); } if (numChildren < 1) { throw new InvalidObjectException( "A CompleteTree must have at least 1 child per internal node: " + numChildren); } int numNodes = 1; if (numChildren == 1) { numInternalNodes = height; numNodes = height + 1; } else { numNodes = 1; for (int i = 0; i < height; i++) { numNodes *= numChildren; } numInternalNodes = (numNodes - 1) / (numChildren - 1); numNodes = (numNodes * numChildren - 1) / (numChildren - 1); } if (numNodes != getNodeSize()) { throw new InvalidObjectException("Calculated number of nodes does not match."); } }
From source file:com.hp.autonomy.hod.client.api.authentication.AuthenticationToken.java
private void readObject(final ObjectInputStream inputStream) throws IOException, ClassNotFoundException { inputStream.defaultReadObject();/*from w w w.j a va 2s. c o m*/ // values may be null if deserialized from an invalid stream //noinspection ConstantConditions if (expiry == null || id == null || secret == null || entityType == null || tokenType == null) { throw new InvalidObjectException("Values must not be null"); } }
From source file:org.grouplens.grapht.reflect.internal.SimpleInjectionPoint.java
private void readObject(ObjectInputStream stream) throws InvalidObjectException { throw new InvalidObjectException("Serialization proxy required"); }