Added exception handling in the main loop for the web server to avoid the main loop thread getting killed off due to an unexpected/unhandled exception.
Moved code for JSON handling and metadata/metadata container into the Common project from the Foundation project.
This commit is contained in:
22
Common/src/com/common/metadata/IMetadata.java
Normal file
22
Common/src/com/common/metadata/IMetadata.java
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (c) 2006,2009 Declarative Engineering LLC.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Declarative Engineering LLC
|
||||
* verson 1 which accompanies this distribution, and is available at
|
||||
* http://declarativeengineering.com/legal/DE_Developer_License_v1.txt
|
||||
*/
|
||||
package com.common.metadata;
|
||||
|
||||
import java.io.Externalizable;
|
||||
import com.common.io.IExternalizable;
|
||||
|
||||
/**
|
||||
* This interface is used by the EntityMetadata and future metadata types that can be passed around to specify what data is required in different situations.
|
||||
*/
|
||||
public interface IMetadata extends IExternalizable, Externalizable {
|
||||
/**
|
||||
* The class of object for which this metadata can be used.
|
||||
* @return The metadata type mapping.
|
||||
*/
|
||||
public Class getType();
|
||||
}//IMetadata//
|
||||
100
Common/src/com/common/metadata/MetadataContainer.java
Normal file
100
Common/src/com/common/metadata/MetadataContainer.java
Normal file
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Copyright (c) 2006,2009 Declarative Engineering LLC.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Declarative Engineering LLC
|
||||
* verson 1 which accompanies this distribution, and is available at
|
||||
* http://declarativeengineering.com/legal/DE_Developer_License_v1.txt
|
||||
*/
|
||||
package com.common.metadata;
|
||||
|
||||
import java.io.Externalizable;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInput;
|
||||
import java.io.ObjectOutput;
|
||||
|
||||
import com.common.comparison.Comparator;
|
||||
import com.common.io.IExternalizable;
|
||||
import com.common.io.IObjectInputStream;
|
||||
import com.common.io.IObjectOutputStream;
|
||||
import com.common.util.LiteHashMap;
|
||||
|
||||
/*
|
||||
* This container is used to pass information about what to include or exclude when performing such operations as cloning models.
|
||||
*/
|
||||
public class MetadataContainer implements IExternalizable, Externalizable {
|
||||
/** Tells the user of the metadata to not include any reflections. */
|
||||
public static final int FLAG_EXCLUDE_REFLECTIONS = 1;
|
||||
|
||||
private LiteHashMap metadataByTypeMap = new LiteHashMap(10, Comparator.getLogicalComparator(), null);
|
||||
private int flags = 0;
|
||||
/**
|
||||
* MetadataContainer constructor.
|
||||
*/
|
||||
public MetadataContainer() {
|
||||
super();
|
||||
}//MetadataContainer()//
|
||||
/**
|
||||
* MetadataContainer constructor.
|
||||
* @param flags One or more of the flag identifiers defined by this class.
|
||||
*/
|
||||
public MetadataContainer(int flags) {
|
||||
super();
|
||||
this.flags = flags;
|
||||
}//MetadataContainer()//
|
||||
/**
|
||||
* MetadataContainer constructor.
|
||||
* @param metadata The set of metadata instances, one for each type for which metadata is provided. The type must match exactly with the object whose metadata is being searched for (ie: type hierarchy is not considered).
|
||||
*/
|
||||
public MetadataContainer(IMetadata[] metadata) {
|
||||
super();
|
||||
|
||||
for(int index = 0; index < metadata.length; index++) {
|
||||
metadataByTypeMap.put(metadata[index].getType(), metadata[index]);
|
||||
}//for//
|
||||
}//MetadataContainer()//
|
||||
/**
|
||||
* Gets the metadata for the given type.
|
||||
* @param type The type whose metadata is to be retreived.
|
||||
* @return The metadata for that exact type, or null if none was specified.
|
||||
*/
|
||||
public IMetadata getMetadata(Class type) {
|
||||
return (IMetadata) metadataByTypeMap.get(type);
|
||||
}//getMetadata()//
|
||||
/**
|
||||
* Determines whether reflections should be excluded based on the flags passed to this metadata container.
|
||||
* @return Whether reflections should be excluded.
|
||||
*/
|
||||
public boolean excludeReflections() {
|
||||
return (flags & FLAG_EXCLUDE_REFLECTIONS) > 0;
|
||||
}//excludeReflections()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.common.io.IExternalizable#writeExternal(com.common.io.IObjectOutputStream)
|
||||
*/
|
||||
public void writeExternal(IObjectOutputStream out) throws IOException {
|
||||
out.writeByte(0);
|
||||
out.writeObject(metadataByTypeMap);
|
||||
}//writeExternal()//
|
||||
/* (non-Javadoc)
|
||||
* @see java.io.Externalizable#writeExternal(java.io.ObjectOutput)
|
||||
*/
|
||||
public void writeExternal(ObjectOutput out) throws IOException {
|
||||
out.writeByte(0);
|
||||
out.writeObject(metadataByTypeMap);
|
||||
}//writeExternal()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.common.io.IExternalizable#readExternal(com.common.io.IObjectInputStream)
|
||||
*/
|
||||
public Object readExternal(IObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
/*byte version = */in.readByte();
|
||||
metadataByTypeMap = (LiteHashMap) in.readObject();
|
||||
|
||||
return null;
|
||||
}//readExternal()//
|
||||
/* (non-Javadoc)
|
||||
* @see java.io.Externalizable#readExternal(java.io.ObjectInput)
|
||||
*/
|
||||
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
|
||||
/*byte version = */in.readByte();
|
||||
metadataByTypeMap = (LiteHashMap) in.readObject();
|
||||
}//readExternal()//
|
||||
}//MetadataContainer//
|
||||
Reference in New Issue
Block a user