Revision 35115 branches/dal_time_support/libraries/libFMap_dal/src/org/gvsig/fmap/dal/DALLibrary.java

View differences:

DALLibrary.java
29 29
import java.util.ArrayList;
30 30
import java.util.List;
31 31

  
32
import org.cresques.cts.IProjection;
33 32
import org.gvsig.fmap.dal.feature.spi.memory.MemoryResource;
34 33
import org.gvsig.fmap.dal.feature.spi.memory.MemoryResourceParameters;
35 34
import org.gvsig.fmap.dal.resource.ResourceManager;
36 35
import org.gvsig.fmap.dal.resource.spi.MultiResource;
37 36
import org.gvsig.fmap.dal.resource.spi.MultiResourceParameters;
38 37
import org.gvsig.fmap.dal.resource.spi.ResourceManagerProviderServices;
39
import org.gvsig.fmap.geom.Geometry;
40 38
import org.gvsig.fmap.geom.GeometryLibrary;
41
import org.gvsig.fmap.geom.primitive.Envelope;
42 39
import org.gvsig.metadata.MetadataLibrary;
43 40
import org.gvsig.metadata.MetadataLocator;
44 41
import org.gvsig.metadata.MetadataManager;
45 42
import org.gvsig.metadata.exceptions.MetadataException;
46
import org.gvsig.timesupport.RelativeInstant;
47
import org.gvsig.timesupport.RelativeInterval;
48 43
import org.gvsig.timesupport.AbsoluteInstant;
49 44
import org.gvsig.timesupport.AbsoluteInterval;
45
import org.gvsig.timesupport.RelativeInstant;
46
import org.gvsig.timesupport.RelativeInterval;
50 47
import org.gvsig.tools.ToolsLibrary;
51 48
import org.gvsig.tools.ToolsLocator;
52 49
import org.gvsig.tools.dataTypes.DataTypesManager;
......
56 53
import org.gvsig.tools.locator.ReferenceNotRegisteredException;
57 54

  
58 55
/**
59
 * Initializes gvSIG's desktop DAL by registering the default implementation for {@link DataManager}
60
 * and {@link ResourceManager}.
61
 *
56
 * Initializes gvSIG's desktop DAL by registering the default implementation for
57
 * {@link DataManager} and {@link ResourceManager}.
58
 * 
62 59
 */
63 60
public class DALLibrary extends AbstractLibrary {
64 61

  
65
	public DALLibrary() {
66
		super(DALLibrary.class,Library.TYPE.API );
67
		require(GeometryLibrary.class);
68
		require(ToolsLibrary.class);
69
		require(MetadataLibrary.class);
70
	}
71
	
72
	protected void doInitialize() throws LibraryException {
73
		// Do nothing
74
	}
62
    public DALLibrary() {
63
        super(DALLibrary.class, Library.TYPE.API);
64
        require(GeometryLibrary.class);
65
        require(ToolsLibrary.class);
66
        require(MetadataLibrary.class);
67
    }
75 68

  
76
	protected void doPostInitialize() throws LibraryException {
77
		List exs = new ArrayList();
78
		
79
		DataTypesManager dataTypesManager = ToolsLocator.getDataTypesManager();
80
		dataTypesManager.addtype(DataTypes.GEOMETRY, "Geometry", "Geometry", Geometry.class, null);
81
		dataTypesManager.addtype(DataTypes.CRS, "CRS","CRS", IProjection.class, null);
82
		dataTypesManager.addtype(DataTypes.ENVELOPE, "Envelope", "Envelope", Envelope.class, null);
83
		dataTypesManager.addtype(DataTypes.RELATIVEINSTANT, "RelativeInstant", "RelativeInstant", RelativeInstant.class, null);
84
        dataTypesManager.addtype(DataTypes.RELATIVEINTERVAL, "RelativeInterval","RelativeInterval", RelativeInterval.class, null);
85
        dataTypesManager.addtype(DataTypes.ABSOLUTEINSTANT, "AbsoluteInstant", "AbsoluteInstant", AbsoluteInstant.class, null);
86
        dataTypesManager.addtype(DataTypes.ABSOLUTEINTERVAL, "AbsoluteInterval", "AbsoluteInterval", AbsoluteInterval.class, null);
69
    protected void doInitialize() throws LibraryException {
70
        // Do nothing
71
    }
87 72

  
88
		
89
		try {
90
			registerDataStoreMetadataDefinition();
91
		} catch (MetadataException e) {
92
			exs.add(e);
93
		}
94
		try {
95
			registerSpatialDataStoreMetadataDefinition();
96
		} catch (MetadataException e) {
97
			exs.add(e);
98
		}
99
		try {
100
			registerFeatureStoreMetadataDefinition();
101
		} catch (MetadataException e) {
102
			exs.add(e);
103
		}
73
    protected void doPostInitialize() throws LibraryException {
74
        List exs = new ArrayList();
75
        
76
        try {
77
            registerDataStoreMetadataDefinition();
78
        } catch (MetadataException e) {
79
            exs.add(e);
80
        }
81
        try {
82
            registerSpatialDataStoreMetadataDefinition();
83
        } catch (MetadataException e) {
84
            exs.add(e);
85
        }
86
        try {
87
            registerFeatureStoreMetadataDefinition();
88
        } catch (MetadataException e) {
89
            exs.add(e);
90
        }
104 91

  
105
		// Validate there is any implementation registered.
106
		DataManager dataManager = DALLocator.getDataManager();
107
		if (dataManager == null) {
108
			throw new ReferenceNotRegisteredException(
109
					DALLocator.DATA_MANAGER_NAME, DALLocator.getInstance());
110
		}
92
        // Validate there is any implementation registered.
93
        DataManager dataManager = DALLocator.getDataManager();
94
        if (dataManager == null) {
95
            throw new ReferenceNotRegisteredException(
96
                DALLocator.DATA_MANAGER_NAME, DALLocator.getInstance());
97
        }
111 98

  
112
		ResourceManagerProviderServices resourceManager =
113
				(ResourceManagerProviderServices) DALLocator.getResourceManager();
114
		if (resourceManager == null) {
115
			throw new ReferenceNotRegisteredException(
116
					DALLocator.RESOURCE_MANAGER_NAME, DALLocator.getInstance());
117
		}
99
        ResourceManagerProviderServices resourceManager =
100
            (ResourceManagerProviderServices) DALLocator.getResourceManager();
101
        if (resourceManager == null) {
102
            throw new ReferenceNotRegisteredException(
103
                DALLocator.RESOURCE_MANAGER_NAME, DALLocator.getInstance());
104
        }
118 105

  
119
		if (!resourceManager.getResourceProviders().contains(
120
				MultiResource.TYPE_NAME)) {
121
			resourceManager.register(MultiResource.TYPE_NAME,
122
					MultiResource.DESCRIPTION, MultiResource.class,
123
					MultiResourceParameters.class);
124
		}
106
        if (!resourceManager.getResourceProviders().contains(
107
            MultiResource.TYPE_NAME)) {
108
            resourceManager.register(MultiResource.TYPE_NAME,
109
                MultiResource.DESCRIPTION, MultiResource.class,
110
                MultiResourceParameters.class);
111
        }
125 112

  
126
		if (!resourceManager.getResourceProviders().contains(
127
				MemoryResource.NAME)) {
128
			resourceManager.register(MemoryResource.NAME,
129
					MemoryResource.DESCRIPTION, MemoryResource.class,
130
					MemoryResourceParameters.class);
131
		}
113
        if (!resourceManager.getResourceProviders().contains(
114
            MemoryResource.NAME)) {
115
            resourceManager.register(MemoryResource.NAME,
116
                MemoryResource.DESCRIPTION, MemoryResource.class,
117
                MemoryResourceParameters.class);
118
        }
132 119

  
133
		if( exs.size()>0 ) {
134
			throw new LibraryException(this.getClass(), exs);
135
		}
136
	}
137
	
138
	private void registerDataStoreMetadataDefinition() throws MetadataException {
139
		MetadataManager manager = MetadataLocator.getMetadataManager();
140
		if( manager.getDefinition(DataStore.METADATA_DEFINITION_NAME)==null ) {
141
			manager.addDefinition(
142
					DataStore.METADATA_DEFINITION_NAME, 
143
					DALLibrary.class.getResourceAsStream("MetadataDefinitions.xml"),
144
					DALLibrary.class.getClassLoader()
145
			);
146
		}
147
	}
120
        if (exs.size() > 0) {
121
            throw new LibraryException(this.getClass(), exs);
122
        }
123
    }
148 124

  
149
	private void registerSpatialDataStoreMetadataDefinition() throws MetadataException {
150
		MetadataManager manager = MetadataLocator.getMetadataManager();
151
		if( manager.getDefinition(DataStore.SPATIAL_METADATA_DEFINITION_NAME)==null ) {
152
			manager.addDefinition(
153
					DataStore.SPATIAL_METADATA_DEFINITION_NAME, 
154
					DALLibrary.class.getResourceAsStream("MetadataDefinitions.xml"),
155
					DALLibrary.class.getClassLoader()
156
			);
157
		}
158
	}
125
    private void registerDataStoreMetadataDefinition() throws MetadataException {
126
        MetadataManager manager = MetadataLocator.getMetadataManager();
127
        if (manager.getDefinition(DataStore.METADATA_DEFINITION_NAME) == null) {
128
            manager
129
                .addDefinition(DataStore.METADATA_DEFINITION_NAME,
130
                    DALLibrary.class
131
                        .getResourceAsStream("MetadataDefinitions.xml"),
132
                    DALLibrary.class.getClassLoader());
133
        }
134
    }
159 135

  
160
	private void registerFeatureStoreMetadataDefinition() throws MetadataException {
161
		MetadataManager manager = MetadataLocator.getMetadataManager();
162
		if( manager.getDefinition(DataStore.FEATURE_METADATA_DEFINITION_NAME)==null ) {
163
			manager.addDefinition(
164
					DataStore.FEATURE_METADATA_DEFINITION_NAME, 
165
					DALLibrary.class.getResourceAsStream("MetadataDefinitions.xml"),
166
					DALLibrary.class.getClassLoader()
167
			);
168
		}
169
	}
136
    private void registerSpatialDataStoreMetadataDefinition()
137
        throws MetadataException {
138
        MetadataManager manager = MetadataLocator.getMetadataManager();
139
        if (manager.getDefinition(DataStore.SPATIAL_METADATA_DEFINITION_NAME) == null) {
140
            manager
141
                .addDefinition(DataStore.SPATIAL_METADATA_DEFINITION_NAME,
142
                    DALLibrary.class
143
                        .getResourceAsStream("MetadataDefinitions.xml"),
144
                    DALLibrary.class.getClassLoader());
145
        }
146
    }
170 147

  
171
}
148
    private void registerFeatureStoreMetadataDefinition()
149
        throws MetadataException {
150
        MetadataManager manager = MetadataLocator.getMetadataManager();
151
        if (manager.getDefinition(DataStore.FEATURE_METADATA_DEFINITION_NAME) == null) {
152
            manager
153
                .addDefinition(DataStore.FEATURE_METADATA_DEFINITION_NAME,
154
                    DALLibrary.class
155
                        .getResourceAsStream("MetadataDefinitions.xml"),
156
                    DALLibrary.class.getClassLoader());
157
        }
158
    }
159

  
160
}

Also available in: Unified diff