Revision 111

View differences:

org.gvsig.dgn/tags/org.gvsig.dgn-2.0.29/org.gvsig.dgn.provider.legend/src/main/java/org/gvsig/fmap/dal/store/dgn/legend/DGNLegendLibrary.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2008 IVER T.I. S.A.   {{Task}}
26
*/
27

  
28
/**
29
 *
30
 */
31
package org.gvsig.fmap.dal.store.dgn.legend;
32

  
33
import org.gvsig.fmap.dal.DALLibrary;
34
import org.gvsig.fmap.dal.store.dgn.DGNLibrary;
35
import org.gvsig.fmap.dal.store.dgn.DGNStoreProvider;
36
import org.gvsig.metadata.MetadataLibrary;
37
import org.gvsig.metadata.MetadataLocator;
38
import org.gvsig.tools.dynobject.DynClass;
39
import org.gvsig.tools.library.AbstractLibrary;
40
import org.gvsig.tools.library.LibraryException;
41

  
42
/**
43
 * @author jmvivo
44
 *
45
 */
46
public class DGNLegendLibrary extends AbstractLibrary {
47

  
48
    @Override
49
    public void doRegistration() {
50
        registerAsServiceOf(DALLibrary.class);
51
        require(DGNLibrary.class);
52
        require(MetadataLibrary.class);
53
    }
54

  
55
	@Override
56
	protected void doInitialize() throws LibraryException {
57
	}
58

  
59
	@Override
60
	protected void doPostInitialize() throws LibraryException {
61
		DynClass metadataDefinition = (DynClass) MetadataLocator.getMetadataManager()
62
			.getDefinition(DGNStoreProvider.METADATA_DEFINITION_NAME);
63
		DGNGetLegendBuilder.register(metadataDefinition);
64
		DGNGetLegend.register(metadataDefinition);
65
		DGNGetLabeling.register(metadataDefinition);
66
	}
67
}
org.gvsig.dgn/tags/org.gvsig.dgn-2.0.29/org.gvsig.dgn.provider.legend/src/main/java/org/gvsig/fmap/dal/store/dgn/legend/DGNGetLegendBuilder.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2008 IVER T.I. S.A.   {{Task}}
26
*/
27

  
28
package org.gvsig.fmap.dal.store.dgn.legend;
29

  
30
import org.gvsig.fmap.dal.store.dgn.LegendBuilder;
31
import org.gvsig.tools.ToolsLocator;
32
import org.gvsig.tools.dynobject.DynClass;
33
import org.gvsig.tools.dynobject.DynMethod;
34
import org.gvsig.tools.dynobject.DynObject;
35
import org.gvsig.tools.dynobject.DynObjectManager;
36
import org.gvsig.tools.dynobject.exception.DynMethodException;
37
import org.gvsig.tools.dynobject.exception.DynMethodNotSupportedException;
38

  
39
public class DGNGetLegendBuilder implements DynMethod {
40
	private static int code = DynObjectManager.NULLCODE;
41

  
42
	static void register(DynClass DGNDynClass) {
43
		if (code != DynObjectManager.NULLCODE) {
44
			return;
45
		}
46
		code = ToolsLocator.getDynObjectManager().registerDynMethod(
47
			DGNDynClass, 
48
			new DGNGetLegendBuilder()
49
		);
50

  
51
	}
52
	
53
	public int getCode() throws DynMethodNotSupportedException {
54
		return code;
55
	}
56

  
57
	public String getDescription() {
58
		return "DGN LegendBuilder creator";
59
	}
60

  
61
	public String getName() {
62
		return LegendBuilder.DYNMETHOD_BUILDER_NAME;
63
	}
64

  
65
	public Object invoke(Object self, DynObject context)
66
			throws DynMethodException {
67
		return new DGNLegendBuilder();
68
	}
69

  
70
}
org.gvsig.dgn/tags/org.gvsig.dgn-2.0.29/org.gvsig.dgn.provider.legend/src/main/java/org/gvsig/fmap/dal/store/dgn/legend/DGNLegendBuilder.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2008 IVER T.I. S.A.   {{Task}}
26
*/
27

  
28
package org.gvsig.fmap.dal.store.dgn.legend;
29

  
30
import java.awt.Color;
31

  
32
import org.gvsig.fmap.dal.DataTypes;
33
import org.gvsig.fmap.dal.feature.spi.FeatureProvider;
34
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider;
35
import org.gvsig.fmap.dal.store.dgn.DGNStoreProvider;
36
import org.gvsig.fmap.dal.store.dgn.LegendBuilder;
37
import org.gvsig.fmap.dal.store.dgn.lib.DGNReader;
38
import org.gvsig.fmap.geom.Geometry;
39
import org.gvsig.fmap.mapcontext.MapContextLocator;
40
import org.gvsig.fmap.mapcontext.MapContextManager;
41
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorialUniqueValueLegend;
42
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
43
import org.gvsig.symbology.SymbologyLocator;
44
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.styling.IAttrInTableLabelingStrategy;
45
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol;
46
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol;
47
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol;
48

  
49
public class DGNLegendBuilder implements LegendBuilder {
50

  
51
	private MapContextManager mapContextManager = MapContextLocator
52
			.getMapContextManager();
53

  
54
	private IVectorialUniqueValueLegend defaultLegend = null;
55
	private IAttrInTableLabelingStrategy labelingStragegy = null;
56

  
57
	public void begin() {
58
		// Nothing to do
59
	}
60

  
61
	public void end() {
62
		// Nothing to do
63
	}
64

  
65
	public Object getLegend() {
66
		return defaultLegend;
67
	}
68

  
69
	public LegendBuilder initialize(FeatureStoreProvider store) {
70
		defaultLegend = (IVectorialUniqueValueLegend) mapContextManager.createLegend(
71
						IVectorialUniqueValueLegend.LEGEND_NAME);
72
		defaultLegend.setShapeType(Geometry.TYPES.GEOMETRY);
73
		defaultLegend
74
				.setClassifyingFieldNames(new String[] { DGNStoreProvider.NAME_FIELD_COLOR });
75
		defaultLegend.setClassifyingFieldTypes(new int[] { DataTypes.INT });
76

  
77
		ISymbol myDefaultSymbol =
78
				mapContextManager.getSymbolManager()
79
				.createSymbol(Geometry.TYPES.GEOMETRY); 
80

  
81
		defaultLegend.setDefaultSymbol(myDefaultSymbol);
82
		defaultLegend.useDefaultSymbol(true);
83

  
84
		labelingStragegy = SymbologyLocator.getSymbologyManager().createAttrInTableLabelingStrategy();
85
		labelingStragegy.setTextField(DGNStoreProvider.NAME_FIELD_TEXT);
86
		labelingStragegy
87
				.setRotationField(DGNStoreProvider.NAME_FIELD_ROTATIONTEXT);
88
		labelingStragegy.setHeightField(DGNStoreProvider.NAME_FIELD_HEIGHTTEXT);
89
		labelingStragegy.setUnit(1); // MapContext.NAMES[1] (meters)
90
		return this;
91
	}
92

  
93
	public void process(FeatureProvider feature, DGNReader dgnReader) {
94
		Integer clave = (Integer) feature.get("Color");
95
		if (clave == null) {
96
			return;
97
		}
98

  
99
		defaultLegend.useDefaultSymbol(false);
100
		if (defaultLegend.getSymbolByValue(clave) == null) {
101
			ISymbol theSymbol;
102
			Color color = dgnReader.DGNLookupColor(clave.intValue());
103
			theSymbol =
104
					mapContextManager.getSymbolManager().createSymbol(
105
					Geometry.TYPES.GEOMETRY, color); 
106

  
107
			theSymbol.setDescription(clave.toString());
108

  
109
			if (theSymbol instanceof IMarkerSymbol) {
110
				((IMarkerSymbol) theSymbol).setSize(1);
111
			}
112

  
113
			if (theSymbol instanceof ILineSymbol) {
114
				ILineSymbol lineSymbol = (ILineSymbol) theSymbol;
115
				lineSymbol.setLineWidth(1);
116
				lineSymbol.setLineColor(color);
117
			}
118

  
119
			if (theSymbol instanceof IFillSymbol) {
120
				IFillSymbol fillSymbol = (IFillSymbol) theSymbol;
121
				fillSymbol.getOutline().setLineColor(color);
122
				fillSymbol.getOutline().setLineWidth(1);
123
				fillSymbol.setFillColor(null);
124
			}
125
			if (theSymbol != null) {
126
				defaultLegend.addSymbol(clave, theSymbol);
127
			}
128
		}
129
	}
130

  
131
	public Object getLabeling() {
132
		return labelingStragegy;
133
	}
134

  
135

  
136
}
org.gvsig.dgn/tags/org.gvsig.dgn-2.0.29/org.gvsig.dgn.provider.legend/src/main/java/org/gvsig/fmap/dal/store/dgn/legend/DGNGetLabeling.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2008 IVER T.I. S.A.   {{Task}}
26
*/
27

  
28
package org.gvsig.fmap.dal.store.dgn.legend;
29

  
30
import org.gvsig.fmap.dal.exception.OpenException;
31
import org.gvsig.fmap.dal.store.dgn.DGNStoreProvider;
32
import org.gvsig.fmap.dal.store.dgn.LegendBuilder;
33
import org.gvsig.tools.ToolsLocator;
34
import org.gvsig.tools.dynobject.DynClass;
35
import org.gvsig.tools.dynobject.DynMethod;
36
import org.gvsig.tools.dynobject.DynObject;
37
import org.gvsig.tools.dynobject.DynObjectManager;
38
import org.gvsig.tools.dynobject.exception.DynMethodException;
39
import org.gvsig.tools.dynobject.exception.DynMethodNotSupportedException;
40

  
41
public class DGNGetLabeling implements DynMethod {
42
	private static int code = DynObjectManager.NULLCODE;
43

  
44
	static void register(DynClass DGNDynClass) {
45
		if (code != DynObjectManager.NULLCODE) {
46
			return;
47
		}
48
		code = ToolsLocator.getDynObjectManager().registerDynMethod(
49
			DGNDynClass, 
50
			new DGNGetLabeling()
51
		);
52

  
53
	}
54
	public int getCode() throws DynMethodNotSupportedException {
55
		return code;
56
	}
57

  
58
	public String getDescription() {
59
		return "DGN Labeling";
60
	}
61

  
62
	public String getName() {
63
		return LegendBuilder.DYNMETHOD_GETLABELING_NAME;
64
	}
65

  
66
	public Object invoke(Object self, DynObject context)
67
			throws DynMethodException {
68
		try {
69
			return ((DGNStoreProvider) self).getLabeling();
70
		} catch (OpenException e) {
71
			//FIXME
72
			throw new RuntimeException(e);
73
		}
74
	}
75

  
76
}
org.gvsig.dgn/tags/org.gvsig.dgn-2.0.29/org.gvsig.dgn.provider.legend/src/main/java/org/gvsig/fmap/dal/store/dgn/legend/DGNGetLegend.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2008 IVER T.I. S.A.   {{Task}}
26
*/
27

  
28
package org.gvsig.fmap.dal.store.dgn.legend;
29

  
30
import org.gvsig.fmap.dal.exception.OpenException;
31
import org.gvsig.fmap.dal.store.dgn.DGNStoreProvider;
32
import org.gvsig.fmap.dal.store.dgn.LegendBuilder;
33
import org.gvsig.tools.ToolsLocator;
34
import org.gvsig.tools.dynobject.DynClass;
35
import org.gvsig.tools.dynobject.DynMethod;
36
import org.gvsig.tools.dynobject.DynObject;
37
import org.gvsig.tools.dynobject.DynObjectManager;
38
import org.gvsig.tools.dynobject.exception.DynMethodException;
39
import org.gvsig.tools.dynobject.exception.DynMethodNotSupportedException;
40

  
41
public class DGNGetLegend implements DynMethod {
42
	private static int code = DynObjectManager.NULLCODE;
43

  
44
	static void register(DynClass DGNDynClass) {
45
		if (code != DynObjectManager.NULLCODE) {
46
			return;
47
		}
48
		code = ToolsLocator.getDynObjectManager().registerDynMethod(
49
			DGNDynClass, 
50
			new DGNGetLegend()
51
		);
52

  
53
	}
54
	public int getCode() throws DynMethodNotSupportedException {
55
		return code;
56
	}
57

  
58
	public String getDescription() {
59
		return "DGN Legend";
60
	}
61

  
62
	public String getName() {
63
		return LegendBuilder.DYNMETHOD_GETLEGEND_NAME;
64
	}
65

  
66
	public Object invoke(Object self, DynObject context)
67
			throws DynMethodException {
68
		try {
69
			return ((DGNStoreProvider) self).getLegend();
70
		} catch (OpenException e) {
71
			throw new RuntimeException(e);
72
		}
73
	}
74

  
75
}
org.gvsig.dgn/tags/org.gvsig.dgn-2.0.29/org.gvsig.dgn.provider.legend/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3
  <modelVersion>4.0.0</modelVersion>
4
  <artifactId>org.gvsig.dgn.provider.legend</artifactId>
5
  <packaging>jar</packaging>
6
  <name>${project.artifactId}</name>
7
  <description>DAL provider for DGN files</description>
8
  <parent>
9
      <groupId>org.gvsig</groupId>
10
      <artifactId>org.gvsig.dgn</artifactId>
11
      <version>2.0.29</version>
12
  </parent>
13

  
14
  <dependencies>
15

  
16
    <dependency>
17
      <groupId>org.gvsig</groupId>
18
      <artifactId>org.gvsig.dgn.provider</artifactId>
19
      <scope>compile</scope>
20
    </dependency>
21

  
22
    <dependency>
23
      <groupId>commons-io</groupId>
24
      <artifactId>commons-io</artifactId>
25
      <scope>compile</scope>
26
    </dependency>
27

  
28
    <dependency>
29
        <groupId>org.gvsig</groupId>
30
        <artifactId>org.gvsig.tools.lib</artifactId>
31
        <scope>compile</scope>
32
    </dependency>
33
    <dependency>
34
        <groupId>org.gvsig</groupId>
35
        <artifactId>org.gvsig.projection.api</artifactId>
36
        <scope>compile</scope>
37
    </dependency>
38
    <dependency>
39
        <groupId>org.gvsig</groupId>
40
        <artifactId>org.gvsig.fmap.dal.api</artifactId>
41
        <scope>compile</scope>
42
    </dependency>
43
    <dependency>
44
        <groupId>org.gvsig</groupId>
45
        <artifactId>org.gvsig.fmap.dal.spi</artifactId>
46
        <scope>compile</scope>
47
    </dependency>
48
    <dependency>
49
        <groupId>org.gvsig</groupId>
50
        <artifactId>org.gvsig.metadata.lib.basic.api</artifactId>
51
        <scope>compile</scope>
52
    </dependency>
53
    <dependency>
54
        <groupId>org.gvsig</groupId>
55
        <artifactId>org.gvsig.fmap.geometry.api</artifactId>
56
        <scope>compile</scope>
57
    </dependency>
58
    <dependency>
59
        <groupId>org.gvsig</groupId>
60
        <artifactId>org.gvsig.fmap.mapcontext.api</artifactId>
61
        <scope>compile</scope>
62
    </dependency>
63

  
64
    <dependency>
65
        <groupId>org.gvsig</groupId>
66
        <artifactId>org.gvsig.symbology.lib.api</artifactId>
67
        <scope>compile</scope>
68
    </dependency>
69
    <dependency>
70
        <groupId>org.gvsig</groupId>
71
        <artifactId>org.gvsig.timesupport.lib.api</artifactId>
72
        <scope>compile</scope>
73
    </dependency>  
74
    <dependency>
75
      <groupId>org.gvsig</groupId>
76
      <artifactId>org.gvsig.utils</artifactId>
77
      <scope>compile</scope>
78
    </dependency>
79

  
80

  
81
    <!-- TESTS -->
82
    <dependency>
83
      <groupId>org.gvsig</groupId>
84
      <artifactId>org.gvsig.tools.lib</artifactId>
85
      <type>test-jar</type>
86
      <scope>test</scope>
87
    </dependency>
88
    <dependency>
89
      <groupId>org.gvsig</groupId>
90
      <artifactId>org.gvsig.compat.se</artifactId>
91
      <scope>test</scope>
92
    </dependency>
93
    <dependency>
94
      <groupId>org.gvsig</groupId>
95
      <artifactId>org.gvsig.fmap.dal.impl</artifactId>
96
      <scope>test</scope>
97
    </dependency>
98
    <dependency>
99
      <groupId>org.gvsig</groupId>
100
      <artifactId>org.gvsig.fmap.geometry.generalpath</artifactId>
101
      <scope>test</scope>
102
    </dependency>
103
    <dependency>
104
      <groupId>org.gvsig</groupId>
105
      <artifactId>org.gvsig.projection.cresques.impl</artifactId>
106
      <scope>test</scope>
107
    </dependency>
108
    <dependency>
109
      <groupId>org.gvsig</groupId>
110
      <artifactId>org.gvsig.timesupport.lib.impl</artifactId>
111
      <scope>test</scope>
112
    </dependency>   
113

  
114

  
115
  </dependencies>
116

  
117
</project>
0 118

  
org.gvsig.dgn/tags/org.gvsig.dgn-2.0.29/org.gvsig.dgn.provider/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.fmap.dal.store.dgn.DGNLibrary
org.gvsig.dgn/tags/org.gvsig.dgn-2.0.29/org.gvsig.dgn.provider/src/main/resources/org/gvsig/fmap/dal/store/dgn/DGNMetadata.xml
1
<?xml version="1.0"?>
2
<!--
3
Definitions of metadata fields of a shp file.  
4
 -->
5
<definitions>
6
  <version>1.0.0</version>
7
  <classes>
8
    
9
    <class name="DGN" namespace="Metadata">
10
      <extends>
11
      	<class namespace="Metadata" name="SpatialProvider"/>
12
      </extends>
13
      <description>Metadata of a DGN store</description>
14
      <fields>
15
      </fields>
16
    </class>
17

  
18
  </classes>
19
</definitions>  
org.gvsig.dgn/tags/org.gvsig.dgn-2.0.29/org.gvsig.dgn.provider/src/main/resources/org/gvsig/fmap/dal/store/dgn/DGNParameters.xml
1
<?xml version= "1.0 "?>
2
<definitions>
3
  <version>1.0.0</version>
4
  <classes>
5
    <class name="DGN">
6
      <extends>
7
      	<class namespace="dal" name="ProviderParameters"/>
8
      </extends>
9
      <description>Store the parameters need to open a dgn file</description>
10
      <fields>
11
        
12
        <!-- General -->
13
        <field name="file" type="file" mandatory="true">
14
          <description>dgn file</description>
15
        </field>
16
        <field name="CRS" type="crs" mandatory="true">
17
          <description>The coordinate reference system used in this dgn file</description>
18
        </field>
19
        <field name="LoadMode" label="Load mode" defaultValue="0" type="integer" mandatory="false">
20
          <description>Set the strategy to use for loading DGN elements</description>
21
     	  <availableValues>
22
            <value label="Plain">0</value>
23
            <value label="Group elements (1)">1</value>
24
     	  </availableValues>
25
        </field>
26
        <field name="sortByGeometryType" label="Sort by geometry type" type="Boolean" defaultValue="true" mandatory="false">
27
          <description>If checked sort the rows of table by the geometry type (none,suface,curve,point)</description>
28
        </field>
29
        <field name="force2d" label="Force 2D" type="Boolean" defaultValue="false" mandatory="false">
30
          <description>If checked and DGN has Z dimension create all geometry in 2D and ignore the Zs.</description>
31
        </field>
32
        <field name="Reload" label="Reload" type="Boolean" defaultValue="false" mandatory="false">
33
          <description>Reload an already loaded DGN as a new layer</description>
34
        </field>
35
        <field name="groupby" label="Field for group" type="String" defaultValue="" mandatory="false">
36
          <description>The field name to use for grouping rows</description>
37
        </field>
38
        <field name="GroupGeometriesOperation" label="Group geometries as" type="integer" defaultValue="0" mandatory="false">
39
          <description>If a 'group by' is applied, apply this operation to the resultant geometries</description>
40
     	  <availableValues>
41
            <value label="None, return the agregate">0</value>
42
            <value label="Convexhull">1</value>
43
            <value label="Union">2</value>
44
            <value label="Intersection">3</value>
45
            <value label="Convert to points">4</value>
46
            <value label="Convert to line">5</value>
47
            <value label="Convert to poligon">7</value>
48
            <value label="Convert to poligon and fix it">7</value>
49
     	  </availableValues>
50
        </field>
51

  
52
        <!-- Advanced -->
53
        <field name="ignoreZ" label="Ignore Z" type="Boolean" defaultValue="false" mandatory="false">
54
          <description>If checked and DGN has Z dimension, set all Zs to 0.</description>
55
        </field>
56
        <field name="useZAsElevation" label="Use Z as elevation" type="Boolean" defaultValue="false" mandatory="false" group="Advanced">
57
          <description>If set, use the Z value to fill the field elevation.</description>
58
        </field>
59
        <field name="elevationFactor" label="Elevation factor" type="Double" defaultValue="1" mandatory="false" group="Advanced">
60
          <description>Factor to apply to elevation when is retrived from the Z coordinate.</description>
61
        </field>
62
        <field name="roundElevation" label="Round elevation" type="Boolean" defaultValue="false" mandatory="false" group="Advanced">
63
          <description>If set, round the elevation to a integer value. This only apply when get elevation from the coordinete Z.</description>
64
        </field>
65
        <field name="LinkFilterIndex" label="Link filter index" type="integer" defaultValue="0" mandatory="false" group="Advanced">
66
          <description>If set, return the link with this index</description>
67
        </field>
68
        <field name="LinkFilterType" label="Link filter type" type="integer" defaultValue="" mandatory="false" group="Advanced">
69
          <description>If set, return the link with this type</description>
70
        </field>
71
        <field name="LinkFilterEntity" label="Link filter entity" type="integer" defaultValue="" mandatory="false" group="Advanced">
72
          <description>If set, return the link with this entity</description>
73
        </field>
74
        <field name="LinkFilterMS" label="Link filter MSLink" type="integer" defaultValue="" mandatory="false" group="Advanced">
75
          <description>If set, return the link with this MSLink</description>
76
        </field>
77
        <field name="LinkFilterData" label="Link filter Data" type="string" defaultValue="" mandatory="false" group="Advanced">
78
          <description>This is a regular expresion. If set, return the link that match this regular expresion in the data of link represented in hexadecimal value</description>
79
        </field>
80

  
81
        <!-- Filter -->
82
        <field name="levelFilter" label="Level" group="Filter" type="String" defaultValue="" mandatory="false">
83
          <description>If specified load only elements with this level. Can use regular expresion to specify the filter.</description>
84
        </field>
85
        <field name="colorFilter" label="Color" group="Filter" type="String" defaultValue="" mandatory="false">
86
          <description>If specified load only elements with this color. Can use regular expresion to specify the filter.</description>
87
        </field>
88
        <field name="styleFilter" label="Style" group="Filter" type="String" defaultValue="" mandatory="false">
89
          <description>If specified load only elements with this style. Can use regular expresion to specify the filter.</description>
90
        </field>
91
        <field name="weightFilter" label="Weight" group="Filter" type="String" defaultValue="" mandatory="false">
92
          <description>If specified load only elements with this weight. Can use regular expresion to specify the filter.</description>
93
        </field>
94
        <field name="typeFilter" label="Type" group="Filter" type="String" defaultValue="" mandatory="false">
95
          <description>If specified load only elements with this type</description>
96
        </field>
97
        <field name="stypeFilter" label="SType" group="Filter" type="String" defaultValue="" mandatory="false">
98
          <description>If specified load only elements with this stype</description>
99
        </field>
100
        <field name="groupFilter" label="Group" group="Filter" type="String" defaultValue="" mandatory="false">
101
          <description>If specified load only elements with this group</description>
102
        </field>
103
        <field name="idFilter" label="Id" group="Filter" type="String" defaultValue="" mandatory="false">
104
          <description>If specified load only elements with this id</description>
105
        </field>
106
        <field name="textFilter" label="Text" group="Filter" type="String" defaultValue="" mandatory="false">
107
          <description>If specified load only elements that match this text</description>
108
        </field>
109
        <field name="geomtypeFilter" label="Geometry type" group="Filter" defaultValue="0" type="Integer" mandatory="false">
110
          <description>If specified load only elements with this type of geometry</description>
111
     	  <availableValues>
112
            <value label="All">0</value>
113
            <value label="Points">1</value>
114
            <value label="Lines">2</value>
115
            <value label="Poligons">3</value>
116
     	  </availableValues>
117
        </field>
118
        <field name="skipCorruptGeometries" label="Skip corrupt geometries" group="Filter" type="Boolean" defaultValue="false" mandatory="false">
119
          <description>If specified skip corrupt geometries</description>
120
        </field>
121
        <field name="cropOperationFilter" label="Crop operation" group="Filter" defaultValue="1" type="Integer" mandatory="false">
122
          <description>If specified load only elements with this type of geometry</description>
123
     	  <availableValues>
124
            <value label="None">0</value>
125
            <value label="Contains">1</value>
126
            <value label="Covered by">2</value>
127
            <value label="Covers">3</value>
128
            <value label="Crosses">4</value>
129
            <value label="Disjoint">5</value>
130
            <value label="Intersect">6</value>
131
            <value label="Overlaps">7</value>
132
            <value label="Touches">8</value>
133
            <value label="With in">9</value>
134
     	  </availableValues>
135
        </field>
136
        <field name="cropFilter" label="Crop to" group="Filter" type="Geometry" defaultValue="" mandatory="false">
137
          <description>Crop the result to this value</description>
138
        </field>
139
        
140
                        
141
        <!-- Debug -->
142
        <field name="XMLFile" label="Output XML file" type="file" group="Debug" mandatory="false">
143
          <description>Generate XML file with DGN dump in this file</description>
144
        </field>
145
        <!--
146
        <field name="debugOptions" label="Debug options" type="String" group="Debug" mandatory="false">
147
          <description></description>
148
        </field>
149
        -->
150
        <field name="logErrors" label="log errors" group="Debug" type="Boolean" defaultValue="false" mandatory="false">
151
          <description>If checked the log of errors are enabled</description>
152
        </field>
153

  
154
      </fields>
155
    </class>
156
  </classes>
157
</definitions>  
org.gvsig.dgn/tags/org.gvsig.dgn-2.0.29/org.gvsig.dgn.provider/src/main/java/org/gvsig/fmap/dal/store/dgn/LegendBuilder.java
1
package org.gvsig.fmap.dal.store.dgn;
2

  
3
import org.gvsig.fmap.dal.feature.spi.FeatureProvider;
4
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider;
5
import org.gvsig.fmap.dal.store.dgn.lib.DGNReader;
6

  
7

  
8
public interface LegendBuilder {
9

  
10
	final public static String DYNMETHOD_BUILDER_NAME = "getLegendBuilder";
11
	final public static String DYNMETHOD_GETLEGEND_NAME = "getLegend";
12
	final public static String DYNMETHOD_GETLABELING_NAME = "getLabeling";
13

  
14
	public LegendBuilder initialize(FeatureStoreProvider store);
15

  
16
	public void begin();
17

  
18
	public void process(FeatureProvider feature, DGNReader dgnReader);
19

  
20
	public void end();
21

  
22
	public Object getLegend();
23
	public Object getLabeling();
24

  
25
}
org.gvsig.dgn/tags/org.gvsig.dgn-2.0.29/org.gvsig.dgn.provider/src/main/java/org/gvsig/fmap/dal/store/dgn/lib/DGNInfo.java
1
/*
2
 * Created on 17-jul-2003
3
 *
4
 * Copyright (c) 2003
5
 * Francisco José Peñarrubia Martínez
6
 * IVER Tecnologías de la Información S.A.
7
 * Salamanca 50
8
 * 46005 Valencia (        SPAIN )
9
 * +34 963163400
10
 * mailto:fran@iver.es
11
 * http://www.iver.es
12
 */
13
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
14
 *
15
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
16
 *
17
 * This program is free software; you can redistribute it and/or
18
 * modify it under the terms of the GNU General Public License
19
 * as published by the Free Software Foundation; either version 2
20
 * of the License, or (at your option) any later version.
21
 *
22
 * This program is distributed in the hope that it will be useful,
23
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25
 * GNU General Public License for more details.
26
 *
27
 * You should have received a copy of the GNU General Public License
28
 * along with this program; if not, write to the Free Software
29
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
30
 *
31
 * For more information, contact:
32
 *
33
 *  Generalitat Valenciana
34
 *   Conselleria d'Infraestructures i Transport
35
 *   Av. Blasco Ib??ez, 50
36
 *   46010 VALENCIA
37
 *   SPAIN
38
 *
39
 *      +34 963862235
40
 *   gvsig@gva.es
41
 *      www.gvsig.gva.es
42
 *
43
 *    or
44
 *
45
 *   IVER T.I. S.A
46
 *   Salamanca 50
47
 *   46005 Valencia
48
 *   Spain
49
 *
50
 *   +34 963163400
51
 *   dac@iver.es
52
 */
53
package org.gvsig.fmap.dal.store.dgn.lib;
54

  
55
/**
56
 * Clase que almacena informaci?n del elemento.
57
 *
58
 * @author Vicente Caballero Navarro
59
 */
60
public class DGNInfo {
61
	public String fp;
62
	public int ftall;
63
	public int next_element_id;
64
	public int nElemBytes;
65
	public byte[] abyElem = new byte[131076]; //131076
66

  
67
	//byte[] temporal=new byte[4];
68
	public int got_tcb;
69
	public int dimension;
70
	public int options;
71
	public double scale;
72
	public double origin_x;
73
	public double origin_y;
74
	public double origin_z;
75
	public int index_built;
76
	public int element_count;
77
	public int max_element_count;
78
	public DGNElementInfo[] element_index;
79
	public int got_color_table;
80
	public byte[][] color_table = new byte[256][3]; //256 3
81
	public int got_bounds;
82
	public double min_x;
83
	public double min_y;
84
	public double min_z;
85
	public double max_x;
86
	public double max_y;
87
	public double max_z;
88
	public int has_spatial_filter;
89
	public int sf_converted_to_uor;
90
	public int select_complex_group;
91
	public int in_complex_group;
92
	public long sf_min_x;
93
	public long sf_min_y;
94
	public long sf_max_x;
95
	public long sf_max_y;
96
	public double sf_min_x_geo;
97
	public double sf_min_y_geo;
98
	public double sf_max_x_geo;
99
	public double sf_max_y_geo;
100
}
org.gvsig.dgn/tags/org.gvsig.dgn-2.0.29/org.gvsig.dgn.provider/src/main/java/org/gvsig/fmap/dal/store/dgn/lib/DGNElemCore.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 */
20
package org.gvsig.fmap.dal.store.dgn.lib;
21

  
22
import java.util.Formatter;
23

  
24
/**
25
 * Clase utilizada para guardar un elemento de tipo Base del cual extienden los
26
 * dem?s tipos.
27
 *
28
 * @author Vicente Caballero Navarro
29
 */
30
public class DGNElemCore {
31
	public int offset;
32
	public int size;
33
	public int element_id; /*!< Element number (zero based) */
34
	public int stype; /*!< Structure type: (DGNST_*) */
35
	public int level; /*!< Element Level: 0-63 */
36
	public int type; /*!< Element type (DGNT_) */
37
	public int complex; /*!< Is element complex? */
38
	public int deleted; /*!< Is element deleted? */
39
	public int graphic_group; /*!< Graphic group number */
40
	public int properties; /*!< Properties: ORing of DGNPF_ flags */
41
	public int color; /*!< Color index (0-255) */
42
	public int weight; /*!< Line Weight (0-31) */
43
	public int style; /*!< Line Style: One of DGNS_* values */
44
	public int attr_bytes; /*!< Bytes of attribute data, usually zero. */
45
	public byte[] attr_data; /*!< Raw attribute data */
46
	public int raw_bytes; /*!< Bytes of raw data, usually zero. */
47
	public byte[] raw_data; /*!< All raw element data including header. */
48
        
49
        protected DGNReader dgnreader = null;
50
        
51
        public DGNElemCore(DGNReader dgnreader) {
52
            this.dgnreader = dgnreader;
53
        }
54
        
55
        public boolean isComplex() {
56
            return this.complex != 0;
57
        }
58
        
59
        public boolean isDeleted() {
60
            return this.deleted != 0;
61
        }
62
        
63
        public boolean isHole() {
64
            if( this.type != DGNFileHeader.DGNT_SHAPE ) {
65
                return false;
66
            }
67
            return (this.properties & DGNFileHeader.DGNPF_HOLE) != 0;
68
        }
69
        
70
        public boolean is3D() {
71
            return this.getDimensions()==3;
72
        }
73
        
74
        public boolean isComplexShapeHeader() {
75
            return type == DGNFileHeader.DGNT_COMPLEX_SHAPE_HEADER;
76
        }
77
        
78
        public boolean isShape() {
79
            return this.type == DGNFileHeader.DGNT_SHAPE;
80
        }
81
        
82
        public boolean isEllipse() {
83
            return type == DGNFileHeader.DGNT_ELLIPSE;
84
        }
85
        
86
        public boolean isCurve() {
87
            return type == DGNFileHeader.DGNT_CURVE;
88
        }
89
        
90
        public int getShapeFillColor() {
91
            return this.dgnreader.DGNGetShapeFillInfo(this);
92
        }
93
        
94
        public String getLevelAsString() {
95
            return String.valueOf(this.level);
96
        }
97
        
98
        public int getLevel() {
99
            return this.level;
100
        }
101
        
102
        public int getStyle() {
103
            return this.style;
104
        }
105

  
106
        public int getWeight() {
107
            return this.weight;
108
        }
109
        
110
        public String getEntityName() {
111
            return this.dgnreader.DGNTypeToName(this.type);
112
        }
113
        
114
        public int getColor() {
115
            return this.color;
116
        }
117
        
118
        public int getID() {
119
            return this.element_id;
120
        }
121
        
122
        public int getGroup() {
123
            return this.graphic_group;
124
        }
125
        
126
        public double getElevation() {
127
            return 0;
128
        }
129

  
130
        public int getDimensions() {
131
            return this.dgnreader.getInfo().dimension;
132
        }
133

  
134
        public int getType() {
135
            return this.type;
136
        }
137

  
138
        public int getSType() {
139
            return this.stype;
140
        }
141
        
142

  
143
        public byte[] getData() {
144
            return this.raw_data;
145
        }
146

  
147
        public String getDataAsHexadecimal() {
148
            if( this.raw_data == null ) {
149
                return null;
150
            }
151
            Formatter out = new Formatter();
152

  
153
            for (int i = 0; i < this.raw_data.length; i++) {
154
                int ch = this.raw_data[i] & 0xff;
155
                out.format("%02X", ch);
156
            }
157
            return out.toString();
158
        }
159
}
org.gvsig.dgn/tags/org.gvsig.dgn-2.0.29/org.gvsig.dgn.provider/src/main/java/org/gvsig/fmap/dal/store/dgn/lib/DGNElemCellHeader.java
1

  
2
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
3
 *
4
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 */
21
package org.gvsig.fmap.dal.store.dgn.lib;
22

  
23
/**
24
 * Clase utilizada para guardar un elemento de tipo CellHeader.
25
 *
26
 * @author Vicente Caballero Navarro
27
 */
28
public class DGNElemCellHeader extends DGNElemCore {
29
	public int totlength; /*!< Total length of cell */
30
	public byte[] name = new byte[7]; //7           /*!< Cell name */
31
	public int cclass; /*!< Class bitmap */
32
	public int[] levels = new int[4]; //4         /*!< Levels used in cell */
33
	public DGNPoint rnglow = new DGNPoint(); /*!< X/Y/Z minimums for cell */
34
	public DGNPoint rnghigh = new DGNPoint(); /*!< X/Y/Z minimums for cell */
35
	public double[] trans = new double[9];
36

  
37
	//9          /*!< 2D/3D Transformation Matrix */
38
	public DGNPoint origin = new DGNPoint(); /*!< Cell Origin */
39
	public double xscale;
40
	public double yscale;
41
	public double rotation;
42
        
43
        public DGNElemCellHeader(DGNReader dgnreader) {
44
            super(dgnreader);
45
        }          
46
}
org.gvsig.dgn/tags/org.gvsig.dgn-2.0.29/org.gvsig.dgn.provider/src/main/java/org/gvsig/fmap/dal/store/dgn/lib/ByteUtils.java
1
/*
2
 * Created on 21-jul-2003
3
 *
4
 * Copyright (c) 2003
5
 * Francisco José Peñarrubia Martínez
6
 * IVER Tecnologías de la Información S.A.
7
 * Salamanca 50
8
 * 46005 Valencia (        SPAIN )
9
 * +34 963163400
10
 * mailto:fran@iver.es
11
 * http://www.iver.es
12
 */
13
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
14
 *
15
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
16
 *
17
 * This program is free software; you can redistribute it and/or
18
 * modify it under the terms of the GNU General Public License
19
 * as published by the Free Software Foundation; either version 2
20
 * of the License, or (at your option) any later version.
21
 *
22
 * This program is distributed in the hope that it will be useful,
23
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25
 * GNU General Public License for more details.
26
 *
27
 * You should have received a copy of the GNU General Public License
28
 * along with this program; if not, write to the Free Software
29
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
30
 *
31
 * For more information, contact:
32
 *
33
 *  Generalitat Valenciana
34
 *   Conselleria d'Infraestructures i Transport
35
 *   Av. Blasco Ib??ez, 50
36
 *   46010 VALENCIA
37
 *   SPAIN
38
 *
39
 *      +34 963862235
40
 *   gvsig@gva.es
41
 *      www.gvsig.gva.es
42
 *
43
 *    or
44
 *
45
 *   IVER T.I. S.A
46
 *   Salamanca 50
47
 *   46005 Valencia
48
 *   Spain
49
 *
50
 *   +34 963163400
51
 *   dac@iver.es
52
 */
53
package org.gvsig.fmap.dal.store.dgn.lib;
54

  
55
import java.math.BigInteger;
56

  
57

  
58
/**
59
 * Clase que engloba m?todos para trabajar con bytes.
60
 *
61
 * @author Vicente Caballero Navarro
62
 */
63
public class ByteUtils {
64
	public static final int SIZE_BOOL = 1;
65
	public static final int SIZE_SHORT = 2;
66
	public static final int SIZE_INT = 4;
67
	public static final int SIZE_LONG = 8;
68
	public static final int SIZE_DOUBLE = 8;
69

  
70
	/** A nibble->char mapping for printing out bytes. */
71
	public static final char[] digits = {
72
			'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd',
73
			'e', 'f'
74
		};
75

  
76
	/**
77
	 * Return the <code>int</code> represented by the bytes in
78
	 * <code>data</code> staring at offset <code>offset[0]</code>.
79
	 *
80
	 * @param data the array from which to read
81
	 * @param offset A single element array whose first element is the index in
82
	 * 		  data from which to begin reading on function entry, and which on
83
	 * 		  function exit has been incremented by the number of bytes read.
84
	 *
85
	 * @return the value of the <code>int</code> decoded
86
	 */
87
	public static final int bytesToInt(byte[] data, int[] offset) {
88
		/**
89
		 * TODO: We use network-order within OceanStore, but temporarily
90
		 * supporting intel-order to work with some JNI code until JNI code is
91
		 * set to interoperate with network-order.
92
		 */
93
		int result = 0;
94

  
95
		for (int i = 0; i < SIZE_INT; ++i) {
96
			result <<= 8;
97
			result |= byteToUnsignedInt(data[offset[0]++]);
98
		}
99

  
100
		return result;
101
	}
102

  
103
	/**
104
	 * Write the bytes representing <code>i</code> into the byte array
105
	 * <code>data</code>, starting at index <code>offset [0]</code>, and
106
	 * increment <code>offset [0]</code> by the number of bytes written; if
107
	 * <code>data == null</code>, increment <code>offset [0]</code> by the
108
	 * number of bytes that would have been written otherwise.
109
	 *
110
	 * @param i the <code>int</code> to encode
111
	 * @param data The byte array to store into, or <code>null</code>.
112
	 * @param offset A single element array whose first element is the index in
113
	 * 		  data to begin writing at on function entry, and which on
114
	 * 		  function exit has been incremented by the number of bytes
115
	 * 		  written.
116
	 */
117
	public static final void intToBytes(int i, byte[] data, int[] offset) {
118
		/**
119
		 * TODO: We use network-order within OceanStore, but temporarily
120
		 * supporting intel-order to work with some JNI code until JNI code is
121
		 * set to interoperate with network-order.
122
		 */
123
		if (data != null) {
124
			for (int j = (offset[0] + SIZE_INT) - 1; j >= offset[0]; --j) {
125
				data[j] = (byte) i;
126
				i >>= 8;
127
			}
128
		}
129

  
130
		offset[0] += SIZE_INT;
131
	}
132

  
133
	/**
134
	 * Return the <code>short</code> represented by the bytes in
135
	 * <code>data</code> staring at offset <code>offset[0]</code>.
136
	 *
137
	 * @param data the array from which to read
138
	 * @param offset A single element array whose first element is the index in
139
	 * 		  data from which to begin reading on function entry, and which on
140
	 * 		  function exit has been incremented by the number of bytes read.
141
	 *
142
	 * @return the value of the <code>short</code> decoded
143
	 */
144
	public static final short bytesToShort(byte[] data, int[] offset) {
145
		/**
146
		 * TODO: We use network-order within OceanStore, but temporarily
147
		 * supporting intel-order to work with some JNI code until JNI code is
148
		 * set to interoperate with network-order.
149
		 */
150
		short result = 0;
151

  
152
		for (int i = 0; i < SIZE_SHORT; ++i) {
153
			result <<= 8;
154
			result |= (short) byteToUnsignedInt(data[offset[0]++]);
155
		}
156

  
157
		return result;
158
	}
159

  
160
	/**
161
	 * Write the bytes representing <code>s</code> into the byte array
162
	 * <code>data</code>, starting at index <code>offset [0]</code>, and
163
	 * increment <code>offset [0]</code> by the number of bytes written; if
164
	 * <code>data == null</code>, increment <code>offset [0]</code> by the
165
	 * number of bytes that would have been written otherwise.
166
	 *
167
	 * @param s the <code>short</code> to encode
168
	 * @param data The byte array to store into, or <code>null</code>.
169
	 * @param offset A single element array whose first element is the index in
170
	 * 		  data to begin writing at on function entry, and which on
171
	 * 		  function exit has been incremented by the number of bytes
172
	 * 		  written.
173
	 */
174
	public static final void shortToBytes(short s, byte[] data, int[] offset) {
175
		/**
176
		 * TODO: We use network-order within OceanStore, but temporarily
177
		 * supporting intel-order to work with some JNI code until JNI code is
178
		 * set to interoperate with network-order.
179
		 */
180
		if (data != null) {
181
			data[offset[0] + 1] = (byte) s;
182
			data[offset[0]] = (byte) (s >> 8);
183
		}
184

  
185
		offset[0] += SIZE_SHORT;
186
	}
187

  
188
	/**
189
	 * Return the <code>long</code> represented by the bytes in
190
	 * <code>data</code> staring at offset <code>offset[0]</code>.
191
	 *
192
	 * @param data the array from which to read
193
	 * @param offset A single element array whose first element is the index in
194
	 * 		  data from which to begin reading on  function entry, and which
195
	 * 		  on function exit has been incremented by the number of bytes
196
	 * 		  read.
197
	 *
198
	 * @return the value of the <code>long</code> decoded
199
	 */
200
	public static final long bytesToLong(byte[] data, int[] offset) {
201
		long result = 0;
202

  
203
		for (int i = 0; i < SIZE_LONG; ++i) {
204
			result <<= 8;
205

  
206
			int res = byteToUnsignedInt(data[offset[0]++]);
207
			result = result | res;
208
		}
209

  
210
		return result;
211
	}
212

  
213
	/**
214
	 * Write the bytes representing <code>l</code> into the byte array
215
	 * <code>data</code>, starting at index <code>offset [0]</code>, and
216
	 * increment <code>offset [0]</code> by the number of bytes written; if
217
	 * <code>data == null</code>, increment <code>offset [0]</code> by the
218
	 * number of bytes that would have been written otherwise.
219
	 *
220
	 * @param l the <code>long</code> to encode
221
	 * @param data The byte array to store into, or <code>null</code>.
222
	 * @param offset A single element array whose first element is the index in
223
	 * 		  data to begin writing at on function entry, and which on
224
	 * 		  function exit has been incremented by the number of bytes
225
	 * 		  written.
226
	 */
227
	public static final void longToBytes(long l, byte[] data, int[] offset) {
228
		/**
229
		 * TODO: We use network-order within OceanStore, but temporarily
230
		 * supporting intel-order to work with some JNI code until JNI code is
231
		 * set to interoperate with network-order.
232
		 */
233
		if (data != null) {
234
			for (int j = (offset[0] + SIZE_LONG) - 1; j >= offset[0]; --j) {
235
				data[j] = (byte) l;
236
				l >>= 8;
237
			}
238
		}
239

  
240
		offset[0] += SIZE_LONG;
241
	}
242

  
243
	/**
244
	 * Return the <code>double</code> represented by the bytes in
245
	 * <code>data</code> staring at offset <code>offset[0]</code>.
246
	 *
247
	 * @param data the array from which to read
248
	 * @param offset A single element array whose first element is the index in
249
	 * 		  data from which to begin reading on  function entry, and which
250
	 * 		  on function exit has been incremented by the number of bytes
251
	 * 		  read.
252
	 *
253
	 * @return the value of the <code>double</code> decoded
254
	 */
255
	public static final double bytesToDouble(byte[] data, int[] offset) {
256
		long bits = bytesToLong(data, offset);
257

  
258
		return Double.longBitsToDouble(bits);
259
	}
260

  
261
	/**
262
	 * Write the bytes representing <code>d</code> into the byte array
263
	 * <code>data</code>, starting at index <code>offset [0]</code>, and
264
	 * increment <code>offset [0]</code> by the number of bytes written; if
265
	 * <code>data == null</code>, increment <code>offset [0]</code> by the
266
	 * number of bytes that would have been written otherwise.
267
	 *
268
	 * @param d the <code>double</code> to encode
269
	 * @param data The byte array to store into, or <code>null</code>.
270
	 * @param offset A single element array whose first element is the index in
271
	 * 		  data to begin writing at on function entry, and which on
272
	 * 		  function exit has been incremented by the number of bytes
273
	 * 		  written.
274
	 */
275
	public static final void doubleToBytes(double d, byte[] data, int[] offset) {
276
		long bits = Double.doubleToLongBits(d);
277
		longToBytes(bits, data, offset);
278
	}
279

  
280
	/**
281
	 * Return the <code>String</code> represented by the bytes in
282
	 * <code>data</code> staring at offset <code>offset[0]</code>. This method
283
	 * relies on the user using the corresponding <code>stringToBytes</code>
284
	 * method to encode the <code>String</code>, so that it may properly
285
	 * retrieve the <code>String</code> length.
286
	 *
287
	 * @param data the array from which to read
288
	 * @param offset A single element array whose first element is the index in
289
	 * 		  data from which to begin reading on function entry, and which on
290
	 * 		  function exit has been incremented by the number of bytes read.
291
	 *
292
	 * @return the value of the <code>String</code> decoded
293
	 */
294
	public static final String bytesToString(byte[] data, int[] offset) {
295
		offset[0] = 0;
296

  
297
		int length = bytesToInt(data, offset);
298
		String st = null;
299

  
300
		if ((length < 0) || (length > data.length)) {
301
			st = new String(data);
302
		} else {
303
			st = new String(data, offset[0], length);
304
		}
305

  
306
		offset[0] += length;
307

  
308
		return st;
309
	}
310

  
311
	/**
312
	 * Write the bytes representing <code>s</code> into the byte array
313
	 * <code>data</code>, starting at index <code>offset [0]</code>, and
314
	 * increment <code>offset [0]</code> by the number of bytes written; if
315
	 * <code>data == null</code>, increment <code>offset [0]</code> by the
316
	 * number of bytes that would have been written otherwise.
317
	 *
318
	 * @param s the <code>String</code> to encode
319
	 * @param data The byte array to store into, or <code>null</code>.
320
	 * @param offset A single element array whose first element is the index in
321
	 * 		  data to begin writing at on function entry, and which on
322
	 * 		  function exit has been incremented by the number of bytes
323
	 * 		  written.
324
	 */
325
	public static final void stringToBytes(String s, byte[] data, int[] offset) {
326
		byte[] s_bytes = s.getBytes();
327

  
328
		if (data != null) {
329
			intToBytes(s_bytes.length, data, offset);
330
			memcpy(data, offset[0], s_bytes, 0, s_bytes.length);
331
		} else {
332
			offset[0] += SIZE_INT;
333
		}
334

  
335
		offset[0] += s_bytes.length;
336
	}
337

  
338
	/**
339
	 * Return the <code>boolean</code> represented by the bytes in
340
	 * <code>data</code> staring at offset <code>offset[0]</code>.
341
	 *
342
	 * @param data the array from which to read
343
	 * @param offset A single element array whose first element is the index in
344
	 * 		  data from which to begin reading on  function entry, and which
345
	 * 		  on function exit has been incremented by the number of bytes
346
	 * 		  read.
347
	 *
348
	 * @return the value of the <code>boolean</code> decoded
349
	 */
350
	public static final boolean bytesToBool(byte[] data, int[] offset) {
351
		boolean result = true;
352

  
353
		if (data[offset[0]] == 0) {
354
			result = false;
355
		}
356

  
357
		offset[0] += SIZE_BOOL;
358

  
359
		return result;
360
	}
361

  
362
	/**
363
	 * Write the bytes representing <code>b</code> into the byte array
364
	 * <code>data</code>, starting at index <code>offset [0]</code>, and
365
	 * increment <code>offset [0]</code> by the number of bytes written; if
366
	 * <code>data == null</code>, increment <code>offset [0]</code> by the
367
	 * number of bytes that would have been written otherwise.
368
	 *
369
	 * @param b the <code>boolean</code> to encode
370
	 * @param data The byte array to store into, or <code>null</code>.
371
	 * @param offset A single element array whose first element is the index in
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff