or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

archive-bases.mdassets.mdcontainers.mdimport-export.mdindex.mdspecifications.mdutilities.md

containers.mddocs/

0

# Container Implementations

1

2

Container implementations provide complete functionality for managing archive contents including classes, resources, libraries, and metadata. These classes form the backbone of ShrinkWrap's container-based API.

3

4

## Base Container Classes

5

6

### ContainerBase<T>

7

8

The foundational container implementation providing comprehensive archive management capabilities.

9

10

```java { .api }

11

public abstract class ContainerBase<T extends Archive<T>> extends MemoryMapArchiveBase<T>

12

implements Archive<T>, ManifestContainer<T>, ServiceProviderContainer<T>,

13

ResourceContainer<T>, ClassContainer<T>, LibraryContainer<T>

14

```

15

16

**Core Container Operations:**

17

18

**Class Management:**

19

```java { .api }

20

public T addClass(Class<?> clazz)

21

public T addClass(String fullyQualifiedClassName)

22

public T addClasses(Class<?>... classes)

23

public T addPackage(Package pack)

24

public T addPackages(boolean recursive, Package... packages)

25

```

26

27

**Resource Management:**

28

```java { .api }

29

public T addAsResource(String resourceName)

30

public T addAsResource(String resourceName, String target)

31

public T addAsResource(Asset asset, String target)

32

public T addAsResource(URL resource, String target)

33

```

34

35

**Library Management:**

36

```java { .api }

37

public T addAsLibrary(Archive<?> archive)

38

public T addAsLibrary(String path)

39

public T addAsLibraries(Archive<?>... archives)

40

```

41

42

**Manifest Operations:**

43

```java { .api }

44

public T addAsManifestResource(String resourceName)

45

public T addAsManifestResource(Asset asset, String target)

46

public T setManifest(Asset asset)

47

public T setManifest(String manifest)

48

```

49

50

**Service Provider Configuration:**

51

```java { .api }

52

public T addAsServiceProvider(Class<?> serviceInterface, Class<?>... serviceImpls)

53

public T addAsServiceProvider(String serviceInterface, String... serviceImpls)

54

```

55

56

### WebContainerBase<T>

57

58

Specialized container for web archives (WAR files) with web-specific operations.

59

60

```java { .api }

61

public abstract class WebContainerBase<T extends Archive<T>> extends ContainerBase<T>

62

implements WebContainer<T>

63

```

64

65

**Web-Specific Operations:**

66

67

**Web Resources:**

68

```java { .api }

69

public T addAsWebResource(String resourceName)

70

public T addAsWebResource(Asset asset, String target)

71

public T addAsWebResource(URL resource, String target)

72

```

73

74

**Web Infrastructure:**

75

```java { .api }

76

public T addAsWebInfResource(String resourceName)

77

public T addAsWebInfResource(Asset asset, String target)

78

public T setWebXML(Asset asset)

79

public T setWebXML(String webXml)

80

```

81

82

### EnterpriseContainerBase<T>

83

84

Container implementation for enterprise archives (EAR files) with module management.

85

86

```java { .api }

87

public abstract class EnterpriseContainerBase<T extends Archive<T>> extends ContainerBase<T>

88

implements EnterpriseContainer<T>

89

```

90

91

**Enterprise Operations:**

92

93

**Module Management:**

94

```java { .api }

95

public T addAsModule(Archive<?> archive)

96

public T addAsLibrary(Archive<?> archive)

97

public T addAsApplicationResource(String resourceName)

98

public T addAsApplicationResource(Asset asset, String target)

99

```

100

101

**Application Configuration:**

102

```java { .api }

103

public T setApplicationXML(Asset asset)

104

public T setApplicationXML(String applicationXml)

105

```

106

107

### ResourceAdapterContainerBase<T>

108

109

Container for resource adapter archives (RAR files) with JCA-specific functionality.

110

111

```java { .api }

112

public abstract class ResourceAdapterContainerBase<T extends Archive<T>> extends ContainerBase<T>

113

implements ResourceAdapterContainer<T>

114

```

115

116

**Resource Adapter Operations:**

117

```java { .api }

118

public T setResourceAdapterXML(Asset asset)

119

public T addAsResourceAdapterResource(String resourceName)

120

```

121

122

## Implementation Classes

123

124

### MemoryMapArchiveImpl

125

126

Complete memory-based archive implementation.

127

128

```java { .api }

129

public class MemoryMapArchiveImpl extends MemoryMapArchiveBase<MemoryMapArchive>

130

implements MemoryMapArchive

131

```

132

133

**Constructors:**

134

```java { .api }

135

public MemoryMapArchiveImpl(String archiveName)

136

```

137

138

### ConfigurableArchiveImpl

139

140

Configurable archive implementation with runtime customization support.

141

142

```java { .api }

143

public class ConfigurableArchiveImpl extends MemoryMapArchiveBase<ConfigurableArchive>

144

implements ConfigurableArchive

145

```

146

147

**Configuration Methods:**

148

```java { .api }

149

public ConfigurableArchiveImpl configure(Configuration configuration)

150

public Configuration getConfiguration()

151

```

152

153

### GenericArchiveImpl

154

155

Generic archive implementation for unknown or custom archive formats.

156

157

```java { .api }

158

public class GenericArchiveImpl extends ContainerBase<GenericArchive>

159

implements GenericArchive

160

```

161

162

**Usage:**

163

```java

164

// Create generic archive for custom formats

165

GenericArchiveImpl archive = new GenericArchiveImpl("custom.archive");

166

archive.addClass(MyClass.class);

167

archive.addAsResource("config.xml");

168

```

169

170

## Advanced Container Features

171

172

### Content Filtering

173

174

All container implementations support content filtering during operations:

175

176

```java

177

// Add classes with filtering

178

archive.addPackages(true,

179

Filters.exclude(TestClass.class),

180

"com.example.core");

181

182

// Add resources selectively

183

archive.addAsResource("config/",

184

Filters.include(".*\\.properties"));

185

```

186

187

### Bulk Operations

188

189

Container classes provide efficient bulk operations:

190

191

```java

192

// Bulk class addition

193

archive.addClasses(UserService.class, OrderService.class, ProductService.class);

194

195

// Bulk library addition

196

archive.addAsLibraries(hibernateJar, springJar, commonsJar);

197

198

// Package scanning with recursion

199

archive.addPackages(true, "com.example.service", "com.example.dao");

200

```

201

202

### Archive Merging

203

204

Containers support merging content from other archives:

205

206

```java

207

// Merge entire archive

208

targetArchive.merge(sourceArchive);

209

210

// Merge with filtering

211

targetArchive.merge(sourceArchive, Filters.exclude(".*Test.*"));

212

213

// Merge specific paths

214

targetArchive.merge(sourceArchive, "/lib", "/META-INF/services");

215

```

216

217

## Container Patterns

218

219

### Builder Pattern Support

220

221

Container implementations work seamlessly with builder patterns:

222

223

```java

224

JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "app.jar")

225

.addClass(Application.class)

226

.addPackage("com.example.core")

227

.addAsResource("META-INF/persistence.xml")

228

.addAsManifestResource("META-INF/MANIFEST.MF");

229

```

230

231

### Service Provider Pattern

232

233

Easy service provider configuration:

234

235

```java

236

// Single service implementation

237

archive.addAsServiceProvider(MyService.class, MyServiceImpl.class);

238

239

// Multiple implementations

240

archive.addAsServiceProvider(Plugin.class,

241

DatabasePlugin.class,

242

CachePlugin.class,

243

LoggingPlugin.class);

244

```

245

246

### Manifest Customization

247

248

Flexible manifest handling:

249

250

```java

251

// Simple manifest setting

252

archive.setManifest(new StringAsset(

253

"Manifest-Version: 1.0\n" +

254

"Main-Class: com.example.Application\n"));

255

256

// Manifest from resource

257

archive.setManifest("META-INF/MANIFEST.MF");

258

259

// Additional manifest resources

260

archive.addAsManifestResource("permissions.xml")

261

.addAsManifestResource("beans.xml");

262

```

263

264

## Thread Safety

265

266

Container implementations maintain thread safety through:

267

268

- Synchronized access to internal archive maps

269

- Immutable path and asset references

270

- Thread-safe collection operations

271

- Atomic content modification operations

272

273

## Performance Considerations

274

275

- **Memory Usage**: Container base uses memory mapping for efficient content storage

276

- **Lazy Loading**: Assets are loaded on-demand rather than eagerly

277

- **Content Deduplication**: Identical content is shared across archive entries

278

- **Bulk Operations**: Optimized for adding multiple items simultaneously